Documentation
¶
Overview ¶
Package ast contains the abstract syntax tree for the validator.
Index ¶
- func BuiltInFunctionName(symbol string) string
- func FunctionNameToBuiltIn(symbol string) func(*Expr) *Expr
- func HasNot(g *Grammar) bool
- func Strip(slit string, sub string) []byte
- func ToFloat64(tok []byte) *float64
- func ToInt64(tok []byte) *int64
- func ToString(s1 string) string
- func ToUint64(tok []byte) *uint64
- type And
- type AnyName
- type AnyNameExcept
- type BuiltIn
- type Comment
- type Concat
- type Contains
- type Empty
- type Expr
- func NewBoolConst(b bool) *Expr
- func NewBoolList(elems ...*Expr) *Expr
- func NewBoolVar() *Expr
- func NewBytesConst(buf []byte) *Expr
- func NewBytesList(elems ...*Expr) *Expr
- func NewBytesVar() *Expr
- func NewDoubleConst(d float64) *Expr
- func NewDoubleList(elems ...*Expr) *Expr
- func NewDoubleVar() *Expr
- func NewEqual(e *Expr) *Expr
- func NewFalse() *Expr
- func NewFunction(name string, params ...*Expr) *Expr
- func NewGreaterEqual(e *Expr) *Expr
- func NewGreaterThan(e *Expr) *Expr
- func NewHasElem(e *Expr) *Expr
- func NewHasPrefix(e *Expr) *Expr
- func NewHasSuffix(e *Expr) *Expr
- func NewIntConst(i int64) *Expr
- func NewIntList(elems ...*Expr) *Expr
- func NewIntVar() *Expr
- func NewLessEqual(e *Expr) *Expr
- func NewLessThan(e *Expr) *Expr
- func NewList(typ types.Type, elems ...*Expr) *Expr
- func NewNestedFunction(name string, params ...*Expr) *Expr
- func NewNotEqual(e *Expr) *Expr
- func NewRegex(e *Expr) *Expr
- func NewStringConst(s string) *Expr
- func NewStringList(elems ...*Expr) *Expr
- func NewStringVar() *Expr
- func NewTrue() *Expr
- func NewType(e *Expr) *Expr
- func NewUintConst(i uint64) *Expr
- func NewUintList(elems ...*Expr) *Expr
- func NewUintVar() *Expr
- func NewVar(typ types.Type) *Expr
- func SetExprComma(e interface{}, c interface{}) *Expr
- func SetRightArrow(expr interface{}, rightArrow interface{}) *Expr
- func (this *Expr) Clone() *Expr
- func (this *Expr) Compare(that *Expr) int
- func (m *Expr) GetBuiltIn() *BuiltIn
- func (m *Expr) GetFunction() *Function
- func (m *Expr) GetList() *List
- func (m *Expr) GetTerminal() *Terminal
- func (this *Expr) GoString() string
- func (this *Expr) HasVar() bool
- func (this *Expr) String() string
- func (this *Expr) Walk(v Visitor)
- type Function
- type Grammar
- func (this *Grammar) AddRef(name string, p *Pattern) *Grammar
- func (this *Grammar) Clone() *Grammar
- func (this *Grammar) Equal(that *Grammar) bool
- func (m *Grammar) GetPatternDecls() []*PatternDecl
- func (m *Grammar) GetTopPattern() *Pattern
- func (this *Grammar) GoString() string
- func (this *Grammar) String() string
- func (this *Grammar) Walk(v Visitor)
- type Interleave
- type Keyword
- type LeafNode
- type List
- type Name
- type NameChoice
- type NameExpr
- func NewAnyName() *NameExpr
- func NewAnyNameExcept(name *NameExpr) *NameExpr
- func NewBoolName(name bool) *NameExpr
- func NewBytesName(name []byte) *NameExpr
- func NewDoubleName(name float64) *NameExpr
- func NewIntName(name int64) *NameExpr
- func NewNameChoice(names ...*NameExpr) *NameExpr
- func NewSDTName(space *Space, term *Terminal) *NameExpr
- func NewStringName(name string) *NameExpr
- func NewUintName(name uint64) *NameExpr
- func (this *NameExpr) Compare(that *NameExpr) int
- func (this *NameExpr) Equal(that *NameExpr) bool
- func (m *NameExpr) GetAnyName() *AnyName
- func (m *NameExpr) GetAnyNameExcept() *AnyNameExcept
- func (m *NameExpr) GetName() *Name
- func (m *NameExpr) GetNameChoice() *NameChoice
- func (this *NameExpr) GetValue() interface{}
- func (this *NameExpr) String() string
- func (this *NameExpr) Walk(v Visitor)
- type Not
- type Optional
- type Or
- type Pattern
- func NewAnd(patterns ...*Pattern) *Pattern
- func NewConcat(patterns ...*Pattern) *Pattern
- func NewContains(pattern *Pattern) *Pattern
- func NewEmpty() *Pattern
- func NewInterleave(patterns ...*Pattern) *Pattern
- func NewLeafNode(e *Expr) *Pattern
- func NewNot(pattern *Pattern) *Pattern
- func NewOptional(pattern *Pattern) *Pattern
- func NewOr(patterns ...*Pattern) *Pattern
- func NewReference(name string) *Pattern
- func NewTreeNode(name *NameExpr, pattern *Pattern) *Pattern
- func NewZAny() *Pattern
- func NewZeroOrMore(pattern *Pattern) *Pattern
- func (this *Pattern) Clone() *Pattern
- func (this *Pattern) Compare(that *Pattern) int
- func (this *Pattern) Equal(that *Pattern) bool
- func (m *Pattern) GetAnd() *And
- func (m *Pattern) GetConcat() *Concat
- func (m *Pattern) GetContains() *Contains
- func (m *Pattern) GetEmpty() *Empty
- func (m *Pattern) GetInterleave() *Interleave
- func (m *Pattern) GetLeafNode() *LeafNode
- func (m *Pattern) GetNot() *Not
- func (m *Pattern) GetOptional() *Optional
- func (m *Pattern) GetOr() *Or
- func (m *Pattern) GetReference() *Reference
- func (m *Pattern) GetTreeNode() *TreeNode
- func (this *Pattern) GetValue() interface{}
- func (m *Pattern) GetZAny() *ZAny
- func (m *Pattern) GetZeroOrMore() *ZeroOrMore
- func (this *Pattern) GoString() string
- func (this *Pattern) Grammar() *Grammar
- func (p *Pattern) Hash() uint64
- func (this *Pattern) String() string
- func (this *Pattern) Walk(v Visitor)
- type PatternDecl
- type RefLookup
- type Reference
- type Space
- type Terminal
- func NewBoolTerminal(v interface{}) *Terminal
- func NewBytesTerminal(stringLit string) (*Terminal, error)
- func NewDoubleTerminal(slit string) (*Terminal, error)
- func NewIntTerminal(slit string) (*Terminal, error)
- func NewStringTerminal(slit string) (*Terminal, error)
- func NewUintTerminal(slit string) (*Terminal, error)
- func NewVariableTerminal(typ types.Type) (*Terminal, error)
- func SetTerminalSpace(term interface{}, s interface{}) *Terminal
- func (this *Terminal) Compare(that *Terminal) int
- func (this *Terminal) Equal(that *Terminal) bool
- func (m *Terminal) GetBoolValue() bool
- func (m *Terminal) GetBytesValue() []byte
- func (m *Terminal) GetDoubleValue() float64
- func (m *Terminal) GetIntValue() int64
- func (m *Terminal) GetStringValue() string
- func (m *Terminal) GetUintValue() uint64
- func (m *Terminal) GetVariable() *Variable
- func (this *Terminal) String() string
- func (this *Terminal) Walk(v Visitor)
- type TreeNode
- type Variable
- type Visitor
- type ZAny
- type ZeroOrMore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuiltInFunctionName ¶
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 ¶
FunctionNameToBuiltIn returns the builtin constructor for a given function name. If a symbol does not exist, nil is returned.
func Strip ¶
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 ¶
ToFloat64 is a parser utility function that returns a pointer to a parsed an float64 or panics.
func ToInt64 ¶
ToInt64 is a parser utility function that returns a pointer to a parsed an int64 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 (*And) GetRightPattern ¶
type AnyName ¶
type AnyName struct {
Underscore *Keyword `json:"Underscore,omitempty"`
}
AnyName is a name expression that represents any name.
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.
type Comment ¶
type Comment string
Comment represents a validator comment as a string
func (Comment) GetContent ¶
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 (*Concat) GetRightPattern ¶
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 ¶
type Empty ¶
type Empty struct {
Empty *Keyword `json:"Empty,omitempty"`
}
Empty is the ast node for 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
NewBoolConst returns a new terminal expression containing the given bool value.
uint(i)
func NewBoolVar ¶
func NewBoolVar() *Expr
NewBoolVar returns a new variable expression of type bool
$bool
func NewBytesConst ¶
NewBytesConst returns a new terminal expression containing the given bytes value.
[]byte(fmt.Sprintf("%#v", buf))
func NewBytesList ¶
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 ¶
NewDoubleConst returns a new terminal expression containing the given double value.
double(d)
func NewDoubleList ¶
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 NewFalse ¶
func NewFalse() *Expr
NewFalse returns a new terminal expression containing a false value.
false
func NewFunction ¶
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 NewIntConst ¶
NewIntConst returns a new terminal expression containing the given int value.
int(i)
func NewIntVar ¶
func NewIntVar() *Expr
NewIntVar returns a new variable expression of type int
$int
func NewNestedFunction ¶
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 NewStringConst ¶
NewStringConst returns a new terminal expression containing the given string value.
"s" `s`
func NewStringList ¶
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 NewUintConst ¶
NewUintConst returns a new terminal expression containing the given uint value.
uint(i)
func NewUintVar ¶
func NewUintVar() *Expr
NewUintVar returns a new variable expression of type uint
$uint
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) GetBuiltIn ¶
func (*Expr) GetFunction ¶
func (*Expr) GetTerminal ¶
func (*Expr) HasVar ¶
HasVar returns whether there exists a variable somewhere in the expression tree. This function is executed recursively.
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) HasVar ¶
HasVar returns whether there exists a varaible somewhere in the function parameters. This function is executed recursively.
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 ¶
NewGrammar converts a refenence lookup map into a Grammar.
func (*Grammar) GetPatternDecls ¶
func (m *Grammar) GetPatternDecls() []*PatternDecl
func (*Grammar) GetTopPattern ¶
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 ¶
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.
type LeafNode ¶
type LeafNode struct {
Expr *Expr `json:"Expr,omitempty"`
}
LeafNode is the ast node for 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) HasVar ¶
HasVar returns whether there exists a variable somewhere in the typed list. This function is executed recursively.
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 (*Name) GetBytesValue ¶
func (*Name) GetDoubleValue ¶
func (*Name) GetIntValue ¶
func (*Name) GetStringValue ¶
func (*Name) GetUintValue ¶
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 ¶
NewAnyNameExcept returns a name expression that represents any name except the given name expression.
!(name)
func NewBoolName ¶
NewBoolName returns a name expression containing the given bool value.
bool(name)
func NewBytesName ¶
NewBytesName returns a name expression containing the given []byte value.
[]byte(name)
func NewDoubleName ¶
NewDoubleName returns a name expression containing the given double value.
double(name)
func NewNameChoice ¶
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 ¶
NewSDTName is a parser utility function that returns a NameExpr given a white space and a terminal value expression.
func NewStringName ¶
NewStringName returns a name expression containing the given string value.
string(name)
func NewUintName ¶
NewUintName returns a name expression containing the given uint value.
uint(name)
func (*NameExpr) GetAnyName ¶
func (*NameExpr) GetAnyNameExcept ¶
func (m *NameExpr) GetAnyNameExcept() *AnyNameExcept
func (*NameExpr) GetNameChoice ¶
func (m *NameExpr) GetNameChoice() *NameChoice
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 ¶
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 ¶
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 (*Or) GetRightPattern ¶
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 ¶
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 ¶
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 NewInterleave ¶
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 NewOr ¶
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 NewTreeNode ¶
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 (*Pattern) GetContains ¶
func (*Pattern) GetInterleave ¶
func (m *Pattern) GetInterleave() *Interleave
func (*Pattern) GetLeafNode ¶
func (*Pattern) GetOptional ¶
func (*Pattern) GetReference ¶
func (*Pattern) GetTreeNode ¶
func (*Pattern) GetZeroOrMore ¶
func (m *Pattern) GetZeroOrMore() *ZeroOrMore
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 ¶
RefLookup represents a validator grammar as a map of references.
func NewRefLookup ¶
NewRefLookup converts a grammar into a reference lookup map.
type Reference ¶
Reference is the ast node for the Reference pattern.
type Space ¶
type Space struct {
Space []string `json:"Space,omitempty"`
}
Space represents a comment or white space.
func AppendSpace ¶
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 ¶
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 ¶
GetComments returns a list of comments contained in the white space.
func (*Space) HasAttachedComment ¶
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 ¶
HasComment returns whether the white space contains a comment.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) GetBoolValue ¶
func (*Terminal) GetBytesValue ¶
func (*Terminal) GetDoubleValue ¶
func (*Terminal) GetIntValue ¶
func (*Terminal) GetStringValue ¶
func (*Terminal) GetUintValue ¶
func (*Terminal) GetVariable ¶
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) GetPattern ¶
type Variable ¶
Variable is a terminal.
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.
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.