Skip to main content
v0.11.0

Grammar

Program
HeaderDecl
Used by Program
ImportDecl
"import" ImportPath ";"
Used by HeaderDecl
ExportDecl
"export" ImportPath ";"
Used by HeaderDecl
ImportPath
PathRoot
"root" | "std" | "self" | "super" | IDENTIFIER
Used by ImportPath
ImportTree
ImportItem| IDENTIFIER "::" ImportTree| "{" ImportItem ( "," ImportItem )* ","? "}"| "*"
Used by ImportPath
ImportItem
IDENTIFIER ( "as" IDENTIFIER )?
Used by ImportTree
Declaration
Used by ProgramBlock
LetDeclaration
"let" IDENTIFIER ( ":" Type )? "=" Expression ";"
Used by Declaration
VarDeclaration
"var" IDENTIFIER ( ":" Type )? "=" Expression ";"
FunDeclaration
NativeBinding? "public"? "fun" IDENTIFIER GenericParams? "(" Params? ")" ( "->" Type )? WhereClause? ( Block | ";" )
NativeBinding
"native" "(" "@" IDENTIFIER ( "." IDENTIFIER )* ")"
StructDeclaration
"public"? "struct" IDENTIFIER GenericParams? WhereClause? "{" StructFields "}"
Used by Declaration
EnumDeclaration
"public"? "enum" IDENTIFIER GenericParams? WhereClause? "{" EnumVariants "}"
Used by Declaration
ExtendBlock
"extend" GenericParams? Type ( ":" ExtendAspectList )? WhereClause? ( "{" ( FunDeclaration | AssocTypeDef )* "}" | ";" )
Used by Declaration
AspectDeclaration
"public"? "aspect" IDENTIFIER GenericParams? ( "{" ( AssocTypeDecl | AspectMethod )* "}" | ";" )
Used by Declaration
AspectMethod
"fun" IDENTIFIER "(" Params? ")" ( "->" Type )? ( Block | ";" )
ExtendAspectList
Bound ( "," Bound )*
Used by ExtendBlock
AssocTypeDef
"type" IDENTIFIER ( "=" Type )? ";"
Used by ExtendBlock
AssocTypeDecl
"type" IDENTIFIER ( ":" BoundList )? ";"
Params
Param ( "," Param )* ","?
Param
"self" | "&self" | "&var self" | IDENTIFIER ( ":" Type )?
Used by Params
StructFields
StructField ( "," StructField )* ","?
StructField
"public"? IDENTIFIER ":" Type
Used by StructFields
EnumVariants
EnumVariant ( "," EnumVariant )* ","?
EnumVariant
IDENTIFIER ( "{" StructFields "}" )?
Used by EnumVariants
GenericParams
"<" GenericParam ( "," GenericParam )* ">"
GenericParam
IDENTIFIER ( ":" BoundList )?
BoundList
Bound ( "+" Bound )*
Bound
"!"? BoundHead
BoundHead
IDENTIFIER ( "<" TypeArgs ">" )? | "(" TypeList? ")" "->" Type
Used by Bound
WhereClause
"where" WhereConstraint ( "," WhereConstraint )*
WhereConstraint
IDENTIFIER ":" BoundList
Used by WhereClause
Statement
Used by Declaration
ExpressionStatement
Expression ";"
Block
"{" Declaration* "}"
IfStatement
"if" "(" Expression ")" Block ( "else" ( IfStatement | Block ) )?
Used by Statement
WhileStatement
"while" "(" Expression ")" Block
Used by Statement
ForStatement
"for" "(" ForInit Expression? ";" Expression? ")" Block| "for" "(" "let" IDENTIFIER "in" Expression ")" Block| "for" "(" "var" IDENTIFIER "in" Expression ")" Block
Used by Statement
ForInit
Used by ForStatement
LoopStatement
"loop" Block
Used by Statement
ReturnStatement
"return" Expression? ";"
Used by Statement
BreakStatement
"break" Expression? ";"
Used by Statement
ContinueStatement
"continue" ";"
Used by Statement
Expression
AssignmentExpression
Used by Expression
LValue
IDENTIFIER | CallExpression "." IDENTIFIER | CallExpression "[" Expression "]"
AssignOp
"=" | "+=" | "-=" | "*=" | "/=" | "%="
LogicalOrExpression
LogicalAndExpression
ComparisonExpression
TermExpression ( ( ">" | ">=" | "<" | "<=" | "!=" | "==" ) TermExpression )?
TermExpression
FactorExpression ( ( "+" | "-" ) FactorExpression )*
FactorExpression
CastExpression ( ( "*" | "/" | "%" ) CastExpression )*
CastExpression
AscribeExpression ( "as" Type )*
AscribeExpression
UnaryExpression ( ":" Type )?
UnaryExpression
( "!" | "-" | "*" | "&" | "&var" ) UnaryExpression | PostfixExpression
PostfixExpression
PrimaryExpression ( "(" Arguments? ")" | "." IDENTIFIER | "[" Expression "]" | "?" )*
Arguments
Expression ( "," Expression )* ","?
PrimaryExpression
INT | FLOAT | STRING | "true" | "false" | "None" | "()"| "(" Expression ( "," Expression )+ ")"| "(" Expression ")"| "[" ( Expression ( "," Expression )* ","? )? "]"| "[" Expression ";" INT "]"| Path| StructLiteral| MatchExpression| IfExpression| LoopExpression| ClosureExpression
Path
( "root" | "std" | "self" | "super" | IDENTIFIER ) ( "::" IDENTIFIER )*
StructLiteral
Path "{" FieldInit ( "," FieldInit )* ","? "}"
FieldInit
IDENTIFIER ( ":" Expression )?
MatchExpression
"match" Expression "{" MatchArm ( "," MatchArm )* ","? "}"
MatchArm
Pattern ( "if" Expression )? "=>" Expression
IfExpression
"if" "(" Expression ")" Block "else" Block
LoopExpression
"loop" Block
ClosureExpression
"(" Params? ")" ( "->" Type )? Block
Pattern
"_"| "None"| IDENTIFIER| "(" Pattern ( "," Pattern )* ")"| IDENTIFIER "::" IDENTIFIER ( "{" PatternFields "}" )?| INT | FLOAT | STRING | "true" | "false"
Used by MatchArm
PatternFields
IDENTIFIER ( "," IDENTIFIER )*
Used by Pattern
Type
IDENTIFIER ( "<" TypeArgs ">" )?| "&" Type| "&var" Type| "()"| "(" Type ( "," Type )+ ")"| Type "[]"| "[" Type ";" INT "]"| "(" TypeList? ")" "->" Type| "impl" Type
TypeArgs
Type ( "," Type )*
TypeList
Type ( "," Type )*