ast

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Overview

Package ast contains the abstract syntax tree for the validator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltInFunctionName

func BuiltInFunctionName(symbol string) string

BuiltInFunctionName returns the full function name for the given builtin symbol. The function returns an empty string when the symbol is not a known builtin symbol.

func FunctionNameToBuiltIn

func FunctionNameToBuiltIn(symbol string) func(*Expr) *Expr

FunctionNameToBuiltIn returns the builtin constructor for a given function name. If a symbol does not exist, nil is returned.

func HasNot

func HasNot(g *Grammar) bool

func Strip

func Strip(slit string, sub string) []byte

Strip is a parser utility function that removes all versions of the given sub string from the slit string and also removes possible surrounding parentheses.

func ToFloat64

func ToFloat64(tok []byte) *float64

ToFloat64 is a parser utility function that returns a pointer to a parsed an float64 or panics.

func ToInt64

func ToInt64(tok []byte) *int64

ToInt64 is a parser utility function that returns a pointer to a parsed an int64 or panics.

func ToString

func ToString(s1 string) string

ToString unquotes a quoted string or returns the original string.

func ToUint64

func ToUint64(tok []byte) *uint64

ToUint64 is a parser utility function that returns a pointer to a parsed an uint64 or panics.

Types

type And

type And struct {
	OpenParen    *Keyword `json:"OpenParen,omitempty"`
	LeftPattern  *Pattern `json:"LeftPattern,omitempty"`
	Ampersand    *Keyword `json:"Ampersand,omitempty"`
	RightPattern *Pattern `json:"RightPattern,omitempty"`
	CloseParen   *Keyword `json:"CloseParen,omitempty"`
}

And is the ast node for the And pattern.

func (*And) GetLeftPattern

func (m *And) GetLeftPattern() *Pattern

func (*And) GetRightPattern

func (m *And) GetRightPattern() *Pattern

func (*And) String

func (this *And) String() string

String returns the validator string representation of the And instance.

func (*And) Walk

func (this *And) Walk(v Visitor)

Walk visits the And pattern and its child patterns.

type AnyName

type AnyName struct {
	Underscore *Keyword `json:"Underscore,omitempty"`
}

AnyName is a name expression that represents any name.

func (*AnyName) String

func (this *AnyName) String() string

String returns the validator string representation of the AnyName instance.

func (*AnyName) Walk

func (this *AnyName) Walk(v Visitor)

Walk visits AnyName.

type AnyNameExcept

type AnyNameExcept struct {
	Exclamation *Keyword  `json:"Exclamation,omitempty"`
	OpenParen   *Keyword  `json:"OpenParen,omitempty"`
	Except      *NameExpr `json:"Except,omitempty"`
	CloseParen  *Keyword  `json:"CloseParen,omitempty"`
}

AnyNameExpr is a name expression that represents any name except the specified name expression.

func (*AnyNameExcept) GetExcept

func (m *AnyNameExcept) GetExcept() *NameExpr

func (*AnyNameExcept) String

func (this *AnyNameExcept) String() string

String returns the validator string representation of the AnyNameExcept instance.

func (*AnyNameExcept) Walk

func (this *AnyNameExcept) Walk(v Visitor)

Walk visits AnyNameExcept and its NameExpr.

type BuiltIn

type BuiltIn struct {
	Symbol *Keyword `json:"Symbol,omitempty"`
	Expr   *Expr    `json:"Expr,omitempty"`
}

BuiltIn is an expression that represents a builtin function. This is represented by a symbol and an expression.

func (*BuiltIn) GetExpr

func (m *BuiltIn) GetExpr() *Expr

func (*BuiltIn) GetSymbol

func (m *BuiltIn) GetSymbol() *Keyword

func (*BuiltIn) String

func (this *BuiltIn) String() string

String returns the validator string representation of the BuiltIn instance.

func (*BuiltIn) Walk

func (this *BuiltIn) Walk(v Visitor)

Walk visits BuiltIn and its Expr.

type Comment

type Comment string

Comment represents a validator comment as a string

func (Comment) GetContent

func (this Comment) GetContent() string

GetContent returns the content of the comment excluding the // or /* */

type Concat

type Concat struct {
	OpenBracket  *Keyword `json:"OpenBracket,omitempty"`
	LeftPattern  *Pattern `json:"LeftPattern,omitempty"`
	Comma        *Keyword `json:"Comma,omitempty"`
	RightPattern *Pattern `json:"RightPattern,omitempty"`
	ExtraComma   *Keyword `json:"ExtraComma,omitempty"`
	CloseBracket *Keyword `json:"CloseBracket,omitempty"`
}

Concat is the ast node for the Concat pattern.

func (*Concat) GetLeftPattern

func (m *Concat) GetLeftPattern() *Pattern

func (*Concat) GetRightPattern

func (m *Concat) GetRightPattern() *Pattern

func (*Concat) String

func (this *Concat) String() string

String returns the validator string representation of the Concat instance.

func (*Concat) Walk

