Some documentation for the pest_meta crate and the semantics of pest grammars #855
Replies: 3 comments 1 reply
-
Semantics of PestTerminalsSensitiveExamples:
Insensitive
Ranges
Start and End of InputFor Stack operations without expression paramaterFor Built-in Rules
|
Escape code | Result | Character Unicode code-point |
---|---|---|
\" |
" (QUOTATION MARK) |
U+0022 |
\r |
Carriage Return (CR) | U+000D |
\n |
Line feed (LF) | U+000A |
\t |
Horizontal tabulation (HT) | U+0009 |
\0 |
Null character (NUL) | U+0000 |
\' |
' (APOSTROPHE) |
U+0027 |
\x ASCII_HEX_DIGITa ASCII_HEX_DIGITb |
Unicode code point U+00ab | U+00ab |
\u{ ASCII_HEX_DIGIT{2,6}code } |
Unicode code point U+code | U+code |
escape designates any of the escape codes listed up there.
Some examples of x-escapes are: \x4D
or \x4d
for letter M
.
Some examples of u-escapes are: \u{61}
for letter a
, \u{03Bc}
for letter μ , \u{1F600}
for 😀
.
x-escapes and u-escapes should always be valid char
s.
TODO
- Check operator precendence
- Add rules about whitespace
- Add section about user-defined rules
- Add explanations for the modifiers
- Complete the examples
- Cover the
PEEK[..]
syntax - Investigate how tags actually tag
- Add all the checks from
Beta Was this translation helpful? Give feedback.
-
Pest meta, parsing and preparing a Pest GrammarThere are several stages in the parsing of a fn parse_and_optimize(
grammar: &str,
) -> Result<UsedBuiltinAndOptimized<'_>, Vec<Error<parser::Rule>>> in pest/meta/src/lib.rs. Below are listed the different transformations this function performs. Validation steps were marked by ☑. Every validation step returns either Ok or
|
Beta Was this translation helpful? Give feedback.
-
This is amazing! Would you be interested in putting this into the docs? |
Beta Was this translation helpful? Give feedback.
-
I'm trying to address the problem of grammars that run indefinitely (by detecting and reporting them) in #851.
For that I need the semantics of pest to be clear to me. So I read slices of the book, didn't find everything I wanted there, then I looked at the docs. There were still question unanswered, such as «what happens when the stack is empty and a
POP
comes by ?». I expected it to simply fail. Turns out it panics ! My surprise lead me to distrust the docs, and I jumped into the source code.I started answering all my questions, and I wrote those two recaps about what I read. I guess those might be integrated in the docs. The thing is that I'm not sure where to add them.
The first one is about the precise semantics of Pest, and is yet incomplete. I think this one should be added to the book, but marked as a reference and not a tutorial because of the tone used. Once the TODOs I listed in here are done, including important things: the white space/comment/trivia and the modifiers (atomic, ...) are essential aspects of pest.
The second one is about the inner workings of the pest_meta crate. I think it could go on that crate's documentation. But maybe it's more addressed to a contributor to pest ?
Please give your thoughts about it, whether this could be useful, if this was already said in part somewhere I didn't check and could be adapted to fit there ? Are there things you would add ?
Beta Was this translation helpful? Give feedback.
All reactions