Documentation ¶
Index ¶
- Constants
- func Expect(s string, t Token)
- func Expected(s string, t Token) error
- func TokenError(format string, t Token, args ...interface{}) error
- func Unexpected(t Token) error
- func UnexpectedEof() error
- type Both
- type Infix
- type Lexer
- type Node
- type Parser
- func (p *Parser) Parse(l *Lexer, prec int) *Node
- func (p *Parser) ParseWith(l *Lexer, prec int, t Token) *Node
- func (p *Parser) RegBoth(k int, s string, bp Both)
- func (p *Parser) RegElse(ep Prefix)
- func (p *Parser) RegInfix(k int, s string, ip Infix)
- func (p *Parser) RegPrefix(k int, s string, pp Prefix)
- type ParserFunc
- type Prefix
- type Source
- type State
- type Token
Constants ¶
const Eof rune = -1
Out of band representation for EOF as a character.
Variables ¶
This section is empty.
Functions ¶
func TokenError ¶
func Unexpected ¶
func UnexpectedEof ¶
func UnexpectedEof() error
Types ¶
type Infix ¶
type Infix interface { Precedence(t Token) int Infix(p *Parser, l *Lexer, left *Node, t Token) *Node }
Handles tokens after the first in a particular call to Parse().
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
A lexical analyser where each state is a function.
func (*Lexer) Init ¶
Initialise a Lexer with a source and a start state before beginning processing.
func (*Lexer) Lookahead ¶
Parse a token from the source as Next(), but remember that token so that it is returned from the next call to Parse() or Lookahead().
func (*Lexer) Next ¶
Parse a token from the source.
Matching process:
- Begin with the start state passed into Init().
- Call the current state, passing in the Lexer.
- This provides the next state.
- If the next state is nil, halt.
- Otherwise go back to step 2 with the current state as the next state.
States should issue calls to Read(), Peek(), Clear() and Save() as required to move through the source and match tokens. These methods should not be called outside the dynamic extent of Next().
A given run through the matching process may produce no tokens (in which case the matching process is repeated), one token (in which case it is returned) or more tokens (in which case the first token match is returned, and the matching process is foregone for retrieving those extra tokens).
type Node ¶
Node in the syntax tree.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
A Pratt operator precedence parser.
type ParserFunc ¶
Simple wrapper round Prefix
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
func (*Source) Clear ¶
func (s *Source) Clear()
Ignore the portion of text currently under consideration.
func (*Source) Peek ¶
Read a character from the source as in Read(), but remember that character so that it is returned from the next call to Read() or Peek().
func (*Source) Read ¶
Read a character from the source. Will return Eof when at the end of the source and panic for any other errors.