Return a lexer error on unexpected input - close #3
This commit is contained in:
parent
ecef933255
commit
83a4037740
@ -81,6 +81,29 @@ EOF
|
||||
expect(results.status).to eq 0
|
||||
end
|
||||
|
||||
it "detects a lexer error when an unknown character is seen" do
|
||||
write_grammar <<EOF
|
||||
ptype int;
|
||||
token int /\\d+/ <<
|
||||
int v;
|
||||
foreach (c; match)
|
||||
{
|
||||
v *= 10;
|
||||
v += (c - '0');
|
||||
}
|
||||
$$ = v;
|
||||
>>
|
||||
Start -> int <<
|
||||
$$ = $1;
|
||||
>>
|
||||
EOF
|
||||
build_parser
|
||||
compile("spec/test_lexer_unknown_character.d")
|
||||
results = run
|
||||
expect(results.stderr).to eq ""
|
||||
expect(results.status).to eq 0
|
||||
end
|
||||
|
||||
it "generates a parser" do
|
||||
write_grammar <<EOF
|
||||
token plus /\\+/;
|
||||
|
19
spec/test_lexer_unknown_character.d
Normal file
19
spec/test_lexer_unknown_character.d
Normal file
@ -0,0 +1,19 @@
|
||||
import testparser;
|
||||
import std.stdio;
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
string input = `x`;
|
||||
auto parser = new Testparser.Parser(input);
|
||||
assert(parser.parse() == Testparser.P_UNEXPECTED_INPUT);
|
||||
|
||||
input = `123`;
|
||||
parser = new Testparser.Parser(input);
|
||||
assert(parser.parse() == Testparser.P_SUCCESS);
|
||||
assert(parser.result == 123u);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user