func (this *Concat) Walk(v Visitor)

Walk visits the Concat pattern and its child patterns.

type Contains

type Contains struct {
	Dot     *Keyword `json:"Dot,omitempty"`
	Pattern *Pattern `json:"Pattern,omitempty"`
}

Contains is the ast node for the Contains pattern.

func (*Contains) GetPattern

func (m *Contains) GetPattern() *Pattern

func (*Contains) String

func (this *Contains) String() string

String returns the validator string representation of the Contains instance.

func (*Contains) Walk

func (this *Contains) Walk(v Visitor)

Walk visits the Contains pattern and its pattern.

type Empty

type Empty struct {
	Empty *Keyword `json:"Empty,omitempty"`
}

Empty is the ast node for the Empty pattern.

func (*Empty) String

func (this *Empty) String() string

String returns the validator string representation of the Empty instance.

func (*Empty) Walk

func (this *Empty) Walk(v Visitor)

Walk visits the Empty pattern.

type Expr

type Expr struct {
	RightArrow *Keyword  `json:"RightArrow,omitempty"`
	Comma      *Keyword  `json:"Comma,omitempty"`
	Terminal   *Terminal `json:"Terminal,omitempty"`
	List       *List     `json:"List,omitempty"`
	Function   *Function `json:"Function,omitempty"`
	BuiltIn    *BuiltIn  `json:"BuiltIn,omitempty"`
}

Expr is a union of all possible expression types, terminal, list, function and builtin function.

func NewBoolConst added in v0.5.2

func NewBoolConst(b bool) *Expr

NewBoolConst returns a new terminal expression containing the given bool value.

uint(i)

func NewBoolList

func NewBoolList(elems ...*Expr) *Expr

NewBoolList returns a list of expressions, each of type bool.

[]bool{elems}

func NewBoolVar

func NewBoolVar() *Expr

NewBoolVar returns a new variable expression of type bool

$bool

func NewBytesConst

func NewBytesConst(buf []byte) *Expr

NewBytesConst returns a new terminal expression containing the given bytes value.

[]byte(fmt.Sprintf("%#v", buf))

func NewBytesList

func NewBytesList(elems ...*Expr) *Expr

NewBytesList returns a list of expressions, each of type []byte.

[][]byte{elems}

func NewBytesVar

func NewBytesVar() *Expr

NewBytesVar returns a new variable expression of type []byte

$[]byte

func NewDoubleConst

func NewDoubleConst(d float64) *Expr

NewDoubleConst returns a new terminal expression containing the given double value.

double(d)

func NewDoubleList

func NewDoubleList(elems ...*Expr) *Expr

NewDoubleList returns a list of expressions, each of type double.

[]double{elems}

func NewDoubleVar

func NewDoubleVar() *Expr

NewDoubleVar returns a new variable expression of type double

$double

func NewEqual

func NewEqual(e *Expr) *Expr

NewEqual returns an builtin equal expression.

== e

func NewFalse

func NewFalse() *Expr

NewFalse returns a new terminal expression containing a false value.

false

func NewFunction

func NewFunction(name string, params ...*Expr) *Expr

NewFunction returns a function expression given a name and a list of parameters.

->name(param1, param2, ...)

This function should be the top level function and not a nested function. If the parameters don't have populated Comma fields, this function will add them. If a parameter has a populared RightArrow field, the contents of the RightArrow field is thrown away.

func NewGreaterEqual

func NewGreaterEqual(e *Expr) *Expr

NewGreaterEqual returns an builtin greater than or equal expression.

>= e

func NewGreaterThan

func NewGreaterThan(e *Expr) *Expr

NewGreaterThan returns an builtin greater than expression.

> e

func NewHasElem

func NewHasElem(e *Expr) *Expr

NewHasElem returns an builtin contains expression.

*= e

func NewHasPrefix

func NewHasPrefix(e *Expr) *Expr

NewHasPrefix returns an builtin has prefix expression.

^= e

func NewHasSuffix

func NewHasSuffix(e *Expr) *Expr

NewHasSuffix returns an builtin has suffix expression.

$= e

func NewIntConst

func NewIntConst(i int64) *Expr

NewIntConst returns a new terminal expression containing the given int value.

int(i)

func NewIntList

func NewIntList(elems ...*Expr) *Expr

NewIntList returns a list of expressions, each of type int.

[]int{elems}

func NewIntVar

func NewIntVar() *Expr

NewIntVar returns a new variable expression of type int

$int

func NewLessEqual

func NewLessEqual(e *Expr) *Expr

NewLessEqual returns an builtin less than or equal expression.

<= e

func NewLessThan

func NewLessThan(e *Expr) *Expr

NewLessThan returns an builtin less than expression.

< e

func NewList

func NewList(typ types.Type, elems ...*Expr) *Expr

NewList returns a typed list of expressions.

[]typ{elems}

func NewNestedFunction

func NewNestedFunction(name string, params ...*Expr) *Expr

NewNestedFunction returns a function expression given a name and a list of parameters.

