From: Kevin Date: Thu, 14 May 2020 01:50:10 +0000 (-0400) Subject: Swap out the old parser with the new one X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fa7c886eaf8aa074180d0b09dcbbae1f3154177b;p=thirdparty%2Fjinja.git Swap out the old parser with the new one This will allow us to figure out where the gaps are within the test suite and also start running a comparison on the timing changes. --- diff --git a/src/jinja2/new_parser.py b/src/jinja2/new_parser.py index 5345cb6f..95ae73ec 100644 --- a/src/jinja2/new_parser.py +++ b/src/jinja2/new_parser.py @@ -1,3 +1,4 @@ +from tatsu.exceptions import FailedSemantics from . import nodes diff --git a/src/jinja2/parser.py b/src/jinja2/parser.py index eedea7a0..7cb55fdd 100644 --- a/src/jinja2/parser.py +++ b/src/jinja2/parser.py @@ -5,6 +5,12 @@ from .exceptions import TemplateSyntaxError from .lexer import describe_token from .lexer import describe_token_expr +import tatsu + +with open('grammar.ebnf', 'r') as grammar_file: + grammar = tatsu.compile(grammar_file.read()) + + _statement_keywords = frozenset( [ "for", @@ -40,6 +46,7 @@ class Parser: def __init__(self, environment, source, name=None, filename=None, state=None): self.environment = environment + self.source = source self.stream = environment._tokenize(source, name, filename, state) self.name = name self.filename = filename @@ -927,8 +934,20 @@ class Parser: return body - def parse(self): - """Parse the whole template into a `Template` node.""" + def parse_old(self): result = nodes.Template(self.subparse(), lineno=1) result.set_environment(self.environment) return result + + def parse(self): + """Parse the whole template into a `Template` node.""" + from .new_parser import JinjaSemantics, parse_template + + return parse_template( + grammar.parse( + self.source, + whitespace='', + parseinfo=True, + semantics=JinjaSemantics(), + ) + )