Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 26 14:24
    kornelski opened #494
  • Feb 23 15:18
    Schaeff commented #493
  • Feb 23 15:04
    Schaeff opened #493
  • Feb 20 00:10
    MaxBondABE commented #482
  • Feb 20 00:09
    MaxBondABE commented #482
  • Feb 20 00:09
    MaxBondABE commented #482
  • Feb 18 20:08
    lukeg101 edited #492
  • Feb 18 20:07
    lukeg101 opened #492
  • Feb 17 08:46
    ClementNerma commented #491
  • Feb 17 08:45
    ClementNerma commented #491
  • Feb 17 04:14
    CAD97 commented #491
  • Feb 17 02:44
    ImJeremyHe edited #491
  • Feb 17 01:41
    ImJeremyHe opened #491
  • Feb 12 13:51
    HollayHorvath opened #490
  • Feb 08 12:32
    dragostis commented #489
  • Jan 29 17:39
    ColonelThirtyTwo commented #489
  • Jan 28 18:00
    ColonelThirtyTwo opened #489
  • Jan 25 17:11
    nilsmartel commented #485
  • Jan 05 10:57
    Geobert closed #488
  • Jan 05 10:57
    Geobert commented #488
Mridul Pentapalli
@craniumrat
Im trying this on the pest editor.
Mridul Pentapalli
@craniumrat
Nevermind, I found my mistake.. forgot the @ ahead of the word rule.
qichao
@chaosprint
Hi, I am trying to recommend Pest to a friend who is trying to build a DSL but hesitating on Macro or Pest. Can anyone mention some advantages and disadvantages? We both agree that Pest is, of course, more elegant, but how is the speed comparison?
R. Tyler Croy
@rtyler
I haven't used Macro @chaosprint , but I've been very happy with Pest :smile_cat:
rtyler
@rtyler:matrix.org
[m]
holy smokes matrix!
Amit Bashan
@amitbashan
Hello everyone! Where can I find a manual explaining the syntax of .pest files?
rtyler
@rtyler:matrix.org
[m]
docs.rs/pest_derive has a good bit
Amit Bashan
@amitbashan
awesome. is there some ebnf to pest syntax automatic conversion?
rtyler
@rtyler:matrix.org
[m]
not that I've ever seen
rtyler
@rtyler:matrix.org
[m]
Hrm, I'm perplexed on how to parse this snippet of code, I basically want to say "anything between these two braces is irrelevant, inculding other balanced braces" such that if I have foo { blah blah blah@{} } I can just parse the foo { } and treat the inside of that entirely as garbage
rtyler
@rtyler:matrix.org
[m]
I think I managed to get it, the pest book was helpful! Turns out I was able to avoid using PUSH/PEEK/POP
Tom Forbes
@orf
Perhaps I'm being really dumb, but the following pest grammar causes a stack overflow when evaluating 1 * 1:
multiplication = {(multiplication ~ ("*" | "/" | "%"))* ~ unary+}
unary = {ASCII_DIGIT+}
I'm not sure why - it's constantly trying to match the multiplication rule. Wouldn't this recurse just fine? multiplication = {(multiplication ~ ("*" | "/" | "%"))? ~ ASCII_DIGIT} also fails.
Gerry Agbobada
@gagbo
Hello, I'm currently trying Pest to write a scheme implementation. Do you know if there are facilities to translate EBNF syntax into Pest, or better, if someone already tried and wrote a pest grammar for R7RS ?
Rémy Grünblatt
@rgrunbla
Hi there.
I'm trying to do the Advent Of Code day 18 (today) using rust and pest. The main idea is this one: parsing small arithmetic expressions, but instead of "*" (multiplying) having precedence, it's "+".
so 5 * 3 + 3 + 3 * 5 should be evaluated as 5 * 9 * 5, for example.
I came with this grammar, mainly extracted from the "arithmetic parsing" part from the pest book : https://0x0.st/iFdk.txt
but now I'm hitting a wall: I'm not succeeding in making the + being "both" left and right associative (meaning I want to consume them first)
How should I go about doing this ?
Gerry Agbobada
@gagbo
looks like it's solved there pest-parser/pest#188
calculation = _{ SOI ~ expr ~ EOI }

