-
-
Save brett19/9030d72afb6f063259aefda7aaf68ab1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Lexical Part */ | |
_letter : 'a'-'z' | 'A'-'Z' ; | |
_digit : '0'-'9' ; | |
_idchar : _letter | _digit | '_' ; | |
id : (_letter | '_') {_idchar} ; | |
!whitespace : ' ' | '\t' | '\n' | '\r' ; | |
/* Syntax Part */ | |
<< import "github.com/couchbaselabs/gojsonsm/parser/ast" >> | |
RootExpression : Expression ; | |
True : "true" << ast.NewBoolValue(true) >> ; | |
False : "false" << ast.NewBoolValue(false) >>; | |
String : | |
"\"" id "\"" << ast.NewStringValue($1) >> | |
| "'" id "'" << ast.NewStringValue($1) >> | |
; | |
FieldRef : | |
id << ast.NewFieldRef($0) >> | |
| FieldRef "." id << ast.AppendToFieldRef($0, $2) >> | |
; | |
Literal : | |
String | |
| True | |
| False | |
; | |
Value : | |
FieldRef | |
| Literal | |
; | |
ComparisonExpr : | |
Value "!=" Value << ast.NewComparisonExpr("!=", $0, $2) >> | |
| Value "==" Value << ast.NewComparisonExpr("==", $0, $2) >> | |
| Value ">" Value << ast.NewComparisonExpr(">", $0, $2) >> | |
| Value ">=" Value << ast.NewComparisonExpr(">=", $0, $2) >> | |
| Value "<" Value << ast.NewComparisonExpr("<", $0, $2) >> | |
| Value "<=" Value << ast.NewComparisonExpr("<=", $0, $2) >> | |
; | |
AndExpr : | |
Expression "&&" Expression << ast.NewPredicateExpr("&&", $0, $2) >> | |
| AndExpr "&&" Expression << ast.AppendToPredicateExpr("&&", $0, $2) >> | |
; | |
OrExpr : | |
Expression "&&" Expression << ast.NewPredicateExpr("||", $0, $2) >> | |
| OrExpr "&&" Expression << ast.AppendToPredicateExpr("||", $0, $2) >> | |
; | |
GroupExpr : | |
"(" Expression ")" << $1, nil >> | |
; | |
NotExpr : | |
"!" GroupExpr << ast.NewNotExpr($1) >> | |
; | |
Expression : | |
ComparisonExpr | |
| NotExpr | |
| GroupExpr | |
| AndExpr | |
| OrExpr | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment