2022-08-19 19:52:57 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include "zen/config.hpp"
|
|
|
|
|
|
|
|
#include "bolt/CST.hpp"
|
|
|
|
#include "bolt/Diagnostics.hpp"
|
|
|
|
#include "bolt/Scanner.hpp"
|
|
|
|
#include "bolt/Parser.hpp"
|
2022-08-21 16:25:52 +02:00
|
|
|
#include "bolt/Checker.hpp"
|
2022-08-19 19:52:57 +02:00
|
|
|
|
|
|
|
using namespace bolt;
|
|
|
|
|
2022-08-24 20:57:26 +02:00
|
|
|
ByteString readFile(std::string Path) {
|
2022-08-19 19:52:57 +02:00
|
|
|
|
|
|
|
std::ifstream File(Path);
|
2022-08-24 20:57:26 +02:00
|
|
|
ByteString Out;
|
2022-08-19 19:52:57 +02:00
|
|
|
|
|
|
|
File.seekg(0, std::ios::end);
|
|
|
|
Out.reserve(File.tellg());
|
|
|
|
File.seekg(0, std::ios::beg);
|
|
|
|
|
|
|
|
Out.assign((std::istreambuf_iterator<char>(File)),
|
|
|
|
std::istreambuf_iterator<char>());
|
|
|
|
|
|
|
|
return Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char* argv[]) {
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr, "Not enough arguments provided.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-08-21 20:56:58 +02:00
|
|
|
ConsoleDiagnostics DE;
|
|
|
|
|
2022-08-19 19:52:57 +02:00
|
|
|
auto Text = readFile(argv[1]);
|
2022-08-24 12:36:43 +02:00
|
|
|
TextFile File { argv[1], Text };
|
2022-08-24 20:57:26 +02:00
|
|
|
VectorStream<ByteString, Char> Chars(Text, EOF);
|
|
|
|
Scanner S(File, Chars);
|
2022-08-19 19:52:57 +02:00
|
|
|
Punctuator PT(S);
|
2022-08-24 12:36:43 +02:00
|
|
|
Parser P(File, PT);
|
2022-08-19 19:52:57 +02:00
|
|
|
|
|
|
|
SourceFile* SF;
|
|
|
|
|
|
|
|
try {
|
|
|
|
SF = P.parseSourceFile();
|
2022-08-21 20:56:58 +02:00
|
|
|
} catch (Diagnostic& D) {
|
|
|
|
DE.addDiagnostic(D);
|
2022-08-24 20:57:26 +02:00
|
|
|
return 1;
|
2022-08-19 19:52:57 +02:00
|
|
|
}
|
|
|
|
|
2022-08-24 12:36:43 +02:00
|
|
|
SF->setParents();
|
|
|
|
|
2022-08-21 20:56:58 +02:00
|
|
|
Checker TheChecker { DE };
|
2022-08-21 16:25:52 +02:00
|
|
|
TheChecker.check(SF);
|
|
|
|
|
2022-08-19 19:52:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|