Documentation
¶
Overview ¶
Package parser builds an *ast.Program from a token stream produced by the lexer. The grammar implemented here is Lua 5.4 (reference manual §9).
The parser is a hand-written, single-pass recursive-descent parser with a Pratt-style operator-precedence layer for expressions. There is no state machine and no lookahead beyond a single peek token — Lua 5.4 is LL(2) at most (see the Name vs. funcname disambiguation in `parseStatement`).
Index ¶
- type Expression
- type Mode
- type Parser
- type Position
- type Range
- type SourceMap
- func (sm *SourceMap) Add(src Expression, tgt Range) (updatedFrom Position)
- func (sm *SourceMap) AddSymbolRange(src Range, tgt Range)
- func (sm *SourceMap) SourcePositionFromTarget(line, col uint32) (src Position, ok bool)
- func (sm *SourceMap) SymbolSourceRangeFromTarget(line, col uint32) (src Range, ok bool)
- func (sm *SourceMap) SymbolTargetRangeFromSource(line, col uint32) (tgt Range, ok bool)
- func (sm *SourceMap) TargetPositionFromSource(line, col uint32) (tgt Position, ok bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expression ¶
Expression containing Go code.
func NewExpression ¶
func NewExpression(value string, from, to Position) Expression
NewExpression creates a Go expression.
type Mode ¶
type Mode int
Mode controls REPL-friendly error reporting (e.g. distinguishing "still typing — give me more input" from a real syntax error).
type Parser ¶
Parser owns the token cursor and parser state.
func New ¶
New constructs a parser ready to consume the supplied lexer's tokens. Call ParseProgram to drive it.
func (*Parser) ParseProgram ¶
ParseProgram drives the top-level block until EOF and returns the AST. Returns the partial AST and an error if one occurred. The parser is single-shot: do not call ParseProgram more than once on the same Parser.
type Position ¶
Source mapping to map from the source code of the template to the in-memory representation.
func NewPosition ¶
NewPosition initialises a position.
type SourceMap ¶
type SourceMap struct {
Expressions []string
SourceLinesToTarget map[uint32]map[uint32]Position
TargetLinesToSource map[uint32]map[uint32]Position
SourceSymbolRangeToTarget map[uint32]map[uint32]Range
TargetSymbolRangeToSource map[uint32]map[uint32]Range
}
func NewSourceMap ¶
func NewSourceMap() *SourceMap
func (*SourceMap) Add ¶
func (sm *SourceMap) Add(src Expression, tgt Range) (updatedFrom Position)
Add an item to the lookup.
func (*SourceMap) AddSymbolRange ¶
func (*SourceMap) SourcePositionFromTarget ¶
SourcePositionFromTarget looks the source position using the target position. If a source exists on the line but not the col, the function will search backwards.
func (*SourceMap) SymbolSourceRangeFromTarget ¶
func (*SourceMap) SymbolTargetRangeFromSource ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package errors defines the typed parser error used throughout the luascript front-end.
|
Package errors defines the typed parser error used throughout the luascript front-end. |
|
Package precedence encodes the Lua 5.4 binary-operator precedence ladder (see Lua 5.4 reference manual §3.4.8).
|
Package precedence encodes the Lua 5.4 binary-operator precedence ladder (see Lua 5.4 reference manual §3.4.8). |