Add $token() user code block expansion

This commit is contained in:
josh committed 2022-10-02 10:43:47 -04:00
1 parent 43fb74fe4b
commit 66d654b6b9
4 files changed
+51 -1

No files matched your search

+23
View File
@@ -169,4 +169,27 @@ EOF
"pass2",
])
end
it "supports returning tokens from pattern code blocks" do
write_grammar <<EOF
token abc;
/def/ <<
writeln("def!");
>>
/ghi/ <<
writeln("ghi!");
return $token(abc);
>>
Start -> abc;
EOF
build_parser
compile("spec/test_return_token_from_pattern.d")
results = run
expect(results.status).to eq 0
verify_lines(results.stdout, [
"def!",
"ghi!",
"def!",
])
end
end
+14
View File
@@ -0,0 +1,14 @@
import testparser;
import std.stdio;
int main()
{
return 0;
}
unittest
{
string input = "defghidef";
auto parser = new Testparser.Parser(cast(const(ubyte) *)input.ptr, input.length);
assert(parser.parse() == true);
}