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

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