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
Adds graph debug documentation to book #379
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -10,6 +10,7 @@ | |||
+ [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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
||
We also can try to identify how the token `fast` works by looking at `@9`, first, and seeing that `f` will cause Logos to 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 alphabetic characters 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`) | ||
|
||
### Enabling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the following section should be one level above, so:
## Enabling
### Step 1...
Also, maybe name the steps (instead of saying step 1, step 2). But this may change as a result of #382.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased and provided a simplified example that leverages your debug
feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also believe that "# Enabling" should be the first section.
f23af3f
to
39a91fd
Compare
39a91fd
to
7ce0526
Compare
Co-authored-by: João Marcos <marcospb19@hotmail.com>
I ran across this comment while having some issues with
regex
support. 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