From 224612c0a70aa8398e6dea5e446efd8dd65c3f27 Mon Sep 17 00:00:00 2001 From: apalala Date: Sun, 10 Dec 2023 11:46:49 -0400 Subject: [PATCH] [bootstrap] make the generated parser be the bootstrap parser --- tatsu/bootstrap.py | 545 +++++++++++--------------------------- tatsu/ngcodegen/python.py | 2 +- 2 files changed, 160 insertions(+), 387 deletions(-) diff --git a/tatsu/bootstrap.py b/tatsu/bootstrap.py index 6c3be580..ce462d20 100644 --- a/tatsu/bootstrap.py +++ b/tatsu/bootstrap.py @@ -1,15 +1,15 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -# CAVEAT UTILITOR +# WARNING: CAVEAT UTILITOR # -# This file was automatically generated by TatSu. +# This file was automatically generated by TatSu. # -# https://pypi.python.org/pypi/tatsu/ +# https://pypi.python.org/pypi/tatsu/ # -# Any changes you make to it will be overwritten the next time -# the file is generated. +# Any changes you make to it will be overwritten the next time +# the file is generated. -# ruff: noqa: C405, I001, F401, SIM117 +# ruff: noqa: C405, COM812, I001, F401, SIM117 import sys from pathlib import Path @@ -30,7 +30,7 @@ def __init__(self, text, /, config: ParserConfig | None = None, **settings): config = ParserConfig.new( config, owner=self, - whitespace=re.compile(r"\s+"), + whitespace='\\s+', nameguard=None, ignorecase=False, namechars='', @@ -41,38 +41,39 @@ def __init__(self, text, /, config: ParserConfig | None = None, **settings): start='start', ) config = config.replace(**settings) - super().__init__(text, config=config) + super().__init__(text, config=config) class EBNFBootstrapParser(Parser): def __init__(self, /, config: ParserConfig | None = None, **settings): config = ParserConfig.new( config, owner=self, - whitespace=re.compile(r"\s+"), + whitespace='\\s+', nameguard=None, ignorecase=False, namechars='', parseinfo=True, comments_re='(?sm)[(][*](?:.|\\n)*?[*][)]', eol_comments_re='#[^\\n]*$', - left_recursion=False, keywords=KEYWORDS, start='start', ) config = config.replace(**settings) + super().__init__(config=config) @tatsumasu() def _start_(self): self._grammar_() + @tatsumasu('Grammar') def _grammar_(self): self._constant('TATSU') self.name_last_node('title') - def block1(): + def block0(): with self._choice(): with self._option(): self._directive_() @@ -82,13 +83,13 @@ def block1(): self.add_last_node_to_name('keywords') self._error( 'expecting one of: ' - ' ' # noqa: COM812 + ' ' ) - self._closure(block1) + self._closure(block0) self._rule_() self.add_last_node_to_name('rules') - def block6(): + def block1(): with self._choice(): with self._option(): self._rule_() @@ -98,10 +99,14 @@ def block6(): self.add_last_node_to_name('keywords') self._error( 'expecting one of: ' - ' ' # noqa: COM812 + ' ' ) - self._closure(block6) + self._closure(block1) self._check_eof() + self._define( + ['title'], + ['directives', 'keywords', 'rules'], + ) self._define( ['title'], @@ -125,7 +130,7 @@ def _directive_(self): self._token('eol_comments') self._error( 'expecting one of: ' - "'comments' 'eol_comments'" # noqa: COM812 + "'comments' 'eol_comments'" ) self.name_last_node('name') self._cut() @@ -134,11 +139,7 @@ def _directive_(self): self._cut() self._regex_() self.name_last_node('value') - - self._define( - ['name', 'value'], - [], - ) + self._define(['name', 'value'], []) with self._option(): with self._group(): self._token('whitespace') @@ -159,14 +160,10 @@ def _directive_(self): self._constant('None') self._error( 'expecting one of: ' - "'False' 'None' " # noqa: COM812 + "'False' 'None' " ) self.name_last_node('value') - - self._define( - ['name', 'value'], - [], - ) + self._define(['name', 'value'], []) with self._option(): with self._group(): with self._choice(): @@ -181,7 +178,7 @@ def _directive_(self): self._error( 'expecting one of: ' "'ignorecase' 'left_recursion'" - "'nameguard' 'parseinfo'" # noqa: COM812 + "'nameguard' 'parseinfo'" ) self.name_last_node('name') self._cut() @@ -192,23 +189,15 @@ def _directive_(self): self._cut() self._boolean_() self.name_last_node('value') - - self._define( - ['value'], - [], - ) + self._define(['value'], []) with self._option(): self._constant(True) self.name_last_node('value') self._error( 'expecting one of: ' - "'::'" # noqa: COM812 + "'::'" ) - - self._define( - ['name', 'value'], - [], - ) + self._define(['name', 'value'], []) with self._option(): with self._group(): self._token('grammar') @@ -218,11 +207,7 @@ def _directive_(self): self._cut() self._word_() self.name_last_node('value') - - self._define( - ['name', 'value'], - [], - ) + self._define(['name', 'value'], []) with self._option(): with self._group(): self._token('namechars') @@ -232,24 +217,18 @@ def _directive_(self): self._cut() self._string_() self.name_last_node('value') - - self._define( - ['name', 'value'], - [], - ) + self._define(['name', 'value'], []) self._error( 'expecting one of: ' "'comments' 'eol_comments' 'grammar'" "'ignorecase' 'left_recursion'" "'namechars' 'nameguard' 'parseinfo'" - "'whitespace'" # noqa: COM812 + "'whitespace'" ) self._cut() + self._define(['name', 'value'], []) - self._define( - ['name', 'value'], - [], - ) + self._define(['name', 'value'], []) @tatsumasu() def _keywords_(self): @@ -258,6 +237,7 @@ def block0(): self._keywords_() self._positive_closure(block0) + @tatsumasu() def _keyword_(self): self._token('@@keyword') @@ -277,10 +257,11 @@ def block0(): self._token('=') self._error( 'expecting one of: ' - "':' '='" # noqa: COM812 + "':' '='" ) self._closure(block0) + @tatsumasu() def _paramdef_(self): with self._choice(): @@ -289,11 +270,7 @@ def _paramdef_(self): self._cut() self._params_() self.name_last_node('params') - - self._define( - ['params'], - [], - ) + self._define(['params'], []) with self._option(): self._token('(') self._cut() @@ -309,35 +286,28 @@ def _paramdef_(self): self._cut() self._kwparams_() self.name_last_node('kwparams') - - self._define( - ['kwparams', 'params'], - [], - ) + self._define(['kwparams', 'params'], []) with self._option(): self._params_() self.name_last_node('params') self._error( 'expecting one of: ' - ' ' # noqa: COM812 + ' ' ) self._token(')') - - self._define( - ['kwparams', 'params'], - [], - ) + self._define(['kwparams', 'params'], []) self._error( 'expecting one of: ' - "'(' '::'" # noqa: COM812 + "'(' '::'" ) + @tatsumasu('Rule') def _rule_(self): - def block1(): + def block0(): self._decorator_() - self._closure(block1) + self._closure(block0) self.name_last_node('decorators') self._name_() self.name_last_node('name') @@ -349,11 +319,7 @@ def block1(): self._cut() self._params_() self.name_last_node('params') - - self._define( - ['params'], - [], - ) + self._define(['params'], []) with self._option(): self._token('(') self._cut() @@ -369,49 +335,35 @@ def block1(): self._cut() self._kwparams_() self.name_last_node('kwparams') - - self._define( - ['kwparams', 'params'], - [], - ) + self._define(['kwparams', 'params'], []) with self._option(): self._params_() self.name_last_node('params') self._error( 'expecting one of: ' - ' ' # noqa: COM812 + ' ' ) self._token(')') - - self._define( - ['kwparams', 'params'], - [], - ) + self._define(['kwparams', 'params'], []) self._error( 'expecting one of: ' - "'(' '::'" # noqa: COM812 + "'(' '::'" ) with self._optional(): self._token('<') self._cut() self._known_name_() self.name_last_node('base') - - self._define( - ['base'], - [], - ) + self._define(['base'], []) self._token('=') self._cut() self._expre_() self.name_last_node('exp') self._token(';') self._cut() + self._define(['base', 'decorators', 'exp', 'kwparams', 'name', 'params'], []) - self._define( - ['base', 'decorators', 'exp', 'kwparams', 'name', 'params'], - [], - ) + self._define(['base', 'decorators', 'exp', 'kwparams', 'name', 'params'], []) @tatsumasu() def _decorator_(self): @@ -429,23 +381,25 @@ def _decorator_(self): self._token('nomemo') self._error( 'expecting one of: ' - "'name' 'nomemo' 'override'" # noqa: COM812 + "'name' 'nomemo' 'override'" ) self.name_last_node('@') + @tatsumasu() def _params_(self): self._first_param_() self.add_last_node_to_name('@') - def block1(): + def block0(): self._token(',') self._literal_() self.add_last_node_to_name('@') with self._ifnot(): self._token('=') self._cut() - self._closure(block1) + self._closure(block0) + @tatsumasu() def _first_param_(self): @@ -458,18 +412,20 @@ def _first_param_(self): 'expecting one of: ' '(?!\\d)\\w+(?:::(?!\\d)\\w+)+ ' ' ' - ' ' # noqa: COM812 + ' ' ) + @tatsumasu() def _kwparams_(self): def sep0(): self._token(',') - def block0(): + def block1(): self._pair_() - self._positive_gather(block0, sep0) + self._positive_gather(block1, sep0) + @tatsumasu() def _pair_(self): @@ -480,6 +436,7 @@ def _pair_(self): self._literal_() self.add_last_node_to_name('@') + @tatsumasu() def _expre_(self): with self._choice(): @@ -490,9 +447,10 @@ def _expre_(self): self._error( 'expecting one of: ' "'|'