Created
March 16, 2025 14:10
-
-
Save xplosunn/65e93c33cf27d386b62a6c958a91318b to your computer and use it in GitHub Desktop.
tenecs grammar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FileTopLevel = Package Import* TopLevelDeclaration* . | |
| Package = "package" (Name ("." Name)*)? . | |
| Name = <ident> . | |
| Import = "import" (Name ("." Name)*)? ("as" Name)? . | |
| TopLevelDeclaration = Struct | TypeAlias | Declaration . | |
| Struct = "struct" Name ("<" (Name ("," Name)*)? ">")? "(" (StructVariable ("," StructVariable)*)? ")" . | |
| StructVariable = Name ":" TypeAnnotation . | |
| TypeAnnotation = TypeAnnotationElement ("|" TypeAnnotationElement)* . | |
| TypeAnnotationElement = SingleNameType | FunctionType . | |
| SingleNameType = Name ("<" TypeAnnotation ("," TypeAnnotation)* ">")? . | |
| FunctionType = ("<" Name ("," Name)* ">")? "(" (FunctionTypeArgument ("," FunctionTypeArgument)*)? ")" "~" ">" TypeAnnotation . | |
| FunctionTypeArgument = (Name ":")? TypeAnnotation . | |
| TypeAlias = "typealias" Name ("<" (Name ("," Name)*)? ">")? "=" TypeAnnotation . | |
| Declaration = Name ":" TypeAnnotation? DeclarationShortCircuit? "=" ExpressionBox . | |
| DeclarationShortCircuit = "?" TypeAnnotation? . | |
| ExpressionBox = Expression AccessOrInvocation* . | |
| Expression = When | If | Declaration | LiteralExpression | ReferenceOrInvocation | LambdaOrList . | |
| When = "when" ExpressionBox "{" WhenIs* WhenOther? "}" . | |
| WhenIs = "is" (Name ":")? TypeAnnotation "=" ">" "{" ExpressionBox* "}" . | |
| WhenOther = "other" Name? "=" ">" "{" ExpressionBox* "}" . | |
| If = "if" ExpressionBox "{" ExpressionBox* "}" ("else" IfThen)* ("else" "{" ExpressionBox* "}")? . | |
| IfThen = "if" ExpressionBox "{" ExpressionBox* "}" . | |
| LiteralExpression = Literal . | |
| Literal = LiteralFloat | LiteralInt | LiteralString | LiteralBool | LiteralNull . | |
| LiteralFloat = <float> . | |
| LiteralInt = "-"? <int> . | |
| LiteralString = <string> . | |
| LiteralBool = "true" | "false" . | |
| LiteralNull = "null" . | |
| ReferenceOrInvocation = Name ArgumentsList? . | |
| ArgumentsList = ("<" TypeAnnotation ("," TypeAnnotation)* ">")? "(" (NamedArgument ("," NamedArgument)*)? ")" . | |
| NamedArgument = (Name "=")? ExpressionBox . | |
| LambdaOrList = LambdaOrListGenerics? (("[" List) | Lambda) . | |
| LambdaOrListGenerics = "<" TypeAnnotation ("," TypeAnnotation)* ">" . | |
| List = (ExpressionBox ("," ExpressionBox)*)? "]" . | |
| Lambda = LambdaSignature "=" ">" (("{" ExpressionBox* "}") | ExpressionBox) . | |
| LambdaSignature = "(" (Parameter ("," Parameter)*)? ")" (":" TypeAnnotation)? . | |
| Parameter = Name (":" TypeAnnotation)? . | |
| AccessOrInvocation = (DotOrArrowName ArgumentsList?) | ArgumentsList . | |
| DotOrArrowName = ("." | ("-" ">")) Name . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment