Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeChar(atom string) (string, error)
- func EscapeChar(char rune) (rune, error)
- func P(format string, stuff ...interface{})
- func StringToRunes(str string) []rune
- func TSPrintf(format string, a ...interface{})
- func VPrintf(format string, a ...interface{})
- func WPrintf(format string, a ...interface{})
- type Env
- type Lexer
- func (lex *Lexer) AddNextStream(s io.RuneScanner)
- func (lexer *Lexer) AppendToken(tok Token)
- func (x *Lexer) DecodeAtom(atom string) (Token, error)
- func (x *Lexer) DecodeBrace(brace rune) Token
- func (lex *Lexer) EmptyToken() Token
- func (lexer *Lexer) GetNextToken() (tok Token, err error)
- func (lexer *Lexer) LexNextRune(r rune) error
- func (lexer *Lexer) Linenum() int
- func (lexer *Lexer) PeekNextToken() (tok Token, err error)
- func (lexer *Lexer) PrependToken(tok Token)
- func (lex *Lexer) PromoteNextStream() (ok bool)
- func (lex *Lexer) Reset()
- func (lex *Lexer) Token(typ TokenType, str string) Token
- type LexerState
- type Node
- type Parser
- func (p *Parser) GetMoreInput(deliverThese []*Node, errorToReport error) error
- func (p *Parser) HaveStuffToSend() chan []ParserReply
- func (p *Parser) InfiniteParsingLoop()
- func (p *Parser) NewInput(s io.RuneScanner)
- func (parser *Parser) ParseExpression(depth int) (res *Node, err error)
- func (p *Parser) ParseTokens() ([]*Node, error)
- func (p *Parser) Reset()
- func (p *Parser) ResetAddNewInput(s io.RuneScanner)
- func (p *Parser) Start()
- func (p *Parser) Stop() error
- type ParserReply
- type Token
- type TokenType
Constants ¶
const SliceDefaultCap = 10
SliceDefaultCap controls how large the internal expression buffers are made to begin with.
Variables ¶
var ( BoolRegex = regexp.MustCompile("^(true|false)$") DecimalRegex = regexp.MustCompile("^-?[0-9]+$") HexRegex = regexp.MustCompile("^0x[0-9a-fA-F]+$") OctRegex = regexp.MustCompile("^0o[0-7]+$") BinaryRegex = regexp.MustCompile("^0b[01]+$") // SymbolRegex = regexp.MustCompile("^[^'#]+$") // (Sigil) symbols can begin with #, $, ?, but // sigils cannot appear later in any symbol. // Symbols cannot contain whitespace nor `~`, `@`, `(`, `)`, `[`, `]`, // `{`, `}`, `'`, `#`, `^`, `\`, `|`, `%`, `"`, `;`. They can optionally // end in `:`. // Nor, obviously, can symbols contain backticks, "`". // Symbols cannot start with a number. DotSymbols cannot have a number // as the first character after '.' SymbolRegex = regexp.MustCompile(`^[#$?]?[^#$?':;\\~@\[\]{}\^|"()%0-9,&][^'#:;\\~@\[\]{}\^|"()%,&*\-]*[:]?$`) // dot symbol examples: `.`, `.a`, `.a.b`, `.a.b.c` // dot symbol non-examples: `.a.`, `..` DotSymbolRegex = regexp.MustCompile(`^[.]$|^([.][^'#:;\\~@\[\]{}\^|"()%.0-9,][^'#:;\\~@\[\]{}\^|"()%.,*+\-]*)+$|^[^'#:;\\~@\[\]{}\^|"()%.0-9,][^'#:;\\~@\[\]{}\^|"()%.,*+\-]*([.][^'#:;\\~@\[\]{}\^|"()%.0-9,][^'#:;\\~@\[\]{}\^|"()%.,*+\-]*)+$`) DotPartsRegex = regexp.MustCompile(`[.]?[^'#:;\\~@\[\]{}\^|"()%.0-9,][^'#:;\\~@\[\]{}\^|"()%.,]*`) CharRegex = regexp.MustCompile("^'\\\\?.'$") FloatRegex = regexp.MustCompile("^-?([0-9]+\\.[0-9]*)$|-?(\\.[0-9]+)$|-?([0-9]+(\\.[0-9]*)?[eE](-?[0-9]+))$") ComplexRegex = regexp.MustCompile("^-?([0-9]+\\.[0-9]*)i?$|-?(\\.[0-9]+)i?$|-?([0-9]+(\\.[0-9]*)?[eE](-?[0-9]+))i?$") BuiltinOpRegex = regexp.MustCompile(`^(\+\+|\-\-|\+=|\-=|=|==|:=|\+|\-|\*|<|>|<=|>=|<-|->|\*=|/=|\*\*|!|!=|<!)$`) )
var EndTk = Token{/* contains filtered or unexported fields */}
var ErrMoreInputNeeded = fmt.Errorf("parser needs more input")
ErrMoreInputeNeeded means that the parser is in the middle of a parse and cannot finish without more input.
var ErrShuttingDown error = fmt.Errorf("lexer shutting down")
ErrShuttingDown is returned to indicate that Parser.Stop() has been invoked and the Parser is in the middle of shutting down.
var ParserHaltRequested = fmt.Errorf("parser halt requested")
ParserHaltRequested means the Parser is in the middle of shutting down afteer Parser.Stop() has been requested.
var Q = func(quietly_ignored ...interface{}) {} // quiet
var ResetRequested = fmt.Errorf("parser reset requested")
ResetRequested means that parsing was interrupted by a client request to reset: stop parsing the old input, and begin again on some new input.
var UnexpectedEnd error = errors.New("Unexpected end of input")
UnexpectedEnd means that the input was exhausted (EOF reached) during the middle of a parse.
var V = VPrintf
var Verbose bool // set to true to debug
var W = WPrintf
var Working bool // currently under investigation
Functions ¶
func DecodeChar ¶
func EscapeChar ¶
func P ¶
func P(format string, stuff ...interface{})
P is a shortcut for a call to fmt.Printf that implicitly starts and ends its message with a newline.
func StringToRunes ¶
Types ¶
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
func (*Lexer) AddNextStream ¶
func (lex *Lexer) AddNextStream(s io.RuneScanner)
func (*Lexer) AppendToken ¶
func (*Lexer) DecodeBrace ¶
func (*Lexer) EmptyToken ¶
func (*Lexer) GetNextToken ¶
func (*Lexer) LexNextRune ¶
func (*Lexer) PeekNextToken ¶
func (*Lexer) PrependToken ¶
func (*Lexer) PromoteNextStream ¶
type LexerState ¶
type LexerState int
const ( LexerNormal LexerState = iota LexerCommentLine // LexerStrLit // LexerStrEscaped // LexerUnquote // LexerBacktickString // LexerFreshAssignOrColon LexerFirstFwdSlash // could be start of // comment or /* LexerCommentBlock LexerCommentBlockAsterisk // could be end of block comment */ LexerBuiltinOperator )
type Parser ¶
type Parser struct { Done chan bool AddInput chan io.RuneScanner ReqReset chan io.RuneScanner ParsedOutput chan []ParserReply LastErr chan error FlagSendNeedInput bool // contains filtered or unexported fields }
Parser turns input rune streams and into Abstract Syntax Trees of Node structs. The four channels ReqReset, AddInput, ParsedOutput, and LastErr provide new input (AddInput); or start over with a new line of input after aborting as with Ctrl-C (ReqReset). The Parser provides output via the ParsedOutput channel, and the last error encountered during parsing is available from the LastErr channel.
Parser.Start() and Parser.Stop() are used to setup and shutdown a parser.
func (*Parser) GetMoreInput ¶
This function should *return* when it has more input for the parser/lexer, which will call it when they get wedged.
Listeners on p.ParsedOutput should know the Convention: sending a length 0 []ParserReply on p.ParsedOutput channel means: we need more input! They should send some in on p.AddInput channel; or request a reset and simultaneously give us new input with p.ReqReset channel.
func (*Parser) HaveStuffToSend ¶
func (p *Parser) HaveStuffToSend() chan []ParserReply
HaveStuffToSend returns a nil chan if the Parser has no buffered output waiting. If there is output waiting, or if the p.FlagSendNeedInput is set, then the p.ParsedOutput channel is returned.
func (*Parser) InfiniteParsingLoop ¶
func (p *Parser) InfiniteParsingLoop()
InfiniteParsingLoop is the background worker go-routine that calls Parser.GetMoreInput() and Parser.ParseExpression() in an infinite loop.
func (*Parser) NewInput ¶
func (p *Parser) NewInput(s io.RuneScanner)
NewInput queues up an additional input source, s, to be used after the previous io.RuneScanners have been exhausted.
func (*Parser) ParseExpression ¶
ParseExpression is the top-level entry point for parsing of one expression. It is called by the background-worker go-routine that is running Parser.InfiniteParsingLoop() to begin a top-level expression parse. It may be called recursively, either by itself or by one of its descendants on the call stack.
func (*Parser) ParseTokens ¶
ParseTokens is the main service the Parser provides. Currently returns first error encountered, ignoring any expressions after that.
func (*Parser) Reset ¶
func (p *Parser) Reset()
Reset() resets the parser but provides no new input. Typically the Parser.ResetAddNewInput() method would be used instead.
func (*Parser) ResetAddNewInput ¶
func (p *Parser) ResetAddNewInput(s io.RuneScanner)
ResetAddNewInput aborts the existing parse and provides a new source of runes to begin anew on.
type ParserReply ¶
ParserReply holds the output of the parser. The return channel ParsedOutput uses this to structure its output.
type TokenType ¶
type TokenType int
const ( TokenTypeEmpty TokenType = iota TokenLParen TokenRParen TokenLSquare TokenRSquare TokenLCurly TokenRCurly TokenDot TokenQuote TokenBacktick TokenTilde TokenTildeAt TokenSymbol TokenBool TokenDecimal TokenHex TokenOct TokenBinary TokenFloat TokenChar TokenString TokenCaret TokenColonOperator TokenThreadingOperator TokenBackslash TokenDollar TokenDotSymbol TokenFreshAssign TokenBacktickString TokenComment TokenBeginBlockComment TokenEndBlockComment TokenSemicolon TokenSymbolColon TokenComma TokenEnd )
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
avail/bio
Package bio implements common I/O abstractions used within the Go toolchain.
|
Package bio implements common I/O abstractions used within the Go toolchain. |
avail/gcprog
Package gcprog implements an encoder for packed GC pointer bitmaps, known as GC programs.
|
Package gcprog implements an encoder for packed GC pointer bitmaps, known as GC programs. |
avail/goobj
Package goobj implements reading of Go object files and archives.
|
Package goobj implements reading of Go object files and archives. |
avail/objfile
Package objfile implements portable access to OS-specific executable files.
|
Package objfile implements portable access to OS-specific executable files. |
compile
Compile, typically invoked as “go tool compile,” compiles a single Go package comprising the files named on the command line.
|
Compile, typically invoked as “go tool compile,” compiles a single Go package comprising the files named on the command line. |