This branch had diverged considerably, so merging it required changing a lot of code. Conflicts: project.gyp spec/compiler/build_tables/action_takes_precedence_spec.cc spec/compiler/build_tables/build_conflict_spec.cc spec/compiler/build_tables/build_parse_table_spec.cc spec/compiler/build_tables/first_symbols_spec.cc spec/compiler/build_tables/item_set_closure_spec.cc spec/compiler/build_tables/item_set_transitions_spec.cc spec/compiler/build_tables/rule_can_be_blank_spec.cc spec/compiler/helpers/containers.h spec/compiler/prepare_grammar/expand_repeats_spec.cc spec/compiler/prepare_grammar/extract_tokens_spec.cc src/compiler/build_tables/action_takes_precedence.h src/compiler/build_tables/build_parse_table.cc src/compiler/build_tables/first_symbols.cc src/compiler/build_tables/first_symbols.h src/compiler/build_tables/item_set_closure.cc src/compiler/build_tables/item_set_transitions.cc src/compiler/build_tables/parse_item.cc src/compiler/build_tables/parse_item.h src/compiler/build_tables/rule_can_be_blank.cc src/compiler/build_tables/rule_can_be_blank.h src/compiler/prepare_grammar/expand_repeats.cc src/compiler/prepare_grammar/extract_tokens.cc src/compiler/prepare_grammar/extract_tokens.h src/compiler/prepare_grammar/prepare_grammar.cc src/compiler/rules/built_in_symbols.cc src/compiler/rules/built_in_symbols.h src/compiler/syntax_grammar.cc src/compiler/syntax_grammar.h
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#include "compiler/compiler_spec_helper.h"
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
static string src_dir() {
|
|
const char * dir = getenv("TREESITTER_DIR");
|
|
if (!dir) dir = getenv("PWD");
|
|
return dir;
|
|
}
|
|
|
|
namespace tree_sitter_examples {
|
|
|
|
extern const Grammar arithmetic;
|
|
extern const Grammar javascript;
|
|
extern const Grammar json;
|
|
extern const Grammar golang;
|
|
extern const Grammar c;
|
|
|
|
} // namespace tree_sitter_examples
|
|
|
|
START_TEST
|
|
|
|
describe("compiling the example grammars", []() {
|
|
string example_parser_dir = src_dir() + "/spec/fixtures/parsers/";
|
|
|
|
auto compile_grammar = [&](const Grammar &grammar, string language) {
|
|
it(("compiles the " + language + " grammar").c_str(), [&]() {
|
|
auto result = compile(grammar, language);
|
|
string code = result.first;
|
|
const GrammarError *error = result.second;
|
|
|
|
if (error)
|
|
AssertThat(error->message, Equals(""));
|
|
|
|
ofstream file(example_parser_dir + language + ".c");
|
|
file << get<0>(result);
|
|
file.close();
|
|
});
|
|
};
|
|
|
|
compile_grammar(tree_sitter_examples::arithmetic, "arithmetic");
|
|
compile_grammar(tree_sitter_examples::json, "json");
|
|
compile_grammar(tree_sitter_examples::javascript, "javascript");
|
|
compile_grammar(tree_sitter_examples::golang, "golang");
|
|
compile_grammar(tree_sitter_examples::c, "c");
|
|
});
|
|
|
|
END_TEST
|