Documentation
¶
Overview ¶
Package precedence encodes the Lua 5.4 binary-operator precedence ladder (see Lua 5.4 reference manual §3.4.8). Levels run from Lowest (a sentinel used as the entrypoint floor) to Call (postfix suffixes that bind tighter than any binary operator).
or -- Or
and -- And
< > <= >= == ~= -- Compare
| -- BitOr
~ (binary xor) -- BitXor
& -- BitAnd
<< >> -- Shift
.. (right-associative) -- Concat
+ - -- Sum
* / // % -- Product
unary not # - ~ -- Unary
^ (right-associative) -- Pow
postfix . [ ( : { string-call -- Call
Index ¶
Constants ¶
const ( Lowest = iota // sentinel: any real precedence is greater Or // or And // and Compare // < > <= >= == ~= BitOr // | BitXor // ~ (binary) BitAnd // & Shift // << >> Concat // .. (right-assoc) Sum // + - Product // * / // % Unary // not # - ~ Pow // ^ (right-assoc) Call // postfix: . [ ( : { string )
Precedence levels, low → high. Right-associativity is *not* encoded here; callers handle it at parse time by recursing with Level-1 on the RHS.
Variables ¶
var LookupTable = map[token.Type]int{ token.Or: Or, token.And: And, token.LT: Compare, token.GT: Compare, token.LTE: Compare, token.GTE: Compare, token.Eq: Compare, token.NotEq: Compare, token.Pipe: BitOr, token.Tilde: BitXor, token.Ampersand: BitAnd, token.LShift: Shift, token.RShift: Shift, token.Concat: Concat, token.Plus: Sum, token.Minus: Sum, token.Asterisk: Product, token.Slash: Product, token.FloorDiv: Product, token.Percent: Product, token.Caret: Pow, token.Dot: Call, token.LBracket: Call, token.LParen: Call, token.Colon: Call, token.Label: Call, }
LookupTable maps a binary or postfix token to its precedence level. The parser consults this for the standard Pratt loop. Unary precedence is not listed because unary operators are handled in the prefix branch.
Functions ¶
func IsRightAssoc ¶
IsRightAssoc reports whether the operator at this token type associates to the right (`..` and `^`). The parser handles right-associativity by recursing on the RHS with `prec - 1`.
Types ¶
This section is empty.