Library: cover some definition errors

This commit is contained in:
Fischlurch 2024-03-25 00:38:35 +01:00
parent 8d432a6e0b
commit dd67b9f97b
3 changed files with 61 additions and 13 deletions

View file

@ -186,11 +186,15 @@ namespace lib {
if ("for" == mat[4])
tag.syntax = mat[3].matched? TagSyntax::END_FOR : TagSyntax::FOR;
else
throw error::Logic(_Fmt{"unexpected keyword \"%s\""} % mat[4]);
throw error::Logic{_Fmt{"unexpected keyword \"%s\""} % mat[4]};
}
else
if (mat[2].matched)
tag.syntax = TagSyntax::ELSE;
else
if ("end" == mat[5])
throw error::Invalid{_Fmt{"unqualified \"end\" without logic-keyword:"
" ...%s${end |↯|}"} % tag.lead};
else
tag.syntax = TagSyntax::KEYID;
}
@ -358,6 +362,13 @@ namespace lib {
auto abbrev = [&](auto s){ return s.length()<16? s : s.substr(s.length()-15); }; // (shorten lead display to 15 chars)
// Syntax / consistency checks...
auto __requireKey = [&](string descr)
{
if (isnil (parseIter->key))
throw error::Invalid{_Fmt{"Tag without key: ...%s${%s |↯|}"}
% abbrev(lead()) % descr
};
};
auto __checkBalanced = [&](Clause c)
{
if (not scopeMatch(c))
@ -400,10 +411,12 @@ namespace lib {
addLead();
break;
case TagSyntax::KEYID:
__requireKey("<placeholder>");
addLead();
addCode(KEY);
break;
case TagSyntax::IF:
__requireKey("if <conditional>");
addLead();
openScope(IF);
addCode(COND);
@ -418,6 +431,7 @@ namespace lib {
closeScope();
break;
case TagSyntax::FOR:
__requireKey("for <data-id>");
addLead();
openScope(FOR);
addCode(ITER);

View file

@ -317,6 +317,38 @@ for} tail...
CHECK (actions[24].code == TextTemplate::Code::TEXT); // a final static segment after the last active tag
CHECK (actions[24].val == " tail...\n"_expect);
CHECK (actions[24].refIDX == 0);
VERIFY_FAIL ("TextTemplate spec without active placeholders"
, TextTemplate::compile("horror boredom"));
VERIFY_FAIL ("Tag without key: ...horror ${<placeholder> |↯|}"
, TextTemplate::compile("horror ${ } vacui"));
VERIFY_FAIL (" ...horror ${if <conditional> |↯|}"
, TextTemplate::compile("horror ${if} late"));
VERIFY_FAIL (" ...horror ${for <data-id> |↯|}"
, TextTemplate::compile("horror ${for} all"));
VERIFY_FAIL ("Misplaced ...horror |↯|${else}"
, TextTemplate::compile("horror ${else} deaf"));
VERIFY_FAIL ("unqualified \"end\" without logic-keyword"
, TextTemplate::compile("horror without ${end}"));
VERIFY_FAIL ("Unbalanced Logic: expect ${end ?? } -- found ...horror ${end |↯|for }"
, TextTemplate::compile("horror ${end for} ever"));
VERIFY_FAIL ("Unbalanced Logic: expect ${end for free} -- found ...${end |↯|if }"
, TextTemplate::compile("horror ${for free}${end if}"));
VERIFY_FAIL ("Unbalanced Logic: expect ${end for free} -- found ... yet ${end |↯|for me}"
, TextTemplate::compile("${if wee} horror ${for free} yet ${end for me}"));
VERIFY_FAIL ("Conflicting ... precipitous ${else} ⟷ ... callous |↯|${else}"
, TextTemplate::compile("${if smarmy} precipitous ${else} callous ${else} horror"));
}

View file

@ -113257,16 +113257,16 @@ std::cout &lt;&lt; tmpl.render({&quot;what&quot;, &quot;World&quot;}) &lt;&lt; s
<icon BUILTIN="idea"/>
</node>
</node>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1711237221184" ID="ID_838370074" MODIFIED="1711237227436" TEXT="Fehlerbehandlung">
<icon BUILTIN="flag-pink"/>
<node COLOR="#338800" CREATED="1711237221184" ID="ID_838370074" LINK="#ID_428622943" MODIFIED="1711322816722" TEXT="Fehlerbehandlung">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1711237228696" ID="ID_1920021000" MODIFIED="1711312079978" TEXT="unbalancierte Konstrukte">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711237235134" ID="ID_889276068" MODIFIED="1711237271250" TEXT="komplett leere Tags">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1711237235134" ID="ID_889276068" MODIFIED="1711322735840" TEXT="komplett leere Tags">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1711237256363" ID="ID_522815331" MODIFIED="1711237271251" TEXT="fehlender Logic-Key">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1711237256363" ID="ID_522815331" MODIFIED="1711322801168" TEXT="fehlender Logic-Key">
<icon BUILTIN="button_ok"/>
</node>
</node>
</node>
@ -113392,11 +113392,11 @@ std::cout &lt;&lt; tmpl.render({&quot;what&quot;, &quot;World&quot;}) &lt;&lt; s
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1710793091784" ID="ID_1970381008" MODIFIED="1710811906348" TEXT="TextTemplate_test">
<icon BUILTIN="pencil"/>
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1710793387393" ID="ID_413372443" MODIFIED="1710811903746" TEXT="simpeUsage">
<icon BUILTIN="hourglass"/>
<node COLOR="#338800" CREATED="1710793387393" ID="ID_413372443" MODIFIED="1711322713365" TEXT="simpeUsage">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1711237120869" ID="ID_1535361808" MODIFIED="1711237133639" TEXT="verify_parsing">
<icon BUILTIN="pencil"/>
<node COLOR="#338800" CREATED="1711237120869" ID="ID_1535361808" MODIFIED="1711322709119" TEXT="verify_parsing">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1711237141859" ID="ID_798155590" MODIFIED="1711237176132" TEXT="Basis-Syntax">
<icon BUILTIN="button_ok"/>
</node>
@ -113406,8 +113406,10 @@ std::cout &lt;&lt; tmpl.render({&quot;what&quot;, &quot;World&quot;}) &lt;&lt; s
<node COLOR="#338800" CREATED="1711237159112" ID="ID_292718692" MODIFIED="1711312317352" TEXT="Compilation in Action-Sequenz">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1711237177758" ID="ID_428622943" MODIFIED="1711237184293" TEXT="Parse-Fehler">
<icon BUILTIN="flag-pink"/>
<node COLOR="#338800" CREATED="1711237177758" ID="ID_428622943" MODIFIED="1711322702127" TEXT="Parse-Fehler">
<icon BUILTIN="button_ok"/>
<node COLOR="#435e98" CREATED="1711322819257" ID="ID_566053113" MODIFIED="1711322849606" TEXT="habe mal F&#xe4;lle f&#xfc;r alle bekannten Exceptions konstruiert"/>
<node COLOR="#435e98" CREATED="1711322831209" ID="ID_1835045684" MODIFIED="1711322849605" TEXT="auch f&#xfc;r leere Tags"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710793507744" ID="ID_1535977723" MODIFIED="1710793518661" TEXT="verify_instantiation">