gc

package module
v0.0.0-...-cc83bf9 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2016 License: MIT Imports: 9 Imported by: 0

README

golang-repl

Documentation

Index

Constants

View Source
const SliceDefaultCap = 10

SliceDefaultCap controls how large the internal expression buffers are made to begin with.

Variables

View Source
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(`^(\+\+|\-\-|\+=|\-=|=|==|:=|\+|\-|\*|<|>|<=|>=|<-|->|\*=|/=|\*\*|!|!=|<!)$`)
)
View Source
var EndTk = Token{/* contains filtered or unexported fields */}
View Source
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.

View Source
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.

View Source
var ParserHaltRequested = fmt.Errorf("parser halt requested")

ParserHaltRequested means the Parser is in the middle of shutting down afteer Parser.Stop() has been requested.

View Source
var Q = func(quietly_ignored ...interface{}) {} // quiet
View Source
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.

View Source
var UnexpectedEnd error = errors.New("Unexpected end of input")

UnexpectedEnd means that the input was exhausted (EOF reached) during the middle of a parse.

View Source
var Verbose bool // set to true to debug
View Source
var Working bool // currently under investigation

Functions

func DecodeChar

func DecodeChar(atom string) (string, error)

func EscapeChar

func EscapeChar(char rune) (rune, error)

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

func StringToRunes(str string) []rune

func TSPrintf

func TSPrintf(format string, a ...interface{})

time-stamped printf

func VPrintf

func VPrintf(format string, a ...interface{})

func WPrintf

func WPrintf(format string, a ...interface{})

Types

type Env

type Env struct{}

the environment in which the parsing takes place

func (*Env) NewParser

func (env *Env) NewParser() *Parser

NewParser creates a new Parser, but does not invoke Parser.Start().

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

func NewLexer

func NewLexer(p *Parser) *Lexer

func (*Lexer) AddNextStream

func (lex *Lexer) AddNextStream(s io.RuneScanner)

func (*Lexer) AppendToken

func (lexer *Lexer) AppendToken(tok Token)

func (*Lexer) DecodeAtom

func (x *Lexer) DecodeAtom(atom string) (Token, error)

func (*Lexer) DecodeBrace

func (x *Lexer) DecodeBrace(brace rune) Token

func (*Lexer) EmptyToken

func (lex *Lexer) EmptyToken() Token

func (*Lexer) GetNextToken

func (lexer *Lexer) GetNextToken() (tok Token, err error)

func (*Lexer) LexNextRune

func (lexer *Lexer) LexNextRune(r rune) error

func (*Lexer) Linenum

func (lexer *Lexer) Linenum() int

func (*Lexer) PeekNextToken

func (lexer *Lexer) PeekNextToken() (tok Token, err error)

func (*Lexer) PrependToken

func (lexer *Lexer) PrependToken(tok Token)

func (*Lexer) PromoteNextStream

func (lex *Lexer) PromoteNextStream() (ok bool)

func (*Lexer) Reset

func (lex *Lexer) Reset()

func (*Lexer) Token

func (lex *Lexer) Token(typ TokenType, str string) Token

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 Node

type Node struct{}

the output Abstract Syntax Tree

var NodeEnd *Node = &Node{}

NodeEnd is a special sentinel to indicate that there are no more Nodes.

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

func (p *Parser) GetMoreInput(deliverThese []*Node, errorToReport error) error

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

func (parser *Parser) ParseExpression(depth int) (res *Node, err error)

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

func (p *Parser) ParseTokens() ([]*Node, error)

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.

func (*Parser) Start

func (p *Parser) Start()

Start begins the parsing on a separate background go-routine, by calling p.InfiniteParsingLoop().

func (*Parser) Stop

func (p *Parser) Stop() error

Stop shuts down a parser. This stops the worker go-routine, and p.Done will be closed after Stop returns. Currently Stop always returns nil.

type ParserReply

type ParserReply struct {
	Expr []*Node
	Err  error
}

ParserReply holds the output of the parser. The return channel ParsedOutput uses this to structure its output.

type Token

type Token struct {
	// contains filtered or unexported fields
}

func (Token) String

func (t Token) String() string

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.

Jump to

Keyboard shortcuts

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