Reorganize compiler directory
This commit is contained in:
parent
023a0c4f70
commit
92cec5758f
51 changed files with 630 additions and 624 deletions
59
spec/compiler/prepare_grammar_spec.cpp
Normal file
59
spec/compiler/prepare_grammar_spec.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include "spec_helper.h"
|
||||
#include "prepare_grammar/perform.h"
|
||||
|
||||
START_TEST
|
||||
|
||||
using namespace tree_sitter::rules;
|
||||
using tree_sitter::prepare_grammar::perform;
|
||||
|
||||
describe("preparing a grammar", []() {
|
||||
it("extracts character-based subtrees into a separate grammar", [&]() {
|
||||
pair<Grammar, Grammar> result = perform(Grammar({
|
||||
{ "rule1", seq({
|
||||
character('a'),
|
||||
character('b'),
|
||||
seq({
|
||||
sym("rule2"),
|
||||
sym("rule3") }),
|
||||
seq({
|
||||
character('a'),
|
||||
character('b') }) }) }
|
||||
}));
|
||||
|
||||
AssertThat(result.first, Equals(Grammar({
|
||||
{ "rule1", seq({
|
||||
sym("1"),
|
||||
seq({
|
||||
sym("rule2"),
|
||||
sym("rule3") }),
|
||||
sym("1") }) }
|
||||
})));
|
||||
|
||||
AssertThat(result.second, Equals(Grammar("", {
|
||||
{ "1", rules::seq({
|
||||
rules::character('a'),
|
||||
rules::character('b') }) }
|
||||
})));
|
||||
});
|
||||
|
||||
it("turns entire rules into tokens when they contain no symbols", [&]() {
|
||||
auto result = perform(Grammar({
|
||||
{ "rule1", sym("rule2") },
|
||||
{ "rule2", seq({
|
||||
character('a'),
|
||||
character('b') }) }
|
||||
}));
|
||||
|
||||
AssertThat(result.first, Equals(Grammar({
|
||||
{ "rule1", sym("rule2") }
|
||||
})));
|
||||
|
||||
AssertThat(result.second, Equals(Grammar("", {
|
||||
{ "rule2", seq({
|
||||
character('a'),
|
||||
character('b') }) }
|
||||
})));
|
||||
});
|
||||
});
|
||||
|
||||
END_TEST
|
||||
Loading…
Add table
Add a link
Reference in a new issue