Giter Site home page Giter Site logo

Comments make parsing fail about elm-ast HOT 15 OPEN

bogdanp avatar bogdanp commented on July 21, 2024 1
Comments make parsing fail

from elm-ast.

Comments (15)

YetAnotherMinion avatar YetAnotherMinion commented on July 21, 2024 2

I did not see a lex combinator defined or used in this codebase. When I look at parsers for other languages I frequently see a lex combinator used to remove the whitespace and comments. Here is an example of parsing JSON using a combinator library in rust https://github.com/Marwes/combine/blob/master/benches/json.rs.

Something like:

lex : Parser s r -> Parser s r
lex p =
    p <* (skipMany (whitespace <|> comments))

Then just wrap just about every low level parser with lex.

from elm-ast.

dillonkearns avatar dillonkearns commented on July 21, 2024 2

@wende that would be outstanding! It would really help me unblock some of my users in https://github.com/dillonkearns/elm-typescript-interop.

from elm-ast.

joonazan avatar joonazan commented on July 21, 2024 1

I think it would make sense to move the code from Elmchemy here. I don't see why someone would want the parser to fail instead of stripping comments.

from elm-ast.

justuswilhelm avatar justuswilhelm commented on July 21, 2024 1

It would be awesome if this can be resolved. Elm-Ast is already providing a lot of value.

Another minimal example that causes a failure:

test : Int
test =
    --
    1

from elm-ast.

Birowsky avatar Birowsky commented on July 21, 2024 1

Pinga wanga

from elm-ast.

dillonkearns avatar dillonkearns commented on July 21, 2024 1

I apologize for the confusion, the examples I tried for parsing comments were not within function bodies (like in this example). So it turns out the behavior hasn't changed and comments like these still cause parsing to fail.

I did indeed find that https://github.com/tunguski/elm-ast resolves the issue, as @muelli suggested (thanks for that tip @muelli!).

I would still love to see this get resolved in this package! It would be nice if we could avoid having too much fragmentation in the Elm AST library ecosystem.

from elm-ast.

wende avatar wende commented on July 21, 2024

Yes. Comments right now are only statements (outside of functions). We're working on a way to go past that, but it's not trivial

from elm-ast.

dynajoe avatar dynajoe commented on July 21, 2024

It may be helpful to do multiple passes of the source. One of which might be filtering out comments.

from elm-ast.

wende avatar wende commented on July 21, 2024

Yeah. The parser doesn't really have a capability for us to do it.
In elmchemy right now we're removing inline comments before we parse the code.

from elm-ast.

wende avatar wende commented on July 21, 2024

@joonazan But we aren't really parsing them, we just ignore them. So that's probably not a desirable behaviour for a parser 😁

from elm-ast.

dillonkearns avatar dillonkearns commented on July 21, 2024

But we aren't really parsing them, we just ignore them. So that's probably not a desirable behaviour for a parser 😁

@wende to your point, since this is not parsing these statements but throwing them away, what if we had an alternative function that acknowledged this? Something like Ast.discardCommentsAndParse? It could do a first pass to throw out comments, and then do the parse to ensure comments don't cause parsing errors. This issue seems to be causing some errors in people's code so it would be nice to offer a workaround.

from elm-ast.

wende avatar wende commented on July 21, 2024

@dillonkearns I like the idea to make it configurable. Could fit the next major version 👍

from elm-ast.

dillonkearns avatar dillonkearns commented on July 21, 2024

Hey @wende any update on this? I still have some users who are blocked on this, it would be great to be able to have some workaround to help strip comments before parsing.

from elm-ast.

muelli avatar muelli commented on July 21, 2024

FTR: @tunguski has a fork here: https://github.com/tunguski/elm-ast that seems work well with comments. At least the example page https://tunguski.github.io/elm-ast/example/ parses the code from #41 (comment)

tunguski#3 refers to tunguski@60a771c

from elm-ast.

dillonkearns avatar dillonkearns commented on July 21, 2024

Hello @wende, it looks like comments are parsing successfully now! Thank you so much for adding that in. Both -- ... and {- ... -} comments are parsing as expected, so this looks to be fully resolved now.

Would you mind closing the issue so it's clear for other users who were waiting for this? Thank you!

from elm-ast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.