rdparser

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewReader

func NewReader() lisp.Reader

NewReader returns a lisp.Reader to use in a lisp.Runtime.

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 New

func New(scanner *token.Scanner) *Parser

New initializes and returns a new Parser that reads tokens from scanner.

func NewFromSource

func NewFromSource(src *TokenSource) *Parser

NewFromSource initializes and returns a Parser that reads tokens from src.

func (*Parser) Accept

func (p *Parser) Accept(typ ...token.Type) bool

func (*Parser) Float

func (p *Parser) Float(x float64) *lisp.LVal

func (*Parser) Int

func (p *Parser) Int(x int) *lisp.LVal

func (*Parser) Location

func (p *Parser) Location() *token.Location

func (*Parser) Parse

func (p *Parser) Parse() (*lisp.LVal, error)

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 (p *Parser) ParseConsExpression() *lisp.LVal

func (*Parser) ParseExpression

func (p *Parser) ParseExpression() *lisp.LVal

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 (p *Parser) ParseFunRef() *lisp.LVal

func (*Parser) ParseList

func (p *Parser) ParseList() *lisp.LVal

func (*Parser) ParseLiteralFloat

func (p *Parser) ParseLiteralFloat() *lisp.LVal

func (*Parser) ParseLiteralInt

func (p *Parser) ParseLiteralInt() *lisp.LVal

func (*Parser) ParseLiteralIntHex

func (p *Parser) ParseLiteralIntHex() *lisp.LVal

func (*Parser) ParseLiteralIntOctal

func (p *Parser) ParseLiteralIntOctal() *lisp.LVal

func (*Parser) ParseLiteralString

func (p *Parser) ParseLiteralString() *lisp.LVal

func (*Parser) ParseLiteralStringRaw

func (p *Parser) ParseLiteralStringRaw() *lisp.LVal

func (*Parser) ParseNegative

func (p *Parser) ParseNegative() *lisp.LVal

func (*Parser) ParseProgram

func (p *Parser) ParseProgram() ([]*lisp.LVal, error)

ParseProgram parses a series of expressions potentially preceded by a hash-bang, `#!`.

func (*Parser) ParseQuote

func (p *Parser) ParseQuote() *lisp.LVal

func (*Parser) ParseSymbol

func (p *Parser) ParseSymbol() *lisp.LVal

func (*Parser) ParseUnbound

func (p *Parser) ParseUnbound() *lisp.LVal

func (*Parser) PeekLocation

func (p *Parser) PeekLocation() *token.Location

func (*Parser) PeekType

func (p *Parser) PeekType() token.Type

func (*Parser) QExpr

func (p *Parser) QExpr(cells []*lisp.LVal) *lisp.LVal

func (*Parser) Quote

func (p *Parser) Quote(v *lisp.LVal) *lisp.LVal

func (*Parser) ReadToken

func (p *Parser) ReadToken() *token.Token

func (*Parser) SExpr

func (p *Parser) SExpr(cells []*lisp.LVal) *lisp.LVal

func (*Parser) String

func (p *Parser) String(s string) *lisp.LVal

func (*Parser) Symbol

func (p *Parser) Symbol(sym string) *lisp.LVal

func (*Parser) TokenText

func (p *Parser) TokenText() string

func (*Parser) TokenType

func (p *Parser) TokenType() token.Type

type TokenGenerator

type TokenGenerator func() []*token.Token

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

type TokenSource struct {
	Token *token.Token
	// contains filtered or unexported fields
}

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) Accept

func (s *TokenSource) Accept(fn func(*token.Token) bool) bool

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.

Jump to

Keyboard shortcuts

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