name(param1, param2, ...)

If the parameters don't have populated Comma fields, this function will add them. If a parameter has a populared RightArrow field, the contents of the RightArrow field is thrown away.

func NewNotEqual

func NewNotEqual(e *Expr) *Expr

NewNotEqual returns an builtin not equal expression.

!= e

func NewRegex

func NewRegex(e *Expr) *Expr

NewRegex returns an builtin regular expression.

~= e

func NewStringConst

func NewStringConst(s string) *Expr

NewStringConst returns a new terminal expression containing the given string value.

"s"
`s`

func NewStringList

func NewStringList(elems ...*Expr) *Expr

NewStringList returns a list of expressions, each of type string.

[]string{elems}

func NewStringVar

func NewStringVar() *Expr

NewStringVar returns a new variable expression of type string

$string

func NewTrue

func NewTrue() *Expr

NewTrue returns a new terminal expression containing a true value.

true

func NewType

func NewType(e *Expr) *Expr

NewType returns an builtin type expression.

:: e

func NewUintConst

func NewUintConst(i uint64) *Expr

NewUintConst returns a new terminal expression containing the given uint value.

uint(i)

func NewUintList

func NewUintList(elems ...*Expr) *Expr

NewUintList returns a list of expressions, each of type uint.

[]uint{elems}

func NewUintVar

func NewUintVar() *Expr

NewUintVar returns a new variable expression of type uint

$uint

func NewVar

func NewVar(typ types.Type) *Expr

NewVar return a variable expression given a type.

$typ

func SetExprComma

func SetExprComma(e interface{}, c interface{}) *Expr

SetExpComma is a parser utility function that takes an expression and a comma Keyword and places the comma inside the returned Expr.

func SetRightArrow

func SetRightArrow(expr interface{}, rightArrow interface{}) *Expr

SetRightArrow is a parser utitliy function that takes an Expression and a RightArrow and places the RightArrow inside the returned Expression.

func (*Expr) Clone

func (this *Expr) Clone() *Expr

Clone returns a copy of the Expr struct

func (*Expr) Compare added in v0.5.2

func (this *Expr) Compare(that *Expr) int

func (*Expr) GetBuiltIn

func (m *Expr) GetBuiltIn() *BuiltIn

func (*Expr) GetFunction

func (m *Expr) GetFunction() *Function

func (*Expr) GetList

func (m *Expr) GetList() *List

func (*Expr) GetTerminal

func (m *Expr) GetTerminal() *Terminal

func (*Expr) GoString

func (this *Expr) GoString() string

GoString returns a go string representing the Expr

func (*Expr) HasVar

func (this *Expr) HasVar() bool

HasVar returns whether there exists a variable somewhere in the expression tree. This function is executed recursively.

func (*Expr) String

func (this *Expr) String() string

String returns the validator string representation of the Expr instance.

func (*Expr) Walk

func (this *Expr) Walk(v Visitor)

Walk visits every possible field that is not nil and not of type Keyword or Space.

type Function

type Function struct {
	Before     *Space   `json:"Before,omitempty"`
	Name       string   `json:"Name"`
	OpenParen  *Keyword `json:"OpenParen,omitempty"`
	Params     []*Expr  `json:"Params,omitempty"`
	CloseParen *Keyword `json:"CloseParen,omitempty"`
}

Function is an expression that represents a function expression, which contains a function name and a list parameters.

func (*Function) GetName

func (m *Function) GetName() string

func (*Function) GetParams

func (m *Function) GetParams() []*Expr

func (*Function) HasVar

func (this *Function) HasVar() bool

HasVar returns whether there exists a varaible somewhere in the function parameters. This function is executed recursively.

func (*Function) String

func (this *Function) String() string

String returns the validator string representation of the Function instance.

func (*Function) Walk

func (this *Function) Walk(v Visitor)

Walk visits Function and every parameter.

type Grammar

type Grammar struct {
	TopPattern   *Pattern       `json:"TopPattern,omitempty"`
	PatternDecls []*PatternDecl `json:"PatternDecls,omitempty"`
	After        *Space         `json:"After,omitempty"`
}

Grammar is the ast node representing the whole grammar.

func NewGrammar

func NewGrammar(m map[string]*Pattern) *Grammar

NewGrammar converts a refenence lookup map into a Grammar.

func (*Grammar) AddRef

func (this *Grammar) AddRef(name string, p *Pattern) *Grammar

AddRef adds a Reference to a Grammar.

func (*Grammar) Clone

func (this *Grammar) Clone() *Grammar

Clone returns a copy of the Grammar struct

func (*Grammar) Equal

func (this *Grammar) Equal(that *Grammar) bool

func (*Grammar) GetPatternDecls

func (m *Grammar) GetPatternDecls() []*PatternDecl

func (*Grammar) GetTopPattern

func (m *Grammar) GetTopPattern() *Pattern

func (*Grammar) GoString

func (this *Grammar) GoString() string

GoString returns a go string representing the Grammar

func (*Grammar) String

