Updated REPL (thanks to cpp-linenoise!)
This commit is contained in:
@@ -53,7 +53,11 @@ Instruction::Instruction(std::vector<Value> toks) {
|
||||
} else if (toks[0].valtype == ValueType::Variable) {
|
||||
instruction = InstructionType::Variable;
|
||||
} else {
|
||||
error("Instruction should be an identifier or variable value");
|
||||
if (inReplMode) {
|
||||
instruction = InstructionType::Variable;
|
||||
} else {
|
||||
error("Instruction should be an identifier or variable value");
|
||||
}
|
||||
}
|
||||
if (instruction == InstructionType::Variable) {
|
||||
for (const auto& tok : toks) {
|
||||
@@ -85,7 +89,7 @@ Value::Value(std::string stringval) {
|
||||
}
|
||||
|
||||
if (stringval.empty()) {
|
||||
valtype = ValueType::String;
|
||||
valtype = ValueType::None;
|
||||
string_val = "";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ enum class InstructionType {
|
||||
};
|
||||
|
||||
enum class ValueType {
|
||||
Processed, Variable, InstructionGroup, List, Map, String, Int, Double, Identifier, Custom, TypePlaceholder
|
||||
Processed, Variable, InstructionGroup, List, Map, String, Int, Double, Identifier, Custom, TypePlaceholder, None
|
||||
};
|
||||
|
||||
struct Instruction;
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "../data/data.h"
|
||||
#include "../vendor/linenoise/linenoise.hpp"
|
||||
|
||||
void repl() {
|
||||
data::initScopes();
|
||||
inReplMode = true;
|
||||
std::cout << "Kyn REPL v0.0.1" << std::endl;
|
||||
std::cout << "Kyn REPL v0.0.2" << std::endl;
|
||||
std::cout << "Type 'exit' to exit" << std::endl;
|
||||
|
||||
std::string full_command;
|
||||
@@ -17,14 +18,11 @@ void repl() {
|
||||
int brace_level = 0;
|
||||
|
||||
while (true) {
|
||||
if (brace_level == 0) {
|
||||
std::cout << "kyn> ";
|
||||
} else {
|
||||
std::cout << ".. > ";
|
||||
}
|
||||
auto prompt = brace_level == 0 ? "kyn> " : ".. > ";
|
||||
auto quit = linenoise::Readline(prompt, line_buf);
|
||||
|
||||
if (!getline(std::cin, line_buf)) {
|
||||
break; // Handle EOF (Ctrl+D)
|
||||
if (quit) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (char c : line_buf) {
|
||||
@@ -44,9 +42,13 @@ void repl() {
|
||||
if (full_command.find_first_not_of(" \t\n\r") != std::string::npos) {
|
||||
std::vector<Instruction> parsed = parse(full_command);
|
||||
for (Instruction inst : parsed) {
|
||||
execute(inst);
|
||||
Value instruction = execute(inst);
|
||||
if (!(instruction.valtype == ValueType::None)) {
|
||||
std::cout << instruction.toString() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
linenoise::AddHistory(full_command.c_str());
|
||||
full_command.clear();
|
||||
brace_level = 0;
|
||||
}
|
||||
|
||||
0
src/vendor/linenoise/linenoise.h
vendored
Normal file
0
src/vendor/linenoise/linenoise.h
vendored
Normal file
2587
src/vendor/linenoise/linenoise.hpp
vendored
Normal file
2587
src/vendor/linenoise/linenoise.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user