com-lihaoyi / fastparse

Writing Fast Parsers Fast in Scala
https://com-lihaoyi.github.io/fastparse
MIT License
1.09k stars 164 forks source link

fastparse 2 usability issues #205

Closed pshirshov closed 5 years ago

pshirshov commented 5 years ago
  1. When we try to port code which was completely legit in fastparse 1, like
  def adt[_: P](sep: P[Unit]): P[AlgebraicType] = P(adtMember.rep(min = 1, sep = sep))

we are getting odd compiler warnings like

a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses

and our parsers are failing with insane errors (like cast exceptions or stack overflows).

fastparse 2 requires all the parsers to combine be defined as by-name parameters but not enforces it. So, the following snippet is correct:

  def adt[_: P](sep: P[Unit]): P[AlgebraicType] = P(adtMember.rep(min = 1, sep = sep))

I think that this behaviour should be enforced somehow - it is possible to verify the nature of the value from within a macro.

  1. Seems like scaladoc fails on expressions with CharsWhileIn:
  final val digits  = "0123456789"
  final val hexDigits = digits + "abcdefABCDEF"
  def HexNum[_: P]: P[Unit] = P("0x" ~ CharsWhileIn(hexDigits))
[error] /work/idealingua/idealingua-core/src/main/scala/com/github/pshirshov/izumi/idealingua/il/parser/structure/syntax/Basic.scala:16:52: Function can only accept constant singleton type
[error]   def HexNum[_: P]: P[Unit] = P("0x" ~ CharsWhileIn(hexDigits))
[error]                                                    ^

The code compiles fine, just scaladoc dies. I guess scaladoc runs before application of these ref transparency optimizations and it's not actually a fastparse issue, but it's very odd and misleading.

lihaoyi commented 5 years ago

It's a bit hard to generally solve this, but we have some work in progress that might help https://github.com/lihaoyi/fastparse/pull/204