-
-
Notifications
You must be signed in to change notification settings - Fork 231
/
operator-token.ts
50 lines (46 loc) · 1 KB
/
operator-token.ts
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
46
47
48
49
50
import { Token } from './token'
import { TokenKind } from '../parser'
export const enum OperatorType {
Binary,
Unary
}
export const operatorPrecedences = {
'==': 2,
'!=': 2,
'>': 2,
'<': 2,
'>=': 2,
'<=': 2,
'contains': 2,
'not': 1,
'and': 0,
'or': 0
}
export const operatorTypes = {
'==': OperatorType.Binary,
'!=': OperatorType.Binary,
'>': OperatorType.Binary,
'<': OperatorType.Binary,
'>=': OperatorType.Binary,
'<=': OperatorType.Binary,
'contains': OperatorType.Binary,
'not': OperatorType.Unary,
'and': OperatorType.Binary,
'or': OperatorType.Binary
}
export class OperatorToken extends Token {
public operator: string
public constructor (
public input: string,
public begin: number,
public end: number,
public file?: string
) {
super(TokenKind.Operator, input, begin, end, file)
this.operator = this.getText()
}
getPrecedence () {
const key = this.getText()
return key in operatorPrecedences ? operatorPrecedences[key] : 1
}
}