aboutsummaryrefslogtreecommitdiff
path: root/src/compiler/lex.zc
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/lex.zc')
-rw-r--r--src/compiler/lex.zc29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/compiler/lex.zc b/src/compiler/lex.zc
index 0b509e4..0348cae 100644
--- a/src/compiler/lex.zc
+++ b/src/compiler/lex.zc
@@ -366,10 +366,31 @@ int fieldscan(int n) {
// a // comment, with ch on its second slash. one that starts a line joins the
// doc comment being collected, if the line above was part of it, or starts a
// new one; a comment after code on the same line is not documentation.
+// a comment //:lines NAME (ch is its colon) says that what follows is the file NAME, with its lines counted
+// from the next one, and turns line tables on from the next top-level item. src/tools/automap.sh writes one
+// before a program it joins to the runtime. the rest of the line is read here and the marker kept: the
+// source is read once to find the signatures and again to compile, and it counts only when compiling reaches it.
+int mark_line() {
+ char[300] b; int n = 0, i, base; word name;
+ while (ch >= 0 && ch != 10) { if (n < 298) { b[n] = ch; n++; } nextch(); }
+ while (n && (b[n - 1] == 13 || b[n - 1] == 32)) n--;
+ b[n] = 0;
+ if (n > 7 && b[1] == 'l' && b[2] == 'i' && b[3] == 'n' && b[4] == 'e' && b[5] == 's' && b[6] == 32) {
+ base = line;
+ if (ch == 10) base = line - 1;
+ if (!lt_nmarks || base > lt_marks[lt_nmarks * 2 - 2]) {
+ if (lt_nmarks * 2 + 2 > lt_markcap) { lt_marks = chk_resize(lt_marks, lt_nmarks * 2, lt_markcap * 2 + 16); lt_markcap = lt_markcap * 2 + 16; }
+ name = chk_resize(0, 0, n); i = 7;
+ while (i <= n) { name[i - 7] = b[i]; i++; }
+ lt_marks[lt_nmarks * 2] = base; lt_marks[lt_nmarks * 2 + 1] = name; lt_nmarks++;
+ }
+ }
+ return 0;
+}
int doccomment(int nl) {
int cl = line, start;
nextch();
- if (ch == ':') { while (ch >= 0 && ch != 10) nextch(); dn = 0; dsect = 1; dlast = cl; docpending = 1; return 0; }
+ if (ch == ':') { mark_line(); dn = 0; dsect = 1; dlast = cl; docpending = 1; return 0; }
if (!nl) { while (ch >= 0 && ch != 10) nextch(); return 0; }
if (dlast != cl - 1) { dn = 0; dsect = 0; }
if (ch == 32) nextch();
@@ -451,7 +472,11 @@ int lex1() {
if (ch != '/') break;
nextch();
if (ch == '/') {
- if (docs_on) doccomment(nl); else while (ch >= 0 && ch != 10) nextch();
+ if (docs_on) doccomment(nl);
+ else {
+ nextch();
+ if (ch == ':') mark_line(); else while (ch >= 0 && ch != 10) nextch();
+ }
tglue = 0; continue;
}
if (ch == '*') {