parse

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2017 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package parse implements the elvish parser.

Index

Constants

This section is empty.

Variables

View Source
var QuotingStyles = []struct {
	Type   PrimaryType
	Quoter string
}{
	{SingleQuoted, "'"},
	{DoubleQuoted, "\""},
}

Functions

func IsArray added in v0.6.0

func IsArray(n Node) bool

func IsAssignment added in v0.6.0

func IsAssignment(n Node) bool

func IsChunk added in v0.6.0

func IsChunk(n Node) bool

func IsCompound added in v0.6.0

func IsCompound(n Node) bool

func IsExitusRedir added in v0.6.0

func IsExitusRedir(n Node) bool

func IsForm added in v0.6.0

func IsForm(n Node) bool

func IsIndexing added in v0.6.0

func IsIndexing(n Node) bool

func IsMapPair added in v0.6.0

func IsMapPair(n Node) bool

func IsPipeline added in v0.6.0

func IsPipeline(n Node) bool

func IsPrimary added in v0.6.0

func IsPrimary(n Node) bool

func IsRedir added in v0.6.0

func IsRedir(n Node) bool

func IsSep added in v0.6.0

func IsSep(n Node) bool

func IsSpace added in v0.6.0

func IsSpace(r rune) bool

func IsSpaceOrNewline added in v0.6.0

func IsSpaceOrNewline(r rune) bool

func PprintAST

func PprintAST(n Node, wr io.Writer)

PprintAST pretty prints the AST part of a Node.

func PprintParseTree

func PprintParseTree(n Node, wr io.Writer)

PprintParseTree pretty prints the parse tree part of a Node.

func Quote

func Quote(s string) string

Quote returns a representation of s in elvish syntax. Bareword is tried first, then single quoted string and finally double quoted string.

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 GetArray added in v0.6.0

func GetArray(n Node) *Array

func (*Array) Begin

func (n *Array) Begin() int

func (*Array) Children

func (n *Array) Children() []Node

func (*Array) End

func (n *Array) End() int

func (*Array) Parent

func (n *Array) Parent() Node

func (*Array) SourceText

func (n *Array) SourceText() string

type Assignment

type Assignment struct {
	Left  *Indexing
	Right *Compound
	// contains filtered or unexported fields
}

Assignment = Indexing '=' Compound

func GetAssignment added in v0.6.0

func GetAssignment(n Node) *Assignment

func (*Assignment) Begin

func (n *Assignment) Begin() int

func (*Assignment) Children

func (n *Assignment) Children() []Node

func (*Assignment) End

func (n *Assignment) End() int

func (*Assignment) Parent

func (n *Assignment) Parent() Node

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 GetChunk added in v0.6.0

func GetChunk(n Node) *Chunk

func Parse

func Parse(srcname, src string) (*Chunk, error)

Parse parses elvish source. If the error is not nil, it always has type ParseError.

func (*Chunk) Begin

func (n *Chunk) Begin() int

func (*Chunk) Children

func (n *Chunk) Children() []Node

func (*Chunk) End

func (n *Chunk) End() int

func (*Chunk) Parent

func (n *Chunk) Parent() Node

func (*Chunk) SourceText

func (n *Chunk) SourceText() string

type Compound

type Compound struct {
	Indexings []*Indexing
	// contains filtered or unexported fields
}

Compound = { Indexing }

func GetCompound added in v0.6.0

func GetCompound(n Node) *Compound

func (*Compound) Begin

func (n *Compound) Begin() int

func (*Compound) Children

func (n *Compound) Children() []Node

func (*Compound) End

func (n *Compound) End() int

func (*Compound) Parent

func (n *Compound) Parent() Node

func (*Compound) SourceText

func (n *Compound) SourceText() string

type Error added in v0.8.0

type Error struct {
	Entries []*ErrorEntry
}

Error stores multiple ErrorEntry's and can pretty print them.

func (*Error) Add added in v0.8.0

func (pe *Error) Add(msg string, ctx util.SourceContext)

func (*Error) Error added in v0.8.0

func (pe *Error) Error() string

func (*Error) Pprint added in v0.8.0

