alteraparser 2.5.0__tar.gz → 2.5.2__tar.gz
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.
- {alteraparser-2.5.0 → alteraparser-2.5.2}/PKG-INFO +1 -1
- {alteraparser-2.5.0 → alteraparser-2.5.2}/pyproject.toml +1 -1
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/ast_.py +4 -1
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/meta/cli.py +0 -18
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/meta/codegen.py +4 -5
- {alteraparser-2.5.0 → alteraparser-2.5.2}/LICENSE +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/README.md +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/__init__.py +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/grammar.py +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/lexer.py +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/lexer_grammar.py +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/meta/__init__.py +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/meta/grammar.py +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/meta/lexer_grammar.py +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/meta/parser.py +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/parser.py +0 -0
- {alteraparser-2.5.0 → alteraparser-2.5.2}/src/alteraparser/token_.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: alteraparser
|
|
3
|
-
Version: 2.5.
|
|
3
|
+
Version: 2.5.2
|
|
4
4
|
Summary: Alteraparser is a library that provides functions to define a grammar that can be passed to a parser.
|
|
5
5
|
Author: Thomas Bollmeier
|
|
6
6
|
Author-email: Thomas Bollmeier <developer@thomas-bollmeier.de>
|
|
@@ -137,7 +137,10 @@ class AstTransformer:
|
|
|
137
137
|
transformed_child = self.transform(child)
|
|
138
138
|
ast.children[idx] = transformed_child
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
saved_id = ast.id
|
|
141
|
+
transformed_ast = self._transformers[ast.name](ast) if ast.name in self._transformers else ast
|
|
142
|
+
transformed_ast.id = saved_id
|
|
143
|
+
return transformed_ast
|
|
141
144
|
|
|
142
145
|
|
|
143
146
|
def transform_ast(ast_transformer: AstTransformer, ast_name: str):
|
|
@@ -1,31 +1,13 @@
|
|
|
1
1
|
from argparse import ArgumentParser
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
import sys
|
|
4
|
-
import tomllib
|
|
5
4
|
|
|
6
5
|
from alteraparser.meta.codegen import generate_python_module_code
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
def _read_project_version() -> str:
|
|
10
|
-
for parent in Path(__file__).resolve().parents:
|
|
11
|
-
pyproject = parent / "pyproject.toml"
|
|
12
|
-
if pyproject.exists():
|
|
13
|
-
content = pyproject.read_text(encoding="utf-8")
|
|
14
|
-
data = tomllib.loads(content)
|
|
15
|
-
return data["project"]["version"]
|
|
16
|
-
raise FileNotFoundError("pyproject.toml not found")
|
|
17
|
-
|
|
18
|
-
|
|
19
7
|
def _create_argument_parser() -> ArgumentParser:
|
|
20
8
|
parser = ArgumentParser(
|
|
21
9
|
description="Generate Python parser code from an Alteraparser grammar."
|
|
22
10
|
)
|
|
23
|
-
parser.add_argument(
|
|
24
|
-
"-v",
|
|
25
|
-
"--version",
|
|
26
|
-
action="version",
|
|
27
|
-
version=f"%(prog)s {_read_project_version()}",
|
|
28
|
-
)
|
|
29
11
|
parser.add_argument(
|
|
30
12
|
"infile",
|
|
31
13
|
nargs="?",
|
|
@@ -80,7 +80,6 @@ class CodeGenerator:
|
|
|
80
80
|
self._write_line(f"def create_{snake_name}_grammar() -> Grammar:")
|
|
81
81
|
self._indent()
|
|
82
82
|
self._write_line("grammar = Grammar()")
|
|
83
|
-
self._write_line(f"lg = {language_name}LexerGrammar()")
|
|
84
83
|
self._write_line()
|
|
85
84
|
|
|
86
85
|
grammar_printer = GrammarPrinter(self, keyword_map_inv)
|
|
@@ -237,15 +236,15 @@ class GrammarPrinter(AstWalker):
|
|
|
237
236
|
keyword = ast.value
|
|
238
237
|
token_type = self._keyword_map[keyword]
|
|
239
238
|
if not identifier:
|
|
240
|
-
self._write_line(f"tok(
|
|
239
|
+
self._write_line(f"tok(\"{token_type}\"){self._delim()} # <-- '{keyword}'")
|
|
241
240
|
else:
|
|
242
|
-
self._write_line(f"tok(
|
|
241
|
+
self._write_line(f"tok(\"{token_type}\", \"{identifier}\"){self._delim()} # <-- '{keyword}'")
|
|
243
242
|
case "token_type":
|
|
244
243
|
token_type = ast.value
|
|
245
244
|
if not identifier:
|
|
246
|
-
self._write_line(f"tok(
|
|
245
|
+
self._write_line(f"tok(\"{token_type}\"){self._delim()}")
|
|
247
246
|
else:
|
|
248
|
-
self._write_line(f"tok(
|
|
247
|
+
self._write_line(f"tok(\"{token_type}\", \"{identifier}\"){self._delim()}")
|
|
249
248
|
|
|
250
249
|
def on_exit(self, ast: Ast):
|
|
251
250
|
if self._in_macro_def:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|