chore(docs): Adds graph debug documentation to book#379
chore(docs): Adds graph debug documentation to book#379jeertmans merged 4 commits intomaciejhirsz:masterfrom
Conversation
jeertmans
left a comment
There was a problem hiding this comment.
Hey! Thank you some much for your contribution! I left a few review comments that I'd like you to address before we can merge :-)
Feel free to accept or reject my suggestions!
book/src/debug-graph.md
Outdated
| # Debug Graph | ||
|
|
||
| It may be beneficial during debugging to be able to visualize how Logos has generated its graph. |
There was a problem hiding this comment.
Maybe add some introduction to the fact that Logos construct a graph internally to generate its code. Here, this comes a bit out of nowhere :-)
book/src/SUMMARY.md
Outdated
| + [Using `Extras`](./extras.md) | ||
| + [Using callbacks](./callbacks.md) | ||
| + [Common regular expressions](./common-regex.md) | ||
| + [Debug Graph](./debug-graph.md) |
There was a problem hiding this comment.
I'd maybe add just a Debugging section, and, in the debug.md file, have one section talking about the graph. So we can later add some other sections, e.g., to talk about regex-syntax's HIR or else.
book/src/debug-graph.md
Outdated
| } | ||
| ``` | ||
|
|
||
| With our graph debugging enabled, we see the following output: |
There was a problem hiding this comment.
| With our graph debugging enabled, we see the following output: | |
| Logos actually constructs a graph that contains the logic for matching tokens: |
book/src/debug-graph.md
Outdated
| } | ||
| ``` | ||
|
|
||
| Lets look at `@9` for the character `.` we see that it will jump `=>` to `2`. We can then follow that by looking at `@2` which resolves to our `::Period` token. It will then continue to look for any matches in the case there is potential continuation after the `.` character. In the _input_ we provided there is not, since it is the end of our input. |
There was a problem hiding this comment.
| Lets look at `@9` for the character `.` we see that it will jump `=>` to `2`. We can then follow that by looking at `@2` which resolves to our `::Period` token. It will then continue to look for any matches in the case there is potential continuation after the `.` character. In the _input_ we provided there is not, since it is the end of our input. | |
| This graph can help us understand how our patterns are matched, and maybe understand why we have a bug at some point. | |
| Let's look at the last node, `9`, for the character `.`. We see that it will jump (`=>`) to `2`. We can then follow that by looking at `2` which resolves to our `::Period` token. It will then continue to look for any matches in the case there is potential continuation after the `.` character. In the _input_ we provided, there is not, since it is the end of our input. |
Note that I have to read a bit more of the code to feel confident about how Graph actually works.
Also, this may be a bit counter-intuitive to take the example of ., where this is the last bit of our input string.
There was a problem hiding this comment.
The thing I was to know (I guess the information is somewhere in the source code) is whether we always enter the graph via its last entry, or not.
There was a problem hiding this comment.
Totally agree about it being counter-intuitive about the . example. I used the . since it seemed a little more straight forward on the graph to understand. Could probably smooth over that some if I reworked some of the wording to lead into a bit more, instead of BLAM, understand this lol
book/src/debug-graph.md
Outdated
|
|
||
| Lets look at `@9` for the character `.` we see that it will jump `=>` to `2`. We can then follow that by looking at `@2` which resolves to our `::Period` token. It will then continue to look for any matches in the case there is potential continuation after the `.` character. In the _input_ we provided there is not, since it is the end of our input. | ||
|
|
||
| We also can try to identify how `fast` works by looking at `@9` that `f` jumps to `7`. This will then resolve the last letters of our word _fast_ by matching `ast` which jumps to `8`. Since our provided _input_ to the lexer does not include alphanumeric character after the word "fast" but rather whitespace, the token `::Fast` will be recognized. Then the graph will look for further potential continuation (ie `[g-z] => 4`) |
There was a problem hiding this comment.
| We also can try to identify how `fast` works by looking at `@9` that `f` jumps to `7`. This will then resolve the last letters of our word _fast_ by matching `ast` which jumps to `8`. Since our provided _input_ to the lexer does not include alphanumeric character after the word "fast" but rather whitespace, the token `::Fast` will be recognized. Then the graph will look for further potential continuation (ie `[g-z] => 4`) | |
| We also can try to identify how `fast` works by looking at `9`, first, and seeing that `f` makes it jump to `7`. This will then resolve the last letters of our word _fast_ by matching `ast` which jumps to `8`. Since our provided _input_ to the lexer does not include alphanumeric character after the word "fast" but rather whitespace, the token `::Fast` will be recognized. Then the graph will look for further potential continuation (i.e., `[g-z] => 4`) |
|
Yeah, sorry for the kind of rushed PR...trying to sneak this in-between family time lol Made some improvements to language and file structure based off of your recommendations. Hopefully, a little less jarring to someone reading it. As for the enable debugging part, I totally agree, I am new to rust but I can try to put something together that properly uses a |
This adds a debug feature, similar to what Clap does, as requested by #379. The current implementation only debugs a few parts of the code, and it may be interesting to add more debug messages in the different crates.
No issue, I did it myself since this was an easy fix. The issue you had was that you needed to declare a |
* chore(lib): add debug feature This adds a debug feature, similar to what Clap does, as requested by #379. The current implementation only debugs a few parts of the code, and it may be interesting to add more debug messages in the different crates. * chore(lint): run cargo fmt
jeertmans
left a comment
There was a problem hiding this comment.
Nice work @afreeland! I left some more comments (sorry to be picky about some ^^'), but I hope you don't mind..
Note that #382 was merged and just added a new debug feature.
f23af3f to
39a91fd
Compare
39a91fd to
7ce0526
Compare
Co-authored-by: João Marcos <marcospb19@hotmail.com>
|
Users wishing to use this functionality may do so, pending this patch making it upstream to logos = { git = "https://github.com/maciejhirsz/logos.git#afreeland:debug-graph", features = ["debug"]} |
|
I haven't had a chance to dive in yet, but does logos have a runtime-accessible public API for fetching, manipulating, and constructing graphs exist besides using macros? Some reasons I can think of why those APIs would be useful: fetching [related to this PR]
manipulating/construction [out of scope for this PR, yet topically related]:
What this PR might look like if there is/were a fetch API The documentation would mention something like this: let graph = Token::graph();
println!("{:#?}", graph)Continuing to use a feature flag to enable Thoughts? |
This is true that is might be nice to expose that as part of the public API. Would you mind creating an issue for that feature request? |
logos-codegen/src/generator/mod.rs
Outdated
| #[cfg(feature = "debug")] | ||
| dbg!(graph); | ||
|
|
There was a problem hiding this comment.
I think you don't need this, because I already added a debug print of the graph in another place
There was a problem hiding this comment.
See here:
logos/logos-codegen/src/lib.rs
Line 298 in 066e125
There was a problem hiding this comment.
Hey @afreeland! Could you address this review please? So I can accept your PR and merge it :-)
[](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [logos](https://logos.maciej.codes/) ([source](https://togithub.com/maciejhirsz/logos)) | dependencies | patch | `0.14.0` -> `0.14.1` | --- ### Release Notes <details> <summary>maciejhirsz/logos (logos)</summary> ### [`v0.14.1`](https://togithub.com/maciejhirsz/logos/releases/tag/v0.14.1): 0.14.1 - Debug feature and fixes #### What's Changed - fix(doc): reset logos2 to logos by [@​jeertmans](https://togithub.com/jeertmans) in [https://github.com/maciejhirsz/logos/pull/372](https://togithub.com/maciejhirsz/logos/pull/372) - chore(book): add JSON-borrowed parser example by [@​jeertmans](https://togithub.com/jeertmans) in [https://github.com/maciejhirsz/logos/pull/373](https://togithub.com/maciejhirsz/logos/pull/373) - Add Rc<T> and Arc<T> sources by [@​InfiniteCoder01](https://togithub.com/InfiniteCoder01) in [https://github.com/maciejhirsz/logos/pull/340](https://togithub.com/maciejhirsz/logos/pull/340) - Fix unicode dot by [@​RustyYato](https://togithub.com/RustyYato) in [https://github.com/maciejhirsz/logos/pull/376](https://togithub.com/maciejhirsz/logos/pull/376) - chore(docs): cleanup examples by [@​jeertmans](https://togithub.com/jeertmans) in [https://github.com/maciejhirsz/logos/pull/381](https://togithub.com/maciejhirsz/logos/pull/381) - chore(lib): add debug feature by [@​jeertmans](https://togithub.com/jeertmans) in [https://github.com/maciejhirsz/logos/pull/382](https://togithub.com/maciejhirsz/logos/pull/382) - Cleanup unused Source features by [@​kmicklas](https://togithub.com/kmicklas) in [https://github.com/maciejhirsz/logos/pull/335](https://togithub.com/maciejhirsz/logos/pull/335) - chore(deps): bump peaceiris/actions-mdbook from 1 to 2 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/maciejhirsz/logos/pull/387](https://togithub.com/maciejhirsz/logos/pull/387) - Fix `Lexer::clone` leak and UB + tests by [@​Jakobeha](https://togithub.com/Jakobeha) in [https://github.com/maciejhirsz/logos/pull/390](https://togithub.com/maciejhirsz/logos/pull/390) - fix(lib): correctly handle miss for loop in loop by [@​lukas-code](https://togithub.com/lukas-code) in [https://github.com/maciejhirsz/logos/pull/393](https://togithub.com/maciejhirsz/logos/pull/393) - chore(lib): remove error branch from LUT if it is unreachable by [@​RustyYato](https://togithub.com/RustyYato) in [https://github.com/maciejhirsz/logos/pull/386](https://togithub.com/maciejhirsz/logos/pull/386) - fix(docs): typo by [@​joerivanruth](https://togithub.com/joerivanruth) in [https://github.com/maciejhirsz/logos/pull/396](https://togithub.com/maciejhirsz/logos/pull/396) - chore(docs): Adds graph debug documentation to book by [@​afreeland](https://togithub.com/afreeland) in [https://github.com/maciejhirsz/logos/pull/379](https://togithub.com/maciejhirsz/logos/pull/379) - chore: drop python linting frmo pre-commit-config by [@​LeoDog896](https://togithub.com/LeoDog896) in [https://github.com/maciejhirsz/logos/pull/403](https://togithub.com/maciejhirsz/logos/pull/403) - refactor: don't use deprecated max_value() method by [@​LeoDog896](https://togithub.com/LeoDog896) in [https://github.com/maciejhirsz/logos/pull/404](https://togithub.com/maciejhirsz/logos/pull/404) - chore(version): bump logos version to 0.14.1 by [@​jeertmans](https://togithub.com/jeertmans) in [https://github.com/maciejhirsz/logos/pull/409](https://togithub.com/maciejhirsz/logos/pull/409) - fix(docs): change old 0.14.0 by [@​jeertmans](https://togithub.com/jeertmans) in [https://github.com/maciejhirsz/logos/pull/410](https://togithub.com/maciejhirsz/logos/pull/410) #### New Contributors - [@​InfiniteCoder01](https://togithub.com/InfiniteCoder01) made their first contribution in [https://github.com/maciejhirsz/logos/pull/340](https://togithub.com/maciejhirsz/logos/pull/340) - [@​RustyYato](https://togithub.com/RustyYato) made their first contribution in [https://github.com/maciejhirsz/logos/pull/376](https://togithub.com/maciejhirsz/logos/pull/376) - [@​Jakobeha](https://togithub.com/Jakobeha) made their first contribution in [https://github.com/maciejhirsz/logos/pull/390](https://togithub.com/maciejhirsz/logos/pull/390) - [@​lukas-code](https://togithub.com/lukas-code) made their first contribution in [https://github.com/maciejhirsz/logos/pull/393](https://togithub.com/maciejhirsz/logos/pull/393) - [@​joerivanruth](https://togithub.com/joerivanruth) made their first contribution in [https://github.com/maciejhirsz/logos/pull/396](https://togithub.com/maciejhirsz/logos/pull/396) - [@​afreeland](https://togithub.com/afreeland) made their first contribution in [https://github.com/maciejhirsz/logos/pull/379](https://togithub.com/maciejhirsz/logos/pull/379) - [@​LeoDog896](https://togithub.com/LeoDog896) made their first contribution in [https://github.com/maciejhirsz/logos/pull/403](https://togithub.com/maciejhirsz/logos/pull/403) **Full Changelog**: maciejhirsz/logos@v0.14...v0.14.1 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/akrantz01/antsi). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
I ran across this comment while having some issues with
regexsupport. Thought this was beneficial information and wanted to try and include it in the book so it was a little more visible to people that may be trying to debug and understand how things are working