[fine] Parser Table Generator?
Look I'm just thinking hard about converting to a parser generator because I want to derive the pretty-printer from the parser without having to repeat myself all over the place. This parser.py is derived from my old LRParsers project, and should go back there eventually, but for now I'm driving the work from here.
This commit is contained in:
parent
a2b3e8b74d
commit
25f9c3ecaf
6 changed files with 2384 additions and 1 deletions
40
fine/grammar/rust.py
Normal file
40
fine/grammar/rust.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import io
|
||||
|
||||
import parser
|
||||
|
||||
|
||||
def generate_rust_parser(output: io.TextIOBase, table: list[dict[str, parser.Action]]):
|
||||
lines = []
|
||||
|
||||
tree_kinds = list(
|
||||
sorted(
|
||||
{
|
||||
action[1]
|
||||
for state in table
|
||||
for action in state.values()
|
||||
if action[0] == "reduce" and action[1][0] != "_"
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
# First, generate the treekind enumeration
|
||||
lines.extend(
|
||||
[
|
||||
"#[derive(Debug, Eq, PartialEq)]",
|
||||
"pub enum TreeKind {",
|
||||
" Error,",
|
||||
"",
|
||||
]
|
||||
)
|
||||
lines.extend(f" {kind}," for kind in tree_kinds)
|
||||
lines.extend(
|
||||
[
|
||||
"}",
|
||||
"",
|
||||
]
|
||||
)
|
||||
|
||||
# Next generate the parse table
|
||||
lines.extend([])
|
||||
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue