Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile-only CLI flag #76

Closed
V0ldek opened this issue Jan 22, 2023 · 2 comments · Fixed by #77
Closed

Compile-only CLI flag #76

V0ldek opened this issue Jan 22, 2023 · 2 comments · Fixed by #77
Labels
area: app Improvements in overall CLI app usability type: feature New feature or request
Milestone

Comments

@V0ldek
Copy link
Member

V0ldek commented Jan 22, 2023

Is your feature request related to a problem? Please describe.
When implementing new selectors or just diagnosing bugs with a particular query, we often have to look at the compilation itself and the resulting automaton. It would be nice to have a way to run the binary only to the point of compilation, and not involve any of the engines.

Describe the solution you'd like
A new variant to the --engine switch sounds ideal. Example run:

just r '$..a.b' -e compiler -v
DEBUG [rsonpath_lib::query::parser] Parsed tokens: $(Descendant("a"))(Child("b"))
INFO  [rsonpath] Preparing query: `$..['a']['b']`

DEBUG [rsonpath_lib::query::automaton] NFA: r1 --a-> d1 --b-> acc
DEBUG [rsonpath_lib::query::automaton::minimizer] New superstate created: {NfaStateId(0)} DFA(1)
DEBUG [rsonpath_lib::query::automaton::minimizer] Expanding superstate: {NfaStateId(0)}, last checkpoint is Some(NfaStateId(0))
DEBUG [rsonpath_lib::query::automaton::minimizer] Considering transition NFA(0) --"a"-> NFA(1)
DEBUG [rsonpath_lib::query::automaton::minimizer] Raw transitions: {"a": {NfaStateId(1)}}
DEBUG [rsonpath_lib::query::automaton::minimizer] New superstate created: {NfaStateId(0), NfaStateId(1)} DFA(2)
DEBUG [rsonpath_lib::query::automaton::minimizer] Normalized transitions: {"a": {NfaStateId(0), NfaStateId(1)}}
DEBUG [rsonpath_lib::query::automaton::minimizer] Translated transitions: [("a", State(2))]
DEBUG [rsonpath_lib::query::automaton::minimizer] Expanding superstate: {NfaStateId(0), NfaStateId(1)}, last checkpoint is Some(NfaStateId(0))
DEBUG [rsonpath_lib::query::automaton::minimizer] Considering transition NFA(0) --"a"-> NFA(1)
DEBUG [rsonpath_lib::query::automaton::minimizer] Considering transition NFA(1) --"b"-> NFA(2)
DEBUG [rsonpath_lib::query::automaton::minimizer] Raw transitions: {"a": {NfaStateId(1)}, "b": {NfaStateId(2)}}
DEBUG [rsonpath_lib::query::automaton::minimizer] New superstate created: {NfaStateId(0), NfaStateId(2)} DFA(3)
DEBUG [rsonpath_lib::query::automaton::minimizer] Normalized transitions: {"a": {NfaStateId(0), NfaStateId(1)}, "b": {NfaStateId(0), NfaStateId(2)}}
DEBUG [rsonpath_lib::query::automaton::minimizer] Translated transitions: [("a", State(2)), ("b", State(3))]
DEBUG [rsonpath_lib::query::automaton::minimizer] Expanding superstate: {NfaStateId(0), NfaStateId(2)}, last checkpoint is Some(NfaStateId(0))
DEBUG [rsonpath_lib::query::automaton::minimizer] Considering transition NFA(0) --"a"-> NFA(1)
DEBUG [rsonpath_lib::query::automaton::minimizer] Raw transitions: {"a": {NfaStateId(1)}}
DEBUG [rsonpath_lib::query::automaton::minimizer] Normalized transitions: {"a": {NfaStateId(0), NfaStateId(1)}}
DEBUG [rsonpath_lib::query::automaton::minimizer] Translated transitions: [("a", State(2))]
DEBUG [rsonpath_lib::stackless] DFA:
 digraph {
  0 -> 0 [label="*"]
  1 -> 2 [label="a"]
  1 -> 1 [label="*"]
  2 -> 2 [label="a"]
  2 -> 3 [label="b"]
  2 -> 1 [label="*"]
  3 -> 2 [label="a"]
  3 -> 1 [label="*"]
}
INFO  [rsonpath] Compilation finished.

Describe alternatives you've considered
A dedicated flag could be used, --compile (short -c). It would be mutually exclusive with -e. Since the run would be completely different we could have the binary just output the compiled automaton to stdout in .dot format, which would make inspecting it easier.

@V0ldek V0ldek added the type: feature New feature or request label Jan 22, 2023
@github-actions github-actions bot added the acceptance: triage Waiting for owner's input label Jan 22, 2023
@github-actions
Copy link

Tagging @V0ldek for notifications

@V0ldek
Copy link
Member Author

V0ldek commented Jan 23, 2023

We should go ahead with a -c/--compile flag. Clap supports mutually exclusive arguments, so we can say that either -e or -c is allowed, but not both.

@V0ldek V0ldek added this to the v1.0.0 milestone Jan 23, 2023
@github-actions github-actions bot added acceptance: go ahead Reviewed, implementation can start and removed acceptance: triage Waiting for owner's input labels Jan 23, 2023
@V0ldek V0ldek added mod: cli area: app Improvements in overall CLI app usability labels Jan 23, 2023
V0ldek added a commit that referenced this issue Jan 23, 2023
Specifying `--compile` or `-c` will cause rsonpath to compile the query and output its automaton, without running the engine.
This option is mutually exclusive with `--engine` or providing an input path.

Related: #76
V0ldek added a commit that referenced this issue Jan 23, 2023
Specifying `--compile` or `-c` will cause rsonpath to compile the query and output its automaton, without running the engine.
This option is mutually exclusive with `--engine` or providing an input path.

Related: #76
V0ldek added a commit that referenced this issue Jan 23, 2023
Specifying `--compile` or `-c` will cause rsonpath to compile the query and output its automaton, without running the engine.
This option is mutually exclusive with `--engine` or providing an input path.

Related: #76
@github-actions github-actions bot removed the acceptance: go ahead Reviewed, implementation can start label Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: app Improvements in overall CLI app usability type: feature New feature or request
Projects
Status: Released
Development

Successfully merging a pull request may close this issue.

1 participant