In parboiled2, how do I report a bug in the parser action?

What's the best way to report a bug in the 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 it is not in the expected range? I tried calling fail

, but it doesn't seem like reality in the parser action. Also, I cannot tell how I should provide the stack value to the rule test

. Am I just throwing an exception ParseError

?

To be more specific, consider the following rule:

def Index = rule {
  capture(oneOrMore(CharPredicate.Digit)) ~> {s => // s is a String
    val i = s.toInt
    if(i > SomeMaxIndexValue) ??? // What do I put here?
    else i
  }
}

      

+3


source to share


1 answer


You can use test

for this. The trick is that actions can also return Rule

.



def Index = rule {
  capture(oneOrMore(CharPredicate.Digit)) ~> {s =>
    val i = s.toInt
    test(i <= SomeMaxIndexValue) ~ push(i)
  }
}

      

+4


source







All Articles