Closed antonkulaga closed 8 years ago
It is also not clear for me why
val notSpace1 = P( !(" ") )
val notSpaceRep = P( !(" ").rep )
val str = "zef8498494zefzef"
notSpace1.parse(str) //succedes
notSpaceRep.parse(str) //fails for uknozn reason
What's wrong with
val notSpaceRep = (!" " ~ AnyChar).rep
?
Or
CharPred(_ != ' ').rep
?
You should hang out in the gitter channel for this kind of thing. They're not bugs or issues with fastparse
val notSpaceRep = (!" " ~ AnyChar).rep
@lihaoyi Have you checked it yourself? Each time I run it in ammonite console it freezes it
Welcome to the Ammonite Repl 0.5.5
(Scala 2.11.7 Java 1.8.0_25)
@ import fastparse.all._
import fastparse.all._
@ val notSpaceRep = (!" " ~ AnyChar).rep
notSpaceRep: Parser[Unit] = (!(" ") ~ AnyChar).rep
@ noSpaceRep.parse("zef8498494zefzef")
Main.scala:84: not found: value noSpaceRep
noSpaceRep.parse("zef8498494zefzef")
^
Compilation Failed
@ notSpaceRep.parse("zef8498494zefzef")
res2: Parsed[Unit] = Success((), 16)
@
@antonkulaga I hadn't tried it but I have now and it seems to work
It is strange because on my PC it freezes ammonite.
Anyway CharPred( != ' ').rep worked for me, maybe it is worth of mentioning in docs that CharPred( != ' ') should be recommended approach to parse "everything but ..."
No idea why it's freezing for you, seems to work great for me.
Docs could always be better, that's already tracked in https://github.com/lihaoyi/fastparse/issues/68. Feel free to post your own ad-hoc guidelines and maybe someone will package them nicely into the docs
Right now "!" is the most confusing sign in FastParse as it is used both for negation and for capturing. Moreover !(something) does not provide any output, so to have something very common and trivial, like a parser like "everything but space" I have to do something like this:
I would be happy to have less verbose way to do this