Questions tagged [petitparser]

PetitParser is a parsing framework for Smalltalk, Java and Dart.

PetitParser is a parsing framework originally written in Smalltalk.

PetitParser combines ideas from scannerless parsing, parser combinators, parsing expression grammars and packrat parsers to model grammars and parsers as objects that can be reconfigured dynamically.

Information can be found at the PetitParser page of the University of Bern.

There are implementations in

To get started with PetitParser you might have a look at:

54 questions
2
votes
1 answer

PetitParser not distributive?

Are rules in PetitParser distributive? There were next rules: integerLiteral --> hexIntegerLiteral / octalIntegerLiteral / decimalIntegerLiteral hexIntegerLiteral --> hexNumeral , (integerTypeSuffix optional) octalIntegerLiteral -->…
Uko
  • 13,134
  • 6
  • 58
  • 106
2
votes
1 answer

Forbid token to parse extra whitespace

Now idea is like this: in Java for octalIntegerLiteral I have a rule octalNumeral, (integerTypeSuffix optional) But I want to get a numbers as token, so I used: octalNumeral javaToken, (integerTypeSuffix optional) The problem is that it starts to…
Uko
  • 13,134
  • 6
  • 58
  • 106
1
vote
1 answer

Can someone point me in the right direction to begin parsing this string in dart?

I have a series of string like this: (((S|69|L || S|69|R || S|72|L || S|72|R) && ((S|62|L && (S|78|L || S|55|L) && (S|77|L || S|1|L)) || (S|62|R && (S|78|R || S|55|R) && (S|77|R || S|1|R)))) && (M|34|L || M|34|R) && (((M|40|L && M|39|L && M|36|L) ||…
Coltuxumab
  • 615
  • 5
  • 16
1
vote
1 answer

Using Flutter's PetiteParser to create FHIRPath

I'd like to ask for some guidance using petitparser (I'm updating this question). There's a json-based grammar called FHIRPath that I'm trying to recreate in dart. I'm new to grammars like this, so it's taken me a little while to understand what I…
Grey
  • 331
  • 3
  • 11
1
vote
1 answer

Parsing delimited strings using petitparser

I was originally looking to (manually) write a simple tokenise/parser for my grammar, but one of my requirements means that tokenising is a bit fiddly. I need to be able to support the notion of delimited strings where the delimiter could be any…
Craig Edwards
  • 2,118
  • 1
  • 18
  • 23
1
vote
1 answer

Can a petitparser parser be reused safely?

Using petitparser in Dart, is it ok to reuse a parser? For example, say we want to parse an IPv4 style address like 192.168.1.21. Initally, I wrote: final ipv4Part = digit().repeat(1, 3).flatten(); final ipv4Address = (ipv4Part & char('.')…
Richard Heap
  • 48,344
  • 9
  • 130
  • 112
1
vote
1 answer

PetitParser evaluator not working properly

when I try running this code on pharo, my answers are somewhat off. I try evaluating 1-2+3 but for some reason, it does 1- (2+3) and I do not understand why this is so. Thanks for your time. number := #digit asParser plus token trim ==> [ :token |…
boss revs
  • 331
  • 2
  • 4
  • 13
1
vote
1 answer

How do I do a "getElementsByTagName" using the Dart Petitparser XML parser?

I may have overlooked it somewhere, but what is the nice way to get all elements of a specific name (similar to the old getElementsByTagName) via the Dart version of PetitParser? I managed to load an XML file and successfully parse it using…
Geert
  • 239
  • 3
  • 12
1
vote
1 answer

Better solution for "Doing something when a parse fails"?

I can't to do something when a parser fails, in petitparser. My solution is: var parser = string("hello").or( epsilon().map((_) { // do something }).seq(failure()) ); I want to know if there is any better solution?
Freewind
  • 193,756
  • 157
  • 432
  • 708
1
vote
1 answer

How to match the start and end of a block

I want to define a special code block, which may starts by any combination of characters of {[<#, and the end will be }]>#. Some example: { block-content } {## block-content ##} #[[<{### block-content ###}>]]# Is it possible with…
Freewind
  • 193,756
  • 157
  • 432
  • 708
1
vote
1 answer

Is there a math parser for petitparser?

is there a dart lib that can parse math strings such as (3+4)/4.5? I tried to build a basic parser with petitparser, but I am in over my head and its just trial and error right now :) Is there an petitparser (Dart or any other language)…
oskbor
  • 1,592
  • 18
  • 35
1
vote
1 answer

How to fail and throw exceptions when a rule can't be fully matched , in PetitParserDart?

I have defined some rules with PetitParserDart: def("start", ref("rule").separatedBy(char('\n'), includeSeparators: false); def("rule", char('(').seq(word().plus()).seq(char(')'))); So the following text will be matched: (aaa) (bbbbbb) But if…
Freewind
  • 193,756
  • 157
  • 432
  • 708
1
vote
1 answer

How to just trim left or right in PetitParserDart

There is a trim() method which will create a parser to trim a string on both side. How to create one which just trim the left or right?
Freewind
  • 193,756
  • 157
  • 432
  • 708
1
vote
1 answer

How to use petitparser to write a JSON formatter?

As far as I know, PetitParser is a parser which we can define grammers and actions to parse some text. I've successfully use its built-in JSON parser to parse some JSON string, but I want to do more. I want to write a JSON formatter which can format…
Freewind
  • 193,756
  • 157
  • 432
  • 708
0
votes
1 answer

What is an example of use case for epsilon in dart petitparser?

I don't understand the comment: /// Returns a parser that consumes nothing and succeeds. /// /// For example, `char('a').or(epsilon())` is equivalent to /// `char('a').optional()`. @useResult Parser epsilon() => epsilonWith(null); Could…
Gpack
  • 1,878
  • 3
  • 18
  • 45