flowquery 1.0.16 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/python-publish.yml +97 -0
- package/dist/compute/runner.d.ts +3 -2
- package/dist/compute/runner.d.ts.map +1 -1
- package/dist/compute/runner.js +7 -7
- package/dist/compute/runner.js.map +1 -1
- package/dist/flowquery.min.js +1 -1
- package/dist/graph/data.d.ts +31 -0
- package/dist/graph/data.d.ts.map +1 -0
- package/dist/graph/data.js +110 -0
- package/dist/graph/data.js.map +1 -0
- package/dist/graph/database.d.ts +20 -0
- package/dist/graph/database.d.ts.map +1 -0
- package/dist/graph/database.js +77 -0
- package/dist/graph/database.js.map +1 -0
- package/dist/graph/hops.d.ts +11 -0
- package/dist/graph/hops.d.ts.map +1 -0
- package/dist/graph/hops.js +25 -0
- package/dist/graph/hops.js.map +1 -0
- package/dist/graph/node.d.ts +35 -0
- package/dist/graph/node.d.ts.map +1 -0
- package/dist/graph/node.js +113 -0
- package/dist/graph/node.js.map +1 -0
- package/dist/graph/node_data.d.ts +11 -0
- package/dist/graph/node_data.d.ts.map +1 -0
- package/dist/graph/node_data.js +20 -0
- package/dist/graph/node_data.js.map +1 -0
- package/dist/graph/node_reference.d.ts +10 -0
- package/dist/graph/node_reference.d.ts.map +1 -0
- package/dist/graph/node_reference.js +52 -0
- package/dist/graph/node_reference.js.map +1 -0
- package/dist/graph/pattern.d.ts +18 -0
- package/dist/graph/pattern.d.ts.map +1 -0
- package/dist/graph/pattern.js +114 -0
- package/dist/graph/pattern.js.map +1 -0
- package/dist/graph/pattern_expression.d.ts +14 -0
- package/dist/graph/pattern_expression.d.ts.map +1 -0
- package/dist/graph/pattern_expression.js +58 -0
- package/dist/graph/pattern_expression.js.map +1 -0
- package/dist/graph/patterns.d.ts +11 -0
- package/dist/graph/patterns.d.ts.map +1 -0
- package/dist/graph/patterns.js +49 -0
- package/dist/graph/patterns.js.map +1 -0
- package/dist/graph/physical_node.d.ts +10 -0
- package/dist/graph/physical_node.d.ts.map +1 -0
- package/dist/graph/physical_node.js +40 -0
- package/dist/graph/physical_node.js.map +1 -0
- package/dist/graph/physical_relationship.d.ts +10 -0
- package/dist/graph/physical_relationship.d.ts.map +1 -0
- package/dist/graph/physical_relationship.js +40 -0
- package/dist/graph/physical_relationship.js.map +1 -0
- package/dist/graph/relationship.d.ts +40 -0
- package/dist/graph/relationship.d.ts.map +1 -0
- package/dist/graph/relationship.js +124 -0
- package/dist/graph/relationship.js.map +1 -0
- package/dist/graph/relationship_data.d.ts +12 -0
- package/dist/graph/relationship_data.d.ts.map +1 -0
- package/dist/graph/relationship_data.js +40 -0
- package/dist/graph/relationship_data.js.map +1 -0
- package/dist/graph/relationship_match_collector.d.ts +19 -0
- package/dist/graph/relationship_match_collector.d.ts.map +1 -0
- package/dist/graph/relationship_match_collector.js +55 -0
- package/dist/graph/relationship_match_collector.js.map +1 -0
- package/dist/graph/relationship_reference.d.ts +8 -0
- package/dist/graph/relationship_reference.d.ts.map +1 -0
- package/dist/graph/relationship_reference.js +37 -0
- package/dist/graph/relationship_reference.js.map +1 -0
- package/dist/parsing/base_parser.d.ts +1 -0
- package/dist/parsing/base_parser.d.ts.map +1 -1
- package/dist/parsing/base_parser.js +4 -1
- package/dist/parsing/base_parser.js.map +1 -1
- package/dist/parsing/context.d.ts +2 -2
- package/dist/parsing/context.js +5 -5
- package/dist/parsing/expressions/boolean.d.ts +8 -0
- package/dist/parsing/expressions/boolean.d.ts.map +1 -0
- package/dist/parsing/expressions/boolean.js +26 -0
- package/dist/parsing/expressions/boolean.js.map +1 -0
- package/dist/parsing/expressions/expression.d.ts +4 -1
- package/dist/parsing/expressions/expression.d.ts.map +1 -1
- package/dist/parsing/expressions/expression.js +15 -8
- package/dist/parsing/expressions/expression.js.map +1 -1
- package/dist/parsing/expressions/operator.d.ts +1 -1
- package/dist/parsing/expressions/operator.d.ts.map +1 -1
- package/dist/parsing/expressions/operator.js.map +1 -1
- package/dist/parsing/functions/function_factory.d.ts +13 -13
- package/dist/parsing/functions/function_factory.d.ts.map +1 -1
- package/dist/parsing/functions/function_factory.js +20 -18
- package/dist/parsing/functions/function_factory.js.map +1 -1
- package/dist/parsing/operations/create_node.d.ts +14 -0
- package/dist/parsing/operations/create_node.d.ts.map +1 -0
- package/dist/parsing/operations/create_node.js +51 -0
- package/dist/parsing/operations/create_node.js.map +1 -0
- package/dist/parsing/operations/create_relationship.d.ts +14 -0
- package/dist/parsing/operations/create_relationship.d.ts.map +1 -0
- package/dist/parsing/operations/create_relationship.js +51 -0
- package/dist/parsing/operations/create_relationship.js.map +1 -0
- package/dist/parsing/operations/match.d.ts +15 -0
- package/dist/parsing/operations/match.d.ts.map +1 -0
- package/dist/parsing/operations/match.js +45 -0
- package/dist/parsing/operations/match.js.map +1 -0
- package/dist/parsing/operations/operation.d.ts +1 -0
- package/dist/parsing/operations/operation.d.ts.map +1 -1
- package/dist/parsing/operations/operation.js +6 -0
- package/dist/parsing/operations/operation.js.map +1 -1
- package/dist/parsing/operations/return.d.ts +1 -0
- package/dist/parsing/operations/return.d.ts.map +1 -1
- package/dist/parsing/operations/return.js +7 -1
- package/dist/parsing/operations/return.js.map +1 -1
- package/dist/parsing/operations/where.d.ts +1 -1
- package/dist/parsing/operations/where.d.ts.map +1 -1
- package/dist/parsing/operations/where.js +4 -0
- package/dist/parsing/operations/where.js.map +1 -1
- package/dist/parsing/parser.d.ts +10 -0
- package/dist/parsing/parser.d.ts.map +1 -1
- package/dist/parsing/parser.js +344 -5
- package/dist/parsing/parser.js.map +1 -1
- package/dist/parsing/token_to_node.d.ts.map +1 -1
- package/dist/parsing/token_to_node.js +7 -0
- package/dist/parsing/token_to_node.js.map +1 -1
- package/dist/tokenization/keyword.d.ts +1 -0
- package/dist/tokenization/keyword.d.ts.map +1 -1
- package/dist/tokenization/keyword.js +1 -0
- package/dist/tokenization/keyword.js.map +1 -1
- package/dist/tokenization/token.d.ts +4 -0
- package/dist/tokenization/token.d.ts.map +1 -1
- package/dist/tokenization/token.js +14 -1
- package/dist/tokenization/token.js.map +1 -1
- package/dist/tokenization/token_type.d.ts +1 -0
- package/dist/tokenization/token_type.d.ts.map +1 -1
- package/dist/tokenization/token_type.js +1 -0
- package/dist/tokenization/token_type.js.map +1 -1
- package/dist/tokenization/tokenizer.d.ts +2 -1
- package/dist/tokenization/tokenizer.d.ts.map +1 -1
- package/dist/tokenization/tokenizer.js +25 -12
- package/dist/tokenization/tokenizer.js.map +1 -1
- package/docs/flowquery.min.js +1 -1
- package/flowquery-py/README.md +166 -0
- package/flowquery-py/pyproject.toml +75 -0
- package/flowquery-py/setup_env.ps1 +92 -0
- package/flowquery-py/setup_env.sh +87 -0
- package/flowquery-py/src/__init__.py +34 -0
- package/flowquery-py/src/__main__.py +10 -0
- package/flowquery-py/src/compute/__init__.py +5 -0
- package/flowquery-py/src/compute/runner.py +60 -0
- package/flowquery-py/src/extensibility.py +52 -0
- package/flowquery-py/src/graph/__init__.py +31 -0
- package/flowquery-py/src/graph/data.py +118 -0
- package/flowquery-py/src/graph/database.py +82 -0
- package/flowquery-py/src/graph/hops.py +43 -0
- package/flowquery-py/src/graph/node.py +112 -0
- package/flowquery-py/src/graph/node_data.py +26 -0
- package/flowquery-py/src/graph/node_reference.py +49 -0
- package/flowquery-py/src/graph/pattern.py +125 -0
- package/flowquery-py/src/graph/pattern_expression.py +62 -0
- package/flowquery-py/src/graph/patterns.py +42 -0
- package/flowquery-py/src/graph/physical_node.py +40 -0
- package/flowquery-py/src/graph/physical_relationship.py +36 -0
- package/flowquery-py/src/graph/relationship.py +135 -0
- package/flowquery-py/src/graph/relationship_data.py +33 -0
- package/flowquery-py/src/graph/relationship_match_collector.py +77 -0
- package/flowquery-py/src/graph/relationship_reference.py +21 -0
- package/flowquery-py/src/io/__init__.py +5 -0
- package/flowquery-py/src/io/command_line.py +67 -0
- package/flowquery-py/src/parsing/__init__.py +17 -0
- package/flowquery-py/src/parsing/alias.py +20 -0
- package/flowquery-py/src/parsing/alias_option.py +11 -0
- package/flowquery-py/src/parsing/ast_node.py +146 -0
- package/flowquery-py/src/parsing/base_parser.py +84 -0
- package/flowquery-py/src/parsing/components/__init__.py +19 -0
- package/flowquery-py/src/parsing/components/csv.py +8 -0
- package/flowquery-py/src/parsing/components/from_.py +10 -0
- package/flowquery-py/src/parsing/components/headers.py +12 -0
- package/flowquery-py/src/parsing/components/json.py +8 -0
- package/flowquery-py/src/parsing/components/null.py +10 -0
- package/flowquery-py/src/parsing/components/post.py +8 -0
- package/flowquery-py/src/parsing/components/text.py +8 -0
- package/flowquery-py/src/parsing/context.py +50 -0
- package/flowquery-py/src/parsing/data_structures/__init__.py +15 -0
- package/flowquery-py/src/parsing/data_structures/associative_array.py +41 -0
- package/flowquery-py/src/parsing/data_structures/json_array.py +30 -0
- package/flowquery-py/src/parsing/data_structures/key_value_pair.py +38 -0
- package/flowquery-py/src/parsing/data_structures/lookup.py +49 -0
- package/flowquery-py/src/parsing/data_structures/range_lookup.py +42 -0
- package/flowquery-py/src/parsing/expressions/__init__.py +57 -0
- package/flowquery-py/src/parsing/expressions/boolean.py +20 -0
- package/flowquery-py/src/parsing/expressions/expression.py +138 -0
- package/flowquery-py/src/parsing/expressions/expression_map.py +26 -0
- package/flowquery-py/src/parsing/expressions/f_string.py +27 -0
- package/flowquery-py/src/parsing/expressions/identifier.py +20 -0
- package/flowquery-py/src/parsing/expressions/number.py +32 -0
- package/flowquery-py/src/parsing/expressions/operator.py +169 -0
- package/flowquery-py/src/parsing/expressions/reference.py +47 -0
- package/flowquery-py/src/parsing/expressions/string.py +27 -0
- package/flowquery-py/src/parsing/functions/__init__.py +75 -0
- package/flowquery-py/src/parsing/functions/aggregate_function.py +60 -0
- package/flowquery-py/src/parsing/functions/async_function.py +62 -0
- package/flowquery-py/src/parsing/functions/avg.py +55 -0
- package/flowquery-py/src/parsing/functions/collect.py +75 -0
- package/flowquery-py/src/parsing/functions/function.py +68 -0
- package/flowquery-py/src/parsing/functions/function_factory.py +173 -0
- package/flowquery-py/src/parsing/functions/function_metadata.py +149 -0
- package/flowquery-py/src/parsing/functions/functions.py +59 -0
- package/flowquery-py/src/parsing/functions/join.py +47 -0
- package/flowquery-py/src/parsing/functions/keys.py +34 -0
- package/flowquery-py/src/parsing/functions/predicate_function.py +46 -0
- package/flowquery-py/src/parsing/functions/predicate_sum.py +47 -0
- package/flowquery-py/src/parsing/functions/rand.py +28 -0
- package/flowquery-py/src/parsing/functions/range_.py +34 -0
- package/flowquery-py/src/parsing/functions/reducer_element.py +15 -0
- package/flowquery-py/src/parsing/functions/replace.py +37 -0
- package/flowquery-py/src/parsing/functions/round_.py +32 -0
- package/flowquery-py/src/parsing/functions/size.py +32 -0
- package/flowquery-py/src/parsing/functions/split.py +47 -0
- package/flowquery-py/src/parsing/functions/stringify.py +47 -0
- package/flowquery-py/src/parsing/functions/sum.py +51 -0
- package/flowquery-py/src/parsing/functions/to_json.py +33 -0
- package/flowquery-py/src/parsing/functions/type_.py +47 -0
- package/flowquery-py/src/parsing/functions/value_holder.py +24 -0
- package/flowquery-py/src/parsing/logic/__init__.py +15 -0
- package/flowquery-py/src/parsing/logic/case.py +29 -0
- package/flowquery-py/src/parsing/logic/else_.py +12 -0
- package/flowquery-py/src/parsing/logic/end.py +8 -0
- package/flowquery-py/src/parsing/logic/then.py +12 -0
- package/flowquery-py/src/parsing/logic/when.py +10 -0
- package/flowquery-py/src/parsing/operations/__init__.py +35 -0
- package/flowquery-py/src/parsing/operations/aggregated_return.py +24 -0
- package/flowquery-py/src/parsing/operations/aggregated_with.py +22 -0
- package/flowquery-py/src/parsing/operations/call.py +74 -0
- package/flowquery-py/src/parsing/operations/create_node.py +34 -0
- package/flowquery-py/src/parsing/operations/create_relationship.py +34 -0
- package/flowquery-py/src/parsing/operations/group_by.py +130 -0
- package/flowquery-py/src/parsing/operations/limit.py +22 -0
- package/flowquery-py/src/parsing/operations/load.py +140 -0
- package/flowquery-py/src/parsing/operations/match.py +29 -0
- package/flowquery-py/src/parsing/operations/operation.py +69 -0
- package/flowquery-py/src/parsing/operations/projection.py +21 -0
- package/flowquery-py/src/parsing/operations/return_op.py +50 -0
- package/flowquery-py/src/parsing/operations/unwind.py +37 -0
- package/flowquery-py/src/parsing/operations/where.py +41 -0
- package/flowquery-py/src/parsing/operations/with_op.py +18 -0
- package/flowquery-py/src/parsing/parser.py +1011 -0
- package/flowquery-py/src/parsing/token_to_node.py +109 -0
- package/flowquery-py/src/tokenization/__init__.py +23 -0
- package/flowquery-py/src/tokenization/keyword.py +48 -0
- package/flowquery-py/src/tokenization/operator.py +29 -0
- package/flowquery-py/src/tokenization/string_walker.py +158 -0
- package/flowquery-py/src/tokenization/symbol.py +19 -0
- package/flowquery-py/src/tokenization/token.py +659 -0
- package/flowquery-py/src/tokenization/token_mapper.py +52 -0
- package/flowquery-py/src/tokenization/token_type.py +21 -0
- package/flowquery-py/src/tokenization/tokenizer.py +214 -0
- package/flowquery-py/src/tokenization/trie.py +124 -0
- package/flowquery-py/src/utils/__init__.py +6 -0
- package/flowquery-py/src/utils/object_utils.py +20 -0
- package/flowquery-py/src/utils/string_utils.py +113 -0
- package/flowquery-py/tests/__init__.py +1 -0
- package/flowquery-py/tests/compute/__init__.py +1 -0
- package/flowquery-py/tests/compute/test_runner.py +1335 -0
- package/flowquery-py/tests/graph/__init__.py +1 -0
- package/flowquery-py/tests/graph/test_create.py +56 -0
- package/flowquery-py/tests/graph/test_data.py +73 -0
- package/flowquery-py/tests/graph/test_match.py +40 -0
- package/flowquery-py/tests/parsing/__init__.py +1 -0
- package/flowquery-py/tests/parsing/test_context.py +34 -0
- package/flowquery-py/tests/parsing/test_expression.py +49 -0
- package/flowquery-py/tests/parsing/test_parser.py +674 -0
- package/flowquery-py/tests/test_extensibility.py +611 -0
- package/flowquery-py/tests/tokenization/__init__.py +1 -0
- package/flowquery-py/tests/tokenization/test_token_mapper.py +60 -0
- package/flowquery-py/tests/tokenization/test_tokenizer.py +164 -0
- package/flowquery-py/tests/tokenization/test_trie.py +30 -0
- package/flowquery-vscode/flowQueryEngine/flowquery.min.js +1 -1
- package/misc/apps/RAG/package.json +1 -1
- package/misc/apps/RAG/src/components/AdaptiveCardRenderer.tsx +76 -8
- package/misc/apps/RAG/src/components/index.ts +19 -10
- package/misc/apps/RAG/src/plugins/loaders/MockData.ts +70 -140
- package/misc/apps/RAG/src/prompts/FlowQuerySystemPrompt.ts +12 -0
- package/package.json +1 -1
- package/src/compute/runner.ts +24 -19
- package/src/graph/data.ts +112 -0
- package/src/graph/database.ts +63 -0
- package/src/graph/hops.ts +22 -0
- package/src/graph/node.ts +99 -0
- package/src/graph/node_data.ts +18 -0
- package/src/graph/node_reference.ts +33 -0
- package/src/graph/pattern.ts +101 -0
- package/src/graph/pattern_expression.ts +37 -0
- package/src/graph/patterns.ts +36 -0
- package/src/graph/physical_node.ts +23 -0
- package/src/graph/physical_relationship.ts +23 -0
- package/src/graph/relationship.ts +116 -0
- package/src/graph/relationship_data.ts +27 -0
- package/src/graph/relationship_match_collector.ts +58 -0
- package/src/graph/relationship_reference.ts +24 -0
- package/src/parsing/base_parser.ts +20 -14
- package/src/parsing/context.ts +14 -14
- package/src/parsing/expressions/boolean.ts +21 -0
- package/src/parsing/expressions/expression.ts +34 -26
- package/src/parsing/expressions/operator.ts +19 -1
- package/src/parsing/functions/function_factory.ts +45 -45
- package/src/parsing/operations/create_node.ts +39 -0
- package/src/parsing/operations/create_relationship.ts +38 -0
- package/src/parsing/operations/match.ts +31 -0
- package/src/parsing/operations/operation.ts +3 -0
- package/src/parsing/operations/return.ts +11 -7
- package/src/parsing/operations/where.ts +10 -6
- package/src/parsing/parser.ts +346 -8
- package/src/parsing/token_to_node.ts +6 -0
- package/src/tokenization/keyword.ts +41 -40
- package/src/tokenization/token.ts +21 -1
- package/src/tokenization/token_type.ts +2 -1
- package/src/tokenization/tokenizer.ts +52 -31
- package/tests/compute/runner.test.ts +654 -0
- package/tests/extensibility.test.ts +97 -93
- package/tests/graph/create.test.ts +36 -0
- package/tests/graph/data.test.ts +58 -0
- package/tests/graph/match.test.ts +29 -0
- package/tests/parsing/parser.test.ts +273 -2
- package/tests/tokenization/tokenizer.test.ts +90 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Converts tokens to AST nodes."""
|
|
2
|
+
|
|
3
|
+
from ..tokenization.token import Token
|
|
4
|
+
from .ast_node import ASTNode
|
|
5
|
+
from .components.csv import CSV
|
|
6
|
+
from .components.json import JSON
|
|
7
|
+
from .components.null import Null
|
|
8
|
+
from .components.text import Text
|
|
9
|
+
from .expressions.boolean import Boolean
|
|
10
|
+
from .expressions.identifier import Identifier
|
|
11
|
+
from .expressions.number import Number
|
|
12
|
+
from .expressions.string import String
|
|
13
|
+
from .expressions.operator import (
|
|
14
|
+
Add,
|
|
15
|
+
And,
|
|
16
|
+
Divide,
|
|
17
|
+
Equals,
|
|
18
|
+
GreaterThan,
|
|
19
|
+
GreaterThanOrEqual,
|
|
20
|
+
Is,
|
|
21
|
+
LessThan,
|
|
22
|
+
LessThanOrEqual,
|
|
23
|
+
Modulo,
|
|
24
|
+
Multiply,
|
|
25
|
+
Not,
|
|
26
|
+
NotEquals,
|
|
27
|
+
Or,
|
|
28
|
+
Power,
|
|
29
|
+
Subtract,
|
|
30
|
+
)
|
|
31
|
+
from .logic.else_ import Else
|
|
32
|
+
from .logic.end import End
|
|
33
|
+
from .logic.then import Then
|
|
34
|
+
from .logic.when import When
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class TokenToNode:
|
|
38
|
+
"""Converts tokens to their corresponding AST nodes."""
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def convert(token: Token) -> ASTNode:
|
|
42
|
+
if token.is_number():
|
|
43
|
+
if token.value is None:
|
|
44
|
+
raise ValueError("Number token has no value")
|
|
45
|
+
return Number(token.value)
|
|
46
|
+
elif token.is_string():
|
|
47
|
+
if token.value is None:
|
|
48
|
+
raise ValueError("String token has no value")
|
|
49
|
+
return String(token.value)
|
|
50
|
+
elif token.is_identifier():
|
|
51
|
+
if token.value is None:
|
|
52
|
+
raise ValueError("Identifier token has no value")
|
|
53
|
+
return Identifier(token.value)
|
|
54
|
+
elif token.is_operator():
|
|
55
|
+
if token.is_add():
|
|
56
|
+
return Add()
|
|
57
|
+
elif token.is_subtract():
|
|
58
|
+
return Subtract()
|
|
59
|
+
elif token.is_multiply():
|
|
60
|
+
return Multiply()
|
|
61
|
+
elif token.is_divide():
|
|
62
|
+
return Divide()
|
|
63
|
+
elif token.is_modulo():
|
|
64
|
+
return Modulo()
|
|
65
|
+
elif token.is_exponent():
|
|
66
|
+
return Power()
|
|
67
|
+
elif token.is_equals():
|
|
68
|
+
return Equals()
|
|
69
|
+
elif token.is_not_equals():
|
|
70
|
+
return NotEquals()
|
|
71
|
+
elif token.is_less_than():
|
|
72
|
+
return LessThan()
|
|
73
|
+
elif token.is_greater_than():
|
|
74
|
+
return GreaterThan()
|
|
75
|
+
elif token.is_greater_than_or_equal():
|
|
76
|
+
return GreaterThanOrEqual()
|
|
77
|
+
elif token.is_less_than_or_equal():
|
|
78
|
+
return LessThanOrEqual()
|
|
79
|
+
elif token.is_and():
|
|
80
|
+
return And()
|
|
81
|
+
elif token.is_or():
|
|
82
|
+
return Or()
|
|
83
|
+
elif token.is_is():
|
|
84
|
+
return Is()
|
|
85
|
+
elif token.is_unary_operator():
|
|
86
|
+
if token.is_not():
|
|
87
|
+
return Not()
|
|
88
|
+
elif token.is_keyword():
|
|
89
|
+
if token.is_json():
|
|
90
|
+
return JSON()
|
|
91
|
+
elif token.is_csv():
|
|
92
|
+
return CSV()
|
|
93
|
+
elif token.is_text():
|
|
94
|
+
return Text()
|
|
95
|
+
elif token.is_when():
|
|
96
|
+
return When()
|
|
97
|
+
elif token.is_then():
|
|
98
|
+
return Then()
|
|
99
|
+
elif token.is_else():
|
|
100
|
+
return Else()
|
|
101
|
+
elif token.is_end():
|
|
102
|
+
return End()
|
|
103
|
+
elif token.is_null():
|
|
104
|
+
return Null()
|
|
105
|
+
elif token.is_boolean():
|
|
106
|
+
return Boolean(token.value)
|
|
107
|
+
else:
|
|
108
|
+
raise ValueError("Unknown token")
|
|
109
|
+
return ASTNode()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Tokenization module for FlowQuery."""
|
|
2
|
+
|
|
3
|
+
from .tokenizer import Tokenizer
|
|
4
|
+
from .token import Token
|
|
5
|
+
from .token_type import TokenType
|
|
6
|
+
from .keyword import Keyword
|
|
7
|
+
from .operator import Operator
|
|
8
|
+
from .symbol import Symbol
|
|
9
|
+
from .token_mapper import TokenMapper
|
|
10
|
+
from .string_walker import StringWalker
|
|
11
|
+
from .trie import Trie
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"Tokenizer",
|
|
15
|
+
"Token",
|
|
16
|
+
"TokenType",
|
|
17
|
+
"Keyword",
|
|
18
|
+
"Operator",
|
|
19
|
+
"Symbol",
|
|
20
|
+
"TokenMapper",
|
|
21
|
+
"StringWalker",
|
|
22
|
+
"Trie",
|
|
23
|
+
]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Keyword enumeration for FlowQuery tokenization."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Keyword(Enum):
|
|
7
|
+
"""Enumeration of all keywords in FlowQuery."""
|
|
8
|
+
|
|
9
|
+
RETURN = "RETURN"
|
|
10
|
+
MATCH = "MATCH"
|
|
11
|
+
WHERE = "WHERE"
|
|
12
|
+
CREATE = "CREATE"
|
|
13
|
+
VIRTUAL = "VIRTUAL"
|
|
14
|
+
MERGE = "MERGE"
|
|
15
|
+
DELETE = "DELETE"
|
|
16
|
+
DETACH = "DETACH"
|
|
17
|
+
SET = "SET"
|
|
18
|
+
REMOVE = "REMOVE"
|
|
19
|
+
FOREACH = "FOREACH"
|
|
20
|
+
WITH = "WITH"
|
|
21
|
+
CALL = "CALL"
|
|
22
|
+
YIELD = "YIELD"
|
|
23
|
+
LOAD = "LOAD"
|
|
24
|
+
HEADERS = "HEADERS"
|
|
25
|
+
POST = "POST"
|
|
26
|
+
FROM = "FROM"
|
|
27
|
+
CSV = "CSV"
|
|
28
|
+
JSON = "JSON"
|
|
29
|
+
TEXT = "TEXT"
|
|
30
|
+
AS = "AS"
|
|
31
|
+
UNWIND = "UNWIND"
|
|
32
|
+
SUM = "SUM"
|
|
33
|
+
COLLECT = "COLLECT"
|
|
34
|
+
DISTINCT = "DISTINCT"
|
|
35
|
+
ORDER = "ORDER"
|
|
36
|
+
BY = "BY"
|
|
37
|
+
ASC = "ASC"
|
|
38
|
+
DESC = "DESC"
|
|
39
|
+
SKIP = "SKIP"
|
|
40
|
+
LIMIT = "LIMIT"
|
|
41
|
+
EOF = "EOF"
|
|
42
|
+
CASE = "CASE"
|
|
43
|
+
WHEN = "WHEN"
|
|
44
|
+
THEN = "THEN"
|
|
45
|
+
ELSE = "ELSE"
|
|
46
|
+
END = "END"
|
|
47
|
+
NULL = "NULL"
|
|
48
|
+
IN = "IN"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Operator enumeration for FlowQuery tokenization."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Operator(Enum):
|
|
7
|
+
"""Enumeration of all operators in FlowQuery."""
|
|
8
|
+
|
|
9
|
+
# Arithmetic
|
|
10
|
+
ADD = "+"
|
|
11
|
+
SUBTRACT = "-"
|
|
12
|
+
MULTIPLY = "*"
|
|
13
|
+
DIVIDE = "/"
|
|
14
|
+
MODULO = "%"
|
|
15
|
+
EXPONENT = "^"
|
|
16
|
+
# Comparison
|
|
17
|
+
EQUALS = "="
|
|
18
|
+
NOT_EQUALS = "<>"
|
|
19
|
+
LESS_THAN = "<"
|
|
20
|
+
LESS_THAN_OR_EQUAL = "<="
|
|
21
|
+
GREATER_THAN = ">"
|
|
22
|
+
GREATER_THAN_OR_EQUAL = ">="
|
|
23
|
+
IS = "IS"
|
|
24
|
+
# Logical
|
|
25
|
+
AND = "AND"
|
|
26
|
+
OR = "OR"
|
|
27
|
+
NOT = "NOT"
|
|
28
|
+
IN = "IN"
|
|
29
|
+
PIPE = "|"
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Utility class for walking through a string character by character during tokenization."""
|
|
2
|
+
|
|
3
|
+
from ..utils.string_utils import StringUtils
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class StringWalker:
|
|
7
|
+
"""Utility class for walking through a string character by character during tokenization.
|
|
8
|
+
|
|
9
|
+
Provides methods to check for specific character patterns, move through the string,
|
|
10
|
+
and extract substrings. Used by the Tokenizer to process input text.
|
|
11
|
+
|
|
12
|
+
Example:
|
|
13
|
+
walker = StringWalker("WITH x as variable")
|
|
14
|
+
while not walker.is_at_end:
|
|
15
|
+
# Process characters
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, text: str):
|
|
19
|
+
"""Creates a new StringWalker for the given text.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
text: The input text to walk through
|
|
23
|
+
"""
|
|
24
|
+
self._text = text
|
|
25
|
+
self._position = 0
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def position(self) -> int:
|
|
29
|
+
return self._position
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def current_char(self) -> str:
|
|
33
|
+
if self._position >= len(self._text):
|
|
34
|
+
return ''
|
|
35
|
+
return self._text[self._position]
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def next_char(self) -> str:
|
|
39
|
+
if self._position + 1 >= len(self._text):
|
|
40
|
+
return ''
|
|
41
|
+
return self._text[self._position + 1]
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def previous_char(self) -> str:
|
|
45
|
+
if self._position - 1 < 0:
|
|
46
|
+
return ''
|
|
47
|
+
return self._text[self._position - 1]
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def is_at_end(self) -> bool:
|
|
51
|
+
return self._position >= len(self._text)
|
|
52
|
+
|
|
53
|
+
def get_string(self, start_position: int) -> str:
|
|
54
|
+
return self._text[start_position:self._position]
|
|
55
|
+
|
|
56
|
+
def get_remaining_string(self) -> str:
|
|
57
|
+
return self._text[self._position:]
|
|
58
|
+
|
|
59
|
+
def check_for_single_comment(self) -> bool:
|
|
60
|
+
if self.single_line_comment_start():
|
|
61
|
+
while not self.is_at_end and not self.new_line():
|
|
62
|
+
self._position += 1
|
|
63
|
+
return True
|
|
64
|
+
return False
|
|
65
|
+
|
|
66
|
+
def check_for_multi_line_comment(self) -> bool:
|
|
67
|
+
if self.multi_line_comment_start():
|
|
68
|
+
while not self.is_at_end:
|
|
69
|
+
if self.multi_line_comment_end():
|
|
70
|
+
self._position += 2
|
|
71
|
+
return True
|
|
72
|
+
self._position += 1
|
|
73
|
+
raise ValueError(f"Unterminated multi-line comment at position {self._position}")
|
|
74
|
+
return False
|
|
75
|
+
|
|
76
|
+
def single_line_comment_start(self) -> bool:
|
|
77
|
+
return self.current_char == '/' and self.next_char == '/'
|
|
78
|
+
|
|
79
|
+
def multi_line_comment_start(self) -> bool:
|
|
80
|
+
return self.current_char == '/' and self.next_char == '*'
|
|
81
|
+
|
|
82
|
+
def multi_line_comment_end(self) -> bool:
|
|
83
|
+
return self.current_char == '*' and self.next_char == '/'
|
|
84
|
+
|
|
85
|
+
def new_line(self) -> bool:
|
|
86
|
+
return self.current_char == '\n'
|
|
87
|
+
|
|
88
|
+
def escaped(self, char: str) -> bool:
|
|
89
|
+
return self.current_char == '\\' and self.next_char == char
|
|
90
|
+
|
|
91
|
+
def escaped_brace(self) -> bool:
|
|
92
|
+
return ((self.current_char == '{' and self.next_char == '{') or
|
|
93
|
+
(self.current_char == '}' and self.next_char == '}'))
|
|
94
|
+
|
|
95
|
+
def opening_brace(self) -> bool:
|
|
96
|
+
return self.current_char == '{'
|
|
97
|
+
|
|
98
|
+
def closing_brace(self) -> bool:
|
|
99
|
+
return self.current_char == '}'
|
|
100
|
+
|
|
101
|
+
def check_for_under_score(self) -> bool:
|
|
102
|
+
found_under_score = self.current_char == '_'
|
|
103
|
+
if found_under_score:
|
|
104
|
+
self._position += 1
|
|
105
|
+
return found_under_score
|
|
106
|
+
|
|
107
|
+
def check_for_letter(self) -> bool:
|
|
108
|
+
found_letter = self.current_char.lower() in StringUtils.letters
|
|
109
|
+
if found_letter:
|
|
110
|
+
self._position += 1
|
|
111
|
+
return found_letter
|
|
112
|
+
|
|
113
|
+
def check_for_digit(self) -> bool:
|
|
114
|
+
found_digit = self.current_char in StringUtils.digits
|
|
115
|
+
if found_digit:
|
|
116
|
+
self._position += 1
|
|
117
|
+
return found_digit
|
|
118
|
+
|
|
119
|
+
def check_for_quote(self) -> str | None:
|
|
120
|
+
quote_char = self.current_char
|
|
121
|
+
if quote_char in ('"', "'", '`'):
|
|
122
|
+
self._position += 1
|
|
123
|
+
return quote_char
|
|
124
|
+
return None
|
|
125
|
+
|
|
126
|
+
def check_for_string(self, value: str) -> bool:
|
|
127
|
+
_string = self._text[self._position:self._position + len(value)]
|
|
128
|
+
found_string = _string.lower() == value.lower()
|
|
129
|
+
if found_string:
|
|
130
|
+
self._position += len(value)
|
|
131
|
+
return found_string
|
|
132
|
+
|
|
133
|
+
def check_for_whitespace(self) -> bool:
|
|
134
|
+
return self.current_char in StringUtils.whitespace
|
|
135
|
+
|
|
136
|
+
def check_for_f_string_start(self) -> bool:
|
|
137
|
+
return self.current_char.lower() == 'f' and self.next_char in ("'", '"', '`')
|
|
138
|
+
|
|
139
|
+
def move_next(self) -> None:
|
|
140
|
+
self._position += 1
|
|
141
|
+
|
|
142
|
+
def move_by(self, steps: int) -> None:
|
|
143
|
+
self._position += steps
|
|
144
|
+
|
|
145
|
+
def move_previous(self) -> None:
|
|
146
|
+
self._position -= 1
|
|
147
|
+
|
|
148
|
+
def is_word(self, word: str | None) -> bool:
|
|
149
|
+
if word is None:
|
|
150
|
+
return False
|
|
151
|
+
return self._text[self._position:self._position + len(word)] == word
|
|
152
|
+
|
|
153
|
+
def word_continuation(self, word: str) -> bool:
|
|
154
|
+
next_pos = self._position + len(word)
|
|
155
|
+
if next_pos >= len(self._text):
|
|
156
|
+
return False
|
|
157
|
+
next_char = self._text[next_pos]
|
|
158
|
+
return next_char in StringUtils.word_valid_chars
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Symbol enumeration for FlowQuery tokenization."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Symbol(Enum):
|
|
7
|
+
"""Enumeration of all symbols in FlowQuery."""
|
|
8
|
+
|
|
9
|
+
LEFT_PARENTHESIS = "("
|
|
10
|
+
RIGHT_PARENTHESIS = ")"
|
|
11
|
+
COMMA = ","
|
|
12
|
+
DOT = "."
|
|
13
|
+
COLON = ":"
|
|
14
|
+
WHITESPACE = ""
|
|
15
|
+
OPENING_BRACE = "{"
|
|
16
|
+
CLOSING_BRACE = "}"
|
|
17
|
+
OPENING_BRACKET = "["
|
|
18
|
+
CLOSING_BRACKET = "]"
|
|
19
|
+
BACKTICK = "`"
|