func (this *Grammar) String() string

String returns the validator string representation of the Grammar instance.

func (*Grammar) Walk

func (this *Grammar) Walk(v Visitor)

Walk visits the Grammar instance and all its possible child pattern and all its pattern declarations.

type Interleave

type Interleave struct {
	OpenCurly      *Keyword `json:"OpenCurly,omitempty"`
	LeftPattern    *Pattern `json:"LeftPattern,omitempty"`
	SemiColon      *Keyword `json:"SemiColon,omitempty"`
	RightPattern   *Pattern `json:"RightPattern,omitempty"`
	ExtraSemiColon *Keyword `json:"ExtraSemiColon,omitempty"`
	CloseCurly     *Keyword `json:"CloseCurly,omitempty"`
}

Interleave is the ast node for the Interleave pattern.

func (*Interleave) GetLeftPattern

func (m *Interleave) GetLeftPattern() *Pattern

func (*Interleave) GetRightPattern

func (m *Interleave) GetRightPattern() *Pattern

func (*Interleave) String

func (this *Interleave) String() string

String returns the validator string representation of the Interleave instance.

func (*Interleave) Walk

func (this *Interleave) Walk(v Visitor)

Walk visits the Interleave pattern and its child patterns.

type Keyword

type Keyword struct {
	Before *Space `json:"Before,omitempty"`
	Value  string `json:"Value"`
}

Keyword represents any possible keyword.

func NewKeyword

func NewKeyword(space interface{}, v interface{}) *Keyword

NewKeyword is a parser utility function that returns a Keyword given a space and a token.

func (*Keyword) GetValue

func (m *Keyword) GetValue() string

func (*Keyword) String

func (this *Keyword) String() string

String returns the validator string representation of the Keyword instance.

type LeafNode

type LeafNode struct {
	Expr *Expr `json:"Expr,omitempty"`
}

LeafNode is the ast node for the LeafNode pattern.

func (*LeafNode) GetExpr

func (m *LeafNode) GetExpr() *Expr

func (*LeafNode) String

func (this *LeafNode) String() string

String returns the validator string representation of the LeafNode instance.

func (*LeafNode) Walk

func (this *LeafNode) Walk(v Visitor)

Walk visits the LeafNode pattern.

type List

type List struct {
	Before     *Space     `json:"Before,omitempty"`
	Type       types.Type `json:"Type"`
	OpenCurly  *Keyword   `json:"OpenCurly,omitempty"`
	Elems      []*Expr    `json:"Elems,omitempty"`
	CloseCurly *Keyword   `json:"CloseCurly,omitempty"`
}

List is an expression that represents a typed list of expressions.

func (*List) GetElems

func (m *List) GetElems() []*Expr

func (*List) GetType

func (m *List) GetType() types.Type

func (*List) HasVar

func (this *List) HasVar() bool

HasVar returns whether there exists a variable somewhere in the typed list. This function is executed recursively.

func (*List) String

func (this *List) String() string

String returns the validator string representation of the List instance.

func (*List) Walk

func (this *List) Walk(v Visitor)

Walk visits List and each element in the list.

type Name

type Name struct {
	Before      *Space   `json:"Before,omitempty"`
	DoubleValue *float64 `json:"DoubleValue,omitempty"`
	IntValue    *int64   `json:"IntValue,omitempty"`
	UintValue   *uint64  `json:"UintValue,omitempty"`
	BoolValue   *bool    `json:"BoolValue,omitempty"`
	StringValue *string  `json:"StringValue,omitempty"`
	BytesValue  []byte   `json:"BytesValue,omitempty"`
}

Name is a name expression and represents a union of all possible name type values.

func (*Name) GetBoolValue

func (m *Name) GetBoolValue() bool

func (*Name) GetBytesValue

func (m *Name) GetBytesValue() []byte

func (*Name) GetDoubleValue

func (m *Name) GetDoubleValue() float64

func (*Name) GetIntValue

func (m *Name) GetIntValue() int64

func (*Name) GetStringValue

func (m *Name) GetStringValue() string

func (*Name) GetUintValue

func (m *Name) GetUintValue() uint64

func (*Name) String

func (this *Name) String() string

String returns the validator string representation of the Name instance.

func (*Name) Walk

func (this *Name) Walk(v Visitor)

Walk visits Name.

type NameChoice

type NameChoice struct {
	OpenParen  *Keyword  `json:"OpenParen,omitempty"`
	Left       *NameExpr `json:"Left,omitempty"`
	Pipe       *Keyword  `json:"Pipe,omitempty"`
	Right      *NameExpr `json:"Right,omitempty"`
	CloseParen *Keyword  `json:"CloseParen,omitempty"`
}

NameChoice is a name expression that represents a choice between two possible name expressions.

func (*NameChoice) GetLeft

func (m *NameChoice) GetLeft() *NameExpr

func (*NameChoice) GetRight

func (m *NameChoice) GetRight() *NameExpr

func (*NameChoice) String

func (this *NameChoice) String() string

