Skip to main content

Module operators

Module operators 

Source
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§

OperatorGrammar
A precedence ladder the parser climbs. Self::CURRENT is the language; Self::LEGACY reproduces the pre-0.11 operator grammar (?? between additive and multiplicative, a to b [exclusive] ranges just above |>) and exists only so harn fix --migrate-operator-syntax can read old source.

Enums§

Associativity
How operators of equal precedence group.
BinaryOperator
A binary operator. Spelling, wire name, and precedence live here so no consumer compares operator text.
OperandSide
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.
UnaryOperator
A prefix operator.

Constants§

RANGE_EXCLUSIVE
Exclusive-end range spelling: 0..n yields 0 through n - 1.
RANGE_INCLUSIVE
Inclusive-end range spelling: 1..=n yields 1 through n.

Functions§

loosest_bare_operand
The loosest precedence an expression may have to appear bare as the side operand of an operator in group parent.
operand_needs_parens
Whether child must be parenthesized to keep its grouping as the side operand of parent in the current grammar.