Documentation ¶
Index ¶
- func NewReader() lisp.Reader
- type Interactive
- type Parser
- func (p *Parser) Accept(typ ...token.Type) bool
- func (p *Parser) Float(x float64) *lisp.LVal
- func (p *Parser) Int(x int) *lisp.LVal
- func (p *Parser) Location() *token.Location
- func (p *Parser) Parse() (*lisp.LVal, error)
- func (p *Parser) ParseConsExpression() *lisp.LVal
- func (p *Parser) ParseExpression() *lisp.LVal
- func (p *Parser) ParseFunRef() *lisp.LVal
- func (p *Parser) ParseList() *lisp.LVal
- func (p *Parser) ParseLiteralFloat() *lisp.LVal
- func (p *Parser) ParseLiteralInt() *lisp.LVal
- func (p *Parser) ParseLiteralIntHex() *lisp.LVal
- func (p *Parser) ParseLiteralIntOctal() *lisp.LVal
- func (p *Parser) ParseLiteralString() *lisp.LVal
- func (p *Parser) ParseLiteralStringRaw() *lisp.LVal
- func (p *Parser) ParseNegative() *lisp.LVal
- func (p *Parser) ParseProgram() ([]*lisp.LVal, error)
- func (p *Parser) ParseQuote() *lisp.LVal
- func (p *Parser) ParseSymbol() *lisp.LVal
- func (p *Parser) ParseUnbound() *lisp.LVal
- func (p *Parser) PeekLocation() *token.Location
- func (p *Parser) PeekType() token.Type
- func (p *Parser) QExpr(cells []*lisp.LVal) *lisp.LVal
- func (p *Parser) Quote(v *lisp.LVal) *lisp.LVal
- func (p *Parser) ReadToken() *token.Token
- func (p *Parser) SExpr(cells []*lisp.LVal) *lisp.LVal
- func (p *Parser) String(s string) *lisp.LVal
- func (p *Parser) Symbol(sym string) *lisp.LVal
- func (p *Parser) TokenText() string
- func (p *Parser) TokenType() token.Type
- type TokenGenerator
- type TokenSource
- type TokenStream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Interactive ¶
type Interactive struct { Read TokenGenerator // contains filtered or unexported fields }
Interactive implements a parser that parses a single expression at a time and defers to a TokenGenerator function when it is necessary to read more tokens.
func NewInteractive ¶
func NewInteractive(read TokenGenerator) *Interactive
NewInteractive initializes and returns a new Interactive parser.
func (*Interactive) IsParsing ¶
func (p *Interactive) IsParsing() bool
IsParsing returns true if p is in the middle of parsing an expression. IsParsing can be called at any time, potentially by concurrent goroutines or when p is nil.
func (*Interactive) Parse ¶
func (p *Interactive) Parse() (*lisp.LVal, error)
Parse parses one expression from the interactive token stream and returns it, or any error encountered. A REPL would call this function in its main runloop. If a parse error is encountered, any buffered tokens (presumably from the current tty line) are discarded so corrected source can be re-read.
func (*Interactive) ParseExpression ¶
func (p *Interactive) ParseExpression() (*lisp.LVal, error)
ParseExpression parses one expression from the interactive token stream and returns it, or any error encountered.
NOTE: ParseExpression is deprecated and Parse should be used instead.
func (*Interactive) Prompt ¶
func (p *Interactive) Prompt() string
Prompt returns a simple prompt that can be used by a REPL token generator.
func (*Interactive) SetPrompts ¶
func (p *Interactive) SetPrompts(prompt, cont string)
SetPrompts configures the string prompts reutrned by p.Prompt(). The cont string is used to prompt the user when the parser is in the middle of parsing an expression at the start of a line.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is a lisp parser.
func NewFromSource ¶
func NewFromSource(src *TokenSource) *Parser
NewFromSource initializes and returns a Parser that reads tokens from src.
func (*Parser) Parse ¶
Parse is a generic entry point that is similar to ParseExpression but is capable of handling EOF before reading an expression.
func (*Parser) ParseConsExpression ¶
func (*Parser) ParseExpression ¶
ParseExpression parses a single expression. Unlike Parse, ParseExpression requires an expression to be present in the input stream and will report unexpected EOF tokens encountered.
func (*Parser) ParseFunRef ¶ added in v1.2.0
func (*Parser) ParseLiteralFloat ¶
func (*Parser) ParseLiteralInt ¶
func (*Parser) ParseLiteralIntHex ¶
func (*Parser) ParseLiteralIntOctal ¶
func (*Parser) ParseLiteralString ¶
func (*Parser) ParseLiteralStringRaw ¶
func (*Parser) ParseNegative ¶
func (*Parser) ParseProgram ¶
ParseProgram parses a series of expressions potentially preceded by a hash-bang, `#!`.
func (*Parser) ParseQuote ¶
func (*Parser) ParseSymbol ¶
func (*Parser) ParseUnbound ¶
func (*Parser) PeekLocation ¶
type TokenGenerator ¶
TokenGenerator implements TokenStream. The function will be called any time a TokenSource wants a token.
func (TokenGenerator) ReadToken ¶
func (fn TokenGenerator) ReadToken() []*token.Token
ReadToken implements TokenStream.
type TokenSource ¶
TokenSource abstracts a TokenStream by adding "memory" and providing methods to process and branch off the stream's tokens.
func NewTokenSource ¶
func NewTokenSource(scanner *token.Scanner) *TokenSource
TokenSource initializes and returns a new token.Source that scans tokens from scanner.
func NewTokenStreamSource ¶
func NewTokenStreamSource(stream TokenStream) *TokenSource
func (*TokenSource) AcceptType ¶
func (s *TokenSource) AcceptType(typ ...token.Type) bool
func (*TokenSource) IsEOF ¶
func (s *TokenSource) IsEOF() bool
func (*TokenSource) Peek ¶
func (s *TokenSource) Peek() *token.Token
func (*TokenSource) Scan ¶
func (s *TokenSource) Scan() bool
type TokenStream ¶
type TokenStream interface { // ReadToken returns a set of token from an input source. When no more // tokens can be generated ReadToken returns a token with type token.EOF. // ReadToken never returns an empty slice. In the presence of io errors a // TokenStream must return a token with type token.ERROR whenever called. ReadToken() []*token.Token }
TokenStream is an arbitrary sequence of tokens. Typically, a TokenStream will be a *lexer.Lexer but other implementations may be desirable for implementation a REPL or other dynamic environments.
func TokenChannel ¶
func TokenChannel(c <-chan []*token.Token) TokenStream
TokenChannel returns a TokenStream that returns tokens receieved from c.