OILS / frontend / syntax.asdl View on Github | oils.pub

686 lines, 301 significant
1# Data types for the Oils AST, aka "Lossless Syntax Tree".
2#
3# Invariant: the source text can be reconstructed byte-for-byte from this tree.
4# The test/lossless.sh suite verifies this.
5
6# We usually try to preserve the physical order of the source in the ASDL
7# fields. One exception is the order of redirects:
8#
9# echo >out.txt hi
10# # versus
11# echo hi >out.txt
12
13# Unrepresented:
14# - let arithmetic (rarely used)
15# - coprocesses # one with arg and one without
16# - select block
17
18# Possible refactorings:
19#
20# # %CompoundWord as first class variant:
21# bool_expr = WordTest %CompoundWord | ...
22#
23# # Can DoubleQuoted have a subset of parts compared with CompoundWord?
24# string_part = ... # subset of word_part
25#
26# - Distinguish word_t with BracedTree vs. those without? seq_word_t?
27
28module syntax
29{
30 use core value {
31 value LiteralBlock
32 }
33
34 # More efficient than the List[bool] pattern we've been using
35 BoolParamBox = (bool b)
36 IntParamBox = (int i)
37
38 # core/main_loop.py
39 parse_result = EmptyLine | Eof | Node(command cmd)
40
41 # 'source' represents the location of a line / token.
42 source =
43 Interactive
44 | Headless
45 | Unused(str comment) # completion and history never show parse errors?
46 | CFlag
47 | Stdin(str comment)
48
49 # MainFile is for main.{osh,ysh}, as well as oshrc/yshrc. They're files
50 # loaded directly by the shell.
51 | MainFile(str path)
52 # A file loaded by 'source' or 'use'.
53 # TODO: provide a chain of locations back to the sourced script! I guess
54 # the debug_stack can do that too.
55 | OtherFile(str path, loc location)
56
57 # Code parsed from a word. (TODO: rename source.Word?)
58 # used for 'eval arg', 'trap arg', 'printf arg',
59 # parseCommand() - this is a string?
60 # dynamic LHS - move this to Reparsed?
61 # complete -W
62 | Dynamic(str what, loc location)
63
64 # Point to the original variable reference
65 | VarRef(Token orig_tok)
66
67 # code parsed from the value of a variable
68 # used for $PS1 $PROMPT_COMMAND
69 | Variable(str var_name, loc location)
70
71 # alias expansion (location of first word)
72 | Alias(str argv0, loc argv0_loc)
73
74 # 2 kinds of reparsing: backticks, and x+1 in a[x+1]=y
75 | Reparsed(str what, Token left_token, Token right_token)
76
77 # For --location-str
78 | Synthetic(str s)
79
80 SourceLine = (int line_num, str content, source src)
81
82 # Note that ASDL generates:
83 # typedef uint16_t Id_t;
84 # So Token is
85 # 8 bytes GC header + 2 + 2 + 4 + 8 + 8 = 32 bytes on 64-bit machines
86 #
87 # We transpose (id, col, length) -> (id, length, col) for C struct packing.
88 Token = (id id, uint16 length, int col, SourceLine? line, str? tval)
89
90 # I wanted to get rid of Token.tval with this separate WideToken type, but it
91 # is more efficient if word_part.Literal %Token literally is the same thing
92 # that comes out of the lexer. Otherwise we have extra garbage.
93
94 # WideToken = (id id, int length, int col, SourceLine? line, str? tval)
95
96 # Slight ASDL bug: CompoundWord has to be defined before using it as a shared
97 # variant. The _product_counter algorithm should be moved into a separate
98 # tag-assigning pass, and shared between gen_python.py and gen_cpp.py.
99 CompoundWord = (List[word_part] parts)
100
101 # Source location for errors
102 loc =
103 Missing # equivalent of runtime.NO_SPID
104 | Token %Token
105 # Very common case: argv arrays need original location
106 | ArgWord %CompoundWord
107 | WordPart(word_part p)
108 | Word(word w)
109 | Arith(arith_expr a)
110 # e.g. for errexit blaming
111 | Command(command c)
112 # the location of a token that's too long
113 | TokenTooLong(SourceLine line, id id, int length, int col)
114
115 # debug_frame_t is an EXECUTION stack (proc func source use eval), while
116 # source_t (in some cases) is like a PARSING stack (files, strings from vars,
117 # etc.)
118 debug_frame =
119 # OSH: main_filename => BASH_SOURCE
120 MainFile(str main_filename)
121 # YSH
122 | Dummy # -c or stdin, not used by BASH_* vars
123
124 # OSH: call_tok => BASH_LINENO, source_name => BASH_SOURCE
125 | Source(CompoundWord source_loc, str source_name)
126
127 # OSH: call_tok => BASH_LINENO, def_tok => BASH_SOURCE
128 # YSH: procs
129 | ProcLike(CompoundWord invoke_loc, Token def_tok, str proc_name)
130 # YSH only
131 | Func(Token call_tok)
132
133 # for io->eval, myfunc()
134 | Token %Token
135
136 # For 'eval', 'use', ...
137 | CompoundWord %CompoundWord
138
139 # Special frame added when running 'trap ERR', for more info, and as a sentinel
140 | BeforeErrTrap(Token tok)
141
142 # Other callbacks:
143 # - Completion hooks - dev.Tracer is missing these
144 # - PS1
145 # - PROMPT_COMMAND
146 # These are similar to loc_t then.
147 # Do we need a stack_base_t? For -c, stdin, plugins, hooks, etc.
148 #
149 # Should we have a generic "main"? Or rely on 'trap arg'?
150
151 #
152 # Shell language
153 #
154
155 bracket_op =
156 WholeArray(id op_id) # * or @
157 | ArrayIndex(arith_expr expr)
158
159 suffix_op =
160 Nullary %Token # ${x@Q} or ${!prefix@} (which also has prefix_op)
161 | Unary(Token op, rhs_word arg_word) # e.g. ${v:-default}
162 # TODO: Implement YSH ${x|html} and ${x %.3f}
163 | Static(Token tok, str arg)
164 | PatSub(CompoundWord pat, rhs_word replace, id replace_mode, Token slash_tok)
165 # optional begin is arith_expr.EmptyZero
166 # optional length is None, because it's handled in a special way
167 | Slice(arith_expr begin, arith_expr? length)
168
169 BracedVarSub = (
170 Token left, # in dynamic ParseVarRef, same as name_tok
171 Token name_tok, # location for the name
172 str var_name, # the name - TODO: remove this, use LazyStr() instead
173 Token? prefix_op, # prefix # or ! operators
174 bracket_op? bracket_op,
175 suffix_op? suffix_op,
176 Token right # in dynamic ParseVarRef, same as name_tok
177 )
178
179 # Variants:
180 # - Look at left token ID for $'' c'' vs r'' '' e.g. Id.Left_DollarSingleQuote
181 # - And """ and ''' e.g. Id.Left_TDoubleQuote
182 DoubleQuoted = (Token left, List[word_part] parts, Token right)
183
184 # Consider making str? sval LAZY, like lexer.LazyStr(tok)
185 SingleQuoted = (Token left, str sval, Token right)
186
187 # e.g. Id.VSub_QMark, Id.VSub_DollarName $foo with lexer.LazyStr()
188 SimpleVarSub = (Token tok)
189
190 CommandSub = (Token left_token, command child, Token right)
191
192 # - can contain word.BracedTree
193 # - no 'Token right' for now, doesn't appear to be used
194 ShArrayLiteral = (Token left, List[word] words, Token right)
195
196 # Unevaluated, typed arguments for func and proc.
197 # Note that ...arg is expr.Spread.
198 ArgList = (
199 Token left, List[expr] pos_args,
200 Token? semi_tok, List[NamedArg] named_args,
201 Token? semi_tok2, expr? block_expr,
202 Token right
203 )
204
205 AssocPair = (CompoundWord key, CompoundWord value)
206
207 word_part =
208 ShArrayLiteral %ShArrayLiteral
209 | BashAssocLiteral(Token left, List[AssocPair] pairs, Token right)
210 | Literal %Token
211 # escaped case is separate so the evaluator doesn't have to check token ID
212 | EscapedLiteral(Token token, str ch)
213 | SingleQuoted %SingleQuoted
214 | DoubleQuoted %DoubleQuoted
215 # Could be SimpleVarSub %Token that's VSub_DollarName, but let's not
216 # confuse with the comon word_part.Literal is common for wno
217 | SimpleVarSub %SimpleVarSub
218 | BracedVarSub %BracedVarSub
219 | ZshVarSub (Token left, CompoundWord ignored, Token right)
220 # For command sub and process sub: $(...) <(...) >(...)
221 | CommandSub %CommandSub
222 # ~ or ~bob
223 | TildeSub(Token left, # always the tilde
224 Token? name, str? user_name)
225 | ArithSub(Token left, arith_expr anode, Token right)
226 # {a,b,c}
227 | BracedTuple(List[CompoundWord] words)
228 # {1..10} or {-5..10..2} or {01..10} (leading zeros matter)
229 # {a..f} or {a..f..2} or {a..f..-2}
230 # the whole range is one Token,
231 | BracedRange(Token blame_tok, id kind, str start, str end, int step)
232 # extended globs are parsed statically, unlike globs
233 | ExtGlob(Token op, List[CompoundWord] arms, Token right)
234 # a regex group is similar to an extended glob part
235 | BashRegexGroup(Token left, CompoundWord? child, Token right)
236
237 # YSH word_part extensions
238
239 # @myarray - Id.Lit_Splice (could be optimized to %Token)
240 | Splice(Token blame_tok, str var_name)
241 # $[d.key], etc.
242 | ExprSub(Token left, expr child, Token right)
243
244 # Use cases for Empty: RHS of 'x=', the argument in "${x:-}".
245 # The latter is semantically necessary. (See osh/word_parse.py).
246 # At runtime: RHS of 'declare x='.
247 rhs_word = Empty | Compound %CompoundWord
248
249 word =
250 # Returns from WordParser, but not generally stored in LST
251 Operator %Token
252 # A Compound word can contain any word_part except the Braced*Part.
253 # We could model this with another variant type but it incurs runtime
254 # overhead and seems like overkill. Note that DoubleQuoted can't
255 # contain a SingleQuoted, etc. either.
256 | Compound %CompoundWord
257 # For word sequences command.Simple, ShArrayLiteral, for_iter.Words
258 # Could be its own type
259 | BracedTree(List[word_part] parts)
260 # For dynamic parsing of test aka [ - the string is already evaluated.
261 | String(id id, str s, CompoundWord? blame_loc)
262
263 # Note: the name 'foo' is derived from token value 'foo=' or 'foo+='
264 sh_lhs =
265 Name(Token left, str name) # Lit_VarLike foo=
266 # TODO: Could be Name %Token
267 | IndexedName(Token left, str name, arith_expr index)
268 | UnparsedIndex(Token left, str name, str index) # for translation
269
270 arith_expr =
271 EmptyZero # these are valid: $(( )) (( )) ${a[@]: : }
272 | EmptyOne # condition is 1 for infinite loop: for (( ; ; ))
273 | VarSub %Token # e.g. $(( x )) Id.Arith_VarLike
274 | Word %CompoundWord # e.g. $(( 123'456'$y ))
275
276 | UnaryAssign(id op_id, arith_expr child)
277 | BinaryAssign(id op_id, arith_expr left, arith_expr right)
278
279 | Unary(id op_id, arith_expr child)
280 | Binary(Token op, arith_expr left, arith_expr right)
281 | TernaryOp(arith_expr cond, arith_expr true_expr, arith_expr false_expr)
282
283 bool_expr =
284 WordTest(word w) # e.g. [[ myword ]]
285 | Binary(id op_id, word left, word right)
286 | Unary(id op_id, word child)
287 | LogicalNot(bool_expr child)
288 | LogicalAnd(bool_expr left, bool_expr right)
289 | LogicalOr(bool_expr left, bool_expr right)
290
291 redir_loc =
292 Fd(int fd) | VarName(str name)
293
294 redir_param =
295 Word %CompoundWord
296 | HereWord(CompoundWord w, bool is_multiline)
297 | HereDoc(word here_begin, # e.g. EOF or 'EOF'
298 Token? here_end_tok, # Token consisting of the whole line
299 # It's always filled in AFTER creation, but
300 # temporarily so optional
301 List[word_part] stdin_parts # one for each line
302 )
303
304 Redir = (Token op, redir_loc loc, redir_param arg)
305
306 assign_op = Equal | PlusEqual
307 AssignPair = (Token left, sh_lhs lhs, assign_op op, rhs_word rhs)
308 # TODO: could put Id.Lit_VarLike foo= into LazyStr() with -1 slice
309 EnvPair = (Token left, str name, rhs_word val)
310
311 List_of_command < List[command]
312
313 condition =
314 Shell %List_of_command # if false; true; then echo hi; fi
315 | YshExpr(expr e) # if (x > 0) { echo hi }
316 # TODO: add more specific blame location
317
318 # Each arm tests one word against multiple words
319 # shell: *.cc|*.h) echo C++ ;;
320 # YSH: *.cc|*.h { echo C++ }
321 #
322 # Three location tokens:
323 # 1. left - shell has ( or *.cc ysh has *.cc
324 # 2. middle - shell has ) ysh has {
325 # 3. right - shell has optional ;; ysh has required }
326 #
327 # For YSH typed case, left can be ( and /
328 # And case_pat may contain more details
329 CaseArm = (
330 Token left, pat pattern, Token middle, List[command] action,
331 Token? right
332 )
333
334 # The argument to match against in a case command
335 # In YSH-style case commands we match against an `expr`, but in sh-style case
336 # commands we match against a word.
337 case_arg =
338 Word(word w)
339 | YshExpr(expr e)
340
341 EggexFlag = (bool negated, Token flag)
342
343 # canonical_flags can be compared for equality. This is needed to splice
344 # eggexes correctly, e.g. / 'abc' @pat ; i /
345 Eggex = (
346 Token left, re regex, List[EggexFlag] flags, Token? trans_pref,
347 str? canonical_flags)
348
349 pat =
350 Else
351 | Words(List[word] words)
352 | YshExprs(List[expr] exprs)
353 | Eggex %Eggex
354
355 # Each if arm starts with either an "if" or "elif" keyword
356 # In YSH, the then keyword is not used (replaced by braces {})
357 IfArm = (
358 Token keyword, condition cond, Token? then_kw, List[command] action,
359 # then_tok used in ysh-ify
360 Token? then_tok)
361
362 for_iter =
363 Args # for x; do echo $x; done # implicit "$@"
364 | Words(List[word] words) # for x in 'foo' *.py { echo $x }
365 # like ShArrayLiteral, but no location for %(
366 | YshExpr(expr e, Token blame) # for x in (mylist) { echo $x }
367 #| Files(Token left, List[word] words)
368 # for x in <> {
369 # for x in < @myfiles > {
370
371 BraceGroup = (
372 Token left, Token? doc_token, List[command] children, Token right
373 )
374
375 Param = (Token blame_tok, str name, TypeExpr? type, expr? default_val)
376 RestParam = (Token blame_tok, str name)
377
378 ParamGroup = (List[Param] params, RestParam? rest_of)
379
380 # 'open' is for proc p { }; closed is for proc p () { }
381 proc_sig =
382 Open
383 | Closed(ParamGroup? word, ParamGroup? positional, ParamGroup? named,
384 Param? block_param)
385
386 Proc = (Token keyword, Token name, proc_sig sig, command body)
387
388 Func = (
389 Token keyword, Token name,
390 ParamGroup? positional, ParamGroup? named,
391 command body
392 )
393
394 # Represents all these case: s=1 s+=1 s[x]=1 ...
395 ParsedAssignment = (Token? left, Token? close, int part_offset, CompoundWord w)
396
397 command =
398 NoOp
399
400 # can wrap many children, e.g. { }, loops, functions
401 | Redirect(command child, List[Redir] redirects)
402
403 | Simple(Token? blame_tok, # TODO: make required (BracedTuple?)
404 List[EnvPair] more_env,
405 List[word] words,
406 ArgList? typed_args, LiteralBlock? block,
407 # is_last_cmd is used for fork() optimizations
408 bool is_last_cmd)
409
410 # This doesn't technically belong in the LST, but it's convenient for
411 # execution
412 | ExpandedAlias(command child, List[EnvPair] more_env)
413 | Sentence(command child, Token terminator)
414 # Represents "bare assignment"
415 # Token left is redundant with pairs[0].left
416 | ShAssignment(Token left, List[AssignPair] pairs)
417
418 | ControlFlow(Token keyword, word? arg_word)
419
420 # ops are | |&
421 | Pipeline(Token? negated, List[command] children, List[Token] ops)
422 # ops are && ||
423 | AndOr(List[command] children, List[Token] ops)
424
425 # Part of for, while, until (but not if, case, ShFunction). No redirects.
426 | DoGroup(Token left, List[command] children, Token right)
427 # A brace group is a compound command, with redirects.
428 | BraceGroup %BraceGroup
429 # Contains a single child, like CommandSub
430 | Subshell(Token left, command child, Token right, bool is_last_cmd)
431 | DParen(Token left, arith_expr child, Token right)
432 | DBracket(Token left, bool_expr expr, Token right)
433
434 # up to 3 iterations variables
435 | ForEach(Token keyword, List[str] iter_names, for_iter iterable,
436 Token? semi_tok, command body)
437 # C-style for loop. Any of the 3 expressions can be omitted.
438 # Note: body is required, but only optional here because of initialization
439 # order.
440 | ForExpr(Token keyword, arith_expr? init, arith_expr? cond,
441 arith_expr? update, command? body)
442 | WhileUntil(Token keyword, condition cond, command body)
443
444 | If(Token if_kw, List[IfArm] arms, Token? else_kw, List[command] else_action,
445 Token? fi_kw)
446 | Case(Token case_kw, case_arg to_match, Token arms_start, List[CaseArm] arms,
447 Token arms_end)
448
449 # The keyword is optional in the case of bash-style functions
450 # (ie. "foo() { ... }") which do not have one.
451 | ShFunction(Token? keyword, Token name_tok, str name, command body)
452
453 | TimeBlock(Token keyword, command pipeline)
454 # Some nodes optimize it out as List[command], but we use CommandList for
455 # 1. the top level
456 # 2. ls ; ls & ls (same line)
457 # 3. CommandSub # single child that's a CommandList
458 # 4. Subshell # single child that's a CommandList
459
460 # TODO: Use List_of_command
461 | CommandList(List[command] children)
462
463 # YSH command constructs
464
465 # var, const.
466 # - Keyword is None for hay blocks
467 # - RHS is None, for use with value.Place
468 # - TODO: consider using BareDecl
469 | VarDecl(Token? keyword, List[NameType] lhs, expr? rhs)
470
471 # this can behave like 'var', can be desugared
472 | BareDecl(Token lhs, expr rhs)
473
474 # setvar, maybe 'auto' later
475 | Mutation(Token keyword, List[y_lhs] lhs, Token op, expr rhs)
476 # = keyword
477 | Expr(Token keyword, expr e)
478 | Proc %Proc
479 | Func %Func
480 | Retval(Token keyword, expr val)
481
482 #
483 # Glob representation, for converting ${x//} to extended regexes.
484 #
485
486 # Example: *.[ch] is:
487 # GlobOp(<Glob_Star '*'>),
488 # GlobLit(Glob_OtherLiteral, '.'),
489 # CharClass(False, ['ch']) # from Glob_CleanLiterals token
490
491 glob_part =
492 Literal(id id, str s)
493 | Operator(id op_id) # * or ?
494 | CharClass(bool negated, List[str] strs)
495
496 # Char classes are opaque for now. If we ever need them:
497 # - Collating symbols are [. .]
498 # - Equivalence classes are [=
499
500 printf_part =
501 Literal %Token
502 # flags are 0 hyphen space + #
503 # type is 's' for %s, etc.
504 | Percent(List[Token] flags, Token? width, Token? precision, Token type)
505
506 #
507 # YSH Language
508 #
509 # Copied and modified from Python-3.7/Parser/Python.asdl !
510
511 expr_context = Load | Store | Del | AugLoad | AugStore | Param
512
513 # Type expressions: Int List[Int] Dict[Str, Any]
514 # Do we have Func[Int, Int => Int] ? I guess we can parse that into this
515 # system.
516 TypeExpr = (Token tok, str name, List[TypeExpr] params)
517
518 # LHS bindings in var/const, and eggex
519 NameType = (Token left, str name, TypeExpr? typ)
520
521 # TODO: Inline this into GenExp and ListComp? Just use a flag there?
522 Comprehension = (List[NameType] lhs, expr iter, expr? cond)
523
524 # Named arguments supplied to call. Token is null for f(; ...named).
525 NamedArg = (Token? name, expr value)
526
527 # Subscripts are lists of expressions
528 # a[:i, n] (we don't have matrices, but we have data frames)
529 Subscript = (Token left, expr obj, expr index)
530
531 # Attributes are obj.attr, d->key, name::scope,
532 Attribute = (expr obj, Token op, Token attr, str attr_name, expr_context ctx)
533
534 y_lhs =
535 Var %Token # Id.Expr_Name
536 | Subscript %Subscript
537 | Attribute %Attribute
538
539 place_op =
540 # &a[i+1]
541 Subscript(Token op, expr index)
542 # &d.mykey
543 | Attribute(Token op, Token attr)
544
545 expr =
546 Var(Token left, str name) # a variable name to evaluate
547 # Constants are typically Null, Bool, Int, Float
548 # and also Str for key in {key: 42}
549 # But string literals are SingleQuoted or DoubleQuoted
550 # Python uses Num(object n), which doesn't respect our "LST" invariant.
551 | Const(Token c, value val)
552
553 # read(&x) json read (&x[0])
554 | Place(Token blame_tok, str var_name, place_op* ops)
555
556 # :| one 'two' "$three" |
557 | ShArrayLiteral %ShArrayLiteral
558
559 # / d+ ; ignorecase; %python /
560 | Eggex %Eggex
561
562 # $name is not an expr, but $? is, e.g. Id.VSub_QMark
563 | SimpleVarSub %SimpleVarSub
564 | BracedVarSub %BracedVarSub
565 | CommandSub %CommandSub
566 | SingleQuoted %SingleQuoted
567 | DoubleQuoted %DoubleQuoted
568
569 | Literal(expr inner)
570 | Lambda(List[NameType] params, expr body)
571
572 | Unary(Token op, expr child)
573 | Binary(Token op, expr left, expr right)
574 # x < 4 < 3 and (x < 4) < 3
575 | Compare(expr left, List[Token] ops, List[expr] comparators)
576 | FuncCall(expr func, ArgList args)
577
578 # TODO: Need a representation for method call. We don't just want
579 # Attribute() and then Call()
580
581 | IfExp(expr test, expr body, expr orelse)
582 | Tuple(Token left, List[expr] elts, expr_context ctx)
583
584 | List(Token left, List[expr] elts, expr_context ctx)
585 | Dict(Token left, List[expr] keys, List[expr] values)
586 # For the values in {n1, n2}
587 | Implicit
588
589 | ListComp(Token left, expr elt, List[Comprehension] generators)
590 # not implemented
591 | DictComp(Token left, expr key, expr value, List[Comprehension] generators)
592 | GeneratorExp(expr elt, List[Comprehension] generators)
593
594 # Ranges are written 1:2, with first class expression syntax. There is no
595 # step as in Python. Use range(0, 10, step=2) for that.
596 | Range(expr lower, Token op, expr upper)
597
598 # Slices occur within [] only. Unlike ranges, the start/end can be #
599 # implicit. Like ranges, denote a step with slice(0, 10, step=2).
600 # a[3:] a[:i]
601 | Slice(expr? lower, Token op, expr? upper)
602
603 | Subscript %Subscript
604 | Attribute %Attribute
605
606 # Ellipsis is like 'Starred' within Python, which are valid on the LHS in
607 # Python for unpacking, and # within list literals for splicing.
608 # (Starred is NOT used for {k:v, **a}. That used a blank "keys"
609 # attribute.)
610
611 # I think we can use { **pairs } like Python
612 | Spread(Token left, expr child)
613
614 #
615 # Regex Language (Eggex)
616 #
617
618 # e.g. alnum digit
619 PosixClass = (Token? negated, str name)
620 # e.g. d w s
621 PerlClass = (Token? negated, str name)
622
623 # Char Sets and Ranges both use Char Codes
624 # with u_braced == true : \u{ff}
625 # with u_braced == false: \xff \\ 'a' a '0' 0
626 # ERE doesn't make a distinction, but compiling to Python/PCRE can use it
627 CharCode = (Token blame_tok, int i, bool u_braced)
628 CharRange = (CharCode start, CharCode end)
629
630 # Note: .NET has && in character classes, making it a recursive language
631
632 class_literal_term =
633 PosixClass %PosixClass
634 | PerlClass %PerlClass
635 | CharRange %CharRange
636 | CharCode %CharCode
637
638 | SingleQuoted %SingleQuoted
639 # @chars
640 | Splice(Token name, str var_name) # coudl be Splice %Token
641
642 # evaluated version of class_literal_term (could be in runtime.asdl)
643 char_class_term =
644 PosixClass %PosixClass
645 | PerlClass %PerlClass
646
647 | CharRange %CharRange
648 # For [ \x00 \\ ]
649 | CharCode %CharCode
650
651 # NOTE: modifier is unused now, can represent L or P
652 re_repeat =
653 Op %Token # + * ? or Expr_DecInt for x{3}
654 | Range(Token? left, str lower, str upper, Token? right) # dot{1,2}
655 # Haven't implemented the modifier, e.g. x{+ P}
656 # | Num(Token times, id modifier)
657 # | Range(Token? lower, Token? upper, id modifier)
658
659 re =
660 Primitive(Token blame_tok, id id) # . ^ $ dot %start %end
661 | PosixClass %PosixClass
662 | PerlClass %PerlClass
663 # syntax [ $x \n ]
664 | CharClassLiteral(bool negated, List[class_literal_term] terms)
665 # evaluated [ 'abc' \n ]
666 | CharClass(bool negated, List[char_class_term] terms)
667
668 # @D
669 | Splice(Token name, str var_name) # TODO: Splice %Token ?
670
671 | SingleQuoted %SingleQuoted
672
673 # Compound:
674 | Repeat(re child, re_repeat op)
675 | Seq(List[re] children)
676 | Alt(List[re] children)
677
678 | Group(re child)
679 # convert_func is filled in on evaluation
680 # TODO: name and func_name can be expanded to strings
681 | Capture(re child, Token? name, Token? func_name)
682 | Backtracking(bool negated, Token name, re child)
683
684 # \u{ff} is parsed as this, but SingleQuoted also evaluates to it
685 | LiteralChars(Token blame_tok, str s)
686}