Extract public compiler API into its own header file
This commit is contained in:
parent
0b4e1c8d0d
commit
9e2dc14182
53 changed files with 466 additions and 409 deletions
|
|
@ -9,19 +9,19 @@ using prepare_grammar::perform;
|
|||
describe("preparing a grammar", []() {
|
||||
describe("extracting tokens", []() {
|
||||
it("moves sub-rules that don't contain symbols into a separate 'lexical' grammar", [&]() {
|
||||
pair<Grammar, Grammar> result = perform(Grammar({
|
||||
pair<Grammar, Grammar> result = perform(Grammar("rule1", {
|
||||
{ "rule1", seq({
|
||||
character('a'),
|
||||
character('b'),
|
||||
character({ 'a' }),
|
||||
character({ 'b' }),
|
||||
seq({
|
||||
sym("rule2"),
|
||||
sym("rule3") }),
|
||||
seq({
|
||||
character('a'),
|
||||
character('b') }) }) }
|
||||
character({ 'a' }),
|
||||
character({ 'b' }) }) }) }
|
||||
}));
|
||||
|
||||
AssertThat(result.first, Equals(Grammar({
|
||||
AssertThat(result.first, Equals(Grammar("rule1", {
|
||||
{ "rule1", seq({
|
||||
aux_sym("token1"),
|
||||
seq({
|
||||
|
|
@ -32,27 +32,27 @@ describe("preparing a grammar", []() {
|
|||
|
||||
AssertThat(result.second, Equals(Grammar("", map<const string, const rule_ptr>(), {
|
||||
{ "token1", rules::seq({
|
||||
rules::character('a'),
|
||||
rules::character('b') }) },
|
||||
rules::character({ 'a' }),
|
||||
rules::character({ 'b' }) }) },
|
||||
})));
|
||||
});
|
||||
|
||||
it("moves entire rules into the lexical grammar when possible, preserving their names", [&]() {
|
||||
auto result = perform(Grammar({
|
||||
auto result = perform(Grammar("rule1", {
|
||||
{ "rule1", sym("rule2") },
|
||||
{ "rule2", seq({
|
||||
character('a'),
|
||||
character('b') }) }
|
||||
character({ 'a' }),
|
||||
character({ 'b' }) }) }
|
||||
}));
|
||||
|
||||
AssertThat(result.first, Equals(Grammar({
|
||||
AssertThat(result.first, Equals(Grammar("rule1", {
|
||||
{ "rule1", sym("rule2") }
|
||||
})));
|
||||
|
||||
AssertThat(result.second, Equals(Grammar("", {
|
||||
{ "rule2", seq({
|
||||
character('a'),
|
||||
character('b') }) },
|
||||
character({ 'a' }),
|
||||
character({ 'b' }) }) },
|
||||
})));
|
||||
});
|
||||
|
||||
|
|
@ -60,8 +60,8 @@ describe("preparing a grammar", []() {
|
|||
auto result = perform(Grammar("rule1", map<const string, const rule_ptr>(), {
|
||||
{ "rule1", sym("rule2") },
|
||||
{ "rule2", seq({
|
||||
character('a'),
|
||||
character('b') }) }
|
||||
character({ 'a' }),
|
||||
character({ 'b' }) }) }
|
||||
}));
|
||||
|
||||
AssertThat(result.first, Equals(Grammar("rule1", map<const string, const rule_ptr>(), {
|
||||
|
|
@ -70,13 +70,13 @@ describe("preparing a grammar", []() {
|
|||
|
||||
AssertThat(result.second, Equals(Grammar("", map<const string, const rule_ptr>(), {
|
||||
{ "rule2", seq({
|
||||
character('a'),
|
||||
character('b') }) },
|
||||
character({ 'a' }),
|
||||
character({ 'b' }) }) },
|
||||
})));
|
||||
});
|
||||
|
||||
it("does not extract blanks into tokens", [&]() {
|
||||
pair<Grammar, Grammar> result = perform(Grammar({
|
||||
pair<Grammar, Grammar> result = perform(Grammar("rule1", {
|
||||
{ "rule1", choice({ sym("rule2"), blank() }) },
|
||||
}));
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ describe("preparing a grammar", []() {
|
|||
|
||||
describe("expanding repeats", []() {
|
||||
it("replaces repeat rules with pairs of recursive rules", [&]() {
|
||||
Grammar result = perform(Grammar({
|
||||
Grammar result = perform(Grammar("rule1", {
|
||||
{ "rule1", seq({
|
||||
sym("x"),
|
||||
repeat(seq({ sym("a"), sym("b") })),
|
||||
|
|
@ -116,7 +116,7 @@ describe("preparing a grammar", []() {
|
|||
});
|
||||
|
||||
it("does not replace repeat rules that can be moved into the lexical grammar", [&]() {
|
||||
pair<Grammar, Grammar> result = perform(Grammar({
|
||||
pair<Grammar, Grammar> result = perform(Grammar("rule1", {
|
||||
{ "rule1", seq({
|
||||
sym("x"),
|
||||
repeat(seq({ str("a"), str("b") })),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue