Skip to content

Commit

Permalink
Improvements to IFM
Browse files Browse the repository at this point in the history
  • Loading branch information
ganelson committed Sep 6, 2023
1 parent 1d295fb commit d0e16e0
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 215 deletions.
2 changes: 1 addition & 1 deletion docs/foundation-module/4-chr.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1><a href="../index.html">
<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Character classes. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">wchar_t</span><span class="plain-syntax"> </span><span class="function-syntax">Characters::tolower</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Characters::tolower</span></span>:<br/>Filenames - <a href="3-fln.html#SP9">&#167;9</a><br/>String Manipulation - <a href="4-sm.html#SP26">&#167;26</a><br/>Tries and Avinues - <a href="4-taa.html#SP2">&#167;2</a><br/>Markdown Rendering - <a href="5-mr.html#SP4">&#167;4</a><br/>Web Structure - <a href="8-ws.html#SP5_4_1_1">&#167;5.4.1.1</a><br/>The Painter - <a href="9-tp.html#SP2_2">&#167;2.2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">wchar_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">) {</span>
<span class="identifier-syntax">wchar_t</span><span class="plain-syntax"> </span><span class="function-syntax">Characters::tolower</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Characters::tolower</span></span>:<br/>Filenames - <a href="3-fln.html#SP9">&#167;9</a><br/>String Manipulation - <a href="4-sm.html#SP26">&#167;26</a><br/>Tries and Avinues - <a href="4-taa.html#SP2">&#167;2</a><br/>Markdown Rendering - <a href="5-mr.html#SP5">&#167;5</a><br/>Web Structure - <a href="8-ws.html#SP5_4_1_1">&#167;5.4.1.1</a><br/>The Painter - <a href="9-tp.html#SP2_2">&#167;2.2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">wchar_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">) {</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">wchar_t</span><span class="plain-syntax">) </span><span class="identifier-syntax">tolower</span><span class="plain-syntax">((</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
<span class="identifier-syntax">wchar_t</span><span class="plain-syntax"> </span><span class="function-syntax">Characters::toupper</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Characters::toupper</span></span>:<br/>Bibliographic Data for Webs - <a href="8-bdfw.html#SP7_2">&#167;7.2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">wchar_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">) {</span>
Expand Down
6 changes: 3 additions & 3 deletions docs/foundation-module/4-pm.html

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions docs/foundation-module/4-sm.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/foundation-module/5-htm.html

Large diffs are not rendered by default.

229 changes: 140 additions & 89 deletions docs/foundation-module/5-im.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/foundation-module/5-mpi2.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ <h1><a href="../index.html">

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">name_inversion</span><span class="plain-syntax"> = </span><span class="constant-syntax">FALSE</span><span class="plain-syntax">;</span>

<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-sm.html#SP13" class="function-link"><span class="function-syntax">Str::get_first_char</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">lemma</span><span class="plain-syntax">) == </span><span class="character-syntax">'@'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax"> </span><a href="4-sm.html#SP25" class="function-link"><span class="function-syntax">Str::delete_first_character</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">lemma</span><span class="plain-syntax">);</span>
<span class="plain-syntax"> </span><span class="identifier-syntax">name_inversion</span><span class="plain-syntax"> = </span><span class="constant-syntax">TRUE</span><span class="plain-syntax">;</span>
Expand Down
31 changes: 20 additions & 11 deletions docs/foundation-module/5-mr.html

Large diffs are not rendered by default.

141 changes: 71 additions & 70 deletions docs/foundation-module/5-mrk.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/foundation-module/9-pl.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h1><a href="../index.html">
<span class="plain-syntax"> </span><span class="identifier-syntax">default_programming_language_path</span><span class="plain-syntax"> = </span><span class="identifier-syntax">P</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">programming_language</span><span class="plain-syntax"> *</span><span class="function-syntax">Languages::find_by_name</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Languages::find_by_name</span></span>:<br/>Inform-Flavoured Markdown - <a href="5-im.html#SP2_2_2">&#167;2.2.2</a>, <a href="5-im.html#SP2_2_4">&#167;2.2.4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">lname</span><span class="plain-syntax">, </span><span class="reserved-syntax">pathname</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">,</span>
<span class="reserved-syntax">programming_language</span><span class="plain-syntax"> *</span><span class="function-syntax">Languages::find_by_name</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Languages::find_by_name</span></span>:<br/>Inform-Flavoured Markdown - <a href="5-im.html#SP3_2_2">&#167;3.2.2</a>, <a href="5-im.html#SP3_2_4">&#167;3.2.4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">lname</span><span class="plain-syntax">, </span><span class="reserved-syntax">pathname</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">,</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">error_if_not_found</span><span class="plain-syntax">) {</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">programming_language</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pl</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="9-pl.html#SP2_1" class="named-paragraph-link"><span class="named-paragraph">If this is the name of a language already known, return that</span><span class="named-paragraph-number">2.1</span></a></span><span class="plain-syntax">;</span>
Expand Down
4 changes: 2 additions & 2 deletions docs/foundation-module/9-tp.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h1><a href="../index.html">
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">colouring_state</span><span class="plain-syntax"> = </span><span class="constant-syntax">PLAIN_COLOUR</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">painter_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Painter::reset_syntax_colouring</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Painter::reset_syntax_colouring</span></span>:<br/><a href="9-tp.html#SP7">&#167;7</a><br/>Inform-Flavoured Markdown - <a href="5-im.html#SP2_2_2">&#167;2.2.2</a>, <a href="5-im.html#SP2_2_4">&#167;2.2.4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">programming_language</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pl</span><span class="plain-syntax">) {</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Painter::reset_syntax_colouring</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Painter::reset_syntax_colouring</span></span>:<br/><a href="9-tp.html#SP7">&#167;7</a><br/>Inform-Flavoured Markdown - <a href="5-im.html#SP3_2_2">&#167;3.2.2</a>, <a href="5-im.html#SP3_2_4">&#167;3.2.4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">programming_language</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pl</span><span class="plain-syntax">) {</span>
<span class="plain-syntax"> </span><span class="identifier-syntax">colouring_state</span><span class="plain-syntax"> = </span><span class="constant-syntax">PLAIN_COLOUR</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="identifier-syntax">painter_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
Expand All @@ -93,7 +93,7 @@ <h1><a href="../index.html">
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Painter::syntax_colour</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Painter::syntax_colour</span></span>:<br/><a href="9-tp.html#SP7">&#167;7</a><br/>Inform-Flavoured Markdown - <a href="5-im.html#SP2_2_2">&#167;2.2.2</a>, <a href="5-im.html#SP2_2_4_1">&#167;2.2.4.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">programming_language</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pl</span><span class="plain-syntax">,</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Painter::syntax_colour</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Painter::syntax_colour</span></span>:<br/><a href="9-tp.html#SP7">&#167;7</a><br/>Inform-Flavoured Markdown - <a href="5-im.html#SP3_2_2">&#167;3.2.2</a>, <a href="5-im.html#SP3_2_4_1">&#167;3.2.4.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">programming_language</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pl</span><span class="plain-syntax">,</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">hash_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">HT</span><span class="plain-syntax">, </span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">matter</span><span class="plain-syntax">, </span><span class="reserved-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">colouring</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">with_comments</span><span class="plain-syntax">) {</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">to</span><span class="plain-syntax"> = </span><a href="4-sm.html#SP8" class="function-link"><span class="function-syntax">Str::len</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">matter</span><span class="plain-syntax">) - </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">with_comments</span><span class="plain-syntax">) {</span>
Expand Down
Binary file modified docs/goldbach/goldbach.pdf
Binary file not shown.
83 changes: 65 additions & 18 deletions foundation-module/Chapter 5/Inform-Flavoured Markdown.w
Original file line number Diff line number Diff line change
Expand Up @@ -572,38 +572,85 @@ void InformFlavouredMarkdown::pbiapi_r(markdown_item *md) {
@h Phrase definition boxes.

@e PHRASE_DEFN_BOXES_MARKDOWNFEATURE
@e PHRASE_HEADER_MIT

@<Add the phrase defn boxes feature@> =
markdown_feature *pd = MarkdownVariations::new_feature(I"phrase defn boxes",
PHRASE_DEFN_BOXES_MARKDOWNFEATURE);
METHOD_ADD(pd, POST_PHASE_I_MARKDOWN_MTID,
InformFlavouredMarkdown::PD_intervene_after_Phase_I);
METHOD_ADD(pd, RENDER_MARKDOWN_MTID, InformFlavouredMarkdown::PD_render);
MarkdownVariations::add_feature(Inform_flavoured_Markdown, PHRASE_DEFN_BOXES_MARKDOWNFEATURE);
Markdown::new_leaf_block_type(PHRASE_HEADER_MIT, I"PHRASE_HEADER");

@ =
int InformFlavouredMarkdown::PD_render(markdown_feature *feature, text_stream *OUT,
markdown_item *md, int mode) {
void InformFlavouredMarkdown::PD_intervene_after_Phase_I(markdown_feature *feature,
markdown_item *md, md_links_dictionary *link_references) {
if (md->type == BLOCK_QUOTE_MIT) {
if ((md->down) && (md->down->type == PARAGRAPH_MIT)) {
match_results mr = Regexp::create_mr();
if ((Regexp::match(&mr, md->down->stashed, L"phrase: *{(%c*?)} *(%c+?)\n(%c*)")) ||
(Regexp::match(&mr, md->down->stashed, L"(phrase): *(%c+?)\n(%c*)"))) {
HTML_OPEN_WITH("div", "class=\"definition\"");
HTML_OPEN_WITH("p", "class=\"defnprototype\"");
WRITE("%S", mr.exp[1]);
HTML_CLOSE("p");
HTML_TAG("br");
markdown_item *remainder =
Markdown::parse_inline_extended(mr.exp[2], InformFlavouredMarkdown::variation());
Markdown::render_extended(OUT, remainder, InformFlavouredMarkdown::variation());
for (markdown_item *ch = md->down->next; ch; ch = ch->next)
Markdown::render_extended(OUT, ch, InformFlavouredMarkdown::variation());
HTML_CLOSE("div");
Regexp::dispose_of(&mr);
return TRUE;
if ((Regexp::match(&mr, md->down->stashed, L"phrase: *%{(%c*?)%} *(%c+?)")) ||
(Regexp::match(&mr, md->down->stashed, L"(phrase): *(%c+?)"))) {
markdown_item *join_to = NULL;
TEMPORARY_TEXT(phrase)
for (int i=0; i<Str::len(mr.exp[1]); i++) {
if (Str::get_at(mr.exp[1], i) == '&') {
@<Insert a phrase header here@>;
Str::clear(phrase);
} else {
PUT_TO(phrase, Str::get_at(mr.exp[1], i));
}
}
@<Insert a phrase header here@>;
DISCARD_TEXT(phrase)
}
Regexp::dispose_of(&mr);
}
}
for (markdown_item *ch = md->down; ch; ch=ch->next) {
InformFlavouredMarkdown::PD_intervene_after_Phase_I(feature, ch, link_references);
}
}

@<Insert a phrase header here@> =
Str::trim_white_space(phrase);
if (Str::len(phrase) > 0) {
markdown_item *ph = Markdown::new_item(PHRASE_HEADER_MIT);
ph->stashed = Str::duplicate(phrase);
if (join_to == NULL) { ph->next = md->down->next; md->down = ph; }
else { ph->next = join_to->next; join_to->next = ph; }
join_to = ph;

markdown_item *im = Markdown::new_item(INDEX_MARKER_MIT);
im->stashed = Str::new();
text_stream *category = I"+to+";
if (Str::begins_with(phrase, I"if ")) category = I"+toif+";
if (Str::begins_with(phrase, I"say ")) category = I"+tosay+";
WRITE_TO(im->stashed, "%S%S", category, phrase);
if (Str::get_last_char(im->stashed) == ':')
Str::delete_last_character(im->stashed);
im->details = 1;
im->next = join_to->next; join_to->next = im;
join_to = im;
}

@

=
int InformFlavouredMarkdown::PD_render(markdown_feature *feature, text_stream *OUT,
markdown_item *md, int mode) {
if ((md->type == BLOCK_QUOTE_MIT) && (md->down) && (md->down->type == PHRASE_HEADER_MIT)) {
HTML_OPEN_WITH("div", "class=\"definition\"");
for (markdown_item *ch = md->down; ch; ch = ch->next)
Markdown::render_extended(OUT, ch, InformFlavouredMarkdown::variation());
HTML_CLOSE("div");
return TRUE;
}
if (md->type == PHRASE_HEADER_MIT) {
HTML_OPEN_WITH("p", "class=\"defnprototype\"");
MDRenderer::stream(OUT, md->stashed, mode);
HTML_CLOSE("p");
return TRUE;
}
return FALSE;
}

Expand Down
1 change: 1 addition & 0 deletions foundation-module/Chapter 5/Markdown Phase II.w
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ notation, also used by indoc.

@<Insert an index item@> =
int name_inversion = FALSE;

if (Str::get_first_char(lemma) == '@') {
Str::delete_first_character(lemma);
name_inversion = TRUE;
Expand Down
8 changes: 8 additions & 0 deletions foundation-module/Chapter 5/Markdown Rendering.w
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,14 @@ void MDRenderer::slice(OUTPUT_STREAM, markdown_item *md, int mode) {
}
}

@ Alternatively:

=
void MDRenderer::stream(OUTPUT_STREAM, text_stream *stream, int mode) {
for (int i=0; i<Str::len(stream); i++)
MDRenderer::char(OUT, Str::get_at(stream, i), mode);
}

@ Down at the individual character level, there are three mutually exclusive
ways to render characters: they all agree on ASCII digits and letters.

Expand Down
1 change: 1 addition & 0 deletions foundation-module/Chapter 5/Markdown.w
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ markdown_item *Markdown::deep_copy(markdown_item *md) {
}
copied->from = md->from;
copied->to = md->to;
copied->stashed = md->stashed;
copied->copied_from = md;
for (markdown_item *c = md->down; c; c = c->next)
Markdown::add_to(Markdown::deep_copy(c), copied);
Expand Down

0 comments on commit d0e16e0

Please sign in to comment.