WHITESPACE = _{ " " | "\t" }

int = { ASCII_DIGIT+ }
add      = { "+" }
multiply = { "*" }

operation = _{ multiply | add }

term = _{ int | "(" ~ expr ~ ")" }

expr = { (multiplication ~ operation)* ~ multiplication }
addition = { (term ~ add)* ~ term }
multiplication = { (addition ~ multiply)* ~ addition }
from my understanding it should work the way you want
Rémy Grünblatt
@rgrunbla
yup, looks like it is that, thanks
Rémy Grünblatt
@rgrunbla
So, small question again
it looks like in 8 + 9 you get an int with spaces inside (which is weird, as int is only composed of ASCII_DIGIT+)
Why is so ?
Rémy Grünblatt
@rgrunbla
is it*
Felix Wiegand
@fxwiegand_gitlab
Hello, i was wondering if someone else used pest to solve yesterdays advent of code puzzle? It worked like a charm for part 1 but i ran into some problem in part 2.
rtyler:matrix.org @rtyler:matrix.org isn't doing advent of code :shrug:
rtyler
@rtyler:matrix.org
[m]
sheesh, getting a shebang grammar to work properly is surprisingly frustrating, the same basic grammar that COMMENT has for single line comments isn't working for some wacky reason
it's like the !NEWLINE isn't being respected
rtyler
@rtyler:matrix.org
[m]
I am feeling a bit silly, there's got to be a simpler pattern for doing order-independent parsing rules here
I have three rules which can match inside of a block, and I just want the user to be able to order them in either which way
rtyler
@rtyler:matrix.org
[m]
perhaps, worth just asking
Ahmed Abd El Mawgood
@oddcoder
does anyone have any idea how to create custom tokenizer for pest ?

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.

The rules itself are also terrible
like the io_here token is nested multiple layers deep under the layer where we have the NEWLINE stated
xaviex
@xaviex
Hey! Is it possible to have more than one Grammar in a module? (Eg. any way to rename the Rule enum so that they do not conflict)
rtyler
@rtyler:matrix.org
[m]
I could not find a way to put my two grammars in the same module, but putting them in two adjacent modules worked fine
the derive macro brings some things in, like Rule which you mention, which will conflict
Inky
@Inky-developer

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?

Dragoș Tiselice
@dragostis

@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.

Until then, if the patch I sent you doesn't work, you can always get around these cases by using the lookaheads. (& or !)
Dragoș Tiselice
@dragostis
Or you could write something likeblock = {"{"~ block ~ (";" ~ block)* ~ "}"} then disambiguate higher up.
Inky
@Inky-developer
The pull request does unfortunately not prevent the time blowup, on my computer a string with 20 curly braces gets parsed in 46ms, but a string with 27 curly braces already takes 6.1 seconds.
I will check if I can get my grammar to work with the lookahead features, thanks for the suggestion!
If you don't mind, could you please elaborate on your last suggestion?
Dragoș Tiselice
@dragostis
You won't have item/expr productions in your code above, only blocks. You'd. have to disambiguate between them in Rust code.
PaulChernoch-Shell
@PaulChernoch-Shell
I have been using Pest for a few weeks. I am porting a Peg.js grammar to Pest. It is going surprisingly well. My pet project is to write a parser and execution engine for the DMN Feel language in Rust, not a trivial exercise (and not a trivial grammar!) I have a recognizer working for the full grammar. Next up is walking the Pairs and constructing Rust Closures out of the parse tree. Before I do that, I needed to implement a smaller parser to handle Duration strings. They follow the XPATH standard for YearMonth or DayTime. This evening I wrote a nice grammar to parse them:
// 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" }
PaulChernoch-Shell
@PaulChernoch-Shell
The tricky part was that I wanted to use the wildcard "?", but I need to have at least one of hour, minute, second in the second half in order to include the "T". Thus I had to explicitly list all permutations. I tried to use Rust Regexes, but they have limits not found in C#, Perl or Java implementaions of Regex. So Pest was the only easy way.