Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Philipp Dörfler
    @phdoerfler
    And I feel like there is a very obvious way to improve this
    but I'm not seeing it
    Philipp Dörfler
    @phdoerfler
    oh right, when I use CharIn("a-zA-Z0-9") then fastparse runs into an endless loop
    Li Haoyi
    @lihaoyi
    why is that awkward? looks clear enough to me, and it probably runs as fast as possible too
    Philipp Dörfler
    @phdoerfler
    Ok, fair. Let me show you a complete small example:
    In RegEx I would use a non greedy match to extract the name without the "!".
    How can I do a non greedy match in fastparse?
    I could of course match everything that is NOT a "!" but a) in examples slightly more involved than this it gets out of hand quickly and b) I personally think non-greedy matching rules make for a nicer to read grammar
    Philipp Dörfler
    @phdoerfler
    image.png
    That's the closest thing to a non greedy match that I was able to come up with
    it's not as generic as I would like it to be but maybe a higher order parser can fix that
    Philipp Dörfler
    @phdoerfler
    nah, not in a nice way at least
    def anyCharExcept[_:P, T](p: => P[T]): P[Unit] = P( (!p ~ AnyChar) )
    Is the only part that is worth factoring out IMHO. Still not a true non-greedy match but I guess we're not gonna see that in fastparse anytime soon so this is probably as good as it gets.
    Nikolas Havrikov
    @havrikov

    Hi, I'm trying to reuse part of the scalaparse parser in my own fasteparse-based parser. Specifically, I'd like to reuse the string parsing.
    However, I cannot figure out how to capture the result of the String subparser that I found in the Literals trait.
    Ideally I'd like to write something like private def string[_: P]: P[String] = P(scalaparse.Scala.Literals.NoInterp.String).!, but this does not compile.

    Any pointers on how to achieve this?

    Reid Spencer
    @reid-spencer
    First time user of fastparse here. So far, I love it. Really great parser library, @lihaoyi ! Thank you. And .. I have a question :) I would like to write a rule that suspends the usual whitespace parsing and captures everything to the end of the line. I've tried using CharPred but it does not capture the white space, unfortunately. I've looked across the documentation and I still can't quite figure it out. Do I need to create my own WhiteSpace object? How can I selectively turn WhiteSpace processing on in most contexts and off in special ones? If I missed a doc link, providing it would be very helpful.
    Li Haoyi
    @lihaoyi
    you can import NoWhitespace._ for the rules you dont want whitespace to be consumed, and import the other whitespace implicit for the rules you want whitespace to be consumed
    put them in different objects so the imported implicits dont clash
    Reid Spencer
    @reid-spencer
    Brilliant! Thank you!
    Li Haoyi
    @lihaoyi
    :+1:
    Reid Spencer
    @reid-spencer
    And it works too! Thanks for your help.
    Glen Marchesani
    @fizzy33
    Hey anyone doing auto completion for a fastparse parser ?
    Philippe Derome
    @phderome
    @reid-spencer thanks for asking that good question. I found myself probably in the same situation in that I have many small parser functions that add whitespace explicitly between tokens all over the place and it feels really silly and poor form. I now have something to look at when I revisit my code.
    Dario Abdulrehman
    @dabd
    I'm a bit confused with the notation def parseA[_: P] = P("a"). Isn't an existential type annotated with some type parameter [_: P] equivalent to just [P]?
    Gábor Bakos
    @aborg0
    That is not existential type, it is a context bound, more like [Sth](implicit x: P[Sth])
    Dario Abdulrehman
    @dabd
    ah, thanks @aborg0
    Philippe Derome
    @phderome

    @reid-spencer thanks for asking that good question. I found myself probably in the same situation in that I have many small parser functions that add whitespace explicitly between tokens all over the place and it feels really silly and poor form. I now have something to look at when I revisit my code.

    using the different implicits as Li suggested does wonders. But if you have your whole parser in a single file and several object/trait, it can be a nightmare. You can break down modularity with single traits (or objects) and place one trait per file (Java style) and then you use one implicit per file/trait. Or if you feel the need to keep some traits together, you should import inside your traits not at file level. This way you have proper fine grain policy of your white space policy. It's very nice.

    @dabd think of this "hidden" implicit parameter as a cleaner global variable that gives you access to state functionality you need. Where are you in each function in the parsing input, what have you backtracked, what's the state of the parsing computation over all? It's all in there as I understand it. Also if you look at the source code, you'll see the usage you see and the one that @aborg0 presents to you.
    Chandrashekhar K
    @chandu_shekhar_twitter
    Hi, I am new to fastparse and scala combi parser, I want to to parse XML and tried to use the scalaparse/XML (https://github.com/lihaoyi/fastparse/blob/master/scalaparse/src/scalaparse/Xml.scala) but it does not seem to work as expected. It seems to be parsing <xml>abcd</abcd> as a success instead of failure. Wondering if anyone can point to a XML parser using fastparse?
    Sakib Hadžiavdić
    @sake92
    @chandu_shekhar_twitter that's not parser's job, as far as I understand
    Chandrashekhar K
    @chandu_shekhar_twitter
    @sake92 Since its an XML parser should it not return failure for invalid XML and return success for only valid XML.
    GRYE
    @GRYE

    Hi everybody!
    Can someone explain how exactly index inside of Failure is computed?

    I try to parse different inputs with shifted failed element, but I still has the same index

    Ichoran
    @Ichoran
    @chandu_shekhar_twitter - That's not a full XML parser. It's designed to support XML syntax inside Scala code. If you wanted to validate whether it's well-formed, you'd do it later (since there are other things you'd need to validate, like whether the Scala is well-formed).
    Chandrashekhar K
    @chandu_shekhar_twitter
    @Ichoran Do we have any full blown XML parser written in fast parse ? Any links or directions on how to do it would be very helpful.
    Ichoran
    @Ichoran
    I'm not sure. I imagine I would search for it the same way you would. I just happen to know that the parser you were using isn't designed to be full-featured.
    It would be rather a lot of work to create a full XML parser with full error checking and everything, so I wouldn't assume that one exists, but maybe it does!
    Why do you want a fastparse XML parser?
    Ian O'Connell
    @ianoc
    random Q, tried looking in the docs/apis and didn't see how you might do it. But I have a files that are many gbs. So with streaming inputs I can not buffer the entire inputs to memory. Is there a converse ability to do an Iterator[Output] from the parser ?
    Li Haoyi
    @lihaoyi
    you can run callbacks from your .map calls
    Philippe Derome
    @phderome
    @chandu_shekhar_twitter if your XML happens to be limited to XPath queries, there's this project: https://nrinaudo.github.io/kantan.xpath/. Here is a good Scala XML reference in general: https://www.scalawilliam.com/1406/xml-processing-in-scala/
    LukeDefeo
    @LukeDefeo
    Is it possible to combine a list of parsers with the | combinator
    i have this
     private val reservedTokens: Map[String, TokenType] =
        Map(
          "(" -> LeftParen,
          ")" -> RightParen,
          //...
    
        )
      def toParser[_: P](kv: (String, TokenType)): P[TokenType] = P(kv._1).map(_ => kv._2)
    
      def combine[_: P](acc: => P[TokenType], value: P[TokenType]): P[TokenType] = P(acc | value)
    
      def all[_: P] = reservedTokens.map(toParser).reduce[P[TokenType]](combine)
    LeftParen is a case object
    LukeDefeo
    @LukeDefeo
    but it doesn't work i get the return value in state position warning
    Philippe Derome
    @phderome
    @LukeDefeo please read this channel on Oct 2-3. A similar question was asked and @lihaoyi answered it. You are asking essentially the same thing now.
    (I am not suggesting you should have read it first, I simply observe that I found it somewhat remarkable when I noticed it and so I could recollect it when reading your request)
    LukeDefeo
    @LukeDefeo
    thanks phillip
    Carl Emmoth
    @AIMMOTH
    Hello, looking at Fastparse and wondering if it can handle case insensitive unicode?