Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Parsing error on - sign or -- sign #15

Closed
berry opened this issue Nov 11, 2018 · 10 comments
Closed

Parsing error on - sign or -- sign #15

berry opened this issue Nov 11, 2018 · 10 comments

Comments

@berry
Copy link

berry commented Nov 11, 2018

Hi Dillon,

I encountered the following error:

Could not parse file `src/DesignCards.elm` at position 700. Errors:
expected end of input

I finally (took me a while) tracked this down to the two following situations. The first:

type
    CardType
    -- comment
    = NoType
    | Ideate
    | Validate
    | Create
    | Facilitate

Elm compiles this code just fine. But, npx elm-typescript-interop reports the error stated above. If I remove the -- comment or move it a line lower no error occurs.

The second situation:

-(sqrt (sWidth ^ 2 + sWidth ^ 2))

This is also valid Elm code, but npx elm-typescript-interop reports the error stated above. If I substitute the - sign with -1 * then no error occurs.

I am using Elm 0.19 en elm-typescript-interop version 0.0.15.

Berry.

@dillonkearns
Copy link
Owner

Hello @berry, unfortunately there are some parsing bugs for the Elm AST libraries out there. You can reproduce the parsing error by pasting it into elm-typescript-interop's underlying parser: https://tunguski.github.io/elm-ast/example/.

Also, neither Bogdanp/elm-ast nor tunguski/elm-ast are planning on updating for Elm 0.19.

tunguski/elm-ast#33 (comment)
Bogdanp/elm-ast#96 (comment)

I think that the Elm community would really benefit from a new Elm AST package that has 0.19 support and doesn't have so many parsing errors. Unfortunately, I don't have the bandwidth to be the one that takes that task on. But I would really love it if someone would step up to the challenge!

I'll close this issue here since I can't help fix it unfortunately. But feel free to open an issue on https://github.com/tunguski/elm-ast and I'll gladly update it if it gets solved there. Thanks!

@berry
Copy link
Author

berry commented Nov 13, 2018

Hi @dillonkearns,

No problem. I already wondered why Elm 0.18 was being installed ;-)

I am certainly no expert on AST libraries. But, in Elm-Slack I found this library mentioned: Elm syntax. It is an Elm parser in Elm. It is 0.19 compatible. I tested it on the code examples mentioned earlier in this issue and it parsed the code correctly. But, maybe you already know this library

I actually found some discussion in elm-syntax on the possibility of using elm-syntax for sharing constants between Typescript and Elm ;-) See: stil4m/elm-syntax#24. That issue references other issues on Elm AST.

I do hope that this issue on an up-to-date Elm AST gets resolved, because I do like your approach with elm-typescript-interop a lot!

@dillonkearns
Copy link
Owner

Hello @berry, thank you for that suggestion! I wasn't aware of that library, I'll explore that! I'll create a separate issue to track that exploration. Thank you! 🙏

@dillonkearns
Copy link
Owner

Here's the issue for reference @berry: #17

@davetapley
Copy link
Contributor

@dillonkearns hi, I'm also here because expected end of input.

Once I found this issue and your link to https://tunguski.github.io/elm-ast/example/ I was able to refactor around the quirks of elm-ast pretty quickly, so thanks for sharing that. However, I did quite a lot of head banging before that. So: Until #17 (or some other fix) is in, would you consider a PR to just print out your advice:

unfortunately there are some parsing bugs for the Elm AST libraries out there. You can reproduce the parsing error by pasting it into elm-typescript-interop's underlying parser: https://tunguski.github.io/elm-ast/example/.

After:

"Could not parse file `{0}` at position {1}. Errors:\n{2}"

@dillonkearns
Copy link
Owner

Hello @dukedave, thanks for the comment! That is an excellent idea. I would love a PR for that. And thanks for asking first, I always like to start with a discussion. This sounds like an uncontroversial one that I am definitely for so I would welcome a PR 👍

By the way, I'm going to be experimenting with https://github.com/stil4m/elm-syntax once I have some free time. I'm hoping that this might have fewer parsing bugs. But regardless, having a better error message would be very useful!

davetapley added a commit to davetapley/elm-typescript-interop that referenced this issue Jan 12, 2019
@muelli
Copy link

muelli commented Mar 11, 2019

unfortunately there are some parsing bugs for the Elm AST libraries out there

FWIW: The IntelliJ Elm plugin has a decent Elm parser.

@dillonkearns
Copy link
Owner

@muelli I think the Elm IntelliJ plugin's Elm parser is highly specialized for building up a format for IntelliJ to consume. And it's also in Kotlin. I'm hoping that still4m/elm-syntax will be up for the task!

@davetapley
Copy link
Contributor

@dillonkearns I made that PR, BTW: #18

@MikeTschudi
Copy link
Contributor

Here is another test case:

capitalize : String -> String
capitalize inValue =
    let
        tempValue = String.toUpper inValue  -- List E.Value
        outValue = String.trim tempValue
    in
        outValue

The trailing comment breaks the parser. A line after the line with the comment appears to be necessary for the break.

I am using Elm 0.19 and elm-typescript-interop version 0.0.15. Reproduced by inserting into elm-typescript-starter before update.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants