Skip to content

Commit

Permalink
Add = as a keyword to Fusion
Browse files Browse the repository at this point in the history
  • Loading branch information
kesmit13 committed Nov 6, 2023
1 parent 87094d6 commit 4d3bec5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion singlestoredb/fusion/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
comma = ws "," ws
open_paren = ws "(" ws
close_paren = ws ")" ws
select = ~r"SELECT"i ws ~r".+" ws
'''

BUILTINS = {
Expand Down Expand Up @@ -55,7 +56,7 @@

def get_keywords(grammar: str) -> Tuple[str, ...]:
"""Return all all-caps words from the beginning of the line."""
m = re.match(r'^\s*([A-Z0-9_]+(\s+|$|;))+', grammar)
m = re.match(r'^\s*((?:[A-Z0-9_]+|=)(\s+|$|;))+', grammar)
if not m:
return tuple()
return tuple(re.split(r'\s+', m.group(0).replace(';', '').strip()))
Expand Down Expand Up @@ -275,6 +276,9 @@ def process_grammar(grammar: str) -> Tuple[Grammar, Tuple[str, ...], Dict[str, A
# Convert literal strings to 'qs'
sql = re.sub(r"'[^']+'", r'qs', sql)

# Convert special characters to literal tokens
sql = re.sub(r'([=]) ', r" '\1' ", sql)

# Convert [...] groups to (...)*
sql = re.sub(r'\[([^\]]+)\]', process_optional, sql)

Expand Down Expand Up @@ -513,6 +517,10 @@ def visit_init(self, node: Node, visited_children: Iterable[Any]) -> Any:
_, out, *_ = visited_children
return out

def visit_select(self, node: Node, visited_children: Iterable[Any]) -> Any:
out = ' '.join(flatten(visited_children))
return {'select': out}

def visit_order_by(self, node: Node, visited_children: Iterable[Any]) -> Any:
"""Handle ORDER BY."""
by = []
Expand Down

0 comments on commit 4d3bec5

Please sign in to comment.