aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hil/parser/binary_op.go
blob: 2e013e01d6ca33066e20e067f5a8cc35937714dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package parser

import (
	"github.com/hashicorp/hil/ast"
	"github.com/hashicorp/hil/scanner"
)

var binaryOps []map[scanner.TokenType]ast.ArithmeticOp

func init() {
	// This operation table maps from the operator's scanner token type
	// to the AST arithmetic operation. All expressions produced from
	// binary operators are *ast.Arithmetic nodes.
	//
	// Binary operator groups are listed in order of precedence, with
	// the *lowest* precedence first. Operators within the same group
	// have left-to-right associativity.
	binaryOps = []map[scanner.TokenType]ast.ArithmeticOp{
		{
			scanner.OR: ast.ArithmeticOpLogicalOr,
		},
		{
			scanner.AND: ast.ArithmeticOpLogicalAnd,
		},
		{
			scanner.EQUAL:    ast.ArithmeticOpEqual,
			scanner.NOTEQUAL: ast.ArithmeticOpNotEqual,
		},
		{
			scanner.GT:  ast.ArithmeticOpGreaterThan,
			scanner.GTE: ast.ArithmeticOpGreaterThanOrEqual,
			scanner.LT:  ast.ArithmeticOpLessThan,
			scanner.LTE: ast.ArithmeticOpLessThanOrEqual,
		},
		{
			scanner.PLUS:  ast.ArithmeticOpAdd,
			scanner.MINUS: ast.ArithmeticOpSub,
		},
		{
			scanner.STAR:    ast.ArithmeticOpMul,
			scanner.SLASH:   ast.ArithmeticOpDiv,
			scanner.PERCENT: ast.ArithmeticOpMod,
		},
	}
}