Documentation ¶
Overview ¶
Package parse implements the elvish parser.
Index ¶
- Variables
- func PprintAST(n Node, wr io.Writer)
- func PprintParseTree(n Node, wr io.Writer)
- func Quote(s string) string
- type Array
- type Assignment
- type Chunk
- type Compound
- type Control
- type ControlKind
- type ExitusRedir
- type Form
- type Indexing
- type MapPair
- type Node
- type Pipeline
- type Primary
- type PrimaryType
- type Redir
- type RedirMode
- type Sep
Constants ¶
This section is empty.
Variables ¶
var QuotingStyles = []struct { Type PrimaryType Quoter string }{ {SingleQuoted, "'"}, {DoubleQuoted, "\""}, }
Functions ¶
func PprintParseTree ¶
PprintParseTree pretty prints the parse tree part of a Node.
Types ¶
type Array ¶
type Array struct { Compounds []*Compound // When non-empty, records the occurences 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 (*Array) SourceText ¶
func (n *Array) SourceText() string
type Assignment ¶
Assignment = Primary '=' Compound
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 (*Chunk) SourceText ¶
func (n *Chunk) SourceText() string
type Compound ¶
type Compound struct { Indexings []*Indexing // contains filtered or unexported fields }
Compound = { Indexing }
func (*Compound) SourceText ¶
func (n *Compound) SourceText() string
type Control ¶
type Control struct { Kind ControlKind Condition *Chunk // Valid for WhileControl. Iterator *Indexing // Valid for ForControl. Array *Array // Valid for ForControl. Body *Chunk // Valid for all except IfControl. Conditions []*Chunk // Valid for IfControl. Bodies []*Chunk // Valid for IfControl. ElseBody *Chunk // Valid for IfControl, WhileControl and ForControl. ExceptBody *Chunk // Valid for TryControl. ExceptVar *Indexing // Valid for TryControl. FinallyBody *Chunk // Valid for TryControl. // contains filtered or unexported fields }
Control = IfControl | WhileControl | ForControl | BeginControl IfControl = If Chunk Then Chunk { Elif Chunk Then Chunk } [ Else Chunk ] Fi WhileControl = While Chunk Do Chunk [ Else Chunk ] Done ForControl = For Primary In Array PipelineSep Do Chunk [ Else Chunk ] Done BeginControl = Begin Chunk Done If = "if" Space { Space } (Similiar for Then, Elif, Else, Fi, While, Do, Done, For, Begin, End)
func (*Control) SourceText ¶
func (n *Control) SourceText() string
type ControlKind ¶
type ControlKind int
ControlKind identifies which control structure a Control represents.
const ( BadControl ControlKind = iota IfControl WhileControl ForControl TryControl BeginControl )
Possible values of ControlKind.
func (ControlKind) String ¶
func (i ControlKind) String() string
type ExitusRedir ¶
type ExitusRedir struct { Dest *Compound // contains filtered or unexported fields }
ExitusRedir = '?' '>' { Space } Compound
func (*ExitusRedir) SourceText ¶
func (n *ExitusRedir) SourceText() string
type Form ¶
type Form struct { Assignments []*Assignment Control *Control Head *Compound Args []*Compound NamedArgs []*MapPair Redirs []*Redir ExitusRedir *ExitusRedir // contains filtered or unexported fields }
Form = { Space } { { Assignment } { Space } }
{ Compound | Control } { Space } { ( Compound | MapPair | Redir | ExitusRedir ) { Space } }
func (*Form) SourceText ¶
func (n *Form) SourceText() string
type Indexing ¶
Indexing = Primary { '[' Array ']' }
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 (*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 Pipeline ¶
Pipeline = Form { '|' Form }
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 List *Array // Valid for List and Lambda Chunk *Chunk // Valid for OutputCapture, ExitusCapture and Lambda MapPairs []*MapPair // Valid for Map Braced []*Compound // Valid for Braced IsRange []bool // Valid for Braced // contains filtered or unexported fields }
Primary is the smallest expression unit.
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 ErrorCapture 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 { Dest *Compound Mode RedirMode SourceIsFd bool Source *Compound // contains filtered or unexported fields }
Redir = { Compound } { '<'|'>'|'<>'|'>>' } { Space } ( '&'? Compound )
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