Skip to content

Commit

Permalink
⚗️ add and operator, and support multi expressions. #13
Browse files Browse the repository at this point in the history
  • Loading branch information
perillaroc committed Apr 11, 2022
1 parent 04fe114 commit 6fdd6c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions takler/core/expression_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def evaluate(self):
return self.left.value() == self.right.value()


@dataclass
class AstOpAnd(AstRoot):
def evaluate(self):
return self.left.evaluate() and self.right.evaluate()


@dataclass
class AstNodePath(AstBase):
node_path: str
Expand Down
10 changes: 7 additions & 3 deletions takler/core/expression_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from lark import Lark, Transformer

from .expression_ast import AstNodePath, AstOpEq, AstNodeStatus, AstRoot
from .expression_ast import AstNodePath, AstOpEq, AstOpAnd, AstNodeStatus, AstRoot
from .state import NodeStatus


Expand All @@ -18,6 +18,9 @@ def st_complete(self, _):
def op_eq(self, _):
return AstOpEq()

def op_and(self, _):
return AstOpAnd()

def expression(self, s):
s[1].left = s[0]
s[1].right = s[2]
Expand All @@ -30,15 +33,16 @@ def expression(self, s):
op_eq: "==" | "eq"
op_gt: ">"
op_ge: ">="
?operator: op_eq | op_gt | op_ge
op_and: "and"
?operator: op_eq | op_gt | op_ge | op_and
st_complete: "complete"
st_aborted: "aborted"
?status: st_complete | st_aborted
node_name: CNAME
expression: node_path operator status
expression: (node_path operator status) | (expression op_and expression)
%import common.CNAME
%import common.WORD
Expand Down

0 comments on commit 6fdd6c3

Please sign in to comment.