Skip to content

Conversation

@c42f
Copy link
Member

@c42f c42f commented Dec 5, 2023

When a missing closing token like ), ] or } is encountered we want the "Expected )" error to point to a location one past the last valid token, not to the trailing error tokens.

For example from #349 here's a poor error message from the existing code:

ERROR: ParseError:
# Error @ REPL[53]:15:5
    ylims!(p, (0, last(ylims(p)))
    xlabel!(p, "Contig length cutoff (kbp)")
#   └─────────────────────────────────────┘ ── Expected `)`

After this change, the error location instead points to the end of the last valid line:

ERROR: ParseError:
# Error @ REPL[53]:15:5
    ylims!(p, (0, last(ylims(p)))
#                                └── Expected `)`

Fix #349, fix #313

When a missing closing token like `)`, `]` or `}` is encountered we want
the "Expected `)`" error to point to a location one past the last valid
token, not to the trailing error tokens.

For example from #349 here's a poor error message from the existing
code:

    ERROR: ParseError:
    # Error @ REPL[53]:15:5
        ylims!(p, (0, last(ylims(p)))
        xlabel!(p, "Contig length cutoff (kbp)")
    #   └─────────────────────────────────────┘ ── Expected `)`

After this change, the error location instead points to the end of the
last valid line:

    ERROR: ParseError:
    # Error @ REPL[53]:15:5
        ylims!(p, (0, last(ylims(p)))
    #                                └── Expected `)`
@codecov
Copy link

codecov bot commented Dec 5, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (acb609d) 96.64% compared to head (d20307c) 95.83%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #397      +/-   ##
==========================================
- Coverage   96.64%   95.83%   -0.81%     
==========================================
  Files          14       13       -1     
  Lines        4172     3940     -232     
==========================================
- Hits         4032     3776     -256     
- Misses        140      164      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@c42f c42f merged commit a6f2d15 into main Dec 5, 2023
@c42f c42f deleted the caf/fix-missing-closer-or-comma-message branch December 5, 2023 11:01
c42f added a commit that referenced this pull request Dec 6, 2023
When a missing closing token like `)`, `]` or `}` is encountered we want
the "Expected `)`" error to point to a location one past the last valid
token, not to the trailing error tokens.

For example from #349 here's a poor error message from the existing
code:

    ERROR: ParseError:
    # Error @ REPL[53]:15:5
        ylims!(p, (0, last(ylims(p)))
        xlabel!(p, "Contig length cutoff (kbp)")
    #   └─────────────────────────────────────┘ ── Expected `)`

After this change, the error location instead points to the end of the
last valid line:

    ERROR: ParseError:
    # Error @ REPL[53]:15:5
        ylims!(p, (0, last(ylims(p)))
    #                                └── Expected `)`
@tecosaur
Copy link
Member

tecosaur commented Feb 4, 2024

A thought on this: when the tokes are paired, it could be helpful to highlight the corresponding un-paired token.

For example, here's some (lisp) code in my editor when I delete an opening paren:

image

@c42f c42f mentioned this pull request Dec 6, 2024
c42f added a commit that referenced this pull request Dec 6, 2024
Previously we relied on the last SyntaxNode consuming all trailing
whitespace when detecting incomplete syntax. However this assumption was
broken by #397 and is generally fragile with respect to any extra
bump_trivia() calls. Fix this by just comparing to the stream position
before any bumping of remaining trivia.
c42f added a commit that referenced this pull request Dec 6, 2024
Previously we relied on the last SyntaxNode consuming all trailing
whitespace when detecting incomplete syntax. However this assumption was
broken by #397 and is generally fragile with respect to any extra
bump_trivia() calls. Fix this by just comparing to the stream position
before any bumping of remaining trivia.
c42f added a commit that referenced this pull request Dec 8, 2024
Previously we relied on the last SyntaxNode consuming all trailing
whitespace when detecting incomplete syntax. However this assumption was
broken by #397 and is generally fragile with respect to any extra
bump_trivia() calls. Fix this by just comparing to the stream position
before any bumping of remaining trivia.
c42f added a commit that referenced this pull request Dec 8, 2024
Previously we relied on the last SyntaxNode consuming all trailing
whitespace when detecting incomplete syntax. However this assumption was
broken by #397 and is generally fragile with respect to any extra
bump_trivia() calls. Fix this by just comparing to the stream position
before any bumping of remaining trivia.
c42f added a commit to JuliaLang/julia that referenced this pull request Oct 17, 2025
…ax.jl#397)

When a missing closing token like `)`, `]` or `}` is encountered we want
the "Expected `)`" error to point to a location one past the last valid
token, not to the trailing error tokens.

For example from JuliaLang/JuliaSyntax.jl#349 here's a poor error message from the existing
code:

    ERROR: ParseError:
    # Error @ REPL[53]:15:5
        ylims!(p, (0, last(ylims(p)))
        xlabel!(p, "Contig length cutoff (kbp)")
    #   └─────────────────────────────────────┘ ── Expected `)`

After this change, the error location instead points to the end of the
last valid line:

    ERROR: ParseError:
    # Error @ REPL[53]:15:5
        ylims!(p, (0, last(ylims(p)))
    #                                └── Expected `)`
c42f added a commit to JuliaLang/julia that referenced this pull request Oct 17, 2025
…iaSyntax.jl#518)

Previously we relied on the last SyntaxNode consuming all trailing
whitespace when detecting incomplete syntax. However this assumption was
broken by JuliaLang/JuliaSyntax.jl#397 and is generally fragile with respect to any extra
bump_trivia() calls. Fix this by just comparing to the stream position
before any bumping of remaining trivia.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Underbracket placement better error message for missing comma.

2 participants