Open bennn opened 8 years ago
Something like this?
(define (type-ann-syntax? stx)
(syntax-parse stx #:datum-literals (:)
[(: . _) #true]
[_ #false]))
(syntax-sloc (read-lang-file ....) #:count-syntax? type-ann-syntax?)
The issue is that the result of read-lang-file
, although it's a syntax object, doesn't have any scopes or bindings associated with it, so it can't do any better that a #:datum-literals (:)
match. If you could expand the syntax first?
(require (only-in typed/racket/base :))
;; type-ann-syntax-from? : Any -> (Expanded-Stx -> Boolean)
(define ((type-ann-syntax-from? src) stx)
(and
(equal? (syntax-source stx) src)
(syntax-parse stx #:literals (:)
[(: . _) #true]
[_ #false])))
(syntax-sloc
(local-expand
(read-lang-file ....)
'top-level
(list))
#:count-syntax? (type-ann-syntax-from? ...))
Something like that?
(Dear Ben use https://github.com/AlexKnauth/syntax-sloc/commit/e39fdbbf3408e526a031c8a68b9ced99f8db222b to make a pull request)
See https://gist.github.com/AlexKnauth/71e7b7953ecfa1e002a6ffd05e55b3cc
It's draft of a module->provided-identifiers
function that handles identifiers that are renamed when imported.
Here's notes on re-using check-syntax to count identifiers from racket/contract
. Overall the approach is no good because it misses identifiers defined outside racket/contract
but re-provided. Anyway:
make-traversal
and syncheck:add-jump-to-definition
to collect a set of identifiers that jump to an identifier defined in the racket/contract
collection. src(Listof Bytes)
argument to lang-file-sloc
. The bytes specify a path relative to the collects folder, as returned by path->collects-relative
. srclang-file-sloc
doesn't use syntax-sloc.rkt
at all. src(BTW -- our current goal is just counting the line numbers of identifiers used from the racket/contract
module. This is different from the number of contract annotations.)
Right now we only count lines of code. We should also be able to count lines of contracts, lines of type annotations, and other things.
Proposal:
type-ann-stx?
,contract-stx?
) and wrappers for LOC