Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Keeping track of line numbers #13

Closed
timholy opened this issue Jan 6, 2015 · 2 comments
Closed

Keeping track of line numbers #13

timholy opened this issue Jan 6, 2015 · 2 comments

Comments

@timholy
Copy link
Member

timholy commented Jan 6, 2015

In JuliaCI/Coverage.jl#36, I'm trying to leverage this to improve our accounting for code coverage. The biggest challenge is keeping track of line numbers appropriately. Here's a good example of the challenge (save this to a file /tmp/testparser.jl):

f1(x) = 2x
if isdefined(:f1)
    f2(x) = 3x
end
f3(x) = 4x

Here's what comes from parsing this file:

julia> io = open("/tmp/testparser.jl")
IOStream(<file /tmp/testparser.jl>)

julia> ast = Parser.parse(io)
:(f1(x) = begin  # none, line 1:   # we're at line 1
            2x
        end)

julia> ast = Parser.parse(io)
:(if isdefined(:f1) # line 2:
        f2(x) = begin  # none, line 2:   # we're at line 2+1 = 3
                3x
            end
    end)

julia> ast = Parser.parse(io)
:(f3(x) = begin  # none, line 1:    # we're at line 1+3 = 4?
            4x
        end)

Because the end doesn't get its own line number, it doesn't seem possible to keep track of the line number just by looking for :line exprs or LineNumberNodes.

@timholy
Copy link
Member Author

timholy commented Jan 7, 2015

Much less important now that I used a hack in Coverage.jl](https://github.com/timholy/Coverage.jl/commit/c244d43df3c393e877a40cc2dea395be5a2de59f). In several respects this hack is probably the right way to do it; there's no bookkeeping of any kind, so no risk you'll ever be wrong.

I'll let you decide what you want to do with this issue.

@jakebolewski
Copy link
Member

I want to preserve compatibility with the scheme parser. We could have the parse function take a line parameter to initialize the parse state, the reported line number would be offset from this based on the input stream. I think this is more of a limitation of how we do line numbers in general for Julia.

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

2 participants