Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6f8207e1a | ||
|
|
eedfe53b96 |
+2
-2
@@ -74,8 +74,8 @@ target_link_libraries(${PROJECT} ruc)
|
|||||||
# Execute target
|
# Execute target
|
||||||
|
|
||||||
add_custom_target(run
|
add_custom_target(run
|
||||||
COMMAND ${PROJECT})
|
COMMAND ${PROJECT}
|
||||||
add_dependencies(run ${PROJECT})
|
DEPENDS ${PROJECT})
|
||||||
|
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# Test targets
|
# Test targets
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (C) 2023 Riyyi
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Riyyi
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
namespace blaze {
|
||||||
|
|
||||||
|
std::string_view Settings::get(std::string_view key) const
|
||||||
|
{
|
||||||
|
VERIFY(m_settings.find(key) != m_settings.end(), "setting does not exist");
|
||||||
|
return m_settings.at(key);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace blaze
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Riyyi
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ruc/meta/assert.h"
|
||||||
|
#include "ruc/singleton.h"
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace blaze {
|
||||||
|
|
||||||
|
class Settings final : public ruc::Singleton<Settings> {
|
||||||
|
public:
|
||||||
|
Settings(s) {}
|
||||||
|
virtual ~Settings() = default;
|
||||||
|
|
||||||
|
std::string_view get(std::string_view key) const;
|
||||||
|
void set(std::string_view key, std::string_view value) { m_settings[key] = value; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<std::string_view, std::string_view> m_settings;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace blaze
|
||||||
+41
-20
@@ -4,37 +4,42 @@
|
|||||||
#include <string> // std::getline
|
#include <string> // std::getline
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include "error.h"
|
#include "ruc/argparser.h"
|
||||||
#include "ruc/format/color.h"
|
#include "ruc/format/color.h"
|
||||||
|
|
||||||
#include "ast.h"
|
#include "ast.h"
|
||||||
|
#include "error.h"
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
#include "printer.h"
|
#include "printer.h"
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
|
#include "settings.h"
|
||||||
#define PRETTY_PRINT 0
|
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
auto read(std::string_view input) -> blaze::ASTNode*
|
auto read(std::string_view input) -> blaze::ASTNode*
|
||||||
{
|
{
|
||||||
blaze::Lexer lexer(input);
|
blaze::Lexer lexer(input);
|
||||||
lexer.tokenize();
|
lexer.tokenize();
|
||||||
// lexer.dump();
|
if (blaze::Settings::the().get("dump-lexer") == "1") {
|
||||||
|
lexer.dump();
|
||||||
|
}
|
||||||
|
|
||||||
blaze::Reader reader(std::move(lexer.tokens()));
|
blaze::Reader reader(std::move(lexer.tokens()));
|
||||||
reader.read();
|
reader.read();
|
||||||
// reader.dump();
|
if (blaze::Settings::the().get("dump-reader") == "1") {
|
||||||
|
reader.dump();
|
||||||
|
}
|
||||||
|
|
||||||
return reader.node();
|
return reader.node();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto eval(blaze::ASTNode* node) -> blaze::ASTNode*
|
auto eval(blaze::ASTNode* ast) -> blaze::ASTNode*
|
||||||
{
|
{
|
||||||
return node;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto print(blaze::ASTNode* node) -> void
|
auto print(blaze::ASTNode* exp) -> void
|
||||||
{
|
{
|
||||||
blaze::Printer printer(node);
|
blaze::Printer printer(exp);
|
||||||
printer.dump();
|
printer.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,25 +57,41 @@ static auto cleanup(int signal) -> void
|
|||||||
std::exit(signal);
|
std::exit(signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto main() -> int
|
auto main(int argc, char* argv[]) -> int
|
||||||
{
|
{
|
||||||
|
bool dump_lexer = false;
|
||||||
|
bool dump_reader = false;
|
||||||
|
bool pretty_print = false;
|
||||||
|
|
||||||
|
// CLI arguments
|
||||||
|
ruc::ArgParser arg_parser;
|
||||||
|
arg_parser.addOption(dump_lexer, 'l', "dump-lexer", nullptr, nullptr);
|
||||||
|
arg_parser.addOption(dump_reader, 'r', "dump-reader", nullptr, nullptr);
|
||||||
|
arg_parser.addOption(pretty_print, 'c', "color", nullptr, nullptr);
|
||||||
|
arg_parser.parse(argc, argv);
|
||||||
|
|
||||||
|
// Set settings
|
||||||
|
blaze::Settings::the().set("dump-lexer", dump_lexer ? "1" : "0");
|
||||||
|
blaze::Settings::the().set("dump-reader", dump_reader ? "1" : "0");
|
||||||
|
blaze::Settings::the().set("pretty-print", pretty_print ? "1" : "0");
|
||||||
|
|
||||||
// Signal callbacks
|
// Signal callbacks
|
||||||
std::signal(SIGINT, cleanup);
|
std::signal(SIGINT, cleanup);
|
||||||
std::signal(SIGTERM, cleanup);
|
std::signal(SIGTERM, cleanup);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
#if PRETTY_PRINT
|
if (!pretty_print) {
|
||||||
print(fg(ruc::format::TerminalColor::Blue), "user>");
|
print("user> ");
|
||||||
print(" ");
|
}
|
||||||
print("\033[1m");
|
else {
|
||||||
#else
|
print(fg(ruc::format::TerminalColor::Blue), "user>");
|
||||||
print("user> ");
|
print(" \033[1m");
|
||||||
#endif
|
}
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline(std::cin, line);
|
std::getline(std::cin, line);
|
||||||
#if PRETTY_PRINT
|
if (pretty_print) {
|
||||||
print("\033[0m");
|
print("\033[0m");
|
||||||
#endif
|
}
|
||||||
|
|
||||||
// Exit with Ctrl-D
|
// Exit with Ctrl-D
|
||||||
if (std::cin.eof() || std::cin.fail()) {
|
if (std::cin.eof() || std::cin.fail()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user