@precedence { annotation member call exp @left mult @left add @left comp @left logic @left pipe @left range } @top Program { Shebang? statement* } statement[@isGroup=Statement] { ImportStatement { kw<"import"> ImportItems ImportFrom String } | FunctionDeclaration { kw<"export">? kw<"fn"> VariableDefinition ParamList Body } | VariableDeclaration { kw<"export">? VariableDefinition Equals expression } | TypeDeclaration { kw<"export">? kw<"type"> identifier ("=" type)? } | ReturnStatement { kw<"return"> expression } | ExpressionStatement { expression } | Annotation { AnnotationName AnnotationList? } } AnnotationList { !annotation "(" commaSep ")" } ParamList { "(" commaSep ")" } Body { "{" statement* "}" } ImportItems { commaSep1NoTrailingComma } ImportItem { identifier (ImportItemAs identifier)? } expression[@isGroup=Expression] { String | Number | VariableName | TagDeclarator | kw<"true"> | kw<"false"> | kw<"nil"> | PipeSubstitution | BinaryExpression { expression !add AddOp expression | expression !mult MultOp expression | expression !exp ExpOp expression | expression !comp CompOp expression | expression !logic LogicOp expression } | UnaryExpression { UnaryOp expression } | ParenthesizedExpression { "(" expression ")" } | IfExpression { kw<"if"> expression Body kw<"else"> Body } | CallExpression { expression !call ArgumentList } | ArrayExpression { "[" commaSep "]" } | ObjectExpression { "{" commaSep "}" } | MemberExpression { expression !member "." PropertyName } | SubscriptExpression { expression !member "[" expression "]" } | PipeExpression { expression (!pipe PipeOperator expression)+ } } UnaryOp { AddOp | BangOp } ObjectProperty { PropertyName (":" | Equals) expression } AnnotationProperty { PropertyName ( AddOp | MultOp | ExpOp | LogicOp | BangOp | CompOp | Equals | PipeOperator | PipeSubstitution ) expression } LabeledArgument { ArgumentLabel Equals expression } ArgumentList { "(" commaSep ")" } type[@isGroup=Type] { PrimitiveType { identifier } | ArrayType { "[" type !member (";" Number "+"?)? "]" } | ObjectType { "{" commaSep "}" } } VariableDefinition { identifier } VariableName { identifier ("::" identifier)*} ArgumentLabel { identifier } @skip { whitespace | LineComment | BlockComment } kw { @specialize[@name={term}] } commaSep { (term ("," term)*)? ","? } commaSep1NoTrailingComma { term ("," term)* } @tokens { String[isolate] { "'" ("\\" _ | !['\\])* "'" | '"' ("\\" _ | !["\\])* '"' } Number { "." @digit+ | @digit+ ("." @digit+)? } @precedence { Number, "." } AddOp { "+" | "-" } MultOp { "/" | "*" | "\\" } ExpOp { "^" } LogicOp { "|" | "&" } BangOp { "!" } CompOp { "==" | "!=" | "<=" | ">=" | "<" | ">" } Equals { "=" } PipeOperator { "|>" } PipeSubstitution { "%" } // Includes non-whitespace unicode characters. identifier { $[a-zA-Z_\u{a1}-\u{167f}\u{1681}-\u{1fff}\u{200e}-\u{2027}\u{202a}-\u{202e}\u{2030}-\u{205e}\u{2061}-\u{2fff}\u{3001}-\u{fefe}\u{ff00}-\u{10ffff}] $[a-zA-Z0-9_\u{a1}-\u{167f}\u{1681}-\u{1fff}\u{200e}-\u{2027}\u{202a}-\u{202e}\u{2030}-\u{205e}\u{2061}-\u{2fff}\u{3001}-\u{fefe}\u{ff00}-\u{10ffff}]* } AnnotationName { "@" identifier? } PropertyName { identifier } TagDeclarator { "$" identifier } whitespace { @whitespace+ } LineComment[isolate] { "//" ![\n]* } BlockComment[isolate] { "/*" blockCommentRest } blockCommentRest { @eof | ![*] blockCommentRest | "*" blockCommentStar } blockCommentStar { @eof | "/" | ![/] blockCommentRest | "*" blockCommentStar } @precedence { LineComment, BlockComment, MultOp } Shebang { "#!" ![\n]* } ImportItemAs { "as" } ImportFrom { "from" } "(" ")" "{" "}" "[" "]" "," "?" ":" "." ".." ";" "::" } @external propSource kclHighlight from "./highlight" @detectDelim