Closed bennn closed 8 years ago
How can it do this without expanding it?
[[ Alex is playing with a filter/stx
. Once that's ready, try:
racket/contract
identifiersyntax-source
matches the original lang-file-sloc
file ]]I just added filter/stx
and syntax-sloc/filter
. The syntax-sloc/filter
function is the one that applies filter/stx
first, and then source-lines
to every element of that filtered list.
Tried the above, it's not great. (These examples are coded, R
denotes a line of contracts that I think we should pick up.)
#lang racket
#| C R |# (define/contract x
#| C |# integer?
#| C |# 1)
#| C |# (define (y z)
#| C |# z)
#| C |# (provide
#| R |# (contract-out
#| R |# [y (-> natural-number/c natural-number/c)]))
Reports 2 lines
and
#lang racket/base
#| C |# (require
#| |# (prefix-in c: (only-in racket/contract ->))
#| |# (rename-in racket/contract [natural-number/c nat/c]))
#| C |# (define nat?
#| R |# nat/c)
#| C |# (define/contract foo
#| R |# (c:->
#| R |# nat/c
#| R |# nat/c)
#| C |# (lambda (x) 3))
Reports 7 lines
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(moving last comment to the issue, closing this because it really does need a different approach)
Checking in, but this is not accurate enough to merge.
Goal (address #4 ):
raco sloc -m racket/contract file.rkt
counts only lines that use identifiers fromracket/contract
raco sloc -m "(racket/string racket/format)" file.rkt
only counts lines fromracket/string
orracket/format
raco sloc -m type-ann file.rkt
counts only lines that contain a "type" -- where a type is an identifier exported from a pre-defined list of modulesThis sort of works:
but adding a
prefix-in
brings the line count to 0.Possibly related, counting does not work at all for
typed/racket
or eventyped-racket/base-env/base-types
.On the agenda:
module->namespace
instead of usingracket/contract
etc directly to make identifiers