JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
274 stars 33 forks source link

Fix line numbers with source fragments #310

Closed c42f closed 1 year ago

c42f commented 1 year ago

When parsing source code fragments incrementally with

* `Meta.parse(str, index)` or
* `parsestmt(str, index)`

we must avoid scanning the rest of str for line numbers for efficiency. In this mode, the user is expected to provide first_line to "manually" specify which line number we're counting from.

Admittedly this is a bit clunky and should be integrated better with SourceFile (which should also be renamed - see issue #190) but for now seems to be the most consistent way to approach things here.

Fixes a bug found over at https://github.com/JuliaLang/julia/pull/46372#issuecomment-1593683826

Update: Switching to using Vector{UInt8} for literal parsing also makes parsing to ParseStream and GreenNode around 10% faster

codecov[bot] commented 1 year ago

Codecov Report

Merging #310 (5ca541c) into main (b0a2837) will decrease coverage by 0.03%. The diff coverage is 97.43%.

@@            Coverage Diff             @@
##             main     #310      +/-   ##
==========================================
- Coverage   96.81%   96.78%   -0.03%     
==========================================
  Files          14       14              
  Lines        4109     4111       +2     
==========================================
+ Hits         3978     3979       +1     
- Misses        131      132       +1     
Impacted Files Coverage Δ
src/kinds.jl 80.59% <ø> (ø)
src/utils.jl 86.66% <83.33%> (+1.21%) :arrow_up:
src/parse_stream.jl 95.37% <92.85%> (-1.06%) :arrow_down:
src/literal_parsing.jl 98.35% <98.36%> (+0.39%) :arrow_up:
src/expr.jl 100.00% <100.00%> (ø)
src/hooks.jl 80.11% <100.00%> (+1.02%) :arrow_up:
src/parser_api.jl 93.75% <100.00%> (-0.10%) :arrow_down:
src/source_files.jl 97.36% <100.00%> (ø)
src/syntax_tree.jl 95.27% <100.00%> (+0.13%) :arrow_up: