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
    I can take a look at some point, but I know Rob appreciates PRs if you have the time.
    Raphael Mäder
    @randm-ch
    There already is one: #107 :)
    Christopher Davenport
    @ChristopherDavenport
    I missed that and updated. :cry:
    Rob Norris
    @tpolecat
    I’m traveling but will try to get caught up next week.
    Raphael Mäder
    @randm-ch
    Thanks guys :thumbsup:
    Ryan Zeigler
    @rzeigler
    is there anything that might cause a stack overflow during parsing besides accidentally writing a left recursive grammar?
    Rob Norris
    @tpolecat
    Yes, if you’re constructing an infinite parser that’s not lazy enough. You may need to use the delay combinator somewhere.
    This is a frustrating thing to debug.
    Ryan Zeigler
    @rzeigler
    not as frustrating as trying to debug antlr...
    Rob Norris
    @tpolecat
    Haha choose your poison.
    Rob Norris
    @tpolecat
    0.7.0-M1 is on sonatype, for 2.13
    Rob Norris
    @tpolecat
    0.7.0-M2 is on sonatype
    Rob Norris
    @tpolecat
    0.7.0-RC1 is on sonatype
    Wojtek Pituła
    @Krever
    Hey, any advice on how to take text between markers? I think I cannot use takeText because its greedy and it doesn't left content for end marker to be satisfied
    Example:
    val result = (string("{{") ~> takeText <~ string("}}")).parse("{{has}}{{red}}").done
    Wojtek Pituła
    @Krever

    And a second question: how could I make the following not fall into infinite loop?

        val p      = takeWhile(_ => true)
        val result = many(p).parse("abcd").done

    manyUntil(p, endOfInput) seems to help, but maybe there is a better option?

    Rob Norris
    @tpolecat
    0.7.0-RC2 is on sonatype
    Wojtek Pituła
    @Krever
    Hey, I can't see anything as parser negation. I wanted not(whitespace) which I obviously can implemented by satisfy but I'm wondering if its possible to have it in generic way.
    Rob Norris
    @tpolecat
    0.7.0 final is out on sonatype
    Jakub Kozłowski
    @kubukoz
    I'm trying to write a parser that decodes comma-separated strings that are also possibly wrapped in quotes. For now I'm stuck at the comma-separated strings part...
    stringOf1(noneOf(",")).sepBy1(char(',')) doesn't cut it
    neither does stringOf1(anyChar).sepBy(char(','))
    Andi Miller
    @andimiller
    what do you mean by doesn't work?
    it accepts the comma in the string?
    Jakub Kozłowski
    @kubukoz
    right, I should give some examples
    FOO1,FOO2 should give two strings in a list
    Rob Norris
    @tpolecat
    @ stringLiteral.sepBy(char(',')).parseOnly(""""foo","b,ar"""") 
    res3: ParseResult[List[String]] = Done("", List("foo", "b,ar"))
    Jakub Kozłowski
    @kubukoz
    "FOO1,2",FOO2 should also be two results
    hmm
    maybe I'm just dumb because I'm using parse.
    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?