func (pe *Error) Pprint(indent string) string

type ErrorEntry added in v0.8.0

type ErrorEntry struct {
	Message string
	Context util.SourceContext
}

ErrorEntry represents one parse error.

type ExitusRedir

type ExitusRedir struct {
	Dest *Compound
	// contains filtered or unexported fields
}

ExitusRedir = '?' '>' { Space } Compound

func GetExitusRedir added in v0.6.0

func GetExitusRedir(n Node) *ExitusRedir

func (*ExitusRedir) Begin

func (n *ExitusRedir) Begin() int

func (*ExitusRedir) Children

func (n *ExitusRedir) Children() []Node

func (*ExitusRedir) End

func (n *ExitusRedir) End() int

func (*ExitusRedir) Parent

func (n *ExitusRedir) Parent() Node

func (*ExitusRedir) SourceText

func (n *ExitusRedir) SourceText() string

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 GetForm added in v0.6.0

func GetForm(n Node) *Form

func (*Form) Begin

func (n *Form) Begin() int

func (*Form) Children

func (n *Form) Children() []Node

func (*Form) End

func (n *Form) End() int

func (*Form) Parent

func (n *Form) Parent() Node

func (*Form) SourceText

func (n *Form) SourceText() string

type Indexing

type Indexing struct {
	Head     *Primary
	Indicies []*Array
	// contains filtered or unexported fields
}

Indexing = Primary { '[' Array ']' }

func GetIndexing added in v0.6.0

func GetIndexing(n Node) *Indexing

func (*Indexing) Begin

func (n *Indexing) Begin() int

func (*Indexing) Children

func (n *Indexing) Children() []Node

func (*Indexing) End

func (n *Indexing) End() int

func (*Indexing) Parent

func (n *Indexing) Parent() Node

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 added in v0.6.0

func GetMapPair(n Node) *MapPair

func (*MapPair) Begin

func (n *MapPair) Begin() int

func (*MapPair) Children

func (n *MapPair) Children() []Node

func (*MapPair) End

func (n *MapPair) End() int

func (*MapPair) Parent

func (n *MapPair) Parent() Node

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

type Pipeline struct {
	Forms      []*Form
	Background bool
	// contains filtered or unexported fields
}

Pipeline = Form { '|' Form }

func GetPipeline added in v0.6.0

func GetPipeline(n Node) *Pipeline

func (*Pipeline) Begin

func (n *Pipeline) Begin() int

func (*Pipeline) Children

func (n *Pipeline) Children() []Node

func (*Pipeline) End

func (n *Pipeline) End() int

func (*Pipeline) Parent

func (n *Pipeline) Parent() Node

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 GetPrimary added in v0.6.0

func GetPrimary(n Node) *Primary

func (*Primary) Begin

func (n *Primary) Begin() int

func (*Primary) Children

func (n *Primary) Children() []Node

func (*Primary) End

func (n *Primary) End() int

func (*Primary) Parent

func (n *Primary) Parent() Node

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 GetRedir added in v0.6.0

func GetRedir(n Node) *Redir

func (*Redir) Begin

func (n *Redir) Begin() int

func (*Redir) Children

func (n *Redir) Children() []Node

func (*Redir) End

func (n *Redir) End() int

func (*Redir) Parent

func (n *Redir) Parent() Node

func (*Redir) SourceText

func (n *Redir) SourceText() string

type RedirMode

type RedirMode int

RedirMode records the mode of an IO redirection.

const (
	BadRedirMode RedirMode = iota
	Read
	Write
	ReadWrite
	Append
)

Possible values for RedirMode.

func (RedirMode) String

func (i RedirMode) String() 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 GetSep added in v0.6.0

func GetSep(n Node) *Sep

func NewSep added in v0.5.0

func NewSep(src string, begin, end int) *Sep

func (*Sep) Begin

func (n *Sep) Begin() int

func (*Sep) Children

func (n *Sep) Children() []Node

func (*Sep) End

func (n *Sep) End() int

func (*Sep) Parent

func (n *Sep) Parent() Node

func (*Sep) SourceText

func (n *Sep) SourceText() string

Jump to

Keyboard shortcuts

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