2022-04-12 02:34:09 +08:00
|
|
|
@top Program { Query }
|
|
|
|
|
2023-10-03 20:16:33 +08:00
|
|
|
@precedence {
|
2024-02-03 02:19:07 +08:00
|
|
|
attr @left
|
|
|
|
unaryop
|
2023-10-03 20:16:33 +08:00
|
|
|
mulop @left
|
|
|
|
addop @left
|
|
|
|
binop @left
|
2024-02-03 02:19:07 +08:00
|
|
|
terop @left
|
2023-10-03 20:16:33 +08:00
|
|
|
and @left
|
|
|
|
or @left
|
|
|
|
}
|
|
|
|
|
|
|
|
@skip {
|
2024-02-03 02:19:07 +08:00
|
|
|
space | LineComment
|
2022-04-12 02:34:09 +08:00
|
|
|
}
|
|
|
|
|
2022-04-21 17:46:33 +08:00
|
|
|
commaSep<content> { content ("," content)* }
|
|
|
|
|
2023-10-03 20:16:33 +08:00
|
|
|
kw<term> { @specialize[@name={term}]<Identifier, term> }
|
|
|
|
|
|
|
|
Query {
|
|
|
|
TagIdentifier ( WhereClause | LimitClause | OrderClause | SelectClause | RenderClause )*
|
|
|
|
}
|
|
|
|
|
|
|
|
WhereClause { kw<"where"> Expression }
|
|
|
|
LimitClause { kw<"limit"> Expression }
|
|
|
|
OrderClause { Order commaSep<OrderBy> }
|
|
|
|
OrderBy { Expression OrderDirection? }
|
|
|
|
SelectClause { kw<"select"> commaSep<Select> }
|
2023-10-30 21:15:12 +08:00
|
|
|
RenderClause { kw<"render"> ( kw<"each"> | kw<"all"> )? PageRef }
|
2023-10-03 20:16:33 +08:00
|
|
|
|
|
|
|
Select { Identifier | Expression kw<"as"> Identifier }
|
2022-04-12 02:34:09 +08:00
|
|
|
|
2024-09-29 19:26:44 +08:00
|
|
|
Order {
|
|
|
|
kw<"order"> kw<"by">
|
|
|
|
}
|
|
|
|
|
2022-12-15 03:04:20 +08:00
|
|
|
OrderDirection {
|
2024-09-29 19:26:44 +08:00
|
|
|
kw<"asc"> | kw<"desc">
|
2022-04-12 02:34:09 +08:00
|
|
|
}
|
|
|
|
|
2023-10-03 20:16:33 +08:00
|
|
|
Value { Number | String | Bool | Regex | kw<"null"> | List }
|
|
|
|
|
|
|
|
Attribute {
|
2024-02-03 02:19:07 +08:00
|
|
|
Expression !attr "." Identifier
|
2023-10-03 20:16:33 +08:00
|
|
|
}
|
2022-04-12 02:34:09 +08:00
|
|
|
|
2023-10-03 20:16:33 +08:00
|
|
|
Call {
|
2024-02-03 02:19:07 +08:00
|
|
|
Identifier "(" commaSep<Expression> ")"
|
|
|
|
| Identifier "(" ")"
|
2023-10-03 20:16:33 +08:00
|
|
|
}
|
2022-04-12 02:34:09 +08:00
|
|
|
|
2024-02-03 02:19:07 +08:00
|
|
|
TopLevelVal { "." }
|
2022-04-12 02:34:09 +08:00
|
|
|
|
2023-10-03 20:16:33 +08:00
|
|
|
ParenthesizedExpression { "(" Expression ")" }
|
|
|
|
|
|
|
|
LogicalExpression {
|
|
|
|
Expression !and kw<"and"> Expression
|
|
|
|
| Expression !or kw<"or"> Expression
|
|
|
|
}
|
|
|
|
|
|
|
|
Expression {
|
|
|
|
Value
|
2024-02-03 02:19:07 +08:00
|
|
|
| Identifier
|
|
|
|
| GlobalIdentifier
|
|
|
|
| Attribute
|
|
|
|
| TopLevelVal
|
2023-10-03 20:16:33 +08:00
|
|
|
| ParenthesizedExpression
|
2024-02-21 15:28:59 +08:00
|
|
|
| LogicalExpression
|
2024-02-03 02:19:07 +08:00
|
|
|
| QueryExpression
|
|
|
|
| UnaryExpression
|
2023-10-03 20:16:33 +08:00
|
|
|
| BinExpression
|
2024-02-03 02:19:07 +08:00
|
|
|
| TernaryExpression
|
2023-10-03 20:16:33 +08:00
|
|
|
| Call
|
2024-02-03 02:19:07 +08:00
|
|
|
| PageRef
|
|
|
|
| Object
|
|
|
|
}
|
|
|
|
|
|
|
|
QueryExpression {
|
|
|
|
"{" Query "}"
|
|
|
|
}
|
|
|
|
|
|
|
|
UnaryExpression {
|
2024-09-29 19:26:44 +08:00
|
|
|
!unaryop kw<"not"> Expression
|
2024-02-03 02:19:07 +08:00
|
|
|
| !unaryop "!" Expression
|
2024-02-21 15:28:59 +08:00
|
|
|
| !unaryop "-" Expression
|
2023-10-03 20:16:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BinExpression {
|
|
|
|
Expression !binop "<" Expression
|
|
|
|
| Expression !binop "<=" Expression
|
|
|
|
| Expression !binop "=" Expression
|
|
|
|
| Expression !binop "!=" Expression
|
|
|
|
| Expression !binop ">=" Expression
|
|
|
|
| Expression !binop ">" Expression
|
|
|
|
| Expression !binop "=~" Expression
|
|
|
|
| Expression !binop "!=~" Expression
|
2024-09-29 19:26:44 +08:00
|
|
|
| Expression !binop kw<"in"> Expression
|
2023-10-03 20:16:33 +08:00
|
|
|
|
|
|
|
| Expression !mulop "*" Expression
|
|
|
|
| Expression !mulop "/" Expression
|
|
|
|
| Expression !mulop "%" Expression
|
|
|
|
| Expression !addop "+" Expression
|
|
|
|
| Expression !addop "-" Expression
|
2024-07-03 01:12:40 +08:00
|
|
|
|
|
|
|
| Expression !or "??" Expression
|
2023-10-03 20:16:33 +08:00
|
|
|
}
|
|
|
|
|
2024-02-03 02:19:07 +08:00
|
|
|
TernaryExpression {
|
|
|
|
Expression !terop "?" Expression !terop ":" Expression
|
|
|
|
}
|
|
|
|
|
|
|
|
List { "[" commaSep<Expression> "]" | "[" "]" }
|
|
|
|
|
|
|
|
KeyVal {
|
|
|
|
String ":" Expression
|
|
|
|
}
|
2022-04-28 17:55:38 +08:00
|
|
|
|
2024-02-03 02:19:07 +08:00
|
|
|
Object { "{" commaSep<KeyVal> "}" | "{" "}" }
|
2022-04-21 17:46:33 +08:00
|
|
|
|
2022-04-12 02:34:09 +08:00
|
|
|
Bool {
|
2024-09-29 19:26:44 +08:00
|
|
|
kw<"true"> | kw<"false">
|
2022-04-12 02:34:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@tokens {
|
|
|
|
space { std.whitespace+ }
|
2022-12-15 03:04:20 +08:00
|
|
|
|
2024-02-03 02:19:07 +08:00
|
|
|
LineComment { "#" ![\n]* }
|
|
|
|
|
2023-10-03 20:16:33 +08:00
|
|
|
TagIdentifier { @asciiLetter (@asciiLetter | @digit | "-" | "_" | "/" )* }
|
|
|
|
|
2024-02-24 19:59:27 +08:00
|
|
|
Identifier { @asciiLetter (@asciiLetter | @digit | "-" | "_")* | "`" ![`]* "`" }
|
2022-12-15 03:04:20 +08:00
|
|
|
|
2024-02-03 02:19:07 +08:00
|
|
|
GlobalIdentifier { "@" @asciiLetter (@asciiLetter | @digit | "-" | "_")* }
|
|
|
|
|
2022-04-12 19:33:07 +08:00
|
|
|
String {
|
2024-02-03 02:19:07 +08:00
|
|
|
"\"" ![\"]* "\""
|
|
|
|
| "'" ![']* "'"
|
2022-04-12 19:33:07 +08:00
|
|
|
}
|
2022-08-09 21:37:47 +08:00
|
|
|
PageRef {
|
2024-02-03 02:19:07 +08:00
|
|
|
"[[" ![\]]* "]]"
|
2022-08-09 21:37:47 +08:00
|
|
|
}
|
2024-02-03 02:19:07 +08:00
|
|
|
Regex { "/" ( ![/\\\n\r] | "\\" _ )+ "/" }
|
2022-04-12 19:33:07 +08:00
|
|
|
|
2024-07-18 02:34:52 +08:00
|
|
|
Number { std.digit+ | std.digit+ "." std.digit+ }
|
2022-12-15 03:04:20 +08:00
|
|
|
|
2024-09-29 19:26:44 +08:00
|
|
|
@precedence { Identifier, Number }
|
2022-04-12 02:34:09 +08:00
|
|
|
}
|