Skip to content

Commit 8ede563

Browse files
committed
Update inweb to 6L38 version
1 parent 020cb10 commit 8ede563

5 files changed

Lines changed: 121 additions & 20 deletions

File tree

src/inwebc/Chapter 3/The Parser.w

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ also give the namespace for its functions.
6161
@<Parse the line as a probable section heading@> =
6262
string rewritten; in_strcpy(rewritten, "");
6363
if ((S->sect_language == C_FOR_INFORM_LANGUAGE) &&
64-
(pattern_match(L->text, "(%C+) (%C+/%C+): (%c+)."))) {
64+
(pattern_match(L->text, "%[(%C+)%] (%C+/%C+): (%c+)."))) {
6565
in_strcpy(S->sect_namespace, found_text1);
6666
in_strcpy(S->sigil, found_text2);
6767
in_strcpy(S->sect_title, found_text3);
@@ -72,8 +72,82 @@ also give the namespace for its functions.
7272
in_strcpy(S->sect_title, found_text2);
7373
L->text_operand = new_string(found_text2);
7474
L->category = SECTION_HEADING_LCAT;
75+
} else if (pattern_match(L->text, "%[(%C+::)%] (%c+).")) {
76+
in_strcpy(S->sect_namespace, found_text1);
77+
in_strcpy(S->sect_title, found_text2);
78+
@<Set the sigil to an automatic abbreviation of the relative pathname@>;
79+
L->text_operand = new_string(found_text2);
80+
L->category = SECTION_HEADING_LCAT;
81+
} else if (pattern_match(L->text, "(%c+).")) {
82+
in_strcpy(S->sect_title, found_text1);
83+
@<Set the sigil to an automatic abbreviation of the relative pathname@>;
84+
L->text_operand = new_string(found_text1);
85+
L->category = SECTION_HEADING_LCAT;
7586
}
7687

88+
@ If no sigil is supplied, we make one ourselves.
89+
90+
@<Set the sigil to an automatic abbreviation of the relative pathname@> =
91+
sprintf(S->sigil, "%s/", C->ch_sigil);
92+
93+
char *from = S->sect_title;
94+
int w = strlen(S->sigil);
95+
char *tail = S->sigil + w;
96+
97+
int letters_from_each_word = 5;
98+
do {
99+
@<Make the tail using this many consonants from each word@>;
100+
if (--letters_from_each_word == 0) break;
101+
} while (strlen(tail) > 5);
102+
103+
@<Terminate with disambiguating numbers in case of collisions@>;
104+
105+
@ We collapse words to an initial letter plus consonants: thus "electricity"
106+
would be "elctrcty", since we don't count "y" as a vowel here.
107+
108+
@<Make the tail using this many consonants from each word@> =
109+
int sn = 0, sw = w;
110+
if (from[sn] == SEP_CHAR) sn++;
111+
int letters_from_current_word = 0;
112+
while ((from[sn]) && (from[sn] != '.')) {
113+
if (from[sn] == ' ') letters_from_current_word = 0;
114+
else {
115+
if (letters_from_current_word < letters_from_each_word) {
116+
if (from[sn] != '-') {
117+
int l = tolower(from[sn]);
118+
if ((letters_from_current_word == 0) ||
119+
((l != 'a') && (l != 'e') && (l != 'i') && (l != 'o') && (l != 'u'))) {
120+
S->sigil[sw++] = l; S->sigil[sw] = 0;
121+
letters_from_current_word++;
122+
}
123+
}
124+
}
125+
}
126+
sn++;
127+
}
128+
129+
@ We never want two sections to have the same sigil.
130+
131+
@<Terminate with disambiguating numbers in case of collisions@> =
132+
char *distail = S->sigil + strlen(S->sigil);
133+
int disnum = 0, collision = FALSE;
134+
do {
135+
if (disnum++ > 0) {
136+
int ldn = 5;
137+
if (disnum >= 1000) ldn = 4;
138+
else if (disnum >= 100) ldn = 3;
139+
else if (disnum >= 10) ldn = 2;
140+
else ldn = 1;
141+
sprintf(distail-ldn, "%d", disnum);
142+
}
143+
collision = FALSE;
144+
for (chapter *C = W->first_chapter; C; C = C->next_chapter)
145+
for (section *S2 = C->first_section; S2; S2 = S2->next_section)
146+
if ((S2 != S) && (strcmp(S2->sigil, S->sigil) == 0)) {
147+
collision = TRUE; break;
148+
}
149+
} while (collision);
150+
77151
@ Note that we report an error if the command isn't one we recognise: we
78152
don't simply ignore the squares and let it fall through into the tangler.
79153
There used to be two other syntaxes for oddball commands (to force page

src/inwebc/Chapter 5/C for Inform.w

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ Here, though, there's a complication:
560560

561561
must expand to:
562562

563-
|if (parse_nt_against_word_range(k_kind_NTM, a1, a2, NULL, NULL)) { ...|
563+
|if (Text__Languages__parse_nt_against_word_range(k_kind_NTM, a1, a2, NULL, NULL)) { ...|
564564

565565
This is all syntactic sugar to make it easier to see parsing in action.
566566
Anyway, it means we have to set |fcall_mode| to remember to add in the
@@ -577,7 +577,7 @@ any trouble.
577577
if (pnt) {
578578
i += in_strlen(putative) - 1;
579579
if (original[i+1] == '(') fcall_mode = TRUE;
580-
if (fcall_mode) fprintf(F, "parse_nt_against_word_range(");
580+
if (fcall_mode) fprintf(F, "Preform__parse_nt_against_word_range(");
581581
fprintf(F, "%s", pnt->as_C_identifier);
582582
if (fcall_mode) {
583583
fprintf(F, ", "); i++;
@@ -785,7 +785,7 @@ int c_for_inform_weave_code_line(FILE *WEAVEOUT, weave_target *wv,
785785
fprintf(WEAVEOUT, "\\nonterminal{%s} |::=|",
786786
L->preform_nonterminal_defined->unangled_name);
787787
if (L->preform_nonterminal_defined->as_function) {
788-
fprintf(WEAVEOUT, "{\\it internal definition");
788+
fprintf(WEAVEOUT, "\\quad{\\it internal definition");
789789
if (L->preform_nonterminal_defined->voracious)
790790
fprintf(WEAVEOUT, " (voracious)");
791791
else if (L->preform_nonterminal_defined->min_word_count ==
@@ -816,19 +816,22 @@ int c_for_inform_weave_code_line(FILE *WEAVEOUT, weave_target *wv,
816816
found_text1, found_text2, found_text3);
817817
string label; in_strcpy(label, "");
818818
int N = preform_production_count;
819-
if (in_string_eq(S->sigil, "9/engin")) {
820-
in_sprintf(label, "${}_{%d}$", N);
821-
} else {
822-
int L = ((N-1)%26) + 1;
823-
if (N <= 26) in_sprintf(label, "%c", 'a'+L-1);
824-
else if (N <= 52) in_sprintf(label, "%c%c", 'a'+L-1, 'a'+L-1);
825-
else if (N <= 78) in_sprintf(label, "%c%c%c", 'a'+L-1, 'a'+L-1, 'a'+L-1);
819+
int L = ((N-1)%26) + 1;
820+
if (N <= 26) in_sprintf(label, "%c", 'a'+L-1);
821+
else if (N <= 52) in_sprintf(label, "%c%c", 'a'+L-1, 'a'+L-1);
822+
else if (N <= 78) in_sprintf(label, "%c%c%c", 'a'+L-1, 'a'+L-1, 'a'+L-1);
823+
else {
824+
int n = (N-1)/26;
825+
in_sprintf(label, "%c${}^{%d}$", 'a'+L-1, n);
826826
}
827827
fprintf(WEAVEOUT, "\\qquad {\\hbox to 0.4in{\\it %s\\hfil}}%s", label, matter);
828828
if (problem[0])
829829
fprintf(WEAVEOUT, "\\hfill$\\longrightarrow$ {\\ttninepoint\\it %s}", problem);
830-
else
831-
fprintf(WEAVEOUT, "%s", concluding_comment);
830+
else if (concluding_comment[0]) {
831+
fprintf(WEAVEOUT, " \\hfill{\\ttninepoint\\it ");
832+
if (concluding_comment) format_identifier(WEAVEOUT, wv, concluding_comment);
833+
fprintf(WEAVEOUT, "}");
834+
}
832835
fprintf(WEAVEOUT, "\n");
833836
return TRUE;
834837
}

src/inwebc/Chapter 5/C-Like Languages.w

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,9 @@ contain namespace dividers written |::|.
332332
}
333333
}
334334
L->function_defined = fn;
335-
if ((W->main_language == C_FOR_INFORM_LANGUAGE) &&
336-
(pattern_match(fname, "%c*::%c*"))) fn->within_namespace = TRUE;
335+
336+
if (W->main_language == C_FOR_INFORM_LANGUAGE)
337+
@<Check that the function has its namespace correctly declared@>;
337338
}
338339
}
339340

@@ -379,6 +380,29 @@ reach an open brace |{|.
379380

380381
@
381382

383+
@<Check that the function has its namespace correctly declared@> =
384+
char *declared_namespace = "";
385+
if (pattern_match(fname, "(%c+::)%c*")) {
386+
declared_namespace = found_text1;
387+
fn->within_namespace = TRUE;
388+
} else if ((strcmp(fname, "main") == 0) && (strcmp(S->sect_namespace, "Main::") == 0))
389+
declared_namespace = "Main::";
390+
if (strcmp(declared_namespace, S->sect_namespace) != 0) {
391+
string err_mess;
392+
if (declared_namespace[0] == 0)
393+
sprintf(err_mess, "Function '%s' should have namespace prefix '%s'",
394+
fname, S->sect_namespace);
395+
else if (S->sect_namespace[0] == 0)
396+
sprintf(err_mess, "Function '%s' declared in a section with no namespace",
397+
fname);
398+
else
399+
sprintf(err_mess, "Function '%s' declared in a section with the wrong namespace '%s'",
400+
fname, S->sect_namespace);
401+
error_in_web(err_mess, L);
402+
}
403+
404+
@
405+
382406
@c
383407
void c_like_subcategorise_code(programming_language *pl, source_line *L) {
384408
if (pattern_match(L->text, "#include <(%C+)>%c*")) {
@@ -629,8 +653,6 @@ int c_like_syntax_colour(programming_language *pl, FILE *WEAVEOUT, weave_target
629653
}
630654
if (ident_from >= 0)
631655
c_like_colour_ident(S, matter, colouring, ident_from, in_strlen(matter)-1);
632-
/* printf("%s\n", matter);
633-
for (int i=0; matter[i]; i++) printf("%c", '0'+colouring[i]); */
634656
return FALSE;
635657
}
636658

src/inwebc/Chapter 6/TeX Format.w

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,13 @@ void tex_endnote(FILE *F, weave_target *wv, int end) {
288288

289289
@c
290290
void tex_identifier(FILE *F, weave_target *wv, char *id) {
291+
int math_mode = FALSE;
291292
for (int i=0; id[i]; i++) {
292293
switch (id[i]) {
293-
case '_': fprintf(F, "\\_"); break;
294+
case '$': math_mode = (math_mode)?FALSE:TRUE; break;
295+
case '_': if (math_mode) fprintf(F, "_"); else fprintf(F, "\\_"); break;
294296
case '"':
295-
if ((id[i] == '"') && ((i==0) || (id[i-1] == ' ')))
297+
if ((id[i] == '"') && ((i==0) || (id[i-1] == ' ') || (id[i-1] == '(')))
296298
fprintf(F, "``");
297299
else
298300
fprintf(F, "''");

src/inwebc/Materials/inweb-macros.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
\titlepage
1818

19-
\def\quotesource#1{{\narrower\smallskip\noindent{\sourcefont #1}\smallskip}}
19+
\def\quotesource#1{\medskip{\narrower\noindent{\sourcefont #1}\par}\smallskip}
2020
\def\cast#1#2{{#1}$\;\rightarrow\;${#2}}
2121
\def\comp#1#2{{#1}$\;\sim\;${#2}}
2222
\def\al{$\alpha$}

0 commit comments

Comments
 (0)