Skip to content

Commit

Permalink
feat: Add string operators and negation (#33)
Browse files Browse the repository at this point in the history
* feat: Add string operators and negation

* Remove pypy from CI
  • Loading branch information
j6k4m8 committed Oct 30, 2023
1 parent ecf659e commit 87dfe7b
Show file tree
Hide file tree
Showing 4 changed files with 1,184 additions and 1,033 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: [3.7, 3.8, 3.9, '3.10', '3.11']

steps:
- uses: actions/checkout@v2
Expand Down
23 changes: 23 additions & 0 deletions grandcypher/__init__.py
Expand Up @@ -29,6 +29,8 @@
"in": lambda x, y: x in y,
"contains": lambda x, y: y in x,
"is": lambda x, y: x is y,
"starts_with": lambda x, y: x.startswith(y),
"ends_with": lambda x, y: x.endswith(y),
}


Expand All @@ -52,6 +54,7 @@
| compound_condition boolean_arithmetic compound_condition
condition : entity_id op entity_id_or_value
| "not"i condition -> condition_not
?entity_id_or_value : entity_id
| value
Expand All @@ -67,6 +70,11 @@
| ">="-> op_gte
| "<="-> op_lte
| "is"i -> op_is
| "in"i -> op_in
| "contains"i -> op_contains
| "starts with"i -> op_starts_with
| "ends with"i -> op_ends_with
return_clause : "return"i entity_id ("," entity_id)*
Expand Down Expand Up @@ -609,6 +617,9 @@ def condition(self, condition):
(entity_id, operator, value) = condition
return (True, entity_id, operator, value)

def condition_not(self, processed_condition):
return (not processed_condition[0][0], *processed_condition[0][1:])

null = lambda self, _: None
true = lambda self, _: True
false = lambda self, _: False
Expand Down Expand Up @@ -639,6 +650,18 @@ def op_lte(self, _):
def op_is(self, _):
return _OPERATORS["is"]

def op_in(self, _):
return _OPERATORS["in"]

def op_contains(self, _):
return _OPERATORS["contains"]

def op_starts_with(self, _):
return _OPERATORS["starts_with"]

def op_ends_with(self, _):
return _OPERATORS["ends_with"]

def json_dict(self, tup):
constraints = {}
for key, value in tup:
Expand Down

0 comments on commit 87dfe7b

Please sign in to comment.