Skip to main content
v0.13.0

Grammar

Program
ImportDecl
→ "import" ImportPath ";"
Used by Program
ExportDecl
→ "export" ImportPath ";"
Used by Program
ImportPath
PathRoot
→ "root"| "std"| "self"| "super"| IDENTIFIER
ImportTree
→ IDENTIFIER "as" IDENTIFIER| IDENTIFIER "::" ImportTree| "{" ImportItem ( "," ImportItem )* ","? "}"| "*"| IDENTIFIER
Used by ImportPath
ImportItem
→ IDENTIFIER ( "as" IDENTIFIER )?
Used by ImportTree
Declaration
TypeAliasDeclaration
→ "public"? "type" IDENTIFIER GenericParams? ":=" Type ";"
Used by Declaration
LetDeclaration
→ "let" !"var" IDENTIFIER ( ":" Type )? ":=" Expression ";"
VarDeclaration
→ ( "let" "var" | "var" ) IDENTIFIER ( ":" Type )? ":=" Expression ";"
FunDeclaration
→ NativeBinding? "public"? "fun" IDENTIFIER GenericParams? "(" Params? ")" ( "->" Type )? WhereClause? ( Block | ";" )
NativeBinding
→ "native" "(" "@" NATIVE_PATH ")"
StructDeclaration
→ "public"? "struct" IDENTIFIER GenericParams? WhereClause? "{" StructFields "}"
Used by Declaration
StructFields
→ ( StructField "," )* StructField?
StructField
→ "public"? IDENTIFIER ":" Type
Used by StructFields
EnumDeclaration
→ "public"? "enum" IDENTIFIER GenericParams? WhereClause? "{" EnumVariants "}"
Used by Declaration
EnumVariants
→ ( EnumVariant "," )* EnumVariant?
EnumVariant
→ IDENTIFIER ( "{" StructFields "}" )?
Used by EnumVariants
ExtendBlock
→ "extend" GenericParams? Type ( ":" ExtendAspect ( "," ExtendAspect )* WhereClause? ";" | ( ":" ExtendAspect )? WhereClause? "{" ( AssocTypeDef | FunDeclaration )* "}" )
Used by Declaration
ExtendAspect
→ "!"? NamedType
Used by ExtendBlock
AssocTypeDef
→ "type" IDENTIFIER ":=" Type ";"
Used by ExtendBlock
AspectDeclaration
→ "public"? "aspect" IDENTIFIER GenericParams? ( ";" | "{" ( AssocTypeDecl | AspectMethod )* "}" )
Used by Declaration
AspectMethod
→ "fun" IDENTIFIER GenericParams? "(" Params? ")" ( "->" Type )? ( Block | ";" )
AssocTypeDecl
→ "type" IDENTIFIER ( ":" BoundList )? ";"
Params
→ Param ( "," Param )* ","?
Param
→ "&" "var"? "self"| "self"| IDENTIFIER ( ":" Type )?
Used by Params
GenericParams
→ "<" GenericParam ( "," GenericParam )* ">"
GenericParam
→ "record"? IDENTIFIER ( ":" BoundList )?
BoundList
→ Bound ( "+" Bound )*
Bound
→ "!"? BoundHead
Used by BoundList
BoundHead
→ RowBound| TypePath ( "<" BoundArg ( "," BoundArg )* ","? ">" )?
Used by Bound
RowBound
→ "{" ( RowField ( "," RowField )* )? ( "," ".." )? ","? "}"
Used by BoundHead
RowField
→ IDENTIFIER ( ":" Type )?
Used by RowBound
BoundArg
Used by BoundHead
AssocBinding
→ IDENTIFIER "=" Type
Used by BoundArg
WhereClause
→ "where" WhereConstraint ( "," WhereConstraint )*
WhereConstraint
→ "record"? IDENTIFIER ":" BoundList
Used by WhereClause
Statement
Used by Declaration
Block
→ "{" BlockItem* Expression? "}"
BlockItem
Used by Block
BlockExprStmt
Used by BlockItem
ExpressionStatement
→ Expression ";"
WhileStatement
→ "while" "(" Expression ")" Block
Used by Statement
ForStatement
→ "for" "(" ForInit Expression? ";" Expression? ")" Block
Used by Statement
ForInit
Used by ForStatement
ForInStatement
→ "for" "(" ( "let" "var"? | "var" )? IDENTIFIER "in" Expression ")" Block
Used by Statement
Expression
AssignmentExpression
Used by Expression
AssignOp
→ "+="| "-="| "*="| "/="| "%="| ":="
LogicalOrExpression
LogicalAndExpression
ComparisonExpression
→ RangeExpression ( ( "==" | "!=" | "<=" | ">=" | "<" | ">" ) RangeExpression )?
RangeExpression
→ TermExpression ( ( "..=" | ".." ) TermExpression )?
TermExpression
→ FactorExpression ( ( "+" | "-" ) FactorExpression )*
FactorExpression
→ CastExpression ( ( "*" | "/" | "%" ) CastExpression )*
CastExpression
→ AscribeExpression ( "as" Type )*
AscribeExpression
→ UnaryExpression ( ":" Type )?
UnaryExpression
→ ( "!" | "-" | "*" | "&" "var"? ) UnaryExpression| PostfixExpression
PostfixExpression
→ PrimaryExpression ( "::<" TypeArgs ">" "(" Arguments? ")" | "(" Arguments? ")" | "." INT | "." IDENTIFIER "::<" TypeArgs ">" "(" Arguments? ")" | "." IDENTIFIER "(" Arguments? ")" | "." IDENTIFIER | "[" Expression "]" | "?" )*
Arguments
→ Expression ( "," Expression )* ","?
PrimaryExpression
ReturnExpression
→ "return" Expression?
BreakExpression
→ "break" Expression?
ContinueExpression
→ "continue"
TupleOrParen
→ "(" Expression ( "," Expression )+ ")"| "(" Expression ")"
RepeatArray
→ "[" Expression ";" INT "]"
ArrayLiteral
→ "[" ( Expression ( "," Expression )* ","? )? "]"
MatchExpression
→ "match" ( "()" | TupleOrParen ) "{" ( MatchArm ( "," MatchArm )* ","? )? "}"
MatchArm
→ Pattern ( "if" Expression )? "=>" ( Block | Expression )
IfExpression
→ "if" "(" Expression ")" ( Block | Expression ) ( "else" ( IfExpression | Block | Expression ) )?
LoopExpression
→ "loop" Block
ClosureExpression
→ CaptureList? "once"? "var"? "|" Params? "|" ( "->" Type )? Block
CaptureList
→ "[" ( CaptureItem ( "," CaptureItem )* ","? )? "]"
CaptureItem
→ "&" "var" IDENTIFIER| "&" IDENTIFIER| IDENTIFIER "." "clone" "(" ")"| IDENTIFIER
Used by CaptureList
StructLiteral
→ TypePath "{" ( FieldInit ( "," FieldInit )* ","? )? "}"
RecordLiteral
→ "{" ( FieldInit ( "," FieldInit )* ","? )? "}"
RecordProjectionExpr
→ TypePath ".{" IDENTIFIER ( "," IDENTIFIER )* ","? "}"
FieldInit
→ IDENTIFIER ( "=" Expression )?
PathExpr
→ PathRoot ( "::" IDENTIFIER )*
TypePath
→ PathRoot ( "::" IDENTIFIER )*
Pattern
TuplePattern
→ "(" Pattern ( "," Pattern )* ")"
Used by Pattern
ArrayPattern
→ "[" ArrayPatternBody "]"
Used by Pattern
ArrayPatternBody
→ ( Pattern ( "," Pattern )* ( "," RestPattern )? | RestPattern )?
Used by ArrayPattern
RestPattern
→ ".." IDENTIFIER
RecordRest
→ ".."
FieldPatternList
→ IDENTIFIER ( "," IDENTIFIER )* ( "," RecordRest )? ","?| RecordRest
RecordPattern
→ "{" FieldPatternList "}"
Used by Pattern
EnumPattern
→ IDENTIFIER "::" IDENTIFIER ( "{" FieldPatternList "}" )?| IDENTIFIER "{" FieldPatternList "}"
Used by Pattern
LiteralPattern
→ SUFFIXED_FLOAT| FLOAT| SUFFIXED_INT| INT| STRING| CHAR| "true"| "false"
Used by Pattern
Type
ExtendsType
→ "extends" NamedType
DynType
→ "dyn" NamedType
TupleType
→ "(" Type ( "," Type )+ ")"
RecordType
→ "{" ( RecordTypeField ( "," RecordTypeField )* ","? )? "}"
RecordTypeField
→ IDENTIFIER ":" Type
Used by RecordType
RecordProjectionType
→ TypePath ".{" IDENTIFIER ( "," IDENTIFIER )* ","? "}"
FunType
→ FunTypeQualifier* "|" TypeList? "|" "->" Type
Used by Type
FunTypeQualifier
→ "once"| "var"
Used by FunType
ReferenceType
→ "&" Type
Used by Type
MutReferenceType
→ "&" "var" Type
Used by Type
SizedArrayType
→ "[" Type ";" INT "]"
Used by Type
ArrayType
Used by Type
NamedType
→ TypePath ( "<" TypeArgs ">" )?
TypeArgs
→ Type ( "," Type )*
TypeList
→ Type ( "," Type )*
Used by FunType