| 1 |
//Copyright 2012 Vastech SA (PTY) LTD |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
int_lit : _digit {_digit} ; |
| 16 |
|
| 17 |
_digit : '0'-'9' ; |
| 18 |
|
| 19 |
string_lit : '"' {.} '"' ; |
| 20 |
|
| 21 |
!whitespace : ' ' | '\t' | '\n' | '\r' ; |
| 22 |
|
| 23 |
<<import "github.com/goccmack/gocc/example/bools/ast">> |
| 24 |
|
| 25 |
BoolExpr |
| 26 |
: BoolExpr1 << $0, nil >> |
| 27 |
; |
| 28 |
|
| 29 |
BoolExpr1 |
| 30 |
: Val << $0, nil >> |
| 31 |
| BoolExpr "&" BoolExpr1 << ast.NewBoolAndExpr($0, $2) >> |
| 32 |
| BoolExpr "|" BoolExpr1 << ast.NewBoolOrExpr($0, $2) >> |
| 33 |
| "(" BoolExpr ")" << ast.NewBoolGroupExpr($1) >> |
| 34 |
; |
| 35 |
|
| 36 |
Val |
| 37 |
: "true" << ast.TRUE, nil >> |
| 38 |
| "false" << ast.FALSE, nil >> |
| 39 |
| CompareExpr << $0, nil >> |
| 40 |
| SubStringExpr << $0, nil >> |
| 41 |
; |
| 42 |
|
| 43 |
CompareExpr |
| 44 |
: int_lit "<" int_lit << ast.NewLessThanExpr($0, $2) >> |
| 45 |
| int_lit ">" int_lit << ast.NewLessThanExpr($2, $0) >> |
| 46 |
; |
| 47 |
|
| 48 |
SubStringExpr |
| 49 |
: string_lit "in" string_lit << ast.NewSubStringExpr($0, $2) >> |
| 50 |
; |