Get test_lexer_unknown_character working for C

This commit is contained in:
josh committed 2023-08-20 18:43:33 -04:00
1 parent 36213d9e9c
commit aef5367378
3 files changed
+45 -3

No files matched your search

+20 -1
View File
@@ -98,7 +98,25 @@ EOF
end
it "detects a lexer error when an unknown character is seen" do
write_grammar <<EOF
case language
when "c"
write_grammar <<EOF
ptype int;
token int /\\d+/ <<
int v = 0;
for (size_t i = 0u; i < match_length; i++)
{
v *= 10;
v += (match[i] - '0');
}
$$ = v;
>>
Start -> int <<
$$ = $1;
>>
EOF
when "d"
write_grammar <<EOF
ptype int;
token int /\\d+/ <<
int v;
@@ -113,6 +131,7 @@ Start -> int <<
$$ = $1;
>>
EOF
end
build_parser(language: language)
compile("spec/test_lexer_unknown_character.#{language}", language: language)
results = run
+18
View File
@@ -0,0 +1,18 @@
#include "testparser.h"
#include <assert.h>
#include <string.h>
int main()
{
char const * input = "x";
p_context_t context;
p_context_init(&context, (uint8_t const *)input, strlen(input));
assert(p_parse(&context) == P_UNEXPECTED_INPUT);
input = "123";
p_context_init(&context, (uint8_t const *)input, strlen(input));
assert(p_parse(&context) == P_SUCCESS);
assert(p_result(&context) == 123u);
return 0;
}