parser

package
v0.0.0-...-82e14e4 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddStringToList

func AddStringToList(list *List, s string) (modified bool)

func ExpressionsAreSame

func ExpressionsAreSame(a Expression, b Expression) (equal bool, err error)

ExpressionsAreSame tells whether the two values are the same Expression. This includes the symbolic representation of each Expression but not their positions in the original source tree. This does not apply any simplification to the expressions before comparing them (for example, "!!a" wouldn't be deemed equal to "a")

func ListIsSorted

func ListIsSorted(list *List) bool

func Print

func Print(file *File) ([]byte, error)

func PrintExpression

func PrintExpression(expression Expression) ([]byte, error)

func RemoveStringFromList

func RemoveStringFromList(list *List, s string) (modified bool)

func SortList

func SortList(file *File, list *List)

func SortLists

func SortLists(file *File)

Types

type Assignment

type Assignment struct {
	Name       string
	NamePos    scanner.Position
	Value      Expression
	OrigValue  Expression
	EqualsPos  scanner.Position
	Assigner   string
	Referenced bool
}

An Assignment is a variable assignment at the top level of a Blueprints file, scoped to the file and and subdirs.

func (*Assignment) End

func (a *Assignment) End() scanner.Position

func (*Assignment) Pos

func (a *Assignment) Pos() scanner.Position

func (*Assignment) String

func (a *Assignment) String() string

type Bool

type Bool struct {
	LiteralPos scanner.Position
	Value      bool
	Token      string
}

func (*Bool) Copy

func (x *Bool) Copy() Expression

func (*Bool) End

func (x *Bool) End() scanner.Position

func (*Bool) Eval

func (x *Bool) Eval() Expression

func (*Bool) Pos

func (x *Bool) Pos() scanner.Position

func (*Bool) String

func (x *Bool) String() string

func (*Bool) Type

func (x *Bool) Type() Type

type Comment

type Comment struct {
	Comment []string
	Slash   scanner.Position
}

func (Comment) End

func (c Comment) End() scanner.Position

func (Comment) Pos

func (c Comment) Pos() scanner.Position

func (Comment) String

func (c Comment) String() string

func (Comment) Text

func (c Comment) Text() string

Return the text of the comment with // or /* and */ stripped

type CommentGroup

type CommentGroup struct {
	Comments []*Comment
}

func (*CommentGroup) End

func (x *CommentGroup) End() scanner.Position

func (*CommentGroup) Pos

func (x *CommentGroup) Pos() scanner.Position

type Definition

type Definition interface {
	Node
	String() string
	// contains filtered or unexported methods
}

Definition is an Assignment or a Module at the top level of a Blueprints file

type Expression

type Expression interface {
	Node
	// Copy returns a copy of the Expression that will not affect the original if mutated
	Copy() Expression
	String() string
	// Type returns the underlying Type enum of the Expression if it were to be evalutated
	Type() Type
	// Eval returns an expression that is fully evaluated to a simple type (List, Map, String, or
	// Bool).  It will return the same object for every call to Eval().
	Eval() Expression
}

An Expression is a Value in a Property or Assignment. It can be a literal (String or Bool), a Map, a List, an Operator that combines two expressions of the same type, or a Variable that references and Assignment.

type File

type File struct {
	Name     string
	Defs     []Definition
	Comments []*CommentGroup
}

func Parse

func Parse(filename string, r io.Reader, scope *Scope) (file *File, errs []error)

func ParseAndEval

func ParseAndEval(filename string, r io.Reader, scope *Scope) (file *File, errs []error)

func (*File) End

func (f *File) End() scanner.Position

func (*File) Pos

func (f *File) Pos() scanner.Position

type Int64

type Int64 struct {
	LiteralPos scanner.Position
	Value      int64
	Token      string
}

func (*Int64) Copy

func (x *Int64) Copy() Expression

func (*Int64) End

func (x *Int64) End() scanner.Position

func (*Int64) Eval

func (x *Int64) Eval() Expression

func (*Int64) Pos

func (x *Int64) Pos() scanner.Position

func (*Int64) String

func (x *Int64) String() string

func (*Int64) Type

func (x *Int64) Type() Type

type List

type List struct {
	LBracePos scanner.Position
	RBracePos scanner.Position
	Values    []Expression
}

func (*List) Copy

func (x *List) Copy() Expression

func (*List) End

func (x *List) End() scanner.Position

func (*List) Eval

func (x *List) Eval() Expression

func (*List) Pos

func (x *List) Pos() scanner.Position

func (*List) String

func (x *List) String() string

func (*List) Type

func (x *List) Type() Type

type Map

type Map struct {
	LBracePos  scanner.Position
	RBracePos  scanner.Position
	Properties []*Property
}

func (*Map) Copy

func (x *Map) Copy() Expression

func (*Map) End

func (x *Map) End() scanner.Position

func (*Map) Eval

func (x *Map) Eval() Expression

func (*Map) GetProperty

func (x *Map) GetProperty(name string) (Property *Property, found bool)

GetProperty looks for a property with the given name. It resembles the bracket operator of a built-in Golang map.

func (*Map) Pos

func (x *Map) Pos() scanner.Position

func (*Map) RemoveProperty

func (x *Map) RemoveProperty(propertyName string) (removed bool)

GetProperty removes the property with the given name, if it exists.

func (*Map) String

func (x *Map) String() string

func (*Map) Type

func (x *Map) Type() Type

type Module

type Module struct {
	Type    string
	TypePos scanner.Position
	Map
}

A Module is a module definition at the top level of a Blueprints file

func (*Module) Copy

func (m *Module) Copy() *Module

func (*Module) End

func (m *Module) End() scanner.Position

func (*Module) Pos

func (m *Module) Pos() scanner.Position

func (*Module) String

func (m *Module) String() string

type Node

type Node interface {
	// Pos returns the position of the first token in the Node
	Pos() scanner.Position
	// End returns the position of the character after the last token in the Node
	End() scanner.Position
}

type NotEvaluated

type NotEvaluated struct {
	Position scanner.Position
}

func (NotEvaluated) Copy

func (n NotEvaluated) Copy() Expression

func (NotEvaluated) End

func (n NotEvaluated) End() scanner.Position

func (NotEvaluated) Eval

func (n NotEvaluated) Eval() Expression

func (NotEvaluated) Pos

func (n NotEvaluated) Pos() scanner.Position

func (NotEvaluated) String

func (n NotEvaluated) String() string

func (NotEvaluated) Type

func (n NotEvaluated) Type() Type

type Operator

type Operator struct {
	Args        [2]Expression
	Operator    rune
	OperatorPos scanner.Position
	Value       Expression
}

func (*Operator) Copy

func (x *Operator) Copy() Expression

func (*Operator) End

func (x *Operator) End() scanner.Position

func (*Operator) Eval

func (x *Operator) Eval() Expression

func (*Operator) Pos

func (x *Operator) Pos() scanner.Position

func (*Operator) String

func (x *Operator) String() string

func (*Operator) Type

func (x *Operator) Type() Type

type ParseError

type ParseError struct {
	Err error
	Pos scanner.Position
}

func (*ParseError) Error

func (e *ParseError) Error() string

type Patch

type Patch struct {
	Start, End  int
	Replacement string
}

A Patch represents a region of a text buffer to be replaced [Start, End) and its Replacement

type PatchList

type PatchList []Patch

A PatchList is a list of sorted, non-overlapping Patch objects

func (*PatchList) Add

func (list *PatchList) Add(start, end int, replacement string) error

Add adds a Patch to a PatchList. It returns a PatchOverlapError if the patch cannot be added.

func (*PatchList) Apply

func (list *PatchList) Apply(in io.ReaderAt, out io.Writer) error

Apply applies all the Patch objects in PatchList to the data from an input ReaderAt to an output Writer.

type PatchOverlapError

type PatchOverlapError error

type Property

type Property struct {
	Name     string
	NamePos  scanner.Position
	ColonPos scanner.Position
	Value    Expression
}

A Property is a name: value pair within a Map, which may be a top level Module.

func (*Property) Copy

func (p *Property) Copy() *Property

func (*Property) End

func (p *Property) End() scanner.Position

func (*Property) Pos

func (p *Property) Pos() scanner.Position

func (*Property) String

func (p *Property) String() string

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

func NewScope

func NewScope(s *Scope) *Scope

func (*Scope) Add

func (s *Scope) Add(assignment *Assignment) error

func (*Scope) Get

func (s *Scope) Get(name string) (*Assignment, bool)

func (*Scope) Remove

func (s *Scope) Remove(name string)

func (*Scope) String

func (s *Scope) String() string

type String

type String struct {
	LiteralPos scanner.Position
	Value      string
}

func (*String) Copy

func (x *String) Copy() Expression

func (*String) End

func (x *String) End() scanner.Position

func (*String) Eval

func (x *String) Eval() Expression

func (*String) Pos

func (x *String) Pos() scanner.Position

func (*String) String

func (x *String) String() string

func (*String) Type

func (x *String) Type() Type

type Type

type Type int
const (
	BoolType Type = iota + 1
	StringType
	Int64Type
	ListType
	MapType
	NotEvaluatedType
)

func (Type) String

func (t Type) String() string

type Variable

type Variable struct {
	Name    string
	NamePos scanner.Position
	Value   Expression
}

func (*Variable) Copy

func (x *Variable) Copy() Expression

func (*Variable) End

func (x *Variable) End() scanner.Position

func (*Variable) Eval

func (x *Variable) Eval() Expression

func (*Variable) Pos

func (x *Variable) Pos() scanner.Position

func (*Variable) String

func (x *Variable) String() string

func (*Variable) Type

func (x *Variable) Type() Type

Jump to

Keyboard shortcuts

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