make loc counts with rloc; test/loc.py goes
rloc (github ldiaz94/rloc) knows Pascal's // and { } comments and
strings, so { in '{' is no comment. The compiler counts 6,096 lines of
code, where loc.py said 6,060: still within the budget.
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | make raz # the compiler, ./raz; its library is lib/ |
| 11 | 11 | make check # every example and test against its expected output |
| 12 | 12 | make bench # must report at least 400,000 lines a second |
| 13 | - make loc # lines of the compiler; the code column is the budget | |
| 13 | + make loc # lines of the compiler, by rloc; the last, code, is the budget | |
| 14 | 14 | make tests # the small Pascal tests of scan, x64, link and elf |
| 15 | 15 | make gdb # gdb stops at a line of a test and names it |
| 16 | 16 | make stress # 40,000 native threads; make check runs a small version |
| @@ -68,9 +68,11 @@ | ||
| 68 | 68 | build/Pretty $$f | cmp -s - $$f || { echo "not formatted: $$f"; fail=1; }; \ |
| 69 | 69 | done; test $$fail = 0 |
| 70 | 70 | |
| 71 | -# lines of the compiler: all of them, and those that aren't blank or comments | |
| 71 | +# lines of the compiler, by rloc: each file's blank, comment and code, | |
| 72 | +# then the lines of code in all | |
| 72 | 73 | loc: |
| 73 | - @python3 test/loc.py src/*.pas | |
| 74 | + @rloc -f src/*.pas | |
| 75 | + @rloc -c src/*.pas | |
| 74 | 76 | |
| 75 | 77 | # raz and its library go together under $(PREFIX)/lib/raz; the link |
| 76 | 78 | # on PATH works since raz finds lib/ beside its real path. |
| @@ -1,16 +0,0 @@ | ||
| 1 | -"""Counts the lines of the compiler's units, or of raz modules: all of | |
| 2 | -them, and the lines of code, those that are neither blank nor only | |
| 3 | -comment. In raz, { and } are literals, not comments.""" | |
| 4 | -import re, sys | |
| 5 | - | |
| 6 | -total = code = 0 | |
| 7 | -for path in sys.argv[1:]: | |
| 8 | - text = open(path).read() | |
| 9 | - comment = r"\(\*.*?\*\)" if path.endswith(".raz") else r"\{[^}]*\}|\(\*.*?\*\)" | |
| 10 | - bare = re.sub(comment, "", text, flags=re.S) | |
| 11 | - n = text.count("\n") | |
| 12 | - c = sum(1 for line in bare.split("\n") if line.strip()) | |
| 13 | - print(f"{path:18} {n:6} {c:6}") | |
| 14 | - total += n | |
| 15 | - code += c | |
| 16 | -print(f"{'total':18} {total:6} {code:6}") |