parse

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2016 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 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 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) 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 {
	Dst *Indexing
	Src *Compound
	// contains filtered or unexported fields
}

Assignment = Primary '=' Compound

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 Parse

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

Parse parses elvish source.

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 (*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 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) Begin

func (n *Control) Begin() int

func (*Control) Children

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

func (*Control) End

func (n *Control) End() int

func (*Control) Parent

func (n *Control) Parent() Node

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) 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
	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) 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 (*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 (*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 (*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 (*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
	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) 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 (*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