#[repr(u8)]pub enum Op {
Show 13 variants
Keyword = 0,
Symbol = 1,
Rule = 2,
Sequence = 3,
Choice = 4,
Optional = 5,
Repeat = 6,
Identifier = 7,
Number = 8,
String = 9,
Operator = 10,
EndOfInput = 11,
KeywordClass = 12,
}Expand description
What a node is.
The discriminants are written into generated::rules as Op::Name, so they are not load
bearing on their own, but xtask’s copy of this enum has to have the same variants in the same
order for the generator to be able to name them. the_ops_match_the_generator is that check.
Variants§
Keyword = 0
A word. a indexes generated::keywords::KEYWORDS, and the comparison is an index compare
because the tokenizer already resolved the token’s word to the same table.
Symbol = 1
Punctuation or an operator. a indexes SYMBOLS and the comparison is on text.
Rule = 2
A reference to a rule. a is the rule index.
Sequence = 3
a is a start index into CHILDREN, b is how many. All of them, in order.
Choice = 4
Same layout. Ordered choice, first success wins, no backtracking into a taken alternative.
Optional = 5
a is the child node. Matches it or matches nothing.
Repeat = 6
a is the child node. One or more. X* is Optional(Repeat(X)) in the table, because
that is what upstream builds and a separate zero or more node would be a second thing to
keep in step for no gain.
Identifier = 7
An identifier matcher. a is a Suggestion, flags bit 0 is RESERVED.
Number = 8
A numeric literal.
String = 9
A string literal, including its adjacent continuations.
Operator = 10
An operator token, subject to the exclusions in OperatorMatcher.
EndOfInput = 11
The end of the input.
KeywordClass = 12
A word in one of the five keyword classes. a is the class mask.
The grammar spells these as an ordered choice of two hundred literals, because a PEG has no
way to say “a word in this set”. Upstream compiles that to two hundred KeywordMatcher
objects and tries them in turn. The words in a list are distinct and a KeywordMatcher is a
case insensitive text compare, so membership in the list is exactly a mask test on the class
the tokenizer already resolved, and the two are the same predicate.