precedence

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 1 Imported by: 0

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

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

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

func IsRightAssoc(t token.Type) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL