diff --git a/spec/compiler/build_tables/perform_spec.cpp b/spec/compiler/build_tables/perform_spec.cpp index 1c9e22b2..37232b89 100644 --- a/spec/compiler/build_tables/perform_spec.cpp +++ b/spec/compiler/build_tables/perform_spec.cpp @@ -2,7 +2,8 @@ #include #include "build_tables/perform.h" -using namespace tree_sitter::rules; +using build_tables::perform; +using namespace rules; typedef unordered_set parse_actions; typedef unordered_set lex_actions; @@ -35,7 +36,7 @@ describe("building parse and lex tables", []() { { "right-paren", str(")") } }); - pair tables = build_tables::perform(grammar, lex_grammar); + pair tables = perform(grammar, lex_grammar); ParseTable table = tables.first; LexTable lex_table = tables.second; diff --git a/spec/compiler/build_tables/rule_transitions_spec.cpp b/spec/compiler/build_tables/rule_transitions_spec.cpp index e9ec1baa..d5393bb8 100644 --- a/spec/compiler/build_tables/rule_transitions_spec.cpp +++ b/spec/compiler/build_tables/rule_transitions_spec.cpp @@ -2,125 +2,126 @@ #include "rule_transitions.h" using build_tables::rule_transitions; +using namespace rules; START_TEST describe("rule transitions", []() { - rules::rule_ptr symbol1 = rules::sym("1"); - rules::rule_ptr symbol2 = rules::sym("2"); - rules::rule_ptr symbol3 = rules::sym("3"); - rules::rule_ptr symbol4 = rules::sym("4"); - rules::rule_ptr char1 = rules::character('a'); + rule_ptr symbol1 = sym("1"); + rule_ptr symbol2 = sym("2"); + rule_ptr symbol3 = sym("3"); + rule_ptr symbol4 = sym("4"); + rule_ptr char1 = character('a'); it("handles symbols", [&]() { AssertThat( rule_transitions(symbol1), - Equals(transition_map({ - { symbol1, rules::blank() } + Equals(transition_map({ + { symbol1, blank() } }))); }); it("handles characters", [&]() { AssertThat( rule_transitions(char1), - Equals(transition_map({ - { char1, rules::blank() } + Equals(transition_map({ + { char1, blank() } }))); }); it("handles character classes", [&]() { - auto rule = rules::character(CharClassDigit); + auto rule = character(CharClassDigit); AssertThat( rule_transitions(rule), - Equals(transition_map({ - { rule, rules::blank() } + Equals(transition_map({ + { rule, blank() } }))); }); it("handles choices", [&]() { AssertThat( - rule_transitions(rules::choice({ symbol1, symbol2 })), - Equals(transition_map({ - { symbol1, rules::blank() }, - { symbol2, rules::blank() } + rule_transitions(choice({ symbol1, symbol2 })), + Equals(transition_map({ + { symbol1, blank() }, + { symbol2, blank() } }))); }); it("handles sequences", [&]() { AssertThat( - rule_transitions(rules::seq({ symbol1, symbol2 })), - Equals(transition_map({ + rule_transitions(seq({ symbol1, symbol2 })), + Equals(transition_map({ { symbol1, symbol2 } }))); }); it("handles_long_sequences", [&]() { AssertThat( - rule_transitions(rules::seq({ + rule_transitions(seq({ symbol1, symbol2, symbol3, symbol4 })), - Equals(transition_map({ - { symbol1, rules::seq({ symbol2, symbol3, symbol4 }) } + Equals(transition_map({ + { symbol1, seq({ symbol2, symbol3, symbol4 }) } }))); }); it("handles choices with common starting symbols", [&]() { AssertThat( rule_transitions( - rules::choice({ - rules::seq({ symbol1, symbol2 }), - rules::seq({ symbol1, symbol3 }) })), - Equals(transition_map({ - { symbol1, rules::choice({ symbol2, symbol3 }) } + choice({ + seq({ symbol1, symbol2 }), + seq({ symbol1, symbol3 }) })), + Equals(transition_map({ + { symbol1, choice({ symbol2, symbol3 }) } }))); }); it("handles strings", [&]() { AssertThat( - rule_transitions(rules::str("bad")), - Equals(transition_map({ - { rules::character('b'), rules::seq({ rules::character('a'), rules::character('d') }) + rule_transitions(str("bad")), + Equals(transition_map({ + { character('b'), seq({ character('a'), character('d') }) } }))); }); it("handles patterns", [&]() { AssertThat( - rule_transitions(rules::pattern("a|b")), - Equals(transition_map({ - { rules::character('a'), rules::blank() }, - { rules::character('b'), rules::blank() } + rule_transitions(pattern("a|b")), + Equals(transition_map({ + { character('a'), blank() }, + { character('b'), blank() } }))); }); it("handles repeats", [&]() { - rules::rule_ptr repeat = rules::repeat(rules::str("ab")); + rule_ptr rule = repeat(str("ab")); AssertThat( - rule_transitions(repeat), - Equals(transition_map({ + rule_transitions(rule), + Equals(transition_map({ { - rules::character('a'), - rules::seq({ - rules::character('b'), - rules::choice({ - repeat, - rules::blank() + character('a'), + seq({ + character('b'), + choice({ + rule, + blank() }) }) }}))); - repeat = rules::repeat(rules::str("a")); + rule = repeat(str("a")); AssertThat( - rule_transitions(repeat), - Equals(transition_map({ + rule_transitions(rule), + Equals(transition_map({ { - rules::character('a'), - rules::choice({ - repeat, - rules::blank() + character('a'), + choice({ + rule, + blank() }) }}))); }); diff --git a/spec/compiler/prepare_grammar_spec.cpp b/spec/compiler/prepare_grammar_spec.cpp index 131c6867..9b6bcbfc 100644 --- a/spec/compiler/prepare_grammar_spec.cpp +++ b/spec/compiler/prepare_grammar_spec.cpp @@ -3,8 +3,8 @@ START_TEST -using namespace tree_sitter::rules; -using tree_sitter::prepare_grammar::perform; +using prepare_grammar::perform; +using namespace rules; describe("preparing a grammar", []() { it("extracts character-based subtrees into a separate grammar", [&]() { diff --git a/spec/compiler/rules/pattern_spec.cpp b/spec/compiler/rules/pattern_spec.cpp index 853c02c7..dba04ece 100644 --- a/spec/compiler/rules/pattern_spec.cpp +++ b/spec/compiler/rules/pattern_spec.cpp @@ -1,7 +1,7 @@ #include "spec_helper.h" #include "rules.h" -using namespace tree_sitter::rules; +using namespace rules; START_TEST diff --git a/spec/compiler/rules/rules_spec.cpp b/spec/compiler/rules/rules_spec.cpp index 5d823919..d48477b6 100644 --- a/spec/compiler/rules/rules_spec.cpp +++ b/spec/compiler/rules/rules_spec.cpp @@ -1,25 +1,23 @@ #include "spec_helper.h" #include "rule_transitions.h" +using namespace rules; + START_TEST -describe("Rules", []() { - rules::rule_ptr symbol1 = rules::sym("1"); - rules::rule_ptr symbol2 = rules::sym("2"); - rules::rule_ptr symbol3 = rules::sym("3"); +describe("constructing rules", []() { + rule_ptr symbol1 = sym("1"); + rule_ptr symbol2 = sym("2"); + rule_ptr symbol3 = sym("3"); - describe("construction", [&]() { - it("constructs binary trees", [&]() { - AssertThat( - rules::seq({ symbol1, symbol2, symbol3 }), - EqualsPointer( - rules::seq({ rules::seq({ symbol1, symbol2 }), symbol3 }))); - - AssertThat( - rules::choice({ symbol1, symbol2, symbol3 }), - EqualsPointer( - rules::choice({ rules::choice({ symbol1, symbol2 }), symbol3 }))); - }); + it("constructs binary trees", [&]() { + AssertThat( + seq({ symbol1, symbol2, symbol3 }), + EqualsPointer(seq({ seq({ symbol1, symbol2 }), symbol3 }))); + + AssertThat( + choice({ symbol1, symbol2, symbol3 }), + EqualsPointer(choice({ choice({ symbol1, symbol2 }), symbol3 }))); }); }); diff --git a/spec/compiler/spec_helper.h b/spec/compiler/spec_helper.h index 9462927b..2fa3a62b 100644 --- a/spec/compiler/spec_helper.h +++ b/spec/compiler/spec_helper.h @@ -70,7 +70,6 @@ namespace snowhouse { inline EqualsPointerConstraint EqualsPointer(const ExpectedType& expected) { return EqualsPointerConstraint(expected); } - } string src_dir(); diff --git a/spec/fixtures/grammars/arithmetic.cpp b/spec/fixtures/grammars/arithmetic.cpp index 3a7e1592..55721508 100644 --- a/spec/fixtures/grammars/arithmetic.cpp +++ b/spec/fixtures/grammars/arithmetic.cpp @@ -2,7 +2,7 @@ #include "rules.h" using namespace tree_sitter; -using namespace tree_sitter::rules; +using namespace rules; namespace test_grammars { Grammar arithmetic() {