String returns the validator string representation of the NameChoice instance.

func (*NameChoice) Walk

func (this *NameChoice) Walk(v Visitor)

Walk visits NameChoice and its NameExpr types.

type NameExpr

type NameExpr struct {
	Name          *Name          `json:"Name,omitempty"`
	AnyName       *AnyName       `json:"AnyName,omitempty"`
	AnyNameExcept *AnyNameExcept `json:"AnyNameExcept,omitempty"`
	NameChoice    *NameChoice    `json:"NameChoice,omitempty"`
}

NameExpr is a special type of expression for field names that contains a union of all the possible name expressions.

func NewAnyName

func NewAnyName() *NameExpr

NewAnyName returns a name expression that represents the any name expression.

_

func NewAnyNameExcept

func NewAnyNameExcept(name *NameExpr) *NameExpr

NewAnyNameExcept returns a name expression that represents any name except the given name expression.

!(name)

func NewBoolName

func NewBoolName(name bool) *NameExpr

NewBoolName returns a name expression containing the given bool value.

bool(name)

func NewBytesName

func NewBytesName(name []byte) *NameExpr

NewBytesName returns a name expression containing the given []byte value.

[]byte(name)

func NewDoubleName

func NewDoubleName(name float64) *NameExpr

NewDoubleName returns a name expression containing the given double value.

double(name)

func NewIntName

func NewIntName(name int64) *NameExpr

NewIntName returns a name expression containing the given int value.

int(name)

func NewNameChoice

func NewNameChoice(names ...*NameExpr) *NameExpr

NewNameChoice returns a name expression which represents of choice of the list of given name expressions. If the number of names provided is:

0, nil is returned;

1, the input name is returned;

2, the ored names is returned;

(names[0] | names[1])

> 2, the left curried ored names is returned.

(names[0] | (names[1] | (...)))

func NewSDTName

func NewSDTName(space *Space, term *Terminal) *NameExpr

NewSDTName is a parser utility function that returns a NameExpr given a white space and a terminal value expression.

func NewStringName

func NewStringName(name string) *NameExpr

NewStringName returns a name expression containing the given string value.

string(name)

func NewUintName

func NewUintName(name uint64) *NameExpr

NewUintName returns a name expression containing the given uint value.

uint(name)

func (*NameExpr) Compare

func (this *NameExpr) Compare(that *NameExpr) int

func (*NameExpr) Equal

func (this *NameExpr) Equal(that *NameExpr) bool

func (*NameExpr) GetAnyName

func (m *NameExpr) GetAnyName() *AnyName

func (*NameExpr) GetAnyNameExcept

func (m *NameExpr) GetAnyNameExcept() *AnyNameExcept

func (*NameExpr) GetName

func (m *NameExpr) GetName() *Name

func (*NameExpr) GetNameChoice

func (m *NameExpr) GetNameChoice() *NameChoice

func (*NameExpr) GetValue

func (this *NameExpr) GetValue() interface{}

func (*NameExpr) String

func (this *NameExpr) String() string

String returns the validator string representation of the NameExpr instance.

func (*NameExpr) Walk

func (this *NameExpr) Walk(v Visitor)

Walk visits every possible field that is not nil and not of type Keyword or Space.

type Not

type Not struct {
	Exclamation *Keyword `json:"Exclamation,omitempty"`
	OpenParen   *Keyword `json:"OpenParen,omitempty"`
	Pattern     *Pattern `json:"Pattern,omitempty"`
	CloseParen  *Keyword `json:"CloseParen,omitempty"`
}

Not is the ast node for the Not pattern.

func (*Not) GetPattern

func (m *Not) GetPattern() *Pattern

func (*Not) String

func (this *Not) String() string

String returns the validator string representation of the Not instance.

func (*Not) Walk

func (this *Not) Walk(v Visitor)

Walk visits the Not pattern and its pattern.

type Optional

type Optional struct {
	OpenParen    *Keyword `json:"OpenParen,omitempty"`
	Pattern      *Pattern `json:"Pattern,omitempty"`
	CloseParen   *Keyword `json:"CloseParen,omitempty"`
	QuestionMark *Keyword `json:"QuestionMark,omitempty"`
}

Optional is the ast node for the Optional pattern.

func (*Optional) GetPattern

func (m *Optional) GetPattern() *Pattern

func (*Optional) String

func (this *Optional) String() string

String returns the validator string representation of the Optional instance.

func (*Optional) Walk

func (this *Optional) Walk(v Visitor)

Walk visits the Optional pattern and its pattern.

type Or

type Or struct {
	OpenParen    *Keyword `json:"OpenParen,omitempty"`
	LeftPattern  *Pattern `json:"LeftPattern,omitempty"`
	Pipe         *Keyword `json:"Pipe,omitempty"`
	RightPattern *Pattern `json:"RightPattern,omitempty"`
	CloseParen   *Keyword `json:"CloseParen,omitempty"`
}

Or is the ast node for the Or pattern.

func (*Or) GetLeftPattern

