Language Initial
This commit is contained in:
parent
73897f11df
commit
b8f2380c60
47 changed files with 831 additions and 14 deletions
9
Language/old/Parser/tests/CLRTests.cpp
Normal file
9
Language/old/Parser/tests/CLRTests.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#include "Parser.hpp"
|
||||
#include "Testing.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
TEST_DEF(CLR) {
|
||||
// TEST(false);
|
||||
}
|
||||
48
Language/old/Parser/tests/GrammarTests.cpp
Normal file
48
Language/old/Parser/tests/GrammarTests.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
#include "Parser.hpp"
|
||||
#include "Testing.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
TEST_DEF(Grammar) {
|
||||
|
||||
String source = R"(
|
||||
Start Body
|
||||
Body : [ Function ] | List | &;
|
||||
List : [ LIST ];
|
||||
)";
|
||||
|
||||
auto state = CfGrammar::initializeCfGrammarParser();
|
||||
|
||||
CfGrammar grammar;
|
||||
|
||||
if (!grammar.parse(state, source)) {
|
||||
TEST(0 && "Parsing is failed\n");
|
||||
CfGrammar::deinitializeCfGrammarParser(state);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!grammar.compile()) {
|
||||
TEST(0 && "Compilation is failed\n");
|
||||
CfGrammar::deinitializeCfGrammarParser(state);
|
||||
return;
|
||||
}
|
||||
|
||||
CfGrammar::deinitializeCfGrammarParser(state);
|
||||
|
||||
printf("Grammar accepted.\n");
|
||||
|
||||
List<CfGrammar::Sentence> sentences;
|
||||
grammar.generateSentences(sentences);
|
||||
|
||||
TEST_ASSERT(sentences.length() == 3);
|
||||
TEST_ASSERT(sentences.first()->data.terms.length() == 1);
|
||||
TEST_ASSERT(sentences.last()->data.terms.length() == 1);
|
||||
|
||||
TEST(sentences.first()->data.terms.first()->data.id == "Function");
|
||||
TEST(sentences.last()->data.terms.first()->data.id == "LIST");
|
||||
|
||||
printf("Example sentences formed from grammar: \n");
|
||||
for (auto sentence : sentences)
|
||||
tp::CfGrammar::printSentence(sentence.data());
|
||||
}
|
||||
23
Language/old/Parser/tests/Tests.cpp
Normal file
23
Language/old/Parser/tests/Tests.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
#include "Parser.hpp"
|
||||
#include "Testing.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
void testGrammar();
|
||||
void testCLR();
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
tp::ModuleManifest* deps[] = { &tp::gModuleParser, nullptr };
|
||||
tp::ModuleManifest testModule("CommandLineTest", nullptr, nullptr, deps);
|
||||
|
||||
if (!testModule.initialize()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
testGrammar();
|
||||
testCLR();
|
||||
|
||||
testModule.deinitialize();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue