Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Rob Norris
    @tpolecat
    So something like stringLiteral with optional quotes
    Jakub Kozłowski
    @kubukoz
    (stringLiteral | stringOf1(noneOf(","))).sepBy(char(',')) works now...
    I should've known "incomplete input" means I should use parseOnly
    Rob Norris
    @tpolecat
    .parseOnly(s) is like .parse(s).done
    Andi Miller
    @andimiller
    you can also use takeWhile1(_ != ',') but it's probably equally fast
    Rob Norris
    @tpolecat
    Note that stringLiteral handles escapes, which you may or may not want to deal with.
    Also if you're specifically parsing CSV you might look at something like kantan
    Christopher Davenport
    @ChristopherDavenport
    Or cormorant, which uses atto... :wink:
    Adelbert Chang
    @adelbertc

    i am having trouble with recursive parsers, i am doing something like

    def op[A](lhs: Parser[A], t: String, rhs: Parser[A]): Parser[(A, A)] =
      (lhs, token(string(t)), rhs).mapN { case (lhs, _, rhs) => (lhs, rhs) }
    
    def exprParser: Parser[Expr] = delay {
      op(exprParser, "&&", exprParser).map { case (l, r) => Expr.And(l, r) } | // the recursive case
      op(node, "<", node).map { case (l, r) => Expr.Lt(l, r) } | // the simple case
      ..
    }

    but when I try to do say exprParser.parseOnly("x > 0 && x < 5") I get what I assume to be infinite loop

    my parsing knowledge is rusty :grimacing:
    hm ok i see, since it's the first parser to consider it'll just keep looping and looping
    but if i move it down the alternatives the parser will just consume say, the < branch and then treat the remaining && x < 5 as remaining input :/
    Christopher Davenport
    @ChristopherDavenport
    Do you have a parser anywhere that matches on ""
    Adelbert Chang
    @adelbertc
    i dont think so?
    Christopher Davenport
    @ChristopherDavenport
    Hmmm.
    Adelbert Chang
    @adelbertc
    i am trying to do the equivalent of
    node := int | variable
    
    expr := node < node | expr && expr
    Ryan Zeigler
    @rzeigler
    exprParser appears left recursive. That is usually a danger sign.
    Adelbert Chang
    @adelbertc
    hmmmmm
    good point
    Adelbert Chang
    @adelbertc
    tpataky
    @tpataky

    Hi, I'm having a bit of trouble with reporting back the precise cause of parsing failures. I've got something like this:

      val expr = ifExpr | letExpr | ... | identifier | literal

    If my ifExpr or letExpr parser successfully parses the 'if' or 'let' token but fails later, I'd like to report this as the reason of the failure. Is there a way to achieve this?

    tpataky
    @tpataky
    No? Is there no combinator to limit backtracking? Can I not achieve this even if I restructure my parsers?
    Jakub Kozłowski
    @kubukoz
    Hey, does anyone know of a bridge between atto and scodec?
    Rob Norris
    @tpolecat
    Nope.
    Jakub Kozłowski
    @kubukoz
    I went with something as simple as using the Parser as a Decoder (that part is quite trivial to implement) and passing a "render" function A => String, so I guess there's not really much room for improvement
    Christopher Davenport
    @ChristopherDavenport
    @tpolecat Is there a way to tell what the excess elements passed to a ParseResult is? i.e. is there a way to tell if I feed in more string which string is the overrrun that went from Partial to Complete?
    Rob Norris
    @tpolecat
    Like, you want to feed in character by character and stop when it's complete?
    Christopher Davenport
    @ChristopherDavenport
    Basically trying to reclaim the excess bits of string to return to the stream that way I can keep streaming and change the parser after the parser is complete.
    Basically I grab exactly 1 line of headers, and then want whatever is left over to be turned over to a different parser that will read the rest as a different format. But I can’t use atto for the whole structure because it needs to stream.
    I can do character by character, since its likely very feasible, but thats probably not very efficient.
    Christopher Davenport
    @ChristopherDavenport
    I think I lose arbitrary characters in the streaming implementation to the ~parser~ ParseResult, and since I can’t recover them that means my next inputs won’t be valid.
    Christopher Davenport
    @ChristopherDavenport
    Ignore my stupidity.
    I missed the positional drop involved in the done constructor. So that its no longer input but is only the excess. My apologies for the misplaced alarm.
    Rob Norris
    @tpolecat
    :+1:
    Oleg Pyzhcov
    @oleg-py
    Hello there. Is it possible to force a parser to consume all input or fail instead of giving "leftovers" in Done?
    Rob Norris
    @tpolecat
    You can do p <~ endOfInput and it will fail if there is more data.
    Christopher Davenport
    @ChristopherDavenport
    Am I incorrect in my understanding that technically the toString implementation of Parsers breaks the Functor and Monad laws? As .map(f).map(g) is different than .map(f.andThen(g)
    It’s toString, so its all cheating, but wanted to make sure we were cheating on purpose
    Rob Norris
    @tpolecat
    yes
    toString is a side-effect
    Christopher Davenport
    @ChristopherDavenport
    Cool, works for me. I’m currently working on a general representation of Atto over abstract inputs, and was trying to understand whythat was in place.
    Rob Norris
    @tpolecat
    Aha, ok. I would look at Oscar's talk from SBTB last year and build something based on that.
    Atto is really weird.
    Christopher Davenport
    @ChristopherDavenport
    Wish you told me that, like 3 hours ago… :laughing:
    I’ve got everything working all the way up to combinators now. :sweat_smile:
    Rob Norris
    @tpolecat
    :-)
    Soren
    @srnb_gitlab
    This is probably asked a lot but I noticed atto-fs2 allows me to stream a String into a parser
    So I was wondering
    I want to get a Stream[F, Expr] out, i.e. parse expression by expression
    But often at times I'll have expressions that have sub-expressions