Documentation
¶
Overview ¶
Package parse parses elvish source. Derived from stdlib package text/template/parse.
Index ¶
- Variables
- func Atou(s string) (uintptr, error)
- func StartsBare(r rune) bool
- func TerminatesBare(r rune) bool
- type ChunkNode
- type CloseRedir
- type ClosureNode
- type Context
- type ContextType
- type FactorNode
- type FactorType
- type FdRedir
- type FilenameRedir
- type FormNode
- type Item
- type ItemEnd
- type ItemType
- type Lexer
- type Node
- type Parser
- type PipelineNode
- type PlainContext
- type Pos
- type Redir
- type StringNode
- type TableNode
- type TablePair
- type TermListNode
- type TermNode
- Bugs
Constants ¶
This section is empty.
Variables ¶
var ItemTypeNames = []string{
"ItemError",
"ItemEOF",
"ItemEndOfLine",
"ItemSpace",
"ItemBare",
"ItemSingleQuoted",
"ItemDoubleQuoted",
"ItemRedirLeader",
"ItemStatusRedirLeader",
"ItemPipe",
"ItemQuestionLParen",
"ItemLParen",
"ItemRParen",
"ItemLBracket",
"ItemRBracket",
"ItemLBrace",
"ItemRBrace",
"ItemDollar",
"ItemCaret",
"ItemSemicolon",
"ItemAmpersand",
}
ItemType names.
Functions ¶
func Atou ¶
Atou is basically shorthand for strconv.ParseUint(s, 10, 0) but returns the first argument as uintptr. Useful for parsing fd.
func StartsBare ¶
StartsBare determines whether r may be the first rune of a bareword.
func TerminatesBare ¶
TerminatesBare determines whether r terminates a bareword.
Types ¶
type ChunkNode ¶
type ChunkNode struct { Pos Nodes []*PipelineNode }
ChunkNode is a list of FormNode's.
type CloseRedir ¶
type CloseRedir struct {
// contains filtered or unexported fields
}
CloseRedir represents the closing of a fd, like >[2=].
type ClosureNode ¶
type ClosureNode struct { Pos ArgNames *TermListNode Chunk *ChunkNode Annotation interface{} }
ClosureNode holds a closure literal.
type Context ¶
type Context struct { Typ ContextType CommandTerm *TermNode PrevTerms *TermListNode PrevFactors *TermNode ThisFactor *FactorNode }
Context contains information from the AST useful for tab completion.
func (*Context) EvalPlain ¶
func (c *Context) EvalPlain() (pctx *PlainContext)
type ContextType ¶
type ContextType int
ContextType categorizes Context.
const ( CommandContext ContextType = iota ArgContext RedirFilenameContext )
ContextType values.
type FactorNode ¶
type FactorNode struct { Pos Typ FactorType Node Node }
FactorNode represents a factor.
type FactorType ¶
type FactorType int
FactorType determines the type of a FactorNode.
const ( StringFactor FactorType = iota // string literal: a `a` a VariableFactor // variable: $a TableFactor // table: [a b c &k v] ClosureFactor // closure: {|a| cmd} ListFactor // list: {a b c} OutputCaptureFactor // output capture: (cmd1|cmd2) StatusCaptureFactor // status capture: ?(cmd1|cmd2) )
FactorType constants.
type FdRedir ¶
type FdRedir struct { OldFd uintptr // contains filtered or unexported fields }
FdRedir represents redirection into another fd, like >[2=3].
func NewFdRedir ¶
NewFdRedir creates a new FdRedir. Public since we need to turn FilenameRedir -> FdRedir when evaluating commands.
type FilenameRedir ¶
FilenameRedir represents redirection into a file, like >a.txt
type FormNode ¶
type FormNode struct { Pos Command *TermNode Args *TermListNode Redirs []Redir StatusRedir string }
FormNode holds a form.
type Item ¶
type Item struct { Typ ItemType // The type of this Item. Pos Pos // The starting position, in bytes, of this Item in the input string. Val string // The value of this Item. End ItemEnd // How an Item ends. }
Item represents a token or text string returned from the scanner.
type ItemEnd ¶
type ItemEnd int
ItemEnd describes the ending of lex items.
const ( MayTerminate ItemEnd = 1 << iota MayContinue ItemTerminated ItemEnd = MayTerminate ItemUnterminated ItemEnd = MayContinue ItemAmbiguious ItemEnd = MayTerminate | MayContinue )
ItemEnd constants.
type ItemType ¶
type ItemType int
ItemType identifies the type of lex items.
const ( ItemError ItemType = iota // error occurred; value is text of error ItemEOF // end of file, always the last Item yielded ItemEndOfLine // a single EOL ItemSpace // run of spaces separating arguments ItemBare // a bare string literal ItemSingleQuoted // a single-quoted string literal ItemDoubleQuoted // a double-quoted string literal ItemRedirLeader // IO redirection leader ItemStatusRedirLeader // status redirection leader, "?>" ItemPipe // pipeline connector, '|' ItemQuestionLParen // question + left paren "?(" ItemLParen // left paren '(' ItemRParen // right paren ')' ItemLBracket // left bracket '[' ItemRBracket // right bracket ']' ItemLBrace // left brace '{' ItemRBrace // right brace '}' ItemDollar // dollar sign '$' ItemCaret // caret sign '^' ItemSemicolon // semicolon ';' ItemAmpersand // ampersand '&' ItemTypeCount )
ItemType constants.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer holds the state of the scanner.
type Node ¶
type Node interface { Position() Pos // byte position of start of node in full original input string // contains filtered or unexported methods }
A Node is an element in the parse tree. The interface is trivial. The interface contains an unexported method so that only types local to this package can satisfy it.
type Parser ¶
type Parser struct { Name string // name of the script represented by the tree. Root *ChunkNode // top-level root of the tree. Ctx *Context // contains filtered or unexported fields }
Parser maintains the states during parsing.
type PipelineNode ¶
PipelineNode is a list of FormNode's.
type PlainContext ¶
type PlainContext struct { Typ ContextType CommandTerm string PrevTerms []string PrevFactors string ThisFactor *FactorNode }
type Pos ¶
type Pos int
Pos represents a byte position in the original input text from which this source was parsed.
type Redir ¶
Redir represents a single IO redirection. Its concrete type may be one of the *Redir types below.
type StringNode ¶
type StringNode struct { Pos Quoted string // The original text of the string, with quotes. Text string // The string, after quote processing. }
StringNode holds a string literal. The value has been "unquoted".
type TermListNode ¶
TermListNode is a list of TermNode's.
type TermNode ¶
type TermNode struct { Pos Nodes []*FactorNode }
TermNode is a list of FactorNode's.
Notes ¶
Bugs ¶
When completing, unterminated quoted string results in errors