2014-01-24 18:25:56 -08:00
|
|
|
#include "spec_helper.h"
|
|
|
|
|
#include "prepare_grammar/expand_repeats.h"
|
|
|
|
|
|
|
|
|
|
START_TEST
|
|
|
|
|
|
|
|
|
|
using prepare_grammar::expand_repeats;
|
|
|
|
|
using namespace rules;
|
|
|
|
|
|
|
|
|
|
describe("expanding repeat rules in a grammar", []() {
|
|
|
|
|
it("replaces repeat rules with pairs of recursive rules", [&]() {
|
|
|
|
|
Grammar result = expand_repeats(Grammar({
|
|
|
|
|
{ "rule1", seq({
|
|
|
|
|
sym("x"),
|
|
|
|
|
repeat(seq({ sym("a"), sym("b") })),
|
|
|
|
|
sym("y")
|
|
|
|
|
}) },
|
|
|
|
|
}));
|
|
|
|
|
|
2014-01-28 13:27:30 -08:00
|
|
|
AssertThat(result, Equals(Grammar("rule1", {
|
2014-01-24 18:25:56 -08:00
|
|
|
{ "rule1", seq({
|
|
|
|
|
sym("x"),
|
2014-01-28 13:27:30 -08:00
|
|
|
aux_sym("repeat_helper1"),
|
2014-01-24 18:25:56 -08:00
|
|
|
sym("y")
|
|
|
|
|
}) },
|
2014-01-28 13:27:30 -08:00
|
|
|
}, {
|
2014-01-24 18:25:56 -08:00
|
|
|
{ "repeat_helper1", seq({
|
|
|
|
|
seq({ sym("a"), sym("b") }),
|
|
|
|
|
choice({
|
2014-01-28 13:27:30 -08:00
|
|
|
aux_sym("repeat_helper1") ,
|
2014-01-24 18:25:56 -08:00
|
|
|
blank()
|
|
|
|
|
}),
|
|
|
|
|
}) }
|
|
|
|
|
})));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
END_TEST
|