func (m *Or) GetLeftPattern() *Pattern

func (*Or) GetRightPattern

func (m *Or) GetRightPattern() *Pattern

func (*Or) String

func (this *Or) String() string

String returns the validator string representation of the Or instance.

func (*Or) Walk

func (this *Or) Walk(v Visitor)

Walk visits the Or pattern and its child patterns.

type Pattern

type Pattern struct {
	Empty      *Empty      `json:"Empty,omitempty"`
	TreeNode   *TreeNode   `json:"TreeNode,omitempty"`
	LeafNode   *LeafNode   `json:"LeafNode,omitempty"`
	Concat     *Concat     `json:"Concat,omitempty"`
	Or         *Or         `json:"Or,omitempty"`
	And        *And        `json:"And,omitempty"`
	ZeroOrMore *ZeroOrMore `json:"ZeroOrMore,omitempty"`
	Reference  *Reference  `json:"Reference,omitempty"`
	Not        *Not        `json:"Not,omitempty"`
	ZAny       *ZAny       `json:"ZAny,omitempty"`
	Contains   *Contains   `json:"Contains,omitempty"`
	Optional   *Optional   `json:"Optional,omitempty"`
	Interleave *Interleave `json:"Interleave,omitempty"`
}

Pattern is the ast node for the union of all possible patterns.

func NewAnd

func NewAnd(patterns ...*Pattern) *Pattern

NewAnd returns a new And pattern. If the number of patterns provided is:

0, nil is returned;

1, the input pattern is returned;

2, the anded pattern is returned;

(pattern[0] & pattern[1])

> 2, the left curried anded pattern is returned.

(pattern[0] & (pattern[1] & (...)))

func NewConcat

func NewConcat(patterns ...*Pattern) *Pattern

NewConcat returns a new Concat pattern. If the number of patterns provided is:

0, nil is returned;

1, the input pattern is returned;

2, the concatenated pattern is returned;

[pattern[0], pattern[1]]

> 2, the left curried concatenated pattern is returned.

[pattern[0], [pattern[1], [...]]]

func NewContains

func NewContains(pattern *Pattern) *Pattern

NewContains returns a new Contains pattern.

.pattern

func NewEmpty

func NewEmpty() *Pattern

NewEmpty returns a new empty pattern.

<empty>

func NewInterleave

func NewInterleave(patterns ...*Pattern) *Pattern

NewInterleave returns a new Interleave pattern. If the number of patterns provided is:

0, nil is returned;

1, the input pattern is returned;

2, the interleaved pattern is returned;

{pattern[0]; pattern[1]}

> 2, the left curried interleaved pattern is returned.

{pattern[0]; {pattern[1]; {...}}}

func NewLeafNode

func NewLeafNode(e *Expr) *Pattern

NewLeafNode returns a new LeafNode pattern.

func NewNot

func NewNot(pattern *Pattern) *Pattern

NewNot returns a new Not pattern.

!(pattern)

func NewOptional

func NewOptional(pattern *Pattern) *Pattern

NewOptional returns a new Optional pattern.

(pattern)?

func NewOr

func NewOr(patterns ...*Pattern) *Pattern

NewOr returns a new Or pattern. If the number of patterns provided is:

0, nil is returned;

1, the input pattern is returned;

2, the ored pattern is returned;

(pattern[0] | pattern[1])

> 2, the left curried ored pattern is returned.

(pattern[0] | (pattern[1] | (...)))

func NewReference

func NewReference(name string) *Pattern

NewReference returns a new Reference pattern.

@name

func NewTreeNode

func NewTreeNode(name *NameExpr, pattern *Pattern) *Pattern

NewTreeNode returns a new TreeNode pattern. Depending on what is appropriate the validator string could be one of the following:

name: pattern
name pattern

func NewZAny

func NewZAny() *Pattern

NewZAny returns a new ZAny pattern.

*

func NewZeroOrMore

func NewZeroOrMore(pattern *Pattern) *Pattern

NewZeroOrMore returns a new ZeroOrMore pattern.

(pattern)*

func (*Pattern) Clone

func (this *Pattern) Clone() *Pattern

Clone returns a copy of the Pattern struct

func (*Pattern) Compare

func (this *Pattern) Compare(that *Pattern) int

func (*Pattern) Equal

func (this *Pattern) Equal(that *Pattern) bool

func (*Pattern) GetAnd

func (m *Pattern) GetAnd() *And

func (*Pattern) GetConcat

func (m *Pattern) GetConcat() *Concat

func (*Pattern) GetContains

func (m *Pattern) GetContains() *Contains

func (*Pattern) GetEmpty

func (m *Pattern) GetEmpty() *Empty

func (*Pattern) GetInterleave

func (m *Pattern) GetInterleave() *Interleave

func (*Pattern) GetLeafNode

func (m *Pattern) GetLeafNode() *LeafNode

func (*Pattern) GetNot

func (m *Pattern) GetNot() *Not

func (*Pattern) GetOptional

func (m *Pattern) GetOptional() *Optional

