AlexKnauth / syntax-sloc

counts the number of source lines of code in a racket syntax object
MIT License
3 stars 1 forks source link

[WIP] filter line counts by module name #5

Closed bennn closed 8 years ago

bennn commented 8 years ago

Checking in, but this is not accurate enough to merge.

Goal (address #4 ):

This sort of works:

#lang racket ;; test.rkt
(provide (contract-out [x natural-number/c]))
(define x 0)
> raco sloc -m racket/contract test.rkt
SLOC(racket/contract)   Source
   1    c.rkt

but adding a prefix-in brings the line count to 0.

Possibly related, counting does not work at all for typed/racket or even typed-racket/base-env/base-types.

On the agenda:

AlexKnauth commented 8 years ago

How can it do this without expanding it?

bennn commented 8 years ago

[[ Alex is playing with a filter/stx. Once that's ready, try:

  1. fully expand
  2. filter for calls to a racket/contract identifier
  3. count lines from syntax objects inside the filtered syntax objects whose syntax-source matches the original lang-file-sloc file ]]
AlexKnauth commented 8 years ago

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.

bennn commented 8 years ago

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

bennn commented 8 years ago

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:

  1. Use check-syntax's 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
  2. Added optional (Listof Bytes) argument to lang-file-sloc. The bytes specify a path relative to the collects folder, as returned by path->collects-relative. src
  3. Note: the update to lang-file-sloc doesn't use syntax-sloc.rkt at all. src
bennn commented 8 years ago

(moving last comment to the issue, closing this because it really does need a different approach)