Comments (14)
@joeandaverde Yup. But given that current parser is totally whitespace agnostic it looks like a major change to entire project
from elm-ast.
Tried to fix it with changing:
application : OpTable -> Parser Expression
application ops =
rec <| \() ->
term ops `chainl` (Application <$ spaces')
to
application : OpTable -> Parser Expression
application ops =
rec <| \() ->
term ops `chainl` (Application <$ choise [spaces', whitespace])
but failed.
(multiple functions and module fixity scanning tests fail in this case, but the example passes)
from elm-ast.
I made an attempt here: Warry@fa8bba8
So it works (seems as permissive as elm itself), but obviously not where indentation matters (case
expressions and let ... in ...
statements). That one will be tougher!
from elm-ast.
I tried out what the Elm compiler does to some pathological cases. It seems pretty complicated: it allows reducing indentation after a function name, but it struggles when keywords like in
are present.
I believe that a perfectly valid way to parse Elm would be to only care about whether there is indentation at all. If there is no indentation, parse it as the beginning of a statement.
from elm-ast.
I think that some expressions that require indentation (i.e. case expressions) need to have all bindings on separate lines. I believe that is why shamansir's solution won't work (at least in part).
This currently works:
z = case Just 1 of Nothing -> 0
Just y -> y
However, this should fail because Nothing -> 0
should be on a new line and indented.
This will require a change to the parser to track newline and indentation state.
from elm-ast.
It seems that if there's only 1 binding for the case expression it can be on the same line as the of
z = case Just 1 of _ -> 12
from elm-ast.
@joeandaverde I have thought about this a lot and made some experiments. Based on that I think that if it is ok to be less strict than the elm compiler, we do not need to track indentation.
It seems that lines containing =
, ->
or :
are special, as they start a new statement or expression part. So just be whitespace-agnostic, but stop taking function arguments if the next line contains one of the aforementioned symbols.
I don't know what the best way to code this would be. Any suggestions? First thing I can think of is to just do a lookahead of the next line.
from elm-ast.
Maybe I misunderstand your suggestion.
Would this still align with your thinking?
type alias Foo =
{ a : Int
, b : Int
}
type Bar
= Apple { a : Int }
| Baz { b : Int }
from elm-ast.
@joonazan Yes. You're right. I even wrote a regex that tracks these lines but for some reason it doesn't want to work in Elm (only Regex 101)
(?:({-(?:\n|.)*?-})|([\w\])}\"][\t ]*)\n[\t ]+((?!.*\s->\s)(?!.*=)(?!.*\bin\b)[\w[({\"]))
I tried to recognize these lines using lookAhead
parser but failed.
If we ignored lines containing ->
and =
it should be fine.
from elm-ast.
Hi All,
during my tests of this library I've found whole list of additional parsing errors. I've created fork of the library which you may find here:
https://github.com/tunguski/elm-ast
I've worked basing on test page parsing all core and http modules. I've got to the point where all these modules are parsed correctly. You may check results here:
https://tunguski.github.io/elm-ast/example/
I assume that most of the issues created in the fork are still open for this project:
https://github.com/tunguski/elm-ast/issues?utf8=%E2%9C%93&q=is%3Aissue%20
Still fork is drastically changed because I have merged Statements and Expressions modules. That was required to fix parsing of Let bindings if I remember correctly. Unfortunately on that stage I did not create issues for all problems found.
Hope this comment will help a bit.
Thanks for all your work!
from elm-ast.
@tunguski Making comments parse as whitespace is ingenious!
This repository has some advantages over yours, but it lacks in functionality. By incorporating your solutions to some issues we will arrive at a great result. Keep up the good work!
from elm-ast.
@tunguski Great work.
I went through your issues and here is the outline of them in this repository:
tunguski#1 - fixed
tunguski#2 - fixed
tunguski#3 - still relevant
tunguski#4 - still relevant
tunguski#5 - fixed
tunguski#6 - fixed
tunguski#7 - fixed
tunguski#8 - fixed
tunguski#9 - fixed
tunguski#10 - fixed
tunguski#11 - not sure
tunguski#12 - fixed
tunguski#13 - fixed
tunguski#14 - still relevant
tunguski#15 - fixed
tunguski#16 - fixed
tunguski#17 - fixed
from elm-ast.
Plus I noticed that your version also doesn't parse characters with escaped sequences like '\n'
from elm-ast.
@wende You're right! I've checked what is actual parsing status using this library and it is 19/27 files parsed correctly (tested on core and http). That's a fundamental change! I would be really happy to switch back to this library when it will be able to parse all core libraries. I'll keep my fingers crossed!
Edit (removed list of code examples): I've created two issues that seem to be only problems (beside proper comments parsing).
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.