Execute rule user code blocks when reducing the rule
This commit is contained in:
1 parent
74beaf7ed8
commit
727c8cd1ea
4 files changed
+90
-13
No files matched your search
@@ -19,6 +19,8 @@ describe Propane do
|
||||
Results = Struct.new(:stdout, :stderr, :status)
|
||||
def run
|
||||
stdout, stderr, status = Open3.capture3("spec/run/testparser")
|
||||
File.binwrite("spec/run/.stderr", stderr)
|
||||
File.binwrite("spec/run/.stdout", stdout)
|
||||
Results.new(stdout, stderr, status)
|
||||
end
|
||||
|
||||
@@ -225,4 +227,29 @@ EOF
|
||||
"pass2",
|
||||
])
|
||||
end
|
||||
|
||||
it "executes user code associated with a parser rule" do
|
||||
write_grammar <<EOF
|
||||
token a;
|
||||
token b;
|
||||
Start -> A B <<
|
||||
writeln("Start!");
|
||||
>>
|
||||
A -> a <<
|
||||
writeln("A!");
|
||||
>>
|
||||
B -> b <<
|
||||
writeln("B!");
|
||||
>>
|
||||
EOF
|
||||
build_parser
|
||||
compile("spec/test_parser_rule_user_code.d")
|
||||
results = run
|
||||
expect(results.status).to eq 0
|
||||
verify_lines(results.stdout, [
|
||||
"A!",
|
||||
"B!",
|
||||
"Start!",
|
||||
])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
import testparser;
|
||||
import std.stdio;
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
string input = "ab";
|
||||
auto parser = new Testparser.Parser(cast(const(ubyte) *)input.ptr, input.length);
|
||||
assert(parser.parse() == true);
|
||||
}
|
||||
Reference in new issue
Block a user