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
10
votes
2 answers

Where could I find more examples of using PetitParser?

I'm looking for additional examples of using PetitParser beyond PPArithmeticParser and PPLambdaParser that are provided in the tests package and a couple of blog posts by Lukas? If anyone's willing to share theirs, it would be much…
Boris Slobodin
  • 233
  • 1
  • 6
10
votes
1 answer

Parsing comments with PetitParser in Pharo

Is there a simpler way to parse 1-line comments than this? comment ^ '//' asParser , (#any asParser starLazy: (#newline asParser)) , #newline asParser ==> [ :result | nil "Ignore comments" ] program ^ (comment /…
Damien Cassou
  • 2,555
  • 1
  • 16
  • 21
7
votes
4 answers

Finding tokens in a Smalltalk String with PetitParser

I want to parse 'This,is,an,example,text' like in findTokens 'This,is,an,example,text' findTokens: $, an OrderedCollection('This' 'is' 'an' 'example' 'text') but cannot figure out how to do it with PetitParser, delimitedBy: and separatedBy:…
user1000565
  • 927
  • 4
  • 12
5
votes
2 answers

How to define Pascal variables in PetitParser

Here is the (simplified) EBNF section I'm trying to implement in PetitParser: variable :: component / identifier component :: indexed / field indexed :: variable , $[ , blah , $] field :: variable , $. , identifier What I did was to add all these…
Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51
5
votes
3 answers

@override of Dart code

I noticed PetitParserDart has a lot of @override in the code, but I don't know how do they be checked? I tried IDEA dart-plugin for @override, but it has no effect at all. How can we use @override with Dart?
Freewind
  • 193,756
  • 157
  • 432
  • 708
5
votes
1 answer

How to consume but not capture some chars, in PetitParser?

I defined a rule: def("invokation", char('@').word().plus().flatten()); For "@who", it will match and get @who as result. How to ask it just return who without @?
Freewind
  • 193,756
  • 157
  • 432
  • 708
5
votes
2 answers

Defining a left-associative parser with PetitParser

In http://pharobooks.gforge.inria.fr/PharoByExampleTwo-Eng/latest/, an ExpressionGrammar is defined. However, it is right-associative parser parse: '1 + 2 + 6'. ======> #(1 $+ #(2 $+ 6)) How can I make it left-associative so that parser parse:…
Damien Cassou
  • 2,555
  • 1
  • 16
  • 21
5
votes
1 answer

How to parse identifiers that start with a keyword with PetitParser?

I would like to parse identifiers in a programming language, by using PetitParser. One of the requirements is that the name of an identifier is not a keyword (such as null), so that null would not be a valid identifier. The smallest parser I can…
Alberto Bacchelli
  • 1,029
  • 1
  • 9
  • 9
4
votes
1 answer

Self-referencing PetitParser's PPCompositeParsers

I have a programming language grammar I would like to explode in several subclasses of PPCompositeParser (e.g., one class will handle instructions, another class will handle expressions, another class with handle program structure). I want to do…
Damien Cassou
  • 2,555
  • 1
  • 16
  • 21
3
votes
1 answer

ref0 not resolved by petitparser

petitparser is a parser generator written in dart to be used e.g. in Flutter. According to this page, petitparser allows to use ref0 to reference the current parse class. In the section Using Grammar Definitions you read this statement: To refer to…
SteAp
  • 11,853
  • 10
  • 53
  • 88
3
votes
2 answers

PetitParser: How to match to token set

In PetitParser2, how do I match a closed set of tokens, like month names? E.g. (in pseudocode) [ :word | MonthNames anySatisfy: [ :mn | mn beginsWith: word ] ] asParser. PPPredicateSequenceParser seemed like a possibility, but it seems you have to…
Sean DeNigris
  • 6,306
  • 1
  • 31
  • 37
3
votes
1 answer

Ignore escaped multi-line quotes

I want to parse a GraphQL document using Dart PetitParser. To be able to support BlockString (multi-line string) I'm looking for a way to get from """ abc \""" def """ this part out abc \""" def Full syntax…
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
3
votes
1 answer

How to get the associativity correct when parsing non-symmetric binary operators with PetitParser?

I'm trying to make a basic math parser with PetitParser, and I fail to get the order correct with non-symmetric binary operator like subtraction or division. I have this small example that can only parse (non-negative) integers and the - binary…
Idan Arye
  • 12,402
  • 5
  • 49
  • 68
3
votes
1 answer

writing a petit parser using smalltalk, how to use created method 'identifier?

i currently have a method pMain | parser | parser := 'proc' asParser, #space asParser, "<---- im trying to use the method identifier here - so i tried self identifier, instead of 'proc' asParser #letter asParser plus, $(…
Hambuzo
  • 83
  • 10
3
votes
1 answer

Custom instance variables and initializing with PetitParser

As far as I know PetitParser initializes each instance variable with a production method of the same name. What should one do, to add a custom instance variable and initialize it in the initialize method for example?
Uko
  • 13,134
  • 6
  • 58
  • 106
1
2 3 4