2020-06-03 11:19:05 -04:00
|
|
|
from langkit.dsl import ASTNode, abstract, Field
|
|
|
|
|
from langkit.parsers import Grammar, List, Pick, Or, Opt, Null
|
|
|
|
|
from language.lexer import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@abstract
|
|
|
|
|
class TemplateNode(ASTNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
"""
|
|
|
|
|
Root node class for Wraplang AST nodes.
|
|
|
|
|
"""
|
|
|
|
|
pass
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Import(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
name = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-06-04 22:50:34 -04:00
|
|
|
class Module(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
import_clauses = Field()
|
|
|
|
|
program = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Template(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
name = Field()
|
|
|
|
|
extending = Field()
|
2020-08-01 22:24:46 -04:00
|
|
|
command = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Var(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
name = Field()
|
|
|
|
|
typ = Field()
|
|
|
|
|
args = Field()
|
2020-07-27 16:55:34 -04:00
|
|
|
init = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Command(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
actions = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-08-16 12:23:23 -04:00
|
|
|
class DeferSection (TemplateNode):
|
|
|
|
|
expression = Field()
|
|
|
|
|
actions = Field ()
|
|
|
|
|
|
2020-06-28 21:23:04 -04:00
|
|
|
class MatchSection(TemplateNode):
|
|
|
|
|
expression = Field()
|
|
|
|
|
actions = Field ()
|
|
|
|
|
|
|
|
|
|
class PickSection (TemplateNode):
|
|
|
|
|
expression = Field ()
|
|
|
|
|
actions = Field ()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
@abstract
|
2020-06-28 21:23:04 -04:00
|
|
|
class TemplateSection(TemplateNode):
|
2020-08-28 16:13:35 -04:00
|
|
|
actions = Field(type=TemplateNode)
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-06-28 21:23:04 -04:00
|
|
|
class WrapSection(TemplateSection):
|
|
|
|
|
pass
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-06-28 21:23:04 -04:00
|
|
|
class WeaveSection(TemplateSection):
|
|
|
|
|
pass
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-08-28 16:13:35 -04:00
|
|
|
class WalkSection(TemplateSection):
|
|
|
|
|
pass
|
|
|
|
|
|
2020-06-06 17:54:44 -04:00
|
|
|
class TemplateCall(TemplateNode):
|
2020-07-05 19:08:01 -04:00
|
|
|
captured = Field()
|
2020-06-28 21:23:04 -04:00
|
|
|
name = Field()
|
|
|
|
|
args = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class MatchCapture(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
captured = Field()
|
|
|
|
|
expression = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-06-13 22:10:38 -04:00
|
|
|
class TokenIdentifier(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
token_node = True
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
@abstract
|
|
|
|
|
class Expr(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
pass
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Number(Expr):
|
2020-06-28 21:23:04 -04:00
|
|
|
token_node = True
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Identifier(Expr):
|
2020-06-28 21:23:04 -04:00
|
|
|
token_node = True
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Literal (Expr):
|
2020-06-28 21:23:04 -04:00
|
|
|
token_node = True
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Str(Expr):
|
2020-06-28 21:23:04 -04:00
|
|
|
token_node = True
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Operator(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
enum_node = True
|
2020-08-21 16:14:32 -04:00
|
|
|
alternatives = [
|
|
|
|
|
'and',
|
|
|
|
|
'or',
|
|
|
|
|
'not',
|
|
|
|
|
'amp',
|
2020-08-31 14:30:45 +02:00
|
|
|
'is',
|
|
|
|
|
'has',
|
|
|
|
|
'many',
|
|
|
|
|
'few',
|
|
|
|
|
'plus',
|
|
|
|
|
'minus',
|
|
|
|
|
'multiply',
|
2020-08-21 16:14:32 -04:00
|
|
|
'divide',
|
|
|
|
|
'eq',
|
|
|
|
|
'neq',
|
|
|
|
|
'lt',
|
|
|
|
|
'gt',
|
|
|
|
|
'lte',
|
|
|
|
|
'gte']
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class BinaryExpr(Expr):
|
2020-06-28 21:23:04 -04:00
|
|
|
lhs = Field()
|
|
|
|
|
op = Field()
|
|
|
|
|
rhs = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class UnaryExpr(Expr):
|
2020-06-28 21:23:04 -04:00
|
|
|
op = Field()
|
|
|
|
|
rhs = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-07-29 16:24:19 -04:00
|
|
|
class Function(Expr):
|
|
|
|
|
name = Field()
|
|
|
|
|
args = Field()
|
|
|
|
|
program = Field()
|
|
|
|
|
|
|
|
|
|
class MatchExpr (Expr):
|
|
|
|
|
match_exp = Field ()
|
|
|
|
|
pick_exp = Field ()
|
|
|
|
|
else_exp = Field ()
|
|
|
|
|
|
2020-06-03 11:19:05 -04:00
|
|
|
class CallExpr (TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
called = Field()
|
|
|
|
|
args = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-08-20 12:56:58 -04:00
|
|
|
class DeferExpr (TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
expression = Field()
|
2020-06-11 14:15:23 -04:00
|
|
|
|
2020-06-03 11:19:05 -04:00
|
|
|
class Argument(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
name = Field()
|
|
|
|
|
value = Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
|
|
|
|
class Selector(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
left=Field()
|
|
|
|
|
right=Field()
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-06-06 17:54:44 -04:00
|
|
|
class TraverseInto (TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
pass
|
2020-06-06 11:16:44 -04:00
|
|
|
|
2020-06-06 17:54:44 -04:00
|
|
|
class TraverseOver (TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
pass
|
2020-06-06 17:54:44 -04:00
|
|
|
|
2020-06-13 22:10:38 -04:00
|
|
|
class NewExpr(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
tree=Field()
|
2020-06-13 22:10:38 -04:00
|
|
|
|
2020-06-17 16:37:22 -04:00
|
|
|
class FoldExpr(TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
default=Field()
|
|
|
|
|
combine=Field()
|
2020-07-24 10:40:05 -04:00
|
|
|
separator=Field()
|
2020-06-28 21:23:04 -04:00
|
|
|
|
2020-08-19 13:10:33 -04:00
|
|
|
class FilterExpr(TemplateNode):
|
|
|
|
|
expression=Field()
|
|
|
|
|
|
2020-06-28 21:23:04 -04:00
|
|
|
class AllExpr(TemplateNode):
|
|
|
|
|
expression=Field()
|
2020-06-17 16:37:22 -04:00
|
|
|
|
2020-06-18 09:23:53 -04:00
|
|
|
class AtRef (TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
token_node = True
|
2020-06-18 09:23:53 -04:00
|
|
|
|
2020-06-21 21:47:49 -04:00
|
|
|
class CreateTemplateTree (TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
root=Field()
|
|
|
|
|
tree=Field()
|
2020-06-21 21:47:49 -04:00
|
|
|
|
2020-06-23 20:29:29 -04:00
|
|
|
class QualifiedMatch (TemplateNode):
|
2020-06-28 21:23:04 -04:00
|
|
|
op = Field()
|
|
|
|
|
rhs = Field()
|
2020-06-23 20:29:29 -04:00
|
|
|
|
2020-07-05 19:08:01 -04:00
|
|
|
class CommandSequence (TemplateNode):
|
2020-08-15 22:11:25 -04:00
|
|
|
sequence = Field()
|
|
|
|
|
|
|
|
|
|
class CommandSequenceElement (TemplateNode):
|
2020-08-01 22:24:46 -04:00
|
|
|
vars = Field()
|
2020-07-12 18:36:27 -04:00
|
|
|
commands = Field()
|
2020-08-15 22:11:25 -04:00
|
|
|
next = Field(type=TemplateNode)
|
|
|
|
|
|
|
|
|
|
class ThenSequence (TemplateNode):
|
|
|
|
|
actions = Field()
|
|
|
|
|
|
|
|
|
|
class ElsmatchSequence (TemplateNode):
|
|
|
|
|
expression = Field()
|
|
|
|
|
actions = Field()
|
|
|
|
|
|
|
|
|
|
class ElseSequence (TemplateNode):
|
|
|
|
|
actions = Field()
|
|
|
|
|
|
2020-07-16 18:54:55 -04:00
|
|
|
class RegExpr (TemplateNode):
|
2020-08-25 14:42:31 -04:00
|
|
|
captured = Field ()
|
|
|
|
|
left = Field(type=TemplateNode)
|
|
|
|
|
right = Field(type=TemplateNode)
|
2020-07-16 18:54:55 -04:00
|
|
|
|
|
|
|
|
class RegExprAnchor (TemplateNode):
|
|
|
|
|
token_node = True
|
|
|
|
|
|
|
|
|
|
class RegExprQuantifier (TemplateNode):
|
|
|
|
|
quantifier = Field ()
|
|
|
|
|
expr = Field ()
|
|
|
|
|
min = Field ()
|
|
|
|
|
max = Field ()
|
|
|
|
|
|
2020-06-03 11:19:05 -04:00
|
|
|
template_grammar = Grammar('main_rule')
|
|
|
|
|
G = template_grammar
|
|
|
|
|
|
|
|
|
|
template_grammar.add_rules(
|
2020-06-28 21:23:04 -04:00
|
|
|
main_rule=Module (List (G.import_clause, empty_valid=True), G.module_scope),
|
|
|
|
|
import_clause=Import('import', G.dotted_name, ';'),
|
2020-08-31 14:30:45 +02:00
|
|
|
|
2020-08-01 22:24:46 -04:00
|
|
|
module_scope=List(Or (G.template, G.command, G.function, G.var), empty_valid=True),
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-08-02 22:40:10 -04:00
|
|
|
template=Template('template', G.identifier, Opt ('extends', G.dotted_name), Or (G.command, Pick (Null (G.command), ';'))),
|
2020-08-31 14:30:45 +02:00
|
|
|
|
|
|
|
|
var=Var('var', G.identifier, ':', G.identifier, Opt ('(', G.arg_list, ')'), Opt ('=>', G.expression), ';'),
|
2020-06-03 11:19:05 -04:00
|
|
|
|
2020-06-28 21:23:04 -04:00
|
|
|
command=Command(
|
2020-08-16 12:23:23 -04:00
|
|
|
Or(
|
|
|
|
|
G.defer_section,
|
|
|
|
|
G.match_section,
|
|
|
|
|
G.pick_section,
|
2020-08-31 14:30:45 +02:00
|
|
|
G.wrap_section,
|
2020-08-16 12:23:23 -04:00
|
|
|
G.weave_section,
|
2020-08-28 16:13:35 -04:00
|
|
|
G.walk_section,
|
2020-08-16 12:23:23 -04:00
|
|
|
G.command_sequence
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
defer_section=DeferSection (
|
|
|
|
|
'defer', Opt (G.expression),
|
2020-06-28 21:23:04 -04:00
|
|
|
Or(
|
|
|
|
|
G.match_section,
|
|
|
|
|
G.pick_section,
|
2020-08-31 14:30:45 +02:00
|
|
|
G.wrap_section,
|
2020-07-05 19:08:01 -04:00
|
|
|
G.weave_section,
|
2020-08-28 16:13:35 -04:00
|
|
|
G.walk_section,
|
2020-08-02 22:40:10 -04:00
|
|
|
G.command_sequence
|
2020-07-05 19:08:01 -04:00
|
|
|
)
|
2020-06-28 21:23:04 -04:00
|
|
|
),
|
|
|
|
|
match_section=MatchSection (
|
|
|
|
|
Pick ('match', G.expression),
|
|
|
|
|
Or (
|
|
|
|
|
G.pick_section,
|
|
|
|
|
G.wrap_section,
|
|
|
|
|
G.weave_section,
|
2020-08-28 16:13:35 -04:00
|
|
|
G.walk_section,
|
2020-08-15 22:11:25 -04:00
|
|
|
G.conditionned_command_sequence,
|
|
|
|
|
Pick (Null (G.command_sequence), ';'))
|
2020-06-28 21:23:04 -04:00
|
|
|
),
|
|
|
|
|
pick_section=PickSection (
|
|
|
|
|
Pick ('pick', G.expression),
|
|
|
|
|
Or (
|
|
|
|
|
G.wrap_section,
|
|
|
|
|
G.weave_section,
|
2020-08-28 16:13:35 -04:00
|
|
|
G.walk_section,
|
2020-07-05 19:08:01 -04:00
|
|
|
G.command_sequence,
|
2020-07-12 18:36:27 -04:00
|
|
|
Pick (Null (G.command_sequence), ';'))
|
2020-06-28 21:23:04 -04:00
|
|
|
),
|
|
|
|
|
weave_section=WeaveSection(
|
|
|
|
|
'weave',
|
|
|
|
|
Or (
|
2020-07-05 19:08:01 -04:00
|
|
|
G.template_call,
|
|
|
|
|
TemplateCall(Null (G.identifier), Null (G.dotted_name), '(', G.arg_list, ')'),
|
2020-06-28 21:23:04 -04:00
|
|
|
G.traverse_decision),
|
|
|
|
|
';'),
|
|
|
|
|
wrap_section=WrapSection(
|
2020-08-31 14:30:45 +02:00
|
|
|
'wrap',
|
2020-06-28 21:23:04 -04:00
|
|
|
Or (
|
2020-07-05 19:08:01 -04:00
|
|
|
G.template_call,
|
2020-08-31 14:30:45 +02:00
|
|
|
G.traverse_decision),
|
2020-06-28 21:23:04 -04:00
|
|
|
';'),
|
2020-08-28 16:13:35 -04:00
|
|
|
walk_section=WalkSection('walk', G.template_call, ';'),
|
2020-08-16 12:23:23 -04:00
|
|
|
command_sequence=CommandSequence ('do', G.command_sequence_element, 'end', ';'),
|
2020-08-15 22:11:25 -04:00
|
|
|
command_sequence_element=CommandSequenceElement (
|
2020-08-31 14:30:45 +02:00
|
|
|
List (G.var, empty_valid = True),
|
|
|
|
|
List (G.command, empty_valid = True),
|
2020-08-15 22:11:25 -04:00
|
|
|
Opt (ThenSequence ('then', G.command_sequence_element))
|
|
|
|
|
),
|
2020-08-16 12:23:23 -04:00
|
|
|
conditionned_command_sequence=CommandSequence ('do', G.conditionned_command_sequence_element, 'end', ';'),
|
2020-08-15 22:11:25 -04:00
|
|
|
conditionned_command_sequence_element=CommandSequenceElement (
|
2020-08-31 14:30:45 +02:00
|
|
|
List (G.var, empty_valid = True),
|
|
|
|
|
List (G.command, empty_valid = True),
|
2020-08-15 22:11:25 -04:00
|
|
|
Opt (Or (
|
|
|
|
|
ThenSequence ('then', G.conditionned_command_sequence_element),
|
|
|
|
|
ElsmatchSequence ('elsmatch', G.expression, 'do', G.conditionned_command_sequence_element),
|
|
|
|
|
ElseSequence ('else', G.command_sequence_element)))
|
2020-08-16 12:23:23 -04:00
|
|
|
),
|
2020-06-28 21:23:04 -04:00
|
|
|
traverse_decision=Or(TraverseInto ('into'), TraverseOver ('over')),
|
2020-06-06 11:16:44 -04:00
|
|
|
|
2020-07-29 16:24:19 -04:00
|
|
|
function=Function('function', G.identifier, '(', Opt (List (G.identifier, sep = ',', empty_valid = True)), ')', G.command_sequence),
|
2020-08-31 14:30:45 +02:00
|
|
|
|
|
|
|
|
root_expression=Or (
|
2020-07-16 18:54:55 -04:00
|
|
|
RegExpr (
|
2020-08-25 14:42:31 -04:00
|
|
|
Null (G.identifier),
|
2020-08-31 14:30:45 +02:00
|
|
|
RegExprAnchor ('\\'),
|
2020-07-16 18:54:55 -04:00
|
|
|
G.regular_expression),
|
2020-08-25 14:42:31 -04:00
|
|
|
G.regular_expression),
|
|
|
|
|
regular_expression=Or(
|
|
|
|
|
RegExpr (
|
|
|
|
|
Opt (Pick (G.identifier, ':')),
|
2020-08-27 14:28:28 -04:00
|
|
|
Or (
|
|
|
|
|
Pick ('(', G.regular_expression_no_terminal, ')'),
|
|
|
|
|
G.regular_expression_quantifier,
|
|
|
|
|
),
|
2020-08-25 14:42:31 -04:00
|
|
|
Opt (Or (Pick ('\\', G.regular_expression), RegExprAnchor ('\\'))),
|
|
|
|
|
),
|
2020-08-27 13:00:37 -04:00
|
|
|
RegExpr (
|
|
|
|
|
Null (G.identifier),
|
|
|
|
|
G.expression,
|
|
|
|
|
Or (Pick ('\\', G.regular_expression), RegExprAnchor ('\\')),
|
|
|
|
|
),
|
2020-08-25 14:42:31 -04:00
|
|
|
G.expression
|
|
|
|
|
),
|
|
|
|
|
regular_expression_no_terminal=Or(
|
|
|
|
|
RegExpr (
|
|
|
|
|
Opt (Pick (G.identifier, ':')),
|
|
|
|
|
Or (
|
|
|
|
|
Pick ('(', G.regular_expression_no_terminal, ')'),
|
|
|
|
|
G.regular_expression_quantifier
|
|
|
|
|
),
|
2020-08-27 13:00:37 -04:00
|
|
|
Opt (Pick ('\\', Or (G.regular_expression_no_terminal, G.expression))),
|
2020-08-25 14:42:31 -04:00
|
|
|
),
|
|
|
|
|
RegExpr (
|
|
|
|
|
Null (G.identifier),
|
|
|
|
|
G.expression,
|
|
|
|
|
Pick ('\\', Or (G.regular_expression_no_terminal, G.expression)),
|
|
|
|
|
),
|
|
|
|
|
),
|
2020-07-16 18:54:55 -04:00
|
|
|
regular_expression_quantifier=RegExprQuantifier (
|
|
|
|
|
Or (Operator.alt_many('many'), Operator.alt_few('few')),
|
2020-08-31 14:30:45 +02:00
|
|
|
'(',
|
|
|
|
|
Or (G.regular_expression_no_terminal, G.expression),
|
2020-07-16 18:54:55 -04:00
|
|
|
Opt (Pick (',', G.integer)),
|
|
|
|
|
Opt (Pick (',', G.integer)),
|
2020-08-31 14:30:45 +02:00
|
|
|
')'),
|
2020-06-28 21:23:04 -04:00
|
|
|
expression=Or (
|
|
|
|
|
BinaryExpr (G.relation, Or (Operator.alt_and('and'), Operator.alt_or('or')), G.expression),
|
|
|
|
|
G.relation),
|
2020-08-21 16:14:32 -04:00
|
|
|
relation=Or (
|
|
|
|
|
BinaryExpr (G.simple_expression, Or (
|
2020-08-31 14:30:45 +02:00
|
|
|
Operator.alt_eq('='),
|
|
|
|
|
Operator.alt_neq('/='),
|
|
|
|
|
Operator.alt_lt('<'),
|
|
|
|
|
Operator.alt_gt('>'),
|
|
|
|
|
Operator.alt_lte('<='),
|
2020-08-21 16:14:32 -04:00
|
|
|
Operator.alt_gte('>=')), G.simple_expression),
|
|
|
|
|
G.simple_expression),
|
2020-07-23 13:29:28 -04:00
|
|
|
simple_expression=Or (BinaryExpr (G.term, Or (Operator.alt_amp('&'), Operator.alt_minus('-'), Operator.alt_plus('+')), G.simple_expression), G.term),
|
|
|
|
|
term=Or (BinaryExpr (G.factor, Or (Operator.alt_multiply('*'), Operator.alt_divide('/')), G.term), G.factor),
|
2020-06-28 21:23:04 -04:00
|
|
|
factor=Or(
|
|
|
|
|
MatchCapture(G.identifier, ':', G.factor),
|
2020-08-31 14:30:45 +02:00
|
|
|
UnaryExpr (Operator.alt_not('not'), G.qualified_primary),
|
2020-06-28 21:23:04 -04:00
|
|
|
G.qualified_primary),
|
2020-09-05 23:06:09 -04:00
|
|
|
qualified_primary=Or (QualifiedMatch (Or (Operator.alt_is('is'), Operator.alt_has ('has')), '(', G.expression, ')'), G.primary),
|
2020-06-28 21:23:04 -04:00
|
|
|
primary=Or(
|
|
|
|
|
Pick ('(', G.expression, ')'),
|
2020-07-29 16:24:19 -04:00
|
|
|
G.match_expr,
|
2020-08-20 12:56:58 -04:00
|
|
|
G.defer_expr,
|
2020-06-28 21:23:04 -04:00
|
|
|
G.literal,
|
|
|
|
|
G.integer,
|
|
|
|
|
G.str,
|
|
|
|
|
G.selected_component,
|
|
|
|
|
G.name
|
|
|
|
|
),
|
2020-07-29 16:24:19 -04:00
|
|
|
match_expr=Pick ('(', G.match_expr_element, ')'),
|
|
|
|
|
match_expr_element=MatchExpr (
|
|
|
|
|
'match', G.expression, 'pick', G.expression,
|
|
|
|
|
Opt ('else', Or (
|
|
|
|
|
Pick ('pick', G.expression),
|
|
|
|
|
G.match_expr_element))),
|
2020-06-28 21:23:04 -04:00
|
|
|
name=Or(
|
|
|
|
|
G.single_name
|
|
|
|
|
),
|
|
|
|
|
single_name=Or (
|
2020-08-31 14:30:45 +02:00
|
|
|
G.at_ref,
|
|
|
|
|
G.new_expr,
|
2020-06-28 21:23:04 -04:00
|
|
|
G.fold_expr,
|
2020-08-19 13:10:33 -04:00
|
|
|
G.filter_expr,
|
2020-06-28 21:23:04 -04:00
|
|
|
G.all_expr,
|
|
|
|
|
G.call_expr,
|
|
|
|
|
G.identifier),
|
2020-08-31 14:30:45 +02:00
|
|
|
selected_component=Selector (G.prefix, '.', G.suffix),
|
|
|
|
|
prefix=Or (
|
2020-06-28 21:23:04 -04:00
|
|
|
G.name
|
|
|
|
|
),
|
|
|
|
|
suffix=Or (
|
|
|
|
|
G.selected_component,
|
|
|
|
|
G.name
|
|
|
|
|
),
|
|
|
|
|
new_expr=NewExpr ('new', '(', G.create_template_tree, ')'),
|
2020-07-05 19:08:01 -04:00
|
|
|
template_call=TemplateCall(Opt (G.identifier, ':'), G.dotted_name, '(', G.arg_list, ')'),
|
2020-06-28 21:23:04 -04:00
|
|
|
create_template_tree=Or(
|
2020-07-12 18:36:27 -04:00
|
|
|
CreateTemplateTree(G.template_call, Opt ('{', List (G.create_template_tree, sep = ',', empty_valid = True), '}')),
|
|
|
|
|
CreateTemplateTree(Null (G.template_call), '{', List (G.create_template_tree, sep = ',', empty_valid = True), '}')),
|
2020-07-24 10:40:05 -04:00
|
|
|
fold_expr=FoldExpr ('fold', '(', G.expression, ',', G.expression, Opt (',', G.expression), ')'),
|
2020-08-20 13:27:12 -04:00
|
|
|
filter_expr=FilterExpr ('filter', '(', G.root_expression, ')'),
|
2020-06-28 21:23:04 -04:00
|
|
|
all_expr=AllExpr ('all', '(', Opt (G.expression), ')'),
|
|
|
|
|
at_ref=AtRef('@'),
|
|
|
|
|
call_expr=CallExpr (G.identifier, '(', G.arg_list, ')'),
|
2020-08-20 12:56:58 -04:00
|
|
|
defer_expr=DeferExpr ('defer', '(', G.expression, ')'),
|
2020-08-19 13:10:33 -04:00
|
|
|
arg_list=List(Argument(Opt (G.identifier, "=>"), G.root_expression), sep=',', empty_valid=True),
|
2020-07-12 18:36:27 -04:00
|
|
|
identifier=Identifier(Token.Identifier),
|
2020-06-28 21:23:04 -04:00
|
|
|
dotted_name=Selector(Opt (G.dotted_name, '.'), G.identifier),
|
|
|
|
|
integer=Number(Token.Integer),
|
|
|
|
|
literal=Literal(Or ("true", "false")),
|
|
|
|
|
str=Str(Token.String)
|
2020-07-12 18:36:27 -04:00
|
|
|
)
|