PackageAnalyzer.jl icon indicating copy to clipboard operation
PackageAnalyzer.jl copied to clipboard

WIP: Use JuliaSyntax to count things out of parsed source code

Open ericphanson opened this issue 2 years ago • 2 comments

xref https://github.com/JuliaEcosystem/PackageAnalyzer.jl/issues/63

so far:

julia> analyze_syntax(PackageAnalyzer)
Dict{String, Int64} with 6 entries:
  "struct"   => 6
  "usings"   => 16
  "call"     => 593
  "function" => 53
  "imports"  => 1
  "exports"  => 7

ericphanson avatar Jan 14 '23 13:01 ericphanson

Overall comments on this:

  • Having a well defined category precedence (eg, code > docstring > comment) would make categorizing lines easy, given there can be multiple categories per line. (cf in the comment about a two-pass system.)
  • The API for JuliaSyntax.SyntaxNode is ... honestly kind of WIP and not entirely awesome haha :grimacing: I feel like some additions to that could really help you here, though I'm not entirely sure what they should be. Ideas welcome.

c42f avatar Mar 06 '23 02:03 c42f

I've just thought of an upstream change that would help make this cleaner.

I'm planning to emit docstrings as nodes of kind K"doc" in the next version - this reflects the fact that it's special surface syntax, not an explicit macro call. (You can already detect this by detecting the special kind K"core_@doc", but I think emitting a K"macrocall" for this is one of those cases where lowering has crept into the parser a little.)

c42f avatar Mar 14 '23 06:03 c42f