2024-07-08 16:47:30 -07:00
|
|
|
@precedence {
|
|
|
|
member
|
|
|
|
call
|
|
|
|
exp @left
|
|
|
|
mult @left
|
|
|
|
add @left
|
|
|
|
comp @left
|
2024-12-16 17:33:08 -05:00
|
|
|
logic @left
|
2024-07-08 16:47:30 -07:00
|
|
|
pipe @left
|
|
|
|
range
|
|
|
|
}
|
|
|
|
|
|
|
|
@top Program {
|
|
|
|
Shebang?
|
|
|
|
statement*
|
|
|
|
}
|
|
|
|
|
|
|
|
statement[@isGroup=Statement] {
|
2024-10-17 00:48:33 -04:00
|
|
|
ImportStatement { kw<"import"> ImportItems ImportFrom String } |
|
2025-01-06 21:55:31 -06:00
|
|
|
FunctionDeclaration { kw<"export">? kw<"fn"> VariableDefinition Equals? ParamList Arrow? Body } |
|
2024-10-17 00:48:33 -04:00
|
|
|
VariableDeclaration { kw<"export">? (kw<"var"> | kw<"let"> | kw<"const">)? VariableDefinition Equals expression } |
|
2024-07-08 16:47:30 -07:00
|
|
|
ReturnStatement { kw<"return"> expression } |
|
|
|
|
ExpressionStatement { expression }
|
|
|
|
}
|
|
|
|
|
|
|
|
ParamList { "(" commaSep<Parameter { VariableDefinition "?"? (":" type)? }> ")" }
|
|
|
|
|
|
|
|
Body { "{" statement* "}" }
|
|
|
|
|
2024-10-17 00:48:33 -04:00
|
|
|
ImportItems { commaSep1NoTrailingComma<ImportItem> }
|
|
|
|
ImportItem { identifier (ImportItemAs identifier)? }
|
|
|
|
|
2024-07-08 16:47:30 -07:00
|
|
|
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 |
|
2024-12-16 17:33:08 -05:00
|
|
|
expression !comp CompOp expression |
|
|
|
|
expression !logic LogicOp expression
|
2024-07-08 16:47:30 -07:00
|
|
|
} |
|
2024-08-14 02:38:37 -04:00
|
|
|
UnaryExpression { UnaryOp expression } |
|
2024-07-08 16:47:30 -07:00
|
|
|
ParenthesizedExpression { "(" expression ")" } |
|
2024-10-04 08:34:09 -04:00
|
|
|
IfExpression { kw<"if"> expression Body kw<"else"> Body } |
|
2024-07-08 16:47:30 -07:00
|
|
|
CallExpression { expression !call ArgumentList } |
|
|
|
|
ArrayExpression { "[" commaSep<expression | IntegerRange { expression !range ".." expression }> "]" } |
|
|
|
|
ObjectExpression { "{" commaSep<ObjectProperty> "}" } |
|
|
|
|
MemberExpression { expression !member "." PropertyName } |
|
|
|
|
SubscriptExpression { expression !member "[" expression "]" } |
|
|
|
|
PipeExpression { expression (!pipe PipeOperator expression)+ }
|
|
|
|
}
|
|
|
|
|
2024-08-14 02:38:37 -04:00
|
|
|
UnaryOp { AddOp | BangOp }
|
|
|
|
|
2025-01-06 10:16:42 -05:00
|
|
|
ObjectProperty { PropertyName (":" | Equals) expression }
|
2024-07-08 16:47:30 -07:00
|
|
|
|
2025-02-07 11:47:45 -05:00
|
|
|
LabeledArgument { ArgumentLabel Equals expression }
|
|
|
|
|
|
|
|
ArgumentList { "(" commaSep<LabeledArgument | expression> ")" }
|
2024-07-08 16:47:30 -07:00
|
|
|
|
|
|
|
type[@isGroup=Type] {
|
|
|
|
@specialize[@name=PrimitiveType]<
|
|
|
|
identifier,
|
2024-09-27 15:44:44 -07:00
|
|
|
"string" | "number" | "bool" | "sketch" | "sketch_surface" | "solid"
|
2024-07-08 16:47:30 -07:00
|
|
|
> |
|
|
|
|
ArrayType { type !member "[" "]" } |
|
|
|
|
ObjectType { "{" commaSep<ObjectProperty { PropertyName ":" type }> "}" }
|
|
|
|
}
|
|
|
|
|
|
|
|
VariableDefinition { identifier }
|
|
|
|
|
|
|
|
VariableName { identifier }
|
|
|
|
|
2025-02-07 11:47:45 -05:00
|
|
|
ArgumentLabel { identifier }
|
|
|
|
|
2024-07-08 16:47:30 -07:00
|
|
|
@skip { whitespace | LineComment | BlockComment }
|
|
|
|
|
|
|
|
kw<term> { @specialize[@name={term}]<identifier, term> }
|
|
|
|
|
|
|
|
commaSep<term> { (term ("," term)*)? ","? }
|
|
|
|
|
2024-10-17 00:48:33 -04:00
|
|
|
commaSep1NoTrailingComma<term> { term ("," term)* }
|
|
|
|
|
2024-07-08 16:47:30 -07:00
|
|
|
@tokens {
|
|
|
|
String[isolate] { "'" ("\\" _ | !['\\])* "'" | '"' ("\\" _ | !["\\])* '"' }
|
|
|
|
|
2025-01-07 15:19:31 -05:00
|
|
|
Number { "." @digit+ | @digit+ ("." @digit+)? }
|
2024-07-08 16:47:30 -07:00
|
|
|
@precedence { Number, "." }
|
|
|
|
|
|
|
|
AddOp { "+" | "-" }
|
|
|
|
MultOp { "/" | "*" | "\\" }
|
|
|
|
ExpOp { "^" }
|
2024-12-16 17:33:08 -05:00
|
|
|
LogicOp { "|" | "&" }
|
2024-08-14 02:38:37 -04:00
|
|
|
BangOp { "!" }
|
2024-10-17 19:29:13 -04:00
|
|
|
CompOp { "==" | "!=" | "<=" | ">=" | "<" | ">" }
|
2024-07-08 16:47:30 -07:00
|
|
|
Equals { "=" }
|
|
|
|
Arrow { "=>" }
|
|
|
|
PipeOperator { "|>" }
|
|
|
|
|
|
|
|
PipeSubstitution { "%" }
|
|
|
|
|
|
|
|
identifier { (@asciiLetter | "_") (@asciiLetter | @digit | "_")* }
|
|
|
|
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]* }
|
|
|
|
|
2024-10-17 00:48:33 -04:00
|
|
|
ImportItemAs { "as" }
|
|
|
|
ImportFrom { "from" }
|
|
|
|
|
2024-07-08 16:47:30 -07:00
|
|
|
"(" ")"
|
|
|
|
"{" "}"
|
|
|
|
"[" "]"
|
|
|
|
"," "?" ":" "." ".."
|
|
|
|
}
|
|
|
|
|
2024-08-17 14:15:11 -07:00
|
|
|
@external propSource kclHighlight from "./highlight"
|
2024-07-08 16:47:30 -07:00
|
|
|
|
|
|
|
@detectDelim
|