Skip to content

Instantly share code, notes, and snippets.

@brett19
Created July 18, 2018 11:09
Show Gist options
  • Save brett19/9030d72afb6f063259aefda7aaf68ab1 to your computer and use it in GitHub Desktop.
Save brett19/9030d72afb6f063259aefda7aaf68ab1 to your computer and use it in GitHub Desktop.
/* 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