bors[bot] on staging.tmp
[ci skip][skip ci][skip netlify] (compare)
bors[bot] on staging.tmp
[ci skip][skip ci][skip netlify] (compare)
bors[bot] on staging.tmp
[ci skip][skip ci][skip netlify] (compare)
bors[bot] on staging.tmp
[ci skip][skip ci][skip netlify] (compare)
bors[bot] on staging.tmp
[ci skip][skip ci][skip netlify] (compare)
bors[bot] on master
Added lister optimization: redu… Added case in factorizer when r… Added case in factorizer when l… and 14 more (compare)
bors[bot] on staging.tmp
bors[bot] on staging
Added lister optimization: redu… Added case in factorizer when r… Added case in factorizer when l… and 14 more (compare)
bors[bot] on staging.tmp
Added lister optimization: redu… Added case in factorizer when r… Added case in factorizer when l… and 14 more (compare)
I am dealing with terrible grammer that goes like this
When an io_here token has been recognized by the grammar (see Shell Grammar), one or more of the subsequent lines immediately following the next NEWLINE token form the body of one or more here-documents and shall be parsed according to the rules of Here-Document.
Hey, I am having big trouble with my grammar for a custom language. This is a very simplified version:
program = {SOI ~ item* ~ EOI}
item = {block ~ ";"}
block = {"{"~item*~expr?~"}"}
expr = {block}
As a bit of context, an item could be some statement, for example let a = 1;
or, as in this grammar, a block: {...};
. However, a block can have as its last element an expression (implicite return) and a block can also be interpreted as an expression. This leads to exponential time for inputs that look like this: {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
.
I know that this is parsed so slowly, because the parser has to backtrack for every {
, leading to a 2^n time where n is the number of brackets.
I am quite desperate, is there any way to fix this?
@Inky-developer, could you please try pest-parser/pest#473 to see if it improves the situation?
Basically these are warts in the optimiser that's currently not that well designed. I have changes in mind for pest3 that will render these cases obsolete.
&
or !
)
// Pest Grammar for parsing XPATH Duration strings like this: P2Y3M1DT5H2M5.5S
// - A "T" divides the year, month, day fields from the hour, minute, second fields.
// - Some parts may be omitted, but at least one must be specified.
// For example, PT10M is ten minutes.
// - If hour, minute and second are all omitted, you must omit the "T".
// - Never omit the "P".
// - Only the Seconds field may have a fraction, the others are integers.
// - A leading minus sign indicates a negative duration. It must come befor ethe "P".
// For example: -P2Y is negative two years.
// - Months can be more than twelve, hours more than 24, etc.
date_time = @{
SOI ~ sign? ~ "P" ~ (
date ~ "T" ~ time
| date
| "T" ~ time
) ~ EOI
}
date = {
year ~ month ~ day
| year ~ month
| year ~ day
| year
| month ~ day
| month
| day
}
time = {
hour ~ minute ~ second
| hour ~ minute
| hour ~ second
| hour
| minute ~ second
| minute
| second
}
sign = !{ "-" }
year = !{ number ~ "Y" }
month = !{ number ~ "M" }
day = !{ number ~ "D" }
hour = !{ number ~ "H" }
minute = !{ number ~ "M" }
second = ${ number ~ "S" }
digits = @{ ASCII_DIGIT+ }
number = @{ digits ~ fraction? }
fraction = @{ "." ~ digits ~ !integral }
integral = { "Y" | "M" | "D" | "H" }
literal
rule is defined as { "{" ~ number ~ "}" ~ CRLF ~ char* }, where number
describes how many characters follows the CRLF. Since this is the only thing in the grammar that behaves this way, I was wondering if there was a "backdoor" Pest could offer me,
hello = { #crate::world }
where i define fn world(Box<ParserState<Rule>>) -> ParseResult<Box<ParserState<Rule>>>
myself. I then added an API that would let me introspect on the current state of the parser
#[derive(pest_derive::Parser)]
#[grammar = "my_grammar.pest"]
pub struct MyParser;
#[cfg(test)]
mod tests {
use pest::Parser;
use crate::{MyParser};
#[test]
fn some_test() {
let result = MyParser::parse(Rule::some_rule, input).unwrap();
}
}
pest
to StackOverflow so it has it's own tag now. I'm also learning Pest now, and I'm kind of a pita when I learn stuff and I ask a lot of questions, so if you're on StackOverflow and you can help out watch the tag. ;)
pest-consume
looks like the most active option. OTOH, there is pest-ast
, which, OTTH, seems to be hanging on pest 3 for two years now.