Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Last active January 11, 2019 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dockimbel/2af078e02e56fcc092aea771de0c5e9a to your computer and use it in GitHub Desktop.
Save dockimbel/2af078e02e56fcc092aea771de0c5e9a to your computer and use it in GitHub Desktop.
Lines of code statistics from Red files
Red [
Title: "Lines of code statistics from Red files"
Author: "Nenad Rakocevic"
File: %rloc.reds
Tabs: 4
Purpose: {
Counts the number of files, lines of code and inline comments in Red/Rebol files, across folders,
filtering files using a list of suffixes and excluding files from a given list of subfolders.
}
]
context [
count-lines: function [src [string!] entry [block!]][ ;-- entry receives [LOC comments]
parse src [
any [
lf (entry/1: entry/1 + 1)
| dbl-quote thru dbl-quote
| #"{" thru #"}"
| #";" to lf (entry/2: entry/2 + 1)
| skip
]
]
]
set 'count-loc function [
dir [file!] "Root folder where to start the analysis"
allowed [block!] "List of matched file extensions"
excluded [block!] "List of excluded folders"
return: [block!] ;"Copy of allowed list expanded with: [files-number LOC comments]"
][
if empty? stats: [][foreach ext allowed [repend stats [ext copy [0 0 0]]]]
foreach file read dir [
either dir? file [
if dir <> %./ [file: dir/:file]
deny?: no
foreach no-go excluded [if deny?: find/match file no-go [break]]
unless deny? [count-loc file allowed excluded]
][
if entry: select stats suffix? file [
entry/1: entry/1 + 1
count-lines read dir/:file next entry
]
]
]
stats
]
]
#example [
count-loc %./ [%.red %.r %.reds] [
%.git/
%.github/
%docs/
%system/library/
%system/tests/
%quick-test/
%tests/
]
; == [%.red [48 16495 776] %.r [39 25186 3507] %.reds [154 85742 7687]]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment