Skip to content

Conversation

@ratmice
Copy link
Collaborator

@ratmice ratmice commented Nov 24, 2024

This is a patch I used for testing softdevteam/sparsevec#25
It adds a -d flag for dumping the state graph from nimbleparse, then exiting.
It also fixes an issue where the pretty printing function produces non-deterministic output.

I'm not certain it is quite up to par, because of the argument parsing an input file is required even though it is never used.
but making the input file 'required unless the -d flag is specified' is also weird. Passing in an unused filename like /dev/null was sufficient for my testing purposes though.


if dump_state_graph {
println!("Stategraph:\n{}\n", sgraph.pp_core_states(&grm));
process::exit(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is that we don't exit here: we print out the stategraph and continue. That simplifies the argument parsing in the sense that users always have to provide .l, .y, and input files. We could be more clever, but documenting that in a digestible way becomes a pain, and I think the simple approach is adequate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the problem with my testing was that I didn't actually have valid input for any of the github provided parsers I was testing, while it is likely that /dev/null would be a valid for most perhaps even all of them, it was easier to just avoid complications with input/AST production.

Perhaps that is a special case that is no longer necessary, and I suppose it is easy to add the exit call if I need something like that again?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That particular use case would probably best be covered by an lrtable binary: it would naturally only take in the grammar (and I suppose optionally a lexer). There is precedence here: we do build an lrlex binary for this sort of testing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be good, there were a couple of actually the most heavily used libraries depending upon grmtools
which I couldn't test with this approach because they used a manually implemented lexer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is useful (without the exit) and worth keeping, but an additional lrtable binary PR would be cool too!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in 2a13f24

There was a little more to it, also needed to avoid duplicate printing of the state graph when there are conflicts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

eprintln!("{}", msg);
}
eprintln!("Usage: {} [-r <cpctplus|none>] [-y <eco|grmtools|original>] [-q] <lexer.l> <parser.y> <input file>", leaf);
eprintln!("Usage: {} [-r <cpctplus|none>] [-y <eco|grmtools|original>] [-q] [-d] <lexer.l> <parser.y> <input file>", leaf);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ye olde unix convention, this would be [-dq].

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in 2a13f24 too.

@ltratt
Copy link
Member

ltratt commented Nov 24, 2024

Please squash.

@ratmice
Copy link
Collaborator Author

ratmice commented Nov 24, 2024

Squashed.

@ltratt ltratt added this pull request to the merge queue Nov 24, 2024
Merged via the queue into softdevteam:master with commit b3a4e58 Nov 24, 2024
2 checks passed
@ratmice ratmice deleted the dump_state_graph branch November 24, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants