Chapter 4
Attributes and Effects
Every node carries attributes. Some are set when the node is built; analysis computes the rest from the rule bodies and recomputes them after a rewrite.
| Attribute | Set by | Meaning |
|---|---|---|
| Want | Building | The node's value is used. A node with Want false builds no value |
| Shape | Building | The static shape of the node's value |
| Nullable | Analysis | The node can succeed without consuming input |
| First | Analysis | The terminal the node must begin with, if it has one |
| Effects | Analysis | A summary of what the node can do |
Nullability
Nullability is the least fixed point over the rules. In summary:
Litis nullable if its text is empty; classes,AnyandScanwith a positive minimum are not. Anchors,Cut,Succeed,Look,Opt,Pred,BindNode,Recover,Missingand aScanwith minimum 0 are.Seqis nullable if every item is;Choiceif any alternative is.Repeatis nullable if its minimum is 0, or is 1 and its body is nullable.Callis nullable as the callee is;Nestas its body is. AnOperatorsRuleis nullable if an operand line's body is.Text,Drop,Capture,Label,TerminalandStreamare nullable as their bodies are.FailNodeandClassRunare not.
First Terminals
The first terminal of a node is what its first character must be, if it has one: either the first code point of a literal, either case of it if the literal is case-insensitive and the code point an ASCII letter, or membership in a class. If the next character is not that, the node fails at once, recording only the expectation of the literal or the class at the current position, after entering as many rule calls as the terminal counts as its depth.
The first terminal follows the first item of a sequence, the bodies of Capture, Text, Drop, Nest and
Terminal, the first class of a ClassRun, and calls of rules that are neither left-recursion leaders nor Operators
Rules, counting one level of depth for each call and Nest on the way. Every other node has none.
Effects
An effect is one thing a node can do besides returning success or failure. A node's effect summary is the set of effects it may have, with the capture slots it may write, in the order they are first written.
| Effect | The node may |
|---|---|
| Consume | Advance the position |
| Fail | Fail |
| Expect | Record expectations |
| Capture | Write capture slots of the enclosing scope |
| Bind | Bind a variable |
| Recover | Append recovered errors |
| Cut | Set the cut flag of the enclosing choice, option or repetition |
| Raise | End the parse with an error |
| Call | Call rules or enter a Nest |
| Commit | Deliver stream elements |
The summary of a node is the union of its children's, with these differences.
- Matching nodes. A non-empty literal, a class,
Any,ClassRun: consume, fail and expect. An anchor: fail and expect.FailNode: fail.Cut: cut.Succeed: none. Choice,Opt,RepeatandLookdo not pass on Cut.Optdoes not pass on Fail, nor doesRepeatwith a minimum of 0.Lookneither consumes nor records expectations, and can fail. ARepeatwith a scope does not pass on the captures of its element.Callhas the effects of the callee, except its captures, bindings and cut, which are the callee's own, and adds Call and Raise: a call can exceed the nesting limit.Nestis the same for its body. AnOperatorsRulehas consume, fail, expect, call and raise, and the effects of its lines.Captureadds Capture and its slot.BindNodeis Bind.Predis Fail. APred, aBindNode, a rule's action and anOperatorsRuleline's action add Raise when their term can raise.Recoverpasses on Fail from neither body nor skip, and adds Recover.Missingis consume, expect, recover and raise: an insertion can exceed the limit of missing tokens.Streamadds Commit.Scanconsumes and expects, and can fail if its minimum is positive.
A rule's own effects, as its callers see them, are those of its body without Capture, Bind and Cut.