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
3
votes
1 answer

How can a PetitParser parse rule signal an error?

I want a parse rule that only recognizes numbers between 0 and 32767. I tried something like: integerConstant ^ (#digit asParser min: 1 max: 5) flatten ==> [ :string | | value | value := string asNumber. (value…
Damien Cassou
  • 2,555
  • 1
  • 16
  • 21
2
votes
1 answer

PetitParser and Parentheses

Sorry, I ran into another question about using PetitParser. I've figured out my recursive issues, but now I have a problem with parentheses. If I need to be able to parse the following two expressions: '(use = "official").empty()' '(( 5 + 5 ) * 5)…
Grey
  • 331
  • 3
  • 11
2
votes
1 answer

How to get the content between two identical elements

I want to parse the root element of such data as follows ... ...anything ... hahahha < elementC > { ”aa“: 11, } If…
ZERO M
  • 21
  • 2
2
votes
1 answer

Building expression parser with Dart petitparser, getting stuck on node visitor

I've got more of my expression parser working (Dart PetitParser to get at AST datastructure created with ExpressionBuilder). It appears to be generating accurate ASTs for floats, parens, power, multiply, divide, add, subtract, unary negative in…
Randal Schwartz
  • 39,428
  • 4
  • 43
  • 70
2
votes
1 answer

Dart PetitParser to get at AST datastructure created with ExpressionBuilder

I'm new to petitparser, but it looks like it's the sonic screwdriver of parsers. For my first project, I'm building code to parse a simple expression that builds an AST tree of my Node objects, then walks that tree with a few rules to minimize the…
Randal Schwartz
  • 39,428
  • 4
  • 43
  • 70
2
votes
1 answer

PetitParser: Is there a parser like plus() but with an upper boundary?

Is there a parser like plus() that has an upper boundary, to model expressions like Item <- [a-zA-Z0-9]{1,5}? Similarly for something like Item <- [a-zA-Z0-9]{3,5}?
Behrang
  • 46,888
  • 25
  • 118
  • 160
2
votes
3 answers

Simple delimiter parser

I'm trying out PetitParser for parsing a simple integer list delimited by commas. For example: "1, 2, 3, 4" I tried creating a integer parser and then use the delimitedBy method. Parser integerParser = digit().plus().flatten().trim().map((String…
2
votes
1 answer

Unsupported operation: References cannot be parsed

static const String tabChar = '\u0009'; Parser tab() => ref(token, tabChar); expect(tab().accept(tabChar), isTrue); with the token method from…
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
2
votes
1 answer

PetitParser arithmatic script from textbook is not working. It keeps saying ParseOn is nill?

I am learning how to use PetitParser on Pharo, Smalltalk and I am using a textbook to learn it. In the textbook, the following script is given. term := PPDelegateParser new. prod := PPDelegateParser new. prim := PPDelegateParser new. term…
2
votes
1 answer

Why does *any* not backtrack in this example?

I'm trying to understand why in the following example I do not get a match on f2. Contrast that with f1 which does succeed as expected. import 'package:petitparser/petitparser.dart'; import 'package:petitparser/debug.dart'; main() { …
user1338952
  • 3,233
  • 2
  • 27
  • 41
2
votes
1 answer

How to use 'debug()' with 'undefined()' parser

I'm trying to debug an undefined parser in petitparser. See the code without debug first: import "package:petitparser/petitparser.dart"; main() { var mynum = undefined(); var parser = string("abc").map((s) { mynum.set(string("888")); …
Freewind
  • 193,756
  • 157
  • 432
  • 708
2
votes
1 answer

How to match `\b` in regex in PetitParserDart?

\b is the "world boundary" in regular expression, how to match it in PetitParserDart? I tried: pattern("\b") & word().plus() & pattern("\b") But it doesn't match anything. The patten above I want is \b\w+\b in regular expression. My real problem…
Freewind
  • 193,756
  • 157
  • 432
  • 708
2
votes
1 answer

How to create a parser which means any char not in ['(',')','{','}'], in PetitParserDart?

I want to define a parser which accept any char except ['(', ')', '{', '}'] in PetitParserDart. I tried: char('(').not() & char(')').not() & char('{').not() & char('}') I'm not sure if it's correct, and is it any simple way to do this? (something…
Freewind
  • 193,756
  • 157
  • 432
  • 708
2
votes
1 answer

How to create a parser which is a whitespace but not a line separator, in PetitParser?

There is a built-in whitespace() parser in PetitParserDart, which checks character in: (9 <= value && value <= 13) || (value == 32) || (value == 160) || (value == 5760) || (value == 6158) || (8192 <= value && value <= 8202) || (value == 8232) ||…
Freewind
  • 193,756
  • 157
  • 432
  • 708
2
votes
3 answers

How to use PetitParser to match the expression inside a dart string?

I want to use PetitParserDart to parse the embed expression inside a dart string. Prepare some objects: class User { String name; } var user1 = new User()..name="Mike"; var user2 = new User()..name="Jeff"; var user3 = new…
Freewind
  • 193,756
  • 157
  • 432
  • 708