feat: support not operator, #575

This commit is contained in:
Harttle
2023-01-03 01:34:03 +08:00
committed by Harttle
parent aafaa0b4f9
commit 3f21382d43
7 changed files with 74 additions and 33 deletions
+28 -9
View File
@@ -1,18 +1,37 @@
import { Token } from './token'
import { TokenKind } from '../parser'
export const precedence = {
'==': 1,
'!=': 1,
'>': 1,
'<': 1,
'>=': 1,
'<=': 1,
'contains': 1,
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 (
@@ -26,6 +45,6 @@ export class OperatorToken extends Token {
}
getPrecedence () {
const key = this.getText()
return key in precedence ? precedence[key] : 1
return key in operatorPrecedences ? operatorPrecedences[key] : 1
}
}