Skip to content

Commit b3a4e58

Browse files
authored
Merge pull request #474 from ratmice/dump_state_graph
nimbleparse: add -d flag to dump state graph
2 parents 4e4a7a2 + b68a9be commit b3a4e58

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lrtable/src/lib/stategraph.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ where
173173
}
174174
o.push_str("}]");
175175
}
176-
for (esym, e_stidx) in self.edges(stidx).iter() {
176+
let mut edges = self.edges(stidx).iter().collect::<Vec<_>>();
177+
edges.sort_by(|(_, x), (_, y)| x.cmp(y));
178+
for (esym, e_stidx) in edges {
177179
write!(
178180
o,
179181
"\n{}{} -> {}",

nimbleparse/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn usage(prog: &str, msg: &str) -> ! {
3232
if !msg.is_empty() {
3333
eprintln!("{}", msg);
3434
}
35-
eprintln!("Usage: {} [-r <cpctplus|none>] [-y <eco|grmtools|original>] [-q] <lexer.l> <parser.y> <input file>", leaf);
35+
eprintln!("Usage: {} [-r <cpctplus|none>] [-y <eco|grmtools|original>] [-dq] <lexer.l> <parser.y> <input file>", leaf);
3636
process::exit(1);
3737
}
3838

@@ -87,6 +87,7 @@ fn main() {
8787
let matches = match Options::new()
8888
.optflag("h", "help", "")
8989
.optflag("q", "quiet", "Don't print warnings such as conflicts")
90+
.optflag("d", "dump-state-graph", "Print the parser state graph")
9091
.optopt(
9192
"r",
9293
"recoverer",
@@ -109,6 +110,7 @@ fn main() {
109110
usage(prog, "");
110111
}
111112

113+
let dump_state_graph = matches.opt_present("d");
112114
let quiet = matches.opt_present("q");
113115

114116
let recoverykind = match matches.opt_str("r") {
@@ -187,6 +189,10 @@ fn main() {
187189
}
188190
};
189191

192+
if dump_state_graph {
193+
println!("Stategraph:\n{}\n", sgraph.pp_core_states(&grm));
194+
}
195+
190196
if !quiet {
191197
if let Some(c) = stable.conflicts() {
192198
let formatter = if let Some(yacc_diagnostic_formatter) = &yacc_diagnostic_formatter {
@@ -213,7 +219,7 @@ fn main() {
213219
if pp_sr {
214220
println!("{}", c.pp_sr(&grm));
215221
}
216-
if pp_rr || pp_sr {
222+
if (pp_rr || pp_sr) && !dump_state_graph {
217223
println!("Stategraph:\n{}\n", sgraph.pp_core_states(&grm));
218224
}
219225
formatter.handle_conflicts::<DefaultLexerTypes<u32>>(

0 commit comments

Comments
 (0)