Skip to content

Commit 8ccfa36

Browse files
committed
Add IterGen parser
1 parent 5d5ca76 commit 8ccfa36

3 files changed

Lines changed: 562 additions & 1 deletion

File tree

syncode/parsers/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import os
22
from syncode.parsers import incremental_parser
3+
from syncode.parsers.itergen_parser import IGParser
34
from syncode.parsers.python_parser import PythonIncrementalParser, PythonIndenter
45
from syncode.parsers.go_parser import GoIncrementalParser
56
import syncode.common as common
67
from syncode.larkm.lark import Lark
78
from syncode.parsers.grammars.grammar import Grammar
89

9-
def create_parser(grammar: Grammar, parser='lalr', **kwargs) -> incremental_parser.IncrementalParser:
10+
def create_parser(
11+
grammar: Grammar,
12+
parser='lalr',
13+
use_symbol_pos_map=False,
14+
**kwargs
15+
) -> incremental_parser.IncrementalParser:
1016
"""
1117
Creates an incremental parser for the given grammar. The parser is cached for future use.
1218
parser (str, optional): The type of parser to use. Can be 'lalr' or 'lr'. Defaults to 'lalr'.
@@ -16,6 +22,10 @@ def create_parser(grammar: Grammar, parser='lalr', **kwargs) -> incremental_pars
1622
cache_filename = parser_cache_dir + f'{grammar}_{parser}_{grammar.hash()}_parser.pkl'
1723
os.makedirs(os.path.dirname(parser_cache_dir), exist_ok=True)
1824

25+
# First check if we should use the IGParser with symbol position map
26+
if use_symbol_pos_map:
27+
return IGParser(base_parser, **kwargs)
28+
1929
if grammar.name == 'python':
2030
indenter = PythonIndenter()
2131

@@ -27,6 +37,7 @@ def create_parser(grammar: Grammar, parser='lalr', **kwargs) -> incremental_pars
2737
return GoIncrementalParser(base_parser, **kwargs)
2838
return incremental_parser.IncrementalParser(base_parser, **kwargs)
2939

40+
3041
def create_base_parser(grammar, parser='lalr', indenter=None, cache_filename=None):
3142
base_parser = Lark( # This is the standard Lark parser
3243
grammar.ebnf,

0 commit comments

Comments
 (0)