diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hil/parser/binary_op.go')
-rw-r--r-- | vendor/github.com/hashicorp/hil/parser/binary_op.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hil/parser/binary_op.go b/vendor/github.com/hashicorp/hil/parser/binary_op.go new file mode 100644 index 0000000..2e013e0 --- /dev/null +++ b/vendor/github.com/hashicorp/hil/parser/binary_op.go | |||
@@ -0,0 +1,45 @@ | |||
1 | package parser | ||
2 | |||
3 | import ( | ||
4 | "github.com/hashicorp/hil/ast" | ||
5 | "github.com/hashicorp/hil/scanner" | ||
6 | ) | ||
7 | |||
8 | var binaryOps []map[scanner.TokenType]ast.ArithmeticOp | ||
9 | |||
10 | func init() { | ||
11 | // This operation table maps from the operator's scanner token type | ||
12 | // to the AST arithmetic operation. All expressions produced from | ||
13 | // binary operators are *ast.Arithmetic nodes. | ||
14 | // | ||
15 | // Binary operator groups are listed in order of precedence, with | ||
16 | // the *lowest* precedence first. Operators within the same group | ||
17 | // have left-to-right associativity. | ||
18 | binaryOps = []map[scanner.TokenType]ast.ArithmeticOp{ | ||
19 | { | ||
20 | scanner.OR: ast.ArithmeticOpLogicalOr, | ||
21 | }, | ||
22 | { | ||
23 | scanner.AND: ast.ArithmeticOpLogicalAnd, | ||
24 | }, | ||
25 | { | ||
26 | scanner.EQUAL: ast.ArithmeticOpEqual, | ||
27 | scanner.NOTEQUAL: ast.ArithmeticOpNotEqual, | ||
28 | }, | ||
29 | { | ||
30 | scanner.GT: ast.ArithmeticOpGreaterThan, | ||
31 | scanner.GTE: ast.ArithmeticOpGreaterThanOrEqual, | ||
32 | scanner.LT: ast.ArithmeticOpLessThan, | ||
33 | scanner.LTE: ast.ArithmeticOpLessThanOrEqual, | ||
34 | }, | ||
35 | { | ||
36 | scanner.PLUS: ast.ArithmeticOpAdd, | ||
37 | scanner.MINUS: ast.ArithmeticOpSub, | ||
38 | }, | ||
39 | { | ||
40 | scanner.STAR: ast.ArithmeticOpMul, | ||
41 | scanner.SLASH: ast.ArithmeticOpDiv, | ||
42 | scanner.PERCENT: ast.ArithmeticOpMod, | ||
43 | }, | ||
44 | } | ||
45 | } | ||