by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Eric K Richardson
    @ekrich
    I didn't write the original. The code worked originally with 2.10 and 2.12. Now that we dropped 2.10, we can upgrade to the newest version. this is the part that is not working from the neg "-".!.? ~ p It complains about the p.
    This is the Native Intermediate Representation (NIR) parser code from Scala Native so it is quite involved.
    Arindam Ray
    @ArindamRayMukherjee
    Aiight I'm a noob myself, so I won't presume to know. Could you do a scastie so the col:line of the error is visible?
    Eric K Richardson
    @ekrich
    Arindam Ray
    @ArindamRayMukherjee
    Any P[] :)
    So I just stuck the code into my intellij and it compiles fine... Why would that work?
    Eric K Richardson
    @ekrich
    Shouldn't work - says the same thing in sbt and scastie.
    It is the only case that uses .!.? together.
    Eric K Richardson
    @ekrich
    @ArindamRayMukherjee Do you have a link to the javadoc for fastparse?
    scaladoc sorry
    Arindam Ray
    @ArindamRayMukherjee
    And reading the code and writing noob Qs here and waiting for the gods to respond haha
    Arindam Ray
    @ArindamRayMukherjee
    Ah I missed the version no sorry
    Eric K Richardson
    @ekrich
    Arindam Ray
    @ArindamRayMukherjee
    Why not go to 2.2.2 by the way?
    Eric K Richardson
    @ekrich
    I went 2.3.0 right?
    Arindam Ray
    @ArindamRayMukherjee
    Ah yeah
    Gábor Bakos
    @aborg0

    What about this?

        def neg[_: P](p: => P[String]): P[String] = P("-".!.? ~ p) map {
          case (a, b) => a.getOrElse("") + b
        }

    The part which removed the warning was the => before the P[String] argument type. I think the new version of FastParse does not really like the static (val) parsers. (The parenthesis around the "-".!.? ~ p expression was mostly for my readability.)

    Eric K Richardson
    @ekrich
    p is the P[String} which should be the macro??
    [error] /Users/eric/workspace/scala-native/nirparser/src/main/scala/scala/scalanative/nir/parser/Base.scala:75:56: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses
    [error]   def neg[_: P](p: P[String]): P[String] = P("-".!.? ~ p) map {
    Gábor Bakos
    @aborg0
    it should be by-name (=>) I think.
    Eric K Richardson
    @ekrich
    I wrapped the p like this "-".!.? ~ P(p) and the error went away??
    Now the tests don't work?
    xuanbachle
    @xuanbachle
    I have this regex "([a-z] | [A-Z])([a-z] | [0-9])*" and can't seem to translate it to fastparse. How can I do that? Basically, I want to parse a symbol that has to start with some character. E.g., Aaab012 would be a valid one to be parsed. I can do it easily with the regex-based parser combinator but don't know how to do it with fastparse ...
    Damian Reeves
    @DamianReeves
    What are the plans for dotty support?
    Arindam Ray
    @ArindamRayMukherjee
    @xuanbachle I just wrote a small test.
            import NoWhitespace._
            def parser[_: P] = P((CharIn("a-zA-Z_") ~ CharIn("a-zA-Z0-9_").rep).!)
            parse("Aaab012", parser(_)) match {
              case Parsed.Success(res, index) =>
                assert(res == "Aaab012")
                assert(index == 7)
              case x: Parsed.Failure =>
                println(x)
                assert(false)}
    m09
    @m09
    What would be the fastest way to parse a chunk of text depending on the previous two letters? The two letters basically indicate a type in my case and I know I can create a huge disjunction, but this seems inadequate: a lot of effort will go into trying bad options and backtracking while I can provide the correct one straight away
    Li Haoyi
    @lihaoyi
    Something like this might work
    (AnyChar ~ AnyChar).!.flatMap{
      case "ab" => ...
      case "cd" => ...
      case "ef" => ...
    }
    m09
    @m09
    Looks great, thanks :)
    Li Haoyi
    @lihaoyi
    I don't remember how much it sped things up by compared to a huge pile of |s, but it was definite a measurable speedup
    Philipp Dörfler
    @phdoerfler
    Quick question: In RegEx I can write foo(.*?)bar and thanks to the lazy / non-greedy modifier, it will match as few characters as possible. And I use this constantly! In almost all cases, I want my quantifiers to match lazy / non-greedy.
    Is there an equivalent in FastParse? In general, whenever I use AnyChar.rep things go south really quick and I would really appreciate a non-greedy version of rep.
    Would it be possible to solve this with a backtracking version of rep? Would that make performance tank? Thoughts please!
    Philipp Dörfler
    @phdoerfler
    And thanks for this wonderful library :) Gotta say, it's kinda fun to write parsers with it, even though it's also frustrating as hell sometimes. But that's just a parser thing I think :)
    Philipp Dörfler
    @phdoerfler
    Speaking of RegEx, a tool to convert regex to fastparse code would be amazing :D
    Philipp Dörfler
    @phdoerfler
    Second question: def dot[_:P] = P(".".! map (_ => Dot)), can I write this nicer? I don't want to capture ".", I just want to emit my Dot case object if it matches
    Li Haoyi
    @lihaoyi
    move the .map outside the P()
    then the types should line up and you wont need a capturep
    Philipp Dörfler
    @phdoerfler
    def dot[_:P] = P(".") map Dot like this?
    image.png
    fwiw Dot is a case object
    Philipp Dörfler
    @phdoerfler
    def dot[_:P] = P(".") map (Unit => Dot) works but that's not exactly nice
    def dot[_:P] = P(".") map (() => Dot) does not work

    using () gives me this:

    type mismatch;
     found   : () => Playground.Dot.type (with underlying type () => Playground.Dot.type)
     required: Unit => ?

    and a sad scalac

    the best thing I managed is this:

    def dot[_:P] = P(".") map (_ => Dot)

    but I'd appreciate a less boiler plate-y solution

    Andy Bailey
    @apps4uco
    Hi, I was just wondering if there is a way to have a parser like fastparse but that has an inverse? That is: Text to object and object to text. Similar to scodec with it's encoder and decoder., It just feels like defining the parser and then how to print it is repeating the logic twice. Any ideas?
    Dominik Piskorz
    @DominikPiskorz
    @apps4uco Look into enumeratum, it sounds like what you need
    Philipp Dörfler
    @phdoerfler
    I am occasionally putting some hours into a regex to fastparse converter. Is that of potential interest to people?
    you feed it a regex and it generates you a parser that hopefully accepts the same input
    It's more of a half automatism, kickstarting, getting people started kind of thing and less a 100% reliable conversion but I think it's neat
    (obviously or else I wouldn't be doing it :P)