AlexKnauth / syntax-sloc

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

raco-sloc: filter search by #lang #3

Closed bennn closed 8 years ago

bennn commented 8 years ago

Add --lang <PREGEXP> command line option to limit search to files whose #lang matches the regular expression.

"Works", but:

Will write docs once we agree on a design.

Examples:

bash-3.2$ raco sloc .
SLOC    Source
  399   .
bash-3.2$ raco sloc --lang racket .
SLOC    Source
   0    .
bash-3.2$ raco sloc --lang racket/base .
SLOC    Source
 169    .
bash-3.2$ raco sloc --lang "scribble.*" *
SLOC    Source
 N/A    README.md
   0    compiled
   0    info.rkt
   0    scribblings
  93    syntax-sloc
   0    typed
bennn commented 8 years ago

Can I commit test files to a new folder in this repo?

AlexKnauth commented 8 years ago

The way DrRacket gets the #lang line is in drracket/private/module-language-tools.rkt. It gets an input port (L176), calls read-language on that port (L199), gets the current line, column, and position after the read (L213). After that it gets the text up to that point (L215).

That can't be the whole story though, otherwise #|#lang scribble/manual|# #!racket would throw it off, and it doesn't.

AlexKnauth commented 8 years ago

Re: test files in a separate folder: Yes that's a good idea.

bennn commented 8 years ago

Current strategy:

  1. call read-language, get the end position (like Dr. Racket)
  2. read-string up to the end position
  3. regexp-match-positions* to get the end of the last #lang or #!
  4. return everything between (3) and (2) as a string
AlexKnauth commented 8 years ago

If I were a user, I would expect raco sloc --lang racket . to only report #lang racket files, and not #lang typed/racket or #lang racket/base. I might expect raco sloc --lang .*racket.* ., or maybe raco sloc --lang #px".*racket.*" . to do that, but not raco sloc --lang racket ..

bennn commented 8 years ago

I can put the ^ and $ back. But then --lang racket won't capture things like #lang sweet-exp racket.

(We could add a second option that enables the old behavior. "old" = current = the pregexp on the command line is matched as-is against the string following #lang or #!)

AlexKnauth commented 8 years ago

You wouldn't have to use ^ and $, you could use regexp-match-exact? instead, and it would make more sense for a short string like a #lang line.

bennn commented 8 years ago

Ok.

Are you alright with --lang racket not matching #lang sweet-exp racket ?

AlexKnauth commented 8 years ago

Yes. If someone wants to use this feature, then they probably would be expecting this and they would be ready to write "racket|sweet-exp racket".

bennn commented 8 years ago
AlexKnauth commented 8 years ago

What's .raco-sloc.rkt.swp?

bennn commented 8 years ago

argh I did git add .

It's a vim-generated swapfile. Can I add *.swp and *.swo to the .gitignore?

AlexKnauth commented 8 years ago

Yes you can add those to the .gitignore.

bennn commented 8 years ago

Removed the unnecessary macro & unused imports.

AlexKnauth commented 8 years ago

Did you address this: https://github.com/AlexKnauth/syntax-sloc/pull/3#discussion_r64140555 ? Otherwise it will report the SLOC as 0 instead of N/A.

bennn commented 8 years ago

I hadn't. That's fixed now.

AlexKnauth commented 8 years ago

I just moved most of the #lang-file-related stuff, incliding your read-#lang function, to this repository: https://github.com/AlexKnauth/lang-file