Skip to content

Instantly share code, notes, and snippets.

@xplosunn
Created March 16, 2025 14:10
Show Gist options
  • Select an option

  • Save xplosunn/65e93c33cf27d386b62a6c958a91318b to your computer and use it in GitHub Desktop.

Select an option

Save xplosunn/65e93c33cf27d386b62a6c958a91318b to your computer and use it in GitHub Desktop.
tenecs grammar
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