func (*Pattern) GetOr

func (m *Pattern) GetOr() *Or

func (*Pattern) GetReference

func (m *Pattern) GetReference() *Reference

func (*Pattern) GetTreeNode

func (m *Pattern) GetTreeNode() *TreeNode

func (*Pattern) GetValue

func (this *Pattern) GetValue() interface{}

func (*Pattern) GetZAny

func (m *Pattern) GetZAny() *ZAny

func (*Pattern) GetZeroOrMore

func (m *Pattern) GetZeroOrMore() *ZeroOrMore

func (*Pattern) GoString

func (this *Pattern) GoString() string

GoString returns a go string representing the Pattern

func (*Pattern) Grammar

func (this *Pattern) Grammar() *Grammar

Grammar turns one Pattern into a Grammar.

func (*Pattern) Hash

func (p *Pattern) Hash() uint64

func (*Pattern) String

func (this *Pattern) String() string

String returns the validator string representation of the Pattern instance.

func (*Pattern) Walk

func (this *Pattern) Walk(v Visitor)

Walk visits the Pattern instance, its non nil patterns.

type PatternDecl

type PatternDecl struct {
	Hash    *Keyword `json:"Hash,omitempty"`
	Before  *Space   `json:"Before,omitempty"`
	Name    string   `json:"Name"`
	Eq      *Keyword `json:"Eq,omitempty"`
	Pattern *Pattern `json:"Pattern,omitempty"`
}

PatternDecl is the ast node for the declaration of a pattern.

func NewPatternDecl

func NewPatternDecl(name string, pattern *Pattern) *PatternDecl

NewPatternDecl creates a new pattern declaration.

#name = pattern

func (*PatternDecl) GetHash

func (m *PatternDecl) GetHash() *Keyword

func (*PatternDecl) GetName

func (m *PatternDecl) GetName() string

func (*PatternDecl) GetPattern

func (m *PatternDecl) GetPattern() *Pattern

func (*PatternDecl) String

func (this *PatternDecl) String() string

String returns the validator string representation of the PatternDecl instance.

func (*PatternDecl) Walk

func (this *PatternDecl) Walk(v Visitor)

Walk visits the PatternDecl instance and its child pattern.

type RefLookup

type RefLookup map[string]*Pattern

RefLookup represents a validator grammar as a map of references.

func NewRefLookup

func NewRefLookup(g *Grammar) RefLookup

NewRefLookup converts a grammar into a reference lookup map.

func (RefLookup) Clone

func (this RefLookup) Clone() RefLookup

Clone returns a copy of the RefLookup map

func (RefLookup) GoString

func (this RefLookup) GoString() string

GoString returns a go string representing the RefLookup

type Reference

type Reference struct {
	At   *Keyword `json:"At,omitempty"`
	Name string   `json:"Name"`
}

Reference is the ast node for the Reference pattern.

func (*Reference) GetName

func (m *Reference) GetName() string

func (*Reference) String

func (this *Reference) String() string

String returns the validator string representation of the Reference instance.

func (*Reference) Walk

func (this *Reference) Walk(v Visitor)

Walk visits the Reference pattern.

type Space

type Space struct {
	Space []string `json:"Space,omitempty"`
}

Space represents a comment or white space.

func AppendSpace

func AppendSpace(ss interface{}, s string) *Space

NewAppendSpace is a parser utility function that returns a Space by append the given string to the given Space's Space field, which is a list of strings.

func NewSpace

func NewSpace(s interface{}) *Space

NewSpace is a parser utility function that returns a Space given a token

func (*Space) GetAttachedComment

func (this *Space) GetAttachedComment() Comment

GetAttachedComment returns the last comment in the whitespace that does not have a newline at the end of the comment. If there is a newline at the end of the comment, this function returns an empty Comment.

func (*Space) GetComments

func (this *Space) GetComments() []Comment

GetComments returns a list of comments contained in the white space.

func (*Space) HasAttachedComment

func (this *Space) HasAttachedComment() bool

HasAttachedComment returns whether the white space has any attached comments. An attached comment is one that does not contain a newline at the end of the white space.

func (*Space) HasComment

func (this *Space) HasComment() bool

HasComment returns whether the white space contains a comment.

func (*Space) String

func (this *Space) String() string

String returns the validator string representation of the Space instance.

type Terminal

type Terminal struct {
	Before      *Space    `json:"Before,omitempty"`
	DoubleValue *float64  `json:"DoubleValue,omitempty"`
	IntValue    *int64    `json:"IntValue,omitempty"`
	UintValue   *uint64   `json:"UintValue,omitempty"`
	BoolValue   *bool     `json:"BoolValue,omitempty"`
	StringValue *string   `json:"StringValue,omitempty"`
	BytesValue  []byte    `json:"BytesValue,omitempty"`
	Variable    *Variable `json:"Variable,omitempty"`
}

Terminal is an expression that represents a literal value or variable.

func NewBoolTerminal

func NewBoolTerminal(v interface{}) *Terminal

