Documentation ¶
Overview ¶
Package parse implements the elvish parser.
Index ¶
- func IsArray(n Node) bool
- func IsAssignment(n Node) bool
- func IsChunk(n Node) bool
- func IsCompound(n Node) bool
- func IsExitusRedir(n Node) bool
- func IsForm(n Node) bool
- func IsIndexing(n Node) bool
- func IsMapPair(n Node) bool
- func IsPipeline(n Node) bool
- func IsPrimary(n Node) bool
- func IsRedir(n Node) bool
- func IsSep(n Node) bool
- func IsSpace(r rune) bool
- func IsSpaceOrNewline(r rune) bool
- func PPrintAST(n Node) string
- func PPrintASTTo(n Node, wr io.Writer)
- func PPrintParseTree(n Node) string
- func PPrintParseTreeTo(n Node, wr io.Writer)
- func Quote(s string) string
- type Array
- type Assignment
- type Chunk
- type Compound
- type Error
- type ErrorEntry
- type ExitusRedir
- type ExprCtx
- type Form
- type Indexing
- type MapPair
- type Node
- type Parser
- type Pipeline
- type Primary
- type PrimaryType
- type Redir
- type RedirMode
- type Sep
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAssignment ¶
func IsCompound ¶
func IsExitusRedir ¶
func IsIndexing ¶
func IsPipeline ¶
func IsSpaceOrNewline ¶
func PPrintASTTo ¶
PPrintASTTo pretty-prints the AST part of a Node to a Writer.
func PPrintParseTree ¶
PPrintParseTree pretty-prints the parse tree part of a Node.
func PPrintParseTreeTo ¶
PPrintParseTreeTo pretty-prints the parse tree part of a Node to a Writer.
Types ¶
type Array ¶
type Array struct { Compounds []*Compound // When non-empty, records the occurrences of semicolons by the indices of // the compounds they appear before. For instance, [; ; a b; c d;] results // in Semicolons={0 0 2 4}. Semicolons []int // contains filtered or unexported fields }
Array = { Space | '\n' } { Compound { Space | '\n' } }
func ParseArray ¶
func (*Array) SourceText ¶
func (n *Array) SourceText() string
type Assignment ¶
Assignment = Indexing '=' Compound
func GetAssignment ¶
func GetAssignment(n Node) *Assignment
func ParseAssignment ¶
func ParseAssignment(ps *Parser) *Assignment
func (*Assignment) SourceText ¶
func (n *Assignment) SourceText() string
type Chunk ¶
type Chunk struct { Pipelines []*Pipeline // contains filtered or unexported fields }
Chunk = { PipelineSep | Space } { Pipeline { PipelineSep | Space } }
func ParseChunk ¶
func (*Chunk) SourceText ¶
func (n *Chunk) SourceText() string
type Compound ¶
type Compound struct { Indexings []*Indexing // contains filtered or unexported fields }
Compound = { Indexing }
func GetCompound ¶
func ParseCompound ¶
func (*Compound) SourceText ¶
func (n *Compound) SourceText() string
type Error ¶
type Error struct {
Entries []*ErrorEntry
}
Error stores multiple ErrorEntry's and can pretty print them.
type ErrorEntry ¶
type ErrorEntry struct { Message string Context util.SourceRange }
ErrorEntry represents one parse error.
type ExitusRedir ¶
type ExitusRedir struct { Dest *Compound // contains filtered or unexported fields }
ExitusRedir = '?' '>' { Space } Compound
func GetExitusRedir ¶
func GetExitusRedir(n Node) *ExitusRedir
func ParseExitusRedir ¶
func ParseExitusRedir(ps *Parser) *ExitusRedir
func (*ExitusRedir) SourceText ¶
func (n *ExitusRedir) SourceText() string
type ExprCtx ¶
type ExprCtx int
ExprCtx represents special contexts of expression parsing.
const ( // NormalExpr represents a normal expression, namely none of the special // ones below. NormalExpr ExprCtx = iota // CmdExpr represents an expression used as the command in a form. In this // context, unquoted <>*^ are treated as bareword characters. CmdExpr // LHSExpr represents an expression used as the left-hand-side in either // assignments or map pairs. In this context, an unquoted = serves as an // expression terminator and is thus not treated as a bareword character. LHSExpr // BracedElemExpr represents an expression used as an element in a braced // expression. In this context, an unquoted , serves as an expression // terminator and is thus not treated as a bareword character. BracedElemExpr )
type Form ¶
type Form struct { Assignments []*Assignment Head *Compound // Left-hand-sides for the spacey assignment. Right-hand-sides are in Args. Vars []*Compound Args []*Compound Opts []*MapPair Redirs []*Redir ExitusRedir *ExitusRedir // contains filtered or unexported fields }
Form = { Space } { { Assignment } { Space } }
{ Compound } { Space } { ( Compound | MapPair | Redir | ExitusRedir ) { Space } }
func (*Form) SourceText ¶
func (n *Form) SourceText() string
type Indexing ¶
Indexing = Primary { '[' Array ']' }
func GetIndexing ¶
func ParseIndexing ¶
func (*Indexing) SourceText ¶
func (n *Indexing) SourceText() string
type MapPair ¶
type MapPair struct {
Key, Value *Compound
// contains filtered or unexported fields
}
MapPair = '&' { Space } Compound { Space } Compound
func GetMapPair ¶
func ParseMapPair ¶
func (*MapPair) SourceText ¶
func (n *MapPair) SourceText() string
type Node ¶
type Node interface { Parent() Node Begin() int End() int SourceText() string Children() []Node // contains filtered or unexported methods }
Node represents a parse tree as well as an AST.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser maintains some mutable states of parsing.
NOTE: The str member is assumed to be valid UF-8.
type Pipeline ¶
Pipeline = Form { '|' Form }
func GetPipeline ¶
func ParsePipeline ¶
func (*Pipeline) SourceText ¶
func (n *Pipeline) SourceText() string
type Primary ¶
type Primary struct { Type PrimaryType // The unquoted string value. Valid for Bareword, SingleQuoted, // DoubleQuoted, Variable, Wildcard and Tilde. Value string Elements []*Compound // Valid for List and Labda Chunk *Chunk // Valid for OutputCapture, ExitusCapture and Lambda MapPairs []*MapPair // Valid for Map and Lambda Braced []*Compound // Valid for Braced // contains filtered or unexported fields }
Primary is the smallest expression unit.
func GetPrimary ¶
func ParsePrimary ¶
func (*Primary) SourceText ¶
func (n *Primary) SourceText() string
type PrimaryType ¶
type PrimaryType int
PrimaryType is the type of a Primary.
const ( BadPrimary PrimaryType = iota Bareword SingleQuoted DoubleQuoted Variable Wildcard Tilde ExceptionCapture OutputCapture List Lambda Map Braced )
Possible values for PrimaryType.
func QuoteAs ¶
func QuoteAs(s string, q PrimaryType) (string, PrimaryType)
QuoteAs returns a representation of s in elvish syntax, using the syntax specified by q, which must be one of Bareword, SingleQuoted, or DoubleQuoted. It returns the quoted string and the actual quoting.
func (PrimaryType) String ¶
func (i PrimaryType) String() string
type Redir ¶
type Redir struct { Left *Compound Mode RedirMode RightIsFd bool Right *Compound // contains filtered or unexported fields }
Redir = { Compound } { '<'|'>'|'<>'|'>>' } { Space } ( '&'? Compound )
func ParseRedir ¶
func (*Redir) SourceText ¶
func (n *Redir) SourceText() string
type Sep ¶
type Sep struct {
// contains filtered or unexported fields
}
Sep is the catch-all node type for leaf nodes that lack internal structures and semantics, and serve solely for syntactic purposes. The parsing of separators depend on the Parent node; as such it lacks a genuine parse method.
func (*Sep) SourceText ¶
func (n *Sep) SourceText() string