Questions tagged [parboiled2]

parboiled2 is a Scala 2.10.3+ library enabling lightweight and easy-to-use, yet powerful, fast and elegant parsing of arbitrary input text.

parboiled2 is a Scala 2.10.3+ library enabling lightweight and easy-to-use, yet powerful, fast and elegant parsing of arbitrary input text. It implements a macro-based parser generator for Parsing Expression Grammars (PEGs), which runs at compile time and translates a grammar rule definition (written in an internal Scala DSL) into corresponding JVM bytecode.

parboiled2 is the successor of parboiled 1.x , which provides a similar capability (for Scala as well as Java) but does not actually generate a parser. Rather parboiled 1.x interprets a rule tree structure (which is also created via an internal DSL) against the input, which results in a much lower parsing performance.

18 questions
3
votes
1 answer

In parboiled2, how should I report an error in a parser action?

What's the best way to report an error in a parser action in parboiled2 (I'm using v 2.1.4)? For example, say I want to read an integer value and report an error if its not within the expected range? I tried calling fail, but that doesn't appear to…
3
votes
1 answer

Clever way to break a Seq[Any] into a case class

I've been parsing a proprietary file format that has sections and each section has a number of records. The sections can be in any order and the records can be in any order. The order is not significant. While sections should not be duplicated, I…
Thomas
  • 364
  • 1
  • 4
  • 13
3
votes
1 answer

Dynamically create parboiled2 rules

Can I generate rules dynamically in parboiled2 parser? The use case is that I have a bunch of rules already defined, but want to add more and not compile every time I add a rule.
gkr
  • 31
  • 2
3
votes
1 answer

Parboiled2 grammar for parsing escaped CSV line

I am trying to parse a single line which contains strings separated by delimiters into a sequence of these strings. It should be able to have any character in the strings, if a field contains a delimiter it needs double quotes around it. In order to…
dreamflasher
  • 1,387
  • 15
  • 22
3
votes
1 answer

Parboiled2 Parser Example

I'm trying to try out this example from parboiled2: scala> class MyParser(val input: org.parboiled2.ParserInput) extends org.parboiled2.Parser { def f = rule { capture("foo" ~ push(42)) } …
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
3
votes
2 answers

How to make parboiled2 match the whole input?

I wrote the following hello-world parboiled2 parser: class MyParser(val input: ParserInput) extends Parser { /* Expr <- Sum Sum <- Product ('+') Product)* Product <- Value (('*') Value)* Value <- Constant | '(' Expr ')' …
Chris B
  • 9,149
  • 4
  • 32
  • 38
2
votes
0 answers

Parboiled2 PopRule example

After reading the documentation on https://github.com/sirthias/parboiled2, I discovered that I could pop something out of the stack with the rule: type PopRule[-L <: HList] = Rule[L, HNil] But I could not find a working example of this type of rule…
2
votes
1 answer

parboiled2 Illegal rule composition

I am writing an cron parser, but compiler complains illegal rule composition, What's wrong with my parser? import org.parboiled2._ sealed trait Part case class Fixed(points: Seq[Int]) extends Part case class Range(start: Int, end: Int) extends…
jilen
  • 5,633
  • 3
  • 35
  • 84
2
votes
1 answer

Understanding Parboiled2's '~' Combinator

Looking at the parboiled2 section, Rule Combinators and Modifiers: I don't understand the a, b, and then a ~ b diagram. So far I've found the documentation straightforward. But I am a bit lost here. Can you please explain each block?
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
2
votes
1 answer

Parboiled2: reference to position in source text from AST

I am writing a DSL, and learning parboiled2, at the same time. Once my AST is built, I would like to run some semantic checks and, if there are any errors, output error messages that reference the offending positions in the source text. I am writing…
Eduardo
  • 8,362
  • 6
  • 38
  • 72
1
vote
2 answers

Parboiled2: How to process dependent fields?

I'm trying to parse a file format, using the excellent parboiled2 library, in which the presence of some fields is dependent upon the value of one or more fields already processed. For example, say I have two fields, the first of which is a flag…
Mike Allen
  • 8,139
  • 2
  • 24
  • 46
1
vote
0 answers

Is there a way in parboiled2 to subclass so that you can, ie accept multiple syntaxes (PowerShell-style, bash/sh-style, Cisco-style)?

Warning I am new to parboiled2. I would like to be able to write my CLI in a way that is somewhat agnostic of the syntax involved. It will always have the same shape, a triplet of: case class Command(command: String, modifiers: Seq[String] = Nil,…
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126
1
vote
1 answer

parboiled2 parser to extract token and fixed text

Need to extract tokens and fixed text. Example: "Hello {token1} today's date is {token2} would you like to call {token3}" would return FixedPart("Hello ") TokenPart(token1) FixedPart(" today's date is ") TokenPart(token2) FixedPart(" would…
Gagan
  • 11
  • 2
1
vote
0 answers

Getting separatedBy to work in parboiled2

This seems pretty simple! class SeparatedParser(val input: ParserInput, val delimiter: String = ",") extends Parser { def pipedField = rule { (zeroOrMore(field).separatedBy("|")) } def field = rule { capture(zeroOrMore(noneOf(delimiter))) } …
Dan Gravell
  • 7,855
  • 7
  • 41
  • 64
1
vote
1 answer

Running a parser within parboiled2

The docs for parboiled2 mention the following to get results: https://github.com/sirthias/parboiled2#access-to-parser-results val parser = new MyParser(input) val result = parser.rootRule.run() However I get a compilation error when attemping what…
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
1
2