NewBoolTerminal is a parser utility function that returns a Terminal of type bool given a bool.

func NewBytesTerminal

func NewBytesTerminal(stringLit string) (*Terminal, error)

NewBytesTerminal is a parser utility function that parses the []byte value out of the input string and returns a Terminal of type []byte.

func NewDoubleTerminal

func NewDoubleTerminal(slit string) (*Terminal, error)

NewDoubleTerminal is a parser utility function that parses the double value out of the input string and returns a Terminal of type double.

func NewIntTerminal

func NewIntTerminal(slit string) (*Terminal, error)

NewIntTerminal is a parser utility function that parses the int value out of the input string and returns a Terminal of type int.

func NewStringTerminal

func NewStringTerminal(slit string) (*Terminal, error)

NewStringTerminal is a parser utility function that returns a Terminal of type string given a string literal. The input string is also unquoted.

func NewUintTerminal

func NewUintTerminal(slit string) (*Terminal, error)

NewUintTerminal is a parser utility function that parses the uint value out of the input string and returns a Terminal of type uint.

func NewVariableTerminal

func NewVariableTerminal(typ types.Type) (*Terminal, error)

NewVariableTerminal is a parser utility function that returns a Terminal given a type.

func SetTerminalSpace

func SetTerminalSpace(term interface{}, s interface{}) *Terminal

SetTerminalSpace is a parser utility function that takes a Terminal and a Space and places the Space inside the returned Terminal.

func (*Terminal) Compare

func (this *Terminal) Compare(that *Terminal) int

func (*Terminal) Equal

func (this *Terminal) Equal(that *Terminal) bool

func (*Terminal) GetBoolValue

func (m *Terminal) GetBoolValue() bool

func (*Terminal) GetBytesValue

func (m *Terminal) GetBytesValue() []byte

func (*Terminal) GetDoubleValue

func (m *Terminal) GetDoubleValue() float64

func (*Terminal) GetIntValue

func (m *Terminal) GetIntValue() int64

func (*Terminal) GetStringValue

func (m *Terminal) GetStringValue() string

func (*Terminal) GetUintValue

func (m *Terminal) GetUintValue() uint64

func (*Terminal) GetVariable

func (m *Terminal) GetVariable() *Variable

func (*Terminal) String

func (this *Terminal) String() string

String returns the validator string representation of the Terminal instance.

func (*Terminal) Walk

func (this *Terminal) Walk(v Visitor)

Walk visits Terminal and its possible Variable.

type TreeNode

type TreeNode struct {
	Name    *NameExpr `json:"Name,omitempty"`
	Colon   *Keyword  `json:"Colon,omitempty"`
	Pattern *Pattern  `json:"Pattern,omitempty"`
}

TreeNode is the ast node for the TreeNode pattern.

func (*TreeNode) GetName

func (m *TreeNode) GetName() *NameExpr

func (*TreeNode) GetPattern

func (m *TreeNode) GetPattern() *Pattern

func (*TreeNode) String

func (this *TreeNode) String() string

String returns the validator string representation of the TreeNode instance.

func (*TreeNode) Walk

func (this *TreeNode) Walk(v Visitor)

Walk visits the TreeNode pattern, its name and its pattern.

type Variable

type Variable struct {
	Type types.Type `json:"Type"`
}

Variable is a terminal.

func (*Variable) GetType

func (m *Variable) GetType() types.Type

func (*Variable) String

func (this *Variable) String() string

String returns the validator string representation of the Variable instance.

func (*Variable) Walk

func (this *Variable) Walk(v Visitor)

Walk visits Variable.

type Visitor

type Visitor interface {
	//Visit takes in an ast type and should return another type that implementes the Visitor interface.
	Visit(node interface{}) interface{}
}

Visitor is used to do a top down walk through the expression tree using the Walk methods.

type ZAny

type ZAny struct {
	Star *Keyword `json:"Star,omitempty"`
}

ZAny is the ast node for the ZAny pattern.

func (*ZAny) String

func (this *ZAny) String() string

String returns the validator string representation of the ZAny instance.

func (*ZAny) Walk

func (this *ZAny) Walk(v Visitor)

Walk visits the ZAny pattern.

type ZeroOrMore

type ZeroOrMore struct {
	OpenParen  *Keyword `json:"OpenParen,omitempty"`
	Pattern    *Pattern `json:"Pattern,omitempty"`
	CloseParen *Keyword `json:"CloseParen,omitempty"`
	Star       *Keyword `json:"Star,omitempty"`
}

ZeroOrMore is the ast node for the ZeroOrMore pattern.

func (*ZeroOrMore) GetPattern

func (m *ZeroOrMore) GetPattern() *Pattern

func (*ZeroOrMore) String

func (this *ZeroOrMore) String() string

String returns the validator string representation of the ZeroOrMore instance.

func (*ZeroOrMore) Walk

func (this *ZeroOrMore) Walk(v Visitor)

Walk visits the ZeroOrMore pattern and its pattern.

Jump to

Keyboard shortcuts

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