Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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
    I was wondering if I could lazily parse those sub-expressions?
    I was taking a look over your scalebythebay talk about functional programming with fixed point types
    And I feel like this is similar
    Where in that, ProfF definitely had sub-IDs that you referenced later, Expr maybe has sub-exprs that I want to get later
    trait Expr
    case class FunctionF[F[_]](name: String, subExprs: Stream[F, Expr])
    case class Function(name: String, subExprs: Vector[Expr]) extends Expr
    I'm wondering how feasible something like this is? I'm recalling your ProfF example from memory and changing it to Stream and Vector, but I may have gotten something else wrong
    Soren
    @srnb_gitlab
    Now, there's other Exprs than Function, and I'm also not sure I ever want to concretely keep a Vector[Expr]
    Soren
    @srnb_gitlab
    How do I make a parser not consume (lookAhead)? I.e. string("//") ~> manyUntil(anyChar, lineTerminator.lookAhead) for a comment?
    Alex Antonov
    @antonoal
    Hi. Is that right that when I've got Done("some non-empty string", ...) and I call .either on it I'm getting Right rather than Left with the input that couldn't hasn't been parsed?
    Rob Norris
    @tpolecat
    Leftover input is ok. If you want to disallow it you can say p <~ endOfInput which will then fail if there's anything left over.
    Alex Antonov
    @antonoal
    ok, will give it a try
    thanks!
    Rob Norris
    @tpolecat
    Or phrase(p) if you prefer.
    Bartosz Szmit
    @bszmit

    Hi ;)
    Is it possible to implement arithmetic grammar WITH substitution and division in atto?
    Grammar like this one (I know it's left recursive)

    <Exp> ::= <Exp> + <Term> | <Exp> - <Term> | <Term>
    <Term> ::= <Term> * <Factor> | <Term> / <Factor> | <Factor>
    <Factor> ::= int | ( <Exp> )

    So far I have only seen grammars without substitution and division. They require left-associativity and I guess it's a reason they are often left out in examples.

    Rob Norris
    @tpolecat
    No, not in that form. Recursive grammars end up being tricky.
    Partly because they're just tricky, partly because atto is derived from Haskell code so it's stricter than it should be in some places, partly because of bugs.
    Rob Norris
    @tpolecat
    A pattern that works iirc is, expr = listof(addend + addened) and then addend = listof(factor * factor) and factor = int | (expr). So it only recurses in the rightmost position. It's been a while, sorry. There should really be an example.
    Bartosz Szmit
    @bszmit
    I think this pattern will work for me. Thank you very much :)
    Rob Norris
    @tpolecat
    Good luck. It's treacherous. Make sure they're all lazy vals because they'll reference each other.
    jportway
    @jportway
    Hi - this is proba bly a stupid question, but i can't find an example anywhere - is there a way to match all text until something that matches another parser is encountered? I have to decode something like this:
    BLAH BLAH This is some 42 text 123\n
    I need to extract it like this:
    [BLAH][BLAH][This is some 42 text][123]
    I can extract the BLAHs easily, and I can write a parser that will match the number at the end :[whitespace number \n] but I don't know how to extract the text in between because I can only delimit that lazily - after I have found the number token at the end. This seems like it should be easy, but I can't find any documentation anywhere on how to do it.
    Rob Norris
    @tpolecat
    Hm, yeah it's not going to backtrack that way.
    jportway
    @jportway
    this seems like it must be a very common case - i'm really surprised there isn't a way to deal with it
    is this where i'd use some kind of recursive parser? I can't find any documentation about how to do that, or what it would be for...
    Rob Norris
    @tpolecat
    You could do (stringOf(elem(!_.isDigit)).token ~ int.token).many1 and then post-process the result into (String, Int). Not great.
    jportway
    @jportway
    ok - so it seems like Atto just isn't intended to do this kind of thing then? It looks like i might save some pain by just trying to stop forcing it into doing something it's not supposed to. Thanks for your help
    Rob Norris
    @tpolecat
    It's an old port of a Haskell library and I admit I have had to figure out its behavior on the fly.