New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StackOverflow during parsing of multi line comments by combinator parser #4824
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4824?orig=1 |
@dcsobral said: |
Wojciech Durczyński (wojciech.durczynski) said:
|
Trond Olsen (tolsen77) said: val str = (1 to 200).mkString("/* ", "\n", " */\n")
at scala.util.parsing.combinator.Parsers$Parser$$anonfun$append$1$$anonfun$apply$1.apply(Parsers.scala:210) at scala.util.parsing.combinator.Parsers$Parser$$anonfun$append$1$$anonfun$apply$1.apply(Parsers.scala:210) |
@paulp said: |
Wojciech Durczyński (wojciech.durczynski) said (edited on Oct 28, 2011 8:41:42 AM UTC): protected def comment: Parser[Any] = (
'*' ~ '/' ^^ { case _ => ' ' }
| chrExcept(EofCh) ~ comment
) causes recursion for every character in multiline comments. protected def comment: Parser[Any] = (
rep('*') ~ '/' ^^ { case _ => ' ' }
| rep('*') ~ comment //to avoid recursion for multiline comments filled with '*'
| rep(chrExcept(EofCh, '*')) ~ comment
) |
Bodo Junglas (bjunglas) said (edited on Sep 9, 2013 9:55:15 PM UTC): protected def comment: Parser[Any] =
rep(chrExcept(EofCh, '*') | '*' ~ not('/')) ~ '*' ~ '/'
^^^ ' ' Probably not the most performant solution, but without recursion whatsoever. |
@gourlaysama said: |
I try to parse simple string that contains a few hundreds of commented lines.
val str = (1 to 300).mkString("/* ", "\n", " */\n")
During parsing of this string by scala.util.parsing.combinator.syntactical.StandardTokenParsers there is an exception:
java.lang.StackOverflowError
at scala.util.parsing.input.CharSequenceReader.first(CharSequenceReader.scala:28)
at scala.util.parsing.combinator.Parsers$$anonfun$acceptIf$1.apply(Parsers.scala:488)
at scala.util.parsing.combinator.Parsers$$anonfun$acceptIf$1.apply(Parsers.scala:487)
at scala.util.parsing.combinator.Parsers$$anon$3.apply(Parsers.scala:182)
at scala.util.parsing.combinator.Parsers$Parser$$anonfun$flatMap$1.apply(Parsers.scala:200)
at scala.util.parsing.combinator.Parsers$Parser$$anonfun$flatMap$1.apply(Parsers.scala:200)
at scala.util.parsing.combinator.Parsers$$anon$3.apply(Parsers.scala:182)
at scala.util.parsing.combinator.Parsers$Parser$$anonfun$map$1.apply(Parsers.scala:203)
at scala.util.parsing.combinator.Parsers$Parser$$anonfun$map$1.apply(Parsers.scala:203)
at scala.util.parsing.combinator.Parsers$$anon$3.apply(Parsers.scala:182)
at scala.util.parsing.combinator.Parsers$Parser$$anonfun$append$1.apply(Parsers.scala:208)
at scala.util.parsing.combinator.Parsers$Parser$$anonfun$append$1.apply(Parsers.scala:208)
at scala.util.parsing.combinator.Parsers$$anon$3.apply(Parsers.scala:182)
The text was updated successfully, but these errors were encountered: