Comments (2)
Good find.
That's because of #1 fix being whitespace agnostic.
It's going to be quite hard to fix it though, but it seems we can't avoid whitespace sensitivity after all
from elm-ast.
In my fork I wrote some code that seems to work fine in this situation.
caseExpression : OpTable -> Parser s Expression
caseExpression ops =
let
binding =
lazy <| \() ->
(,)
<$> (wsAndComments *> expression ops)
<*> (symbol "->" *> expression ops)
in
lazy <| \() ->
withLocation (\location ->
Case <$> (symbol "case" *> expression ops) <* symbol "of" <*> many
( lookAhead (wsAndComments *>
(primitive (\state inputStream ->
(state, inputStream, Ok (location.column <= (currentLocation inputStream).column))
)))
|> andThen (\isIndented ->
case isIndented of
True -> wsAndComments *> binding
False -> spaces_ *> binding
)
)
)
results in
FunctionDeclaration
(Function "foo" []
(Case (Variable ["pattern"])
([ (Variable ["A"], Integer 1)
, (Variable ["B"], Case (Variable ["variable"])
([ (Variable ["C"],Integer 2)
, (Variable ["_"],Integer 3)
]
)
)
, (Variable ["_"],Integer 4)])))
You would need to fit it into your code as it uses wsAndComments
which is something unique for my fork.
The idea is to remember what was the first column of case
word and parse only relatively indented code. Checking is next line indented "enough" is done by lookAhead
parser that finds next non whitespace (or comment) token and checks it's indentation relatively to "base" token.
It won't work with tabs and spaces mixed!
Still it is enough for the scope of core code I test on.
Hope it helps!
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.