Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser: suboptimal parser error #7653

Open
JonathanStarup opened this issue Apr 30, 2024 · 4 comments
Open

Parser: suboptimal parser error #7653

JonathanStarup opened this issue Apr 30, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@JonathanStarup
Copy link
Contributor

JonathanStarup commented Apr 30, 2024

I'm not sure if this is too minor in the current stage of development, but I would hope this error to be prettier at some point

enum E { case Tag(Int32) }
def example(e: E): Int32 = match e {
    case E.tag(x) => x
}
❌ -- Parse Error -------------------------------------------------- .../Example.flix
>> Parse Error: Expected CurlyR, but found Dot
12 |     case E.tag(x) => x
               ^
               Here
Syntactic Context: Unknown.
❌ -- Parse Error -------------------------------------------------- .../Example.flix
>> Parse Error: Expected declaration but found NameLowerCase
12 |     case E.tag(x) => x
                ^^^
                Here
Syntactic Context: Unknown.
❌ -- Parse Error -------------------------------------------------- .../Example.flix
>> Parse Error: Expected declaration but found ParenL
12 |     case E.tag(x) => x
                   ^
                   Here
Syntactic Context: Unknown.
❌ -- Parse Error -------------------------------------------------- .../Example.flix
>> Parse Error: Expected declaration but found NameLowerCase
12 |     case E.tag(x) => x
                    ^
                    Here
Syntactic Context: Unknown.
❌ -- Parse Error -------------------------------------------------- .../Example.flix
>> Parse Error: Expected declaration but found ParenR
12 |     case E.tag(x) => x
                     ^
                     Here
Syntactic Context: Unknown.
❌ -- Parse Error -------------------------------------------------- .../Example.flix
>> Parse Error: Expected declaration but found ArrowThickR
12 |     case E.tag(x) => x
                       ^^
                       Here
Syntactic Context: Unknown.
❌ -- Parse Error -------------------------------------------------- .../Example.flix
>> Parse Error: Expected declaration but found NameLowerCase
12 |     case E.tag(x) => x
                          ^
                          Here
Syntactic Context: Unknown.
❌ -- Parse Error -------------------------------------------------- .../Example.flix
>> Parse Error: Expected declaration but found CurlyR
13 | }
     ^
     Here
Syntactic Context: Unknown.
❌ -- Parse Error -------------------------------------------------- .../Example.flix
>> Parse Error: Malformed match rule.
12 |     case E.tag(x) => x
         ^^^^^^
         Here
Syntactic Context: OtherExpr.
@magnus-madsen magnus-madsen changed the title suboptimal parser error Parser: suboptimal parser error May 1, 2024
@magnus-madsen magnus-madsen added the bug Something isn't working label May 1, 2024
@herluf-ba
Copy link
Contributor

Hard agree 👍 Thanks for making me aware of it

@herluf-ba
Copy link
Contributor

@JonathanStarup I think this is already better on master actually. I merged some improvements yesterday. Trying your example I get:

-- Parse Error -------------------------------------------------- main/foo.flix

>> Parse Error: Expected '}' before '.'

3 |     case E.tag(x) => x
             ^
             Here
Syntactic Context: OtherExpr.

-- Parse Error -------------------------------------------------- main/foo.flix

>> Parse Error: Expected <declaration> before '('

3 |     case E.tag(x) => x
                  ^
                  Here
Syntactic Context: OtherDecl.

@JonathanStarup
Copy link
Contributor Author

Cool :) thats better yeah. will it be something like hey you have a lowercase constructor or how ambitious is the parser errors?

@herluf-ba
Copy link
Contributor

herluf-ba commented May 1, 2024

Something like that is feasible, and I hope to do that in the next couple of months :)
Right now the first error message stems from the tag-pattern parse rule, specifically in the call to name:

    private def tagPat()(implicit s: State): Mark.Closed = {
      val mark = open()
      name(NAME_TAG, allowQualified = true, context = SyntacticContext.Pat.OtherPat)
      if (at(TokenKind.ParenL)) {
        tuplePat()
      }
      close(mark, TreeKind.Pattern.Tag)
    }

What I would like to to is add another optional argument to name, expect and expectAny to maybe add a contextual tip or something.

name(NAME_TAG, allowQualified = true, context = SyntacticContext.Pat.OtherPat, Some("Constructors use uppercase names"))

Which could land us at:

-- Parse Error -------------------------------------------------- main/foo.flix

>> Expected <Name> before <name>

3 |     case E.tag(x) => x
               ^^^
               Here
Hint: Constructors use uppercase names.

Although there is a nice challenge left, with how qualified names can work when we also terminate fixpoint constraints with ., before that can happen 👍

@magnus-madsen magnus-madsen added enhancement New feature or request and removed bug Something isn't working labels May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants