Remove std.stdio import and printing of unexpected tokens

This commit is contained in:
Josh Holtrop 2023-07-17 21:57:31 -04:00
parent d39fa61af0
commit c4bcb465da
2 changed files with 19 additions and 13 deletions

View File

@ -3,12 +3,10 @@
*
* This file is generated by Propane.
*/
<% if @grammar.modulename %>
module <%= @grammar.modulename %>;
module <%= @grammar.modulename %>;
<% end %>
import std.stdio;
/**************************************************************************
* User code blocks
@ -913,16 +911,6 @@ public size_t <%= @grammar.prefix %>parse(<%= @grammar.prefix %>context_t * cont
continue;
}
/* Error, unexpected token. */
write("Unexpected token ");
if (token != INVALID_TOKEN_ID)
{
writeln(<%= @grammar.prefix %>token_names[token]);
}
else
{
writeln("{other}");
}
/* A token was successfully lexed, so the input text position was
* advanced. However, this is an unexpected token, so we want to reset
* the context text position to point to the token rather than the text

View File

@ -228,6 +228,9 @@ EOF
it "executes user code when matching lexer token" do
write_grammar <<EOF
<<
import std.stdio;
>>
token abc <<
writeln("abc!");
>>
@ -251,6 +254,9 @@ EOF
it "supports a pattern statement" do
write_grammar <<EOF
<<
import std.stdio;
>>
token abc;
/def/ <<
writeln("def!");
@ -272,6 +278,9 @@ EOF
it "supports returning tokens from pattern code blocks" do
write_grammar <<EOF
<<
import std.stdio;
>>
token abc;
/def/ <<
writeln("def!");
@ -295,6 +304,9 @@ EOF
it "supports lexer modes" do
write_grammar <<EOF
<<
import std.stdio;
>>
token abc;
token def;
tokenid string;
@ -328,6 +340,9 @@ EOF
it "executes user code associated with a parser rule" do
write_grammar <<EOF
<<
import std.stdio;
>>
token a;
token b;
Start -> A B <<
@ -393,6 +408,9 @@ EOF
it "provides matched text to user code blocks" do
write_grammar <<EOF
<<
import std.stdio;
>>
token id /[a-zA-Z_][a-zA-Z0-9_]*/ <<
writeln("Matched token is ", match);
>>