Comments (15)
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.
@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.
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.
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.
Pinga wanga
from elm-ast.
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.
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.
It may be helpful to do multiple passes of the source. One of which might be filtering out comments.
from elm-ast.
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.
@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.
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.
@dillonkearns I like the idea to make it configurable. Could fit the next major version
from elm-ast.
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.
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.
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)
- Operator location with whitespace around
- Pattern matching exception
- Allow nested comments
- Variables can't be negated with a minus HOT 2
- Parse error: function accessed with module name HOT 2
- Can't name values starting with keywords HOT 1
- Parse character escape codes
- Can't parse type tuples with functions inside
- Function type declaration in let expression HOT 1
- `::` doesn't compose with other operators HOT 2
- Can't parse record updates as a non-last parameter in a function
- Bad performance on arguments in new lines
- Fast and correct type parsing written by Elm core team HOT 5
- Add correct parsing of hex numbers
- Can't parse tuples with empty records. HOT 1
- Regex parser for name should not include '-' character for elm 0.18 HOT 1
- Parsing lambdas is extremely slow HOT 1
- Comments may cause parsing failure HOT 1
- Cannot parse an empty list with a space in it
- 0.19 Status? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elm-ast.