// DO NOT EDIT // This is generated file, see build.sh // Sources: license.bnf lexer.bnf, import.bnf, grammar.bnf, expr.bnf, keyword.bnf // Copyright 2013 Walter Schulze // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. _lineComment : '/' '/' {.} '\n' ; _blockComment : '/' '*' {. | '*'} '*' '/' ; _comment : _lineComment | _blockComment ; _ws : ' ' | '\t' | '\n' | '\r' ; //whitespace space : _comment | _ws { _ws } ; _decimal_digit : '0' - '9' ; _octal_digit : '0' - '7' ; _hex_digit : '0' - '9' | 'A' - 'F' | 'a' - 'f'; _int_lit : _decimal_lit | _octal_lit | _hex_lit ; _decimal_lit : ( '1' - '9' ) { _decimal_digit } ; _octal_lit : '0' { _octal_digit } ; _hex_lit : '0' ( 'x' | 'X' ) _hex_digit { _hex_digit } ; _singed_int_lit : ['-'] _int_lit ; int_lit: _int '(' _singed_int_lit ')' | '0' | ['-'] _decimal_lit ; uint_cast_lit: _uint '(' _int_lit ')' ; _decimals : _decimal_digit { _decimal_digit } ; _exponent : ( 'e' | 'E' ) [ '+' | '-' ] _decimals ; _float_lit : ( _decimals '.' _decimals _exponent ) | ( _decimals '.' ( _decimals | _exponent ) ) | ( '.' ( _decimals | _exponent ) ) | ( _decimals _exponent ) ; double_cast_lit : _double '(' ['-'] ( _float_lit | _int_lit ) ')' ; _upcase : 'A'-'Z' ; _lowcase : 'a'-'z' ; _id_char : _upcase | _lowcase | '_' | _decimal_digit ; _id : (_upcase | _lowcase | '_' ) {_id_char} ; id : _id ; _double : 'd' 'o' 'u' 'b' 'l' 'e' ; _int : 'i' 'n' 't'; _uint : 'u' 'i' 'n' 't'; _bytes : '[' ']' 'b' 'y' 't' 'e' ; _string : 's' 't' 'r' 'i' 'n' 'g' ; _bool : 'b' 'o' 'o' 'l' ; _qualid : _id { '.' _id } ; double_var : '$' _double ; int_var : '$' _int ; uint_var : '$' _uint ; bytes_var : '$' _bytes ; string_var : '$' _string ; bool_var : '$' _bool ; _big_u_value : '\\' 'U' _hex_digit _hex_digit _hex_digit _hex_digit _hex_digit _hex_digit _hex_digit _hex_digit ; _little_u_value : '\\' 'u' _hex_digit _hex_digit _hex_digit _hex_digit ; _hex_byte_u_value : '\\' 'x' _hex_digit _hex_digit ; _octal_byte_u_value : '\\' _octal_digit _octal_digit _octal_digit ; _byte_value : _octal_byte_u_value | _hex_byte_u_value ; _raw_string : '`' {.} '`' ; _escaped_char : '\\' ( 'a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v' | '\\' | '\'' | '"' ) ; _unicode_value : . | _little_u_value | _big_u_value | _escaped_char ; _interpreted_string : '"' { _unicode_value | _byte_value } '"' ; string_lit : _raw_string | _interpreted_string ; _char_lit : '\'' (_unicode_value | _byte_value) '\'' ; _byte_elem : _int_lit | _char_lit ; bytes_cast_lit : _bytes '{' { _ws } [ _byte_elem { { _ws } ',' { _ws } _byte_elem } ] { _ws } '}' ; << import ( . "github.com/katydid/validator-go/validator/ast" "github.com/katydid/validator-go/validator/types" "github.com/katydid/validator-go/validator/token" "strconv" ) func newString(v interface{}) string { t := v.(*token.Token) return string(t.Lit) } func unquote(s1 string) string { s, err := strconv.Unquote(s1) if err != nil { return s1 } return s } >> AllGrammar : Grammar | GrammarWithEndingSpace ; Grammar : Pattern << &Grammar{TopPattern: $0.(*Pattern)}, nil >> | Pattern PatternDecls << &Grammar{TopPattern: $0.(*Pattern), PatternDecls: $1.([]*PatternDecl)}, nil >> | PatternDecls << &Grammar{PatternDecls:$0.([]*PatternDecl)}, nil >> ; GrammarWithEndingSpace : Pattern Space << &Grammar{TopPattern: $0.(*Pattern), After: $1.(*Space)}, nil >> | Pattern PatternDecls Space << &Grammar{TopPattern: $0.(*Pattern), PatternDecls: $1.([]*PatternDecl), After: $2.(*Space)}, nil >> | PatternDecls Space << &Grammar{PatternDecls: $0.([]*PatternDecl), After: $1.(*Space)}, nil >> ; PatternDecls : PatternDecl << []*PatternDecl{$0.(*PatternDecl)}, nil >> | PatternDecls PatternDecl << append($0.([]*PatternDecl), $1.(*PatternDecl)), nil >> ; PatternDecl : Hash Space id Equal Pattern << &PatternDecl{ Hash: $0.(*Keyword), Before: $1.(*Space), Name: newString($2), Eq: $3.(*Keyword), Pattern: $4.(*Pattern), }, nil >> | Hash id Equal Pattern << &PatternDecl{ Hash: $0.(*Keyword), Name: newString($1), Eq: $2.(*Keyword), Pattern: $3.(*Pattern), }, nil >> ; Empty : "" << &Keyword{Value: ""}, nil >> | Space "" << &Keyword{ Before: $0.(*Space), Value: "", }, nil >> ; DepthPattern : StartConcat | StartInterleave | Dot Pattern << &Pattern{Contains: &Contains{ Dot: $0.(*Keyword), Pattern: $1.(*Pattern), }}, nil >> | AllExpr << &Pattern{LeafNode: &LeafNode{ Expr: $0.(*Expr), }}, nil >> ; TreeNode : NameExpr Colon Pattern << &Pattern{TreeNode: &TreeNode{ Name: $0.(*NameExpr), Colon: $1.(*Keyword), Pattern: $2.(*Pattern), }}, nil >> | NameExpr DepthPattern << &Pattern{TreeNode: &TreeNode{ Name: $0.(*NameExpr), Pattern: $1.(*Pattern), }}, nil >> ; Pattern : Empty << &Pattern{Empty: &Empty{Empty: $0.(*Keyword)}}, nil >> | Star << &Pattern{ZAny: &ZAny{Star: $0.(*Keyword)}}, nil >> | TreeNode | DepthPattern | StartOr | StartAnd | OpenParen Pattern CloseParen Star << &Pattern{ZeroOrMore: &ZeroOrMore{ OpenParen: $0.(*Keyword), Pattern: $1.(*Pattern), CloseParen: $2.(*Keyword), Star: $3.(*Keyword), }}, nil >> | OpenParen Pattern CloseParen QuestionMark << &Pattern{Optional: &Optional{ OpenParen: $0.(*Keyword), Pattern: $1.(*Pattern), CloseParen: $2.(*Keyword), QuestionMark: $3.(*Keyword), }}, nil >> | At id << &Pattern{Reference: &Reference{ At: $0.(*Keyword), Name: newString($1), }}, nil >> | Exclamation OpenParen Pattern CloseParen << &Pattern{Not: &Not{ Exclamation: $0.(*Keyword), OpenParen: $1.(*Keyword), Pattern: $2.(*Pattern), CloseParen: $3.(*Keyword), }}, nil >> ; StartConcat : OpenBracket Pattern Comma ContinueConcat CloseBracket << &Pattern{Concat: &Concat{ OpenBracket: $0.(*Keyword), LeftPattern: $1.(*Pattern), Comma: $2.(*Keyword), RightPattern: $3.(*Pattern), CloseBracket: $4.(*Keyword), }}, nil >> | OpenBracket Pattern Comma ContinueConcat Comma CloseBracket << &Pattern{Concat: &Concat{ OpenBracket: $0.(*Keyword), LeftPattern: $1.(*Pattern), Comma: $2.(*Keyword), RightPattern: $3.(*Pattern), ExtraComma: $4.(*Keyword), CloseBracket: $5.(*Keyword), }}, nil >> ; ContinueConcat : Pattern | ContinueConcat Comma Pattern << &Pattern{Concat: &Concat{ LeftPattern: $0.(*Pattern), Comma: $1.(*Keyword), RightPattern: $2.(*Pattern), }}, nil >> ; StartOr : OpenParen Pattern Pipe ContinueOr CloseParen << &Pattern{Or: &Or{ OpenParen: $0.(*Keyword), LeftPattern: $1.(*Pattern), Pipe: $2.(*Keyword), RightPattern: $3.(*Pattern), CloseParen: $4.(*Keyword), }}, nil >> ; ContinueOr : Pattern | ContinueOr Pipe Pattern << &Pattern{Or: &Or{ LeftPattern: $0.(*Pattern), Pipe: $1.(*Keyword), RightPattern: $2.(*Pattern), }}, nil >> ; StartAnd : OpenParen Pattern Ampersand ContinueAnd CloseParen << &Pattern{And: &And{ OpenParen: $0.(*Keyword), LeftPattern: $1.(*Pattern), Ampersand: $2.(*Keyword), RightPattern: $3.(*Pattern), CloseParen: $4.(*Keyword), }}, nil >> ; ContinueAnd : Pattern | ContinueAnd Ampersand Pattern << &Pattern{And: &And{ LeftPattern: $0.(*Pattern), Ampersand: $1.(*Keyword), RightPattern: $2.(*Pattern), }}, nil >> ; StartInterleave : OpenCurly Pattern SemiColon ContinueInterleave CloseCurly << &Pattern{Interleave: &Interleave{ OpenCurly: $0.(*Keyword), LeftPattern: $1.(*Pattern), SemiColon: $2.(*Keyword), RightPattern: $3.(*Pattern), CloseCurly: $4.(*Keyword), }}, nil >> | OpenCurly Pattern SemiColon ContinueInterleave SemiColon CloseCurly << &Pattern{Interleave: &Interleave{ OpenCurly: $0.(*Keyword), LeftPattern: $1.(*Pattern), SemiColon: $2.(*Keyword), RightPattern: $3.(*Pattern), ExtraSemiColon: $4.(*Keyword), CloseCurly: $5.(*Keyword), }}, nil >> ; ContinueInterleave : Pattern | ContinueInterleave SemiColon Pattern << &Pattern{Interleave: &Interleave{ LeftPattern: $0.(*Pattern), SemiColon: $1.(*Keyword), RightPattern: $2.(*Pattern), }}, nil >> ; AllExpr : RightArrow Expr << SetRightArrow($1, $0), nil >> | BuiltIn << &Expr{BuiltIn: $0.(*BuiltIn)}, nil >> ; Expr : SpaceTerminal << &Expr{Terminal: $0.(*Terminal)}, nil >> | Function << &Expr{Function: $0.(*Function)}, nil >> | BuiltIn << &Expr{BuiltIn: $0.(*BuiltIn)}, nil >> | List << &Expr{List: $0.(*List)}, nil >> ; Name : Space Literal << NewSDTName($0.(*Space), $1.(*Terminal)), nil >> | Literal << NewSDTName(nil, $0.(*Terminal)), nil >> | Space id << NewSDTName($0.(*Space), &Terminal{StringValue: ptr(newString($1))}), nil >> | id << NewSDTName(nil, &Terminal{StringValue: ptr(newString($0))}), nil >> ; NameExpr : Underscore << &NameExpr{AnyName: &AnyName{Underscore: $0.(*Keyword)}}, nil >> | Name | Exclamation OpenParen NameExpr CloseParen << &NameExpr{AnyNameExcept: &AnyNameExcept{ Exclamation: $0.(*Keyword), OpenParen: $1.(*Keyword), Except: $2.(*NameExpr), CloseParen: $3.(*Keyword), }}, nil >> | StartNameChoice ; StartNameChoice : OpenParen NameExpr Pipe ContinueNameChoice CloseParen << &NameExpr{NameChoice: &NameChoice{ OpenParen: $0.(*Keyword), Left: $1.(*NameExpr), Pipe: $2.(*Keyword), Right: $3.(*NameExpr), CloseParen: $4.(*Keyword), }}, nil >> ; ContinueNameChoice : NameExpr | ContinueNameChoice Pipe NameExpr << &NameExpr{NameChoice: &NameChoice{ Left: $0.(*NameExpr), Pipe: $1.(*Keyword), Right: $2.(*NameExpr), }}, nil >> ; Function : Space id OpenParen Exprs CloseParen << &Function{Before: $0.(*Space), Name: newString($1), OpenParen: $2.(*Keyword), Params: $3.([]*Expr), CloseParen: $4.(*Keyword)}, nil >> | Space id OpenParen CloseParen << &Function{Before: $0.(*Space), Name: newString($1), OpenParen: $2.(*Keyword), CloseParen: $3.(*Keyword)}, nil >> | id OpenParen Exprs CloseParen << &Function{Name: newString($0), OpenParen: $1.(*Keyword), Params: $2.([]*Expr), CloseParen: $3.(*Keyword)}, nil >> | id OpenParen CloseParen << &Function{Name: newString($0), OpenParen: $1.(*Keyword), CloseParen: $2.(*Keyword)}, nil >> ; BuiltIn : EqualEqual Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | ExclamationEqual Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | LessThan Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | GreaterThan Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | GreaterEqual Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | LessEqual Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | TildeEqual Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | StarEqual Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | CaretEqual Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | DollarEqual Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> | ColonColon Expr << &BuiltIn{Symbol: $0.(*Keyword), Expr: $1.(*Expr)}, nil >> ; List : Space ListType OpenCurly Exprs CloseCurly << &List{Before: $0.(*Space), Type: $1.(types.Type), OpenCurly: $2.(*Keyword), Elems: $3.([]*Expr), CloseCurly: $4.(*Keyword)}, nil >> | ListType OpenCurly Exprs CloseCurly << &List{Type: $0.(types.Type), OpenCurly: $1.(*Keyword), Elems: $2.([]*Expr), CloseCurly: $3.(*Keyword)}, nil >> | Space ListType OpenCurly CloseCurly << &List{Before: $0.(*Space), Type: $1.(types.Type), OpenCurly: $2.(*Keyword), CloseCurly: $3.(*Keyword)}, nil >> | ListType OpenCurly CloseCurly << &List{Type: $0.(types.Type), OpenCurly: $1.(*Keyword), CloseCurly: $2.(*Keyword)}, nil >> ; Exprs : Expr << []*Expr{$0.(*Expr)}, nil >> | Exprs Comma Expr << append($0.([]*Expr), SetExprComma($2, $1)), nil >> ; ListType : "[]bool" << types.LIST_BOOL, nil >> | "[]int" << types.LIST_INT, nil >> | "[]uint" << types.LIST_UINT, nil >> | "[]double" << types.LIST_DOUBLE, nil >> | "[]string" << types.LIST_STRING, nil >> | "[][]byte" << types.LIST_BYTES, nil >> ; SpaceTerminal : Terminal << $0, nil >> | Space Terminal << SetTerminalSpace($1, $0), nil >> ; Literal : Bool << NewBoolTerminal($0), nil >> | int_lit << NewIntTerminal(newString($0)) >> | uint_cast_lit << NewUintTerminal(newString($0)) >> | double_cast_lit << NewDoubleTerminal(newString($0)) >> | string_lit << NewStringTerminal(newString($0)) >> | bytes_cast_lit << NewBytesTerminal(newString($0)) >> ; Terminal : Literal | bool_var << NewVariableTerminal(types.SINGLE_BOOL) >> | int_var << NewVariableTerminal(types.SINGLE_INT) >> | uint_var << NewVariableTerminal(types.SINGLE_UINT) >> | double_var << NewVariableTerminal(types.SINGLE_DOUBLE) >> | string_var << NewVariableTerminal(types.SINGLE_STRING) >> | bytes_var << NewVariableTerminal(types.SINGLE_BYTES) >> ; Bool : "true" << true, nil >> | "false" << false, nil >> ; Equal : "=" << &Keyword{Value: "="}, nil >> | Space "=" << &Keyword{ Before: $0.(*Space), Value: "=", }, nil >> ; OpenParen : "(" << &Keyword{Value: "("}, nil >> | Space "(" << &Keyword{ Before: $0.(*Space), Value: "(", }, nil >> ; CloseParen : ")" << &Keyword{Value: ")"}, nil >> | Space ")" << &Keyword{ Before: $0.(*Space), Value: ")", }, nil >> ; OpenCurly : "{" << &Keyword{Value: "{"}, nil >> | Space "{" << &Keyword{ Before: $0.(*Space), Value: "{", }, nil >> ; CloseCurly : "}" << &Keyword{Value: "}"}, nil >> | Space "}" << &Keyword{ Before: $0.(*Space), Value: "}", }, nil >> ; Comma : "," << &Keyword{Value: ","}, nil >> | Space "," << &Keyword{ Before: $0.(*Space), Value: ",", }, nil >> ; SemiColon : ";" << &Keyword{Value: ";"}, nil >> | Space ";" << &Keyword{ Before: $0.(*Space), Value: ";", }, nil >> ; Hash : "#" << &Keyword{Value: "#"}, nil >> | Space "#" << &Keyword{ Before: $0.(*Space), Value: "#", }, nil >> ; Ampersand : "&" << &Keyword{Value: "&"}, nil >> | Space "&" << &Keyword{ Before: $0.(*Space), Value: "&", }, nil >> ; Pipe : "|" << &Keyword{Value: "|"}, nil >> | Space "|" << &Keyword{ Before: $0.(*Space), Value: "|", }, nil >> ; OpenBracket : "[" << &Keyword{Value: "["}, nil >> | Space "[" << &Keyword{ Before: $0.(*Space), Value: "[", }, nil >> ; CloseBracket : "]" << &Keyword{Value: "]"}, nil >> | Space "]" << &Keyword{ Before: $0.(*Space), Value: "]", }, nil >> ; Colon : ":" << &Keyword{Value: ":"}, nil >> | Space ":" << &Keyword{ Before: $0.(*Space), Value: ":", }, nil >> ; Exclamation : "!" << &Keyword{Value: "!"}, nil >> | Space "!" << &Keyword{ Before: $0.(*Space), Value: "!", }, nil >> ; Star : "*" << &Keyword{Value: "*"}, nil >> | Space "*" << &Keyword{ Before: $0.(*Space), Value: "*", }, nil >> ; Underscore : "_" << &Keyword{Value: "_"}, nil >> | Space "_" << &Keyword{ Before: $0.(*Space), Value: "_", }, nil >> ; Dot : "." << &Keyword{Value: "."}, nil >> | Space "." << &Keyword{ Before: $0.(*Space), Value: ".", }, nil >> ; At : "@" << &Keyword{Value: "@"}, nil >> | Space "@" << &Keyword{ Before: $0.(*Space), Value: "@", }, nil >> ; RightArrow : "->" << &Keyword{Value: "->"}, nil >> | Space "->" << &Keyword{ Before: $0.(*Space), Value: "->", }, nil >> ; EqualEqual : "==" << &Keyword{Value: "=="}, nil >> | Space "==" << &Keyword{ Before: $0.(*Space), Value: "==", }, nil >> ; ExclamationEqual : "!=" << &Keyword{Value: "!="}, nil >> | Space "!=" << &Keyword{ Before: $0.(*Space), Value: "!=", }, nil >> ; LessThan : "<" << &Keyword{Value: "<"}, nil >> | Space "<" << &Keyword{ Before: $0.(*Space), Value: "<", }, nil >> ; GreaterThan : ">" << &Keyword{Value: ">"}, nil >> | Space ">" << &Keyword{ Before: $0.(*Space), Value: ">", }, nil >> ; LessEqual : "<=" << &Keyword{Value: "<="}, nil >> | Space "<=" << &Keyword{ Before: $0.(*Space), Value: "<=", }, nil >> ; GreaterEqual : ">=" << &Keyword{Value: ">="}, nil >> | Space ">=" << &Keyword{ Before: $0.(*Space), Value: ">=", }, nil >> ; TildeEqual : "~=" << &Keyword{Value: "~="}, nil >> | Space "~=" << &Keyword{ Before: $0.(*Space), Value: "~=", }, nil >> ; StarEqual : "*=" << &Keyword{Value: "*="}, nil >> | Space "*=" << &Keyword{ Before: $0.(*Space), Value: "*=", }, nil >> ; CaretEqual : "^=" << &Keyword{Value: "^="}, nil >> | Space "^=" << &Keyword{ Before: $0.(*Space), Value: "^=", }, nil >> ; DollarEqual : "$=" << &Keyword{Value: "$="}, nil >> | Space "$=" << &Keyword{ Before: $0.(*Space), Value: "$=", }, nil >> ; ColonColon : "::" << &Keyword{Value: "::"}, nil >> | Space "::" << &Keyword{ Before: $0.(*Space), Value: "::", }, nil >> ; QuestionMark : "?" << &Keyword{Value: "?"}, nil >> | Space "?" << &Keyword{ Before: $0.(*Space), Value: "?", }, nil >> ; Space : Space space << AppendSpace($0, newString($1)), nil >> | space << &Space{Space: []string{newString($0)}}, nil >> ;