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

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