How do you set maxValueStackSize?

34 views
Skip to first unread message

Robert Kreuzer

unread,
Nov 30, 2015, 11:04:50 AM11/30/15
to parboiled2.org User List
Hi there,

I am getting a org.parboiled2.ValueStackOverflowException for a larger input. I am trying to work around it by increasing the maxValueStackSize, but I cannot figure out where to set it.

I have a Parser

class JobParser(val input: ParserInput) extends Parser with ExpressionParser {...}

and I am using it like this:

val parsedJob = parser.job.run(maxValueStackSize = 2048)

But setting maxValueStackSize here does not compile. Where should I set it instead?

Thanks,
Robert

Alexander Myltsev

unread,
Dec 1, 2015, 9:19:20 AM12/1/15
to parboiled2.org User List
Hi Robert, 

Could you paste your compilation error here? 

A.

Robert Kreuzer

unread,
Dec 1, 2015, 11:33:45 AM12/1/15
to parboiled2.org User List
Hi Alexander,

the error I am getting is:

too many arguments for macro method run: ()(implicit scheme: org.parboiled2.Parser.DeliveryScheme[shapeless.::[com.blabla.Job,shapeless.HNil]])scheme.Result

Also the type of 'parser.job' is Rule1[Job], if that helps.

Best,
Robert

Alexander Myltsev

unread,
Dec 1, 2015, 11:45:19 AM12/1/15
to parboiled2.org User List
Try this:

parser.job.run("someInput", maxValueStackSize = 2048)

Robert Kreuzer

unread,
Dec 2, 2015, 3:49:36 AM12/2/15
to parboiled2.org User List
That gives the same error as above, when I try it.
But I am already passing the input to the parser, when constructing it:

        val parser = new JobParser(job)
        val parsedJob = parser.job.run()


This code is working, but for very large inputs it throws the ValueStackOverflowException.
Can I maybe set the maxValueStackSize as an attribute on the JobParser itself somehow?

Best,
Robert

Mathias Doenitz

unread,
Dec 2, 2015, 2:58:26 PM12/2/15
to parboil...@googlegroups.com
Robert,

`maxValueStackSize` is a constructor parameter of the `Parser` class.

So, if you currently have

class JobParser(val input: ParserInput) extends Parser {
...
}

you should change it to

class JobParser(val input: ParserInput) extends Parser(maxValueStackSize = 16384) {
...
}

HTH and cheers,
Mathias

---
mat...@parboiled.org
http://www.parboiled.org
> --
> You received this message because you are subscribed to the Google Groups "parboiled2.org User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to parboiled-use...@googlegroups.com.
> Visit this group at http://groups.google.com/group/parboiled-user.
> To view this discussion on the web visit https://groups.google.com/d/msgid/parboiled-user/54b71d21-f49c-4ba9-bf06-3be0e1210e4d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Robert Kreuzer

unread,
Dec 3, 2015, 3:50:16 AM12/3/15
to parboiled2.org User List
Mathias,

thanks for your help, that did the trick!
I didn't realize that you can pass arguments to classes that you are inheriting from in Scala.

Best,
Robert

Alexander Myltsev

unread,
Dec 3, 2015, 6:43:47 AM12/3/15
to parboiled2.org User List
Example as follows worked out for me:


object ABCParser extends App {
  object Parser extends SimpleParser {
    val InputLine = rule { &(A ~ 'c') ~ oneOrMore('a') ~ B ~ !(ch('a') | 'b' | 'c') ~ EOI }

    val A: Rule0 = rule { 'a' ~ optional(A) ~ 'b' }

    val B: Rule0 = rule { 'b' ~ optional(B) ~ 'c' }
  }

  repl()

  @tailrec
  def repl(): Unit =
    StdIn.readLine("---\nEnter expression for abc-parser > ") match {
      case "" ⇒ // terminate
      case line ⇒
        Parser.InputLine.run(line, maxValueStackSize = 2048) match {
          case Success(_)             ⇒ println("Expression is valid")
          case Failure(e: ParseError) ⇒ println("Expression is not valid: " + e.format(line))
          case Failure(e)             ⇒ println("Unexpected error during parsing run: " + e)
        }
        repl()
    }
}

Alexander Myltsev

unread,
Dec 3, 2015, 6:44:48 AM12/3/15
to parboiled2.org User List
BTW what version of parboiled do you use? May be you should upgrade it.

Robert Kreuzer

unread,
Dec 3, 2015, 7:02:59 AM12/3/15
to parboiled2.org User List
Hi Alexander,

I'm using parboiled 2.1.0 (so the latest version, I think).
And I'm importing 'import org.parboiled2._'.
I'm not sure why passing maxValueStackSize to run() doesn't work for me, but I could get it to work by passing it directly to the Parser constructor, as suggested by Mathias.
Thanks for looking into this, I appreciate it.

Robert
Reply all
Reply to author
Forward
0 new messages