Expand description
Operator vocabulary: spelling, precedence, and associativity.
This module is the single owner of Harn’s expression-operator grammar. The
parser climbs OperatorGrammar::CURRENT, the formatter and harn fix
decide parenthesization with operand_needs_parens, and the spec’s
precedence table and the tree-sitter grammar’s precedence constants are
generated from or drift-checked against Precedence::ALL.
The groups follow Swift’s standard precedence groups where Harn has the
same operator: ?? binds looser than range formation and arithmetic and
tighter than comparison, and range formation (a..b, a..=b) binds looser
than arithmetic and does not associate.
Structs§
- Operator
Grammar - A precedence ladder the parser climbs.
Self::CURRENTis the language;Self::LEGACYreproduces the pre-0.11 operator grammar (??between additive and multiplicative,a to b [exclusive]ranges just above|>) and exists only soharn fix --migrate-operator-syntaxcan read old source.
Enums§
- Associativity
- How operators of equal precedence group.
- Binary
Operator - A binary operator. Spelling, wire name, and precedence live here so no consumer compares operator text.
- Operand
Side - Which operand of an operator a child expression occupies.
- Precedence
- Expression precedence groups, loosest first. The derived ordering is the
binding order of
OperatorGrammar::CURRENT. - Unary
Operator - A prefix operator.
Constants§
- RANGE_
EXCLUSIVE - Exclusive-end range spelling:
0..nyields0throughn - 1. - RANGE_
INCLUSIVE - Inclusive-end range spelling:
1..=nyields1throughn.
Functions§
- loosest_
bare_ operand - The loosest precedence an expression may have to appear bare as the
sideoperand of an operator in groupparent. - operand_
needs_ parens - Whether
childmust be parenthesized to keep its grouping as thesideoperand ofparentin the current grammar.