add trait checking
This commit is contained in:
@@ -3,7 +3,7 @@ import * as ohm from "ohm-js";
|
||||
export const boringGrammar = ohm.grammar(String.raw`
|
||||
Boringlang {
|
||||
ReturnStatement = "return" Expression ";"
|
||||
LetStatement = "let" Identifier (":" TypeUsage)? "=" Expression ";"
|
||||
LetStatement = "let" identifier (":" TypeUsage)? "=" Expression ";"
|
||||
AssignmentStatement = VariableUsage "=" Expression ";"
|
||||
| StructGetter "=" Expression ";"
|
||||
ExpressionStatement = Expression ";"
|
||||
@@ -16,12 +16,12 @@ export const boringGrammar = ohm.grammar(String.raw`
|
||||
LiteralBool = "true" | "false"
|
||||
LiteralString = "\"" (~"\"" any)* "\""
|
||||
| "'" (~"'" any)* "'"
|
||||
LiteralStructField = Identifier ":" Expression
|
||||
LiteralStruct = Identifier "{" ListOf<LiteralStructField, ","> "}"
|
||||
Identifier = (letter | "_")+ (letter | digit | "_")*
|
||||
LiteralStructField = identifier ":" Expression
|
||||
LiteralStruct = identifier "{" ListOf<LiteralStructField, ","> "}"
|
||||
identifier = (letter | "_")+(letter | digit | "_")*
|
||||
FunctionCall = Expression "(" ListOf<Expression, ","> ")"
|
||||
StructGetter = Expression "." Identifier
|
||||
VariableUsage = Identifier
|
||||
StructGetter = Expression "." identifier
|
||||
VariableUsage = identifier
|
||||
IfExpression = "if" "(" Expression ")" Block ("else" Block)?
|
||||
Term = LiteralInt
|
||||
| LiteralFloat
|
||||
@@ -41,16 +41,16 @@ export const boringGrammar = ohm.grammar(String.raw`
|
||||
| FunctionCall
|
||||
| Factor
|
||||
Block = "{" Statement* Expression? "}"
|
||||
NamedTypeUsage = Identifier
|
||||
NamedTypeUsage = identifier
|
||||
TypeUsage = NamedTypeUsage
|
||||
| "fn" "(" ListOf<TypeUsage, ","> ")" ":" TypeUsage -- function_tu
|
||||
FunctionArgument = Identifier ":" TypeUsage
|
||||
FunctionDeclaration = "fn" Identifier "(" ListOf<FunctionArgument, ","> ")" ":" TypeUsage
|
||||
FunctionArgument = identifier ":" TypeUsage
|
||||
FunctionDeclaration = "fn" identifier "(" ListOf<FunctionArgument, ","> ")" ":" TypeUsage
|
||||
Function = FunctionDeclaration Block
|
||||
StructTypeField = Identifier ":" TypeUsage
|
||||
StructTypeDeclaration = "type" Identifier "struct" "{" ListOf<StructTypeField, ","> "}"
|
||||
StructTypeField = identifier ":" TypeUsage
|
||||
StructTypeDeclaration = "type" identifier "struct" "{" ListOf<StructTypeField, ","> "}"
|
||||
TraitMethod = FunctionDeclaration ";"
|
||||
TraitTypeDeclaration = "type" Identifier "trait" "{" TraitMethod* "}"
|
||||
TraitTypeDeclaration = "type" identifier "trait" "{" TraitMethod* "}"
|
||||
TypeDeclaration = StructTypeDeclaration
|
||||
| TraitTypeDeclaration
|
||||
Impl = "impl" (NamedTypeUsage "for")? NamedTypeUsage "{" Function* "}"
|
||||
|
||||
Reference in New Issue
Block a user