-
Notifications
You must be signed in to change notification settings - Fork 36
Description
I've been exploring using StaticLint.jl to do static error analysis on my code, but an issue that I'm running into (and I think it has to do with CSTParser) is that the file offsets that CSTParser outputs for where commands are located in the file are not exactly the beginning and end of the commands. Sometimes it seems quite arbitrary. Consider the following super simple file:
using LinearAlgebra
include("foo.jl")
include("bar.jl")
I parse the file using the following code:
using CSTParser
const root_filepath = "/tmp/julia_test/c.jl"
source = read(root_filepath, String)
cst = CSTParser.parse(source, true)
println(cst)
And this is what it outputs:
1:62 file
1:23 using
1:17 1:0 OP: .
1:17 LinearAlgebra
24:44 call
24:30 include
31:38 STRING: foo.jl
45:62 call
45:51 include
52:59 STRING: bar.jl
My understanding is that on the left we have information of the form <starting offset>:<ending offset>
where offset
is basically the character number starting from the beginning of the file, that points to the beginning and ending of the corresponding operation/string/variable/etc. So take for example the above output:
LinearAlgebra
is said to reside on offsets1:17
. In fact, it is on offsets7:19
- An
include
command is said to reside on offsets24:30
. This is correct! - The string
foo.jl
is said to reside on offsets31:38
. In fact, it is on offsets32:39
So you see - already in this simple file there seem to be three cases, each with different behaviour - a "really bad" error (LinearAlgebra
), an error that is an offset of one character (foo.jl
), and a correct answer (include
).
Perhaps I do not fully understand how CSTParser works, in which case I'd really appreciate an explanation. At the end of the day, I would like to get to a state where StaticLint.jl return the correct file offset pointing to the error in the file. I believe that it is currently not doing so because CSTParser returns this weird-looking information.
My system info:
- OS: Ubuntu 20.04.1 LTS
- Julia: 1.5.3
- CSTParser.jl: [00ebfdb7] CSTParser v3.1.1-DEV
https://github.com/julia-vscode/CSTParser.jl#master
- Editor (this shouldn't matter, I think): GNU Emacs 27.1.90