構文一覧
This content is not available in your language yet.
このページは、Sobakasu の主要な構文を形式的に確認したいときのための簡易文法です。通常の使い方を知りたい場合は、各機能の説明ページを先に参照してください。
この一覧は読みやすさを優先しており、コンパイラが不正なコードから復帰するための細かな処理までは記載していません。
'token'— その文字列をそのまま書くname— 別に定義された構文規則?— 0 回または 1 回*— 0 回以上+— 1 回以上
compilation-unit := declaration* EOFモジュールと use
Section titled “モジュールと use”module-declaration := 'public'? 'module' IDENTIFIER ';'
use-declaration := 'public'? 'use' use-tree ';'use-tree := path | path 'as' IDENTIFIER | path '::' '*' | path '::' '{' use-tree (',' use-tree)* ','? '}' | 'self' ('as' IDENTIFIER)?
path := IDENTIFIER ('::' IDENTIFIER)*状態変数、定数、ローカル変数
Section titled “状態変数、定数、ローカル変数”state-block := 'state' '{' state-member* '}'state-member := 'public'? sync-modifier? IDENTIFIER type-clause? '=' (expression | 'field') ';'
sync-modifier := 'sync' | 'sync' '(' ('none' | 'linear' | 'smooth') ')'
const-declaration := 'public'? 'const' IDENTIFIER type-clause? '=' expression ';'
let-statement := 'let' 'mutable'? binding-pattern type-clause? ('=' expression)? ';'type-clause := ':' typefunction-declaration := 'public'? 'function' function-name generic-parameters? parameter-list? return-type? (block | external-binding)
parameter-list := '(' parameter-items? ')'parameter-items := 'state' (',' parameter (',' parameter)*)? | parameter (',' parameter)*parameter := IDENTIFIER ':' type | 'mutable'? 'self'return-type := '->' typeself / mutable self は implementation メソッドの先頭に一つだけ指定できる専用の引数です。型注釈は付けません。通常の引数に mutable は指定できません。
type := path type-arguments? | '[' type ']' | '(' (type (',' type)* ','?)? ')'
type-arguments := '<' type (',' type)* '>'generic-parameters := '<' IDENTIFIER (',' IDENTIFIER)* '>'(T) は括弧で囲んだ T と同じ型です。1 要素タプル型は (T,) と書きます。
struct、enum、外部型
Section titled “struct、enum、外部型”struct-declaration := 'public'? 'struct' IDENTIFIER generic-parameters? ('=' 'extern' external-name)? '{' field* '}'
field := IDENTIFIER ':' type ('=' 'extern' member-name)? ','?
type-declaration := 'public'? 'type' IDENTIFIER '=' 'extern' external-name ';'
enum-declaration := 'public'? 'enum' IDENTIFIER generic-parameters? ('=' 'extern' external-name)? '{' enum-variant* '}'
enum-variant := IDENTIFIER | IDENTIFIER '(' type (',' type)* ','? ')' | IDENTIFIER '{' field* '}'外部の列挙型では、バリアントの後ろに = extern member-name を指定できる場合があります。
implementation
Section titled “implementation”implementation-declaration := 'public'? 'implementation' generic-parameters? type ('=' 'extern' external-name)? '{' function-declaration* '}'現在の implementation 内では static を修飾子として使用しません。
behavior とイベント
Section titled “behavior とイベント”behavior-declaration := 'behavior' '{' behavior-member* '}'behavior-member := function-declaration | event-declaration | receive-declaration
event-declaration := 'on' IDENTIFIER parameter-list? (':' type)? blockreceive-declaration := 'public'? 'receive' IDENTIFIER parameter-list? blockreceive には戻り値型を指定できません。
send-statement := 'send' behavior-call 'to' expression ';'behavior-call := 'behavior' '::' IDENTIFIER argument-list | 'behavior' '::' IDENTIFIER '(' 'state' (',' expression (',' expression)*)? ')' | 'state' '.' IDENTIFIER argument-listargument-list := '(' (expression (',' expression)*)? ')'behavior::name(state, ...) では、先頭の state は compile-time capability であり、runtime 引数には含まれません。send では修飾のない callable 名を使用できません。
if-expression := 'if' expression block ('else' (block | if-expression))?while-expression := loop-label? 'while' expression blockloop-expression := loop-label? 'loop' blockloop-label := LABEL_IDENTIFIER ':'
break-statement := 'break' LABEL_IDENTIFIER? expression? ';'continue-statement := 'continue' LABEL_IDENTIFIER? ';'redo-statement := 'redo' LABEL_IDENTIFIER? ';'return-statement := 'return' expression? ';'match-expression := 'match' expression '{' match-arm* '}'match-arm := match-pattern '=>' (expression | block) ','?
match-pattern := literal-pattern | '_' | path '::' IDENTIFIER | path '::' IDENTIFIER '(' binding (',' binding)* ','? ')' | path '::' IDENTIFIER '{' binding (',' binding)* ','? '}'現在、列挙型のバリアントから値を受け取る binding には単純な識別子を使用します。
基本式と後置構文
Section titled “基本式と後置構文”primary-expression := literal | name | parenthesized-or-tuple | array-literal | if-expression | match-expression | while-expression | loop-expression | 'new' type argument-list | 'extern' expression
postfix-expression := primary-expression (type-arguments | '.' member-name | '::' member-name | argument-list | '[' expression ']' | aggregate-initializer)*演算子の優先順位と結合規則は 演算子 を参照してください。