Started cleanup of code

Restarting work on this, going to do some refactoring on the project
first.
master
Ruben Dahl 2023-07-30 19:22:43 +02:00
parent 048b26ca2b
commit fe9589cc82
11 changed files with 435 additions and 245 deletions

View File

@ -1,27 +1 @@
# CeeVLang Documentation # CeeV Lang Rewrite
## Includes
```cpp
#include "colors.h"
#include <deque>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
```
## Functions
```cpp
int read_file(std::deque<std::string> args);
```
* Param: std::deque\<std::string\> args - The arguments from main() in ceev.cc, with used
values stripped out.
* Returns: int exit_code
* Reads the file and outputs it.
Currently a work in progress.

View File

@ -1,37 +1,107 @@
#include "colors.h" #include "colors.h"
std::string black(std::string input) {return "\x1b[30m" + input + "\x1b[0m";} static std::string black(const std::string& input) {
std::string red(std::string input) {return "\x1b[31m" + input + "\x1b[0m";} return "\x1b[30m" + input + "\x1b[0m";
std::string green(std::string input) {return "\x1b[32m" + input + "\x1b[0m";} }
std::string yellow(std::string input) {return "\x1b[33m" + input + "\x1b[0m";} static std::string red(const std::string& input) {
std::string blue(std::string input) {return "\x1b[34m" + input + "\x1b[0m";} return "\x1b[31m" + input + "\x1b[0m";
std::string magenta(std::string input) {return "\x1b[35m" + input + "\x1b[0m";} }
std::string cyan(std::string input) {return "\x1b[36m" + input + "\x1b[0m";} static std::string green(const std::string& input) {
std::string white(std::string input) {return "\x1b[37m" + input + "\x1b[0m";} return "\x1b[32m" + input + "\x1b[0m";
std::string bright_black(std::string input) {return "\x1b[90m" + input + "\x1b[0m";} }
std::string bright_red(std::string input) {return "\x1b[91m" + input + "\x1b[0m";} static std::string yellow(const std::string& input) {
std::string bright_green(std::string input) {return "\x1b[92m" + input + "\x1b[0m";} return "\x1b[33m" + input + "\x1b[0m";
std::string bright_yellow(std::string input) {return "\x1b[93m" + input + "\x1b[0m";} }
std::string bright_blue(std::string input) {return "\x1b[94m" + input + "\x1b[0m";} static std::string blue(const std::string& input) {
std::string bright_magenta(std::string input) {return "\x1b[95m" + input + "\x1b[0m";} return "\x1b[34m" + input + "\x1b[0m";
std::string bright_cyan(std::string input) {return "\x1b[96m" + input + "\x1b[0m";} }
std::string bright_white(std::string input) {return "\x1b[97m" + input + "\x1b[0m";} static std::string magenta(const std::string& input) {
std::string bg_black(std::string input) {return "\x1b[40m" + input + "\x1b[0m";} return "\x1b[35m" + input + "\x1b[0m";
std::string bg_red(std::string input) {return "\x1b[41m" + input + "\x1b[0m";} }
std::string bg_green(std::string input) {return "\x1b[42m" + input + "\x1b[0m";} static std::string cyan(const std::string& input) {
std::string bg_yellow(std::string input) {return "\x1b[43m" + input + "\x1b[0m";} return "\x1b[36m" + input + "\x1b[0m";
std::string bg_blue(std::string input) {return "\x1b[44m" + input + "\x1b[0m";} }
std::string bg_magenta(std::string input) {return "\x1b[45m" + input + "\x1b[0m";} static std::string white(const std::string& input) {
std::string bg_cyan(std::string input) {return "\x1b[46m" + input + "\x1b[0m";} return "\x1b[37m" + input + "\x1b[0m";
std::string bg_white(std::string input) {return "\x1b[47m" + input + "\x1b[0m";} }
std::string bg_bright_black(std::string input) {return "\x1b[100m" + input + "\x1b[0m";} static std::string bright_black(const std::string& input) {
std::string bg_bright_red(std::string input) {return "\x1b[101m" + input + "\x1b[0m";} return "\x1b[90m" + input + "\x1b[0m";
std::string bg_bright_green(std::string input) {return "\x1b[102m" + input + "\x1b[0m";} }
std::string bg_bright_yellow(std::string input) {return "\x1b[103m" + input + "\x1b[0m";} static std::string bright_red(const std::string& input) {
std::string bg_bright_blue(std::string input) {return "\x1b[104m" + input + "\x1b[0m";} return "\x1b[91m" + input + "\x1b[0m";
std::string bg_bright_magenta(std::string input) {return "\x1b[105m" + input + "\x1b[0m";} }
std::string bg_bright_cyan(std::string input) {return "\x1b[106m" + input + "\x1b[0m";} static std::string bright_green(const std::string& input) {
std::string bg_bright_white(std::string input) {return "\x1b[107m" + input + "\x1b[0m";} return "\x1b[92m" + input + "\x1b[0m";
std::string bold(std::string input) {return "\x1b[1m" + input + "\x1b[0m";} }
std::string underline(std::string input) {return "\x1b[4m" + input + "\x1b[0m";} static std::string bright_yellow(const std::string& input) {
std::string reverse(std::string input) {return "\x1b[7m" + input + "\x1b[0m";} return "\x1b[93m" + input + "\x1b[0m";
}
static std::string bright_blue(const std::string& input) {
return "\x1b[94m" + input + "\x1b[0m";
}
static std::string bright_magenta(const std::string& input) {
return "\x1b[95m" + input + "\x1b[0m";
}
static std::string bright_cyan(const std::string& input) {
return "\x1b[96m" + input + "\x1b[0m";
}
static std::string bright_white(const std::string& input) {
return "\x1b[97m" + input + "\x1b[0m";
}
static std::string bg_black(const std::string& input) {
return "\x1b[40m" + input + "\x1b[0m";
}
static std::string bg_red(const std::string& input) {
return "\x1b[41m" + input + "\x1b[0m";
}
static std::string bg_green(const std::string& input) {
return "\x1b[42m" + input + "\x1b[0m";
}
static std::string bg_yellow(const std::string& input) {
return "\x1b[43m" + input + "\x1b[0m";
}
static std::string bg_blue(const std::string& input) {
return "\x1b[44m" + input + "\x1b[0m";
}
static std::string bg_magenta(const std::string& input) {
return "\x1b[45m" + input + "\x1b[0m";
}
static std::string bg_cyan(const std::string& input) {
return "\x1b[46m" + input + "\x1b[0m";
}
static std::string bg_white(const std::string& input) {
return "\x1b[47m" + input + "\x1b[0m";
}
static std::string bg_bright_black(const std::string& input) {
return "\x1b[100m" + input + "\x1b[0m";
}
static std::string bg_bright_red(const std::string& input) {
return "\x1b[101m" + input + "\x1b[0m";
}
static std::string bg_bright_green(const std::string& input) {
return "\x1b[102m" + input + "\x1b[0m";
}
static std::string bg_bright_yellow(const std::string& input) {
return "\x1b[103m" + input + "\x1b[0m";
}
static std::string bg_bright_blue(const std::string& input) {
return "\x1b[104m" + input + "\x1b[0m";
}
static std::string bg_bright_magenta(const std::string& input) {
return "\x1b[105m" + input + "\x1b[0m";
}
static std::string bg_bright_cyan(const std::string& input) {
return "\x1b[106m" + input + "\x1b[0m";
}
static std::string bg_bright_white(const std::string& input) {
return "\x1b[107m" + input + "\x1b[0m";
}
static std::string bold(const std::string& input) {
return "\x1b[1m" + input + "\x1b[0m";
}
static std::string underline(const std::string& input) {
return "\x1b[4m" + input + "\x1b[0m";
}
static std::string reverse(const std::string& input) {
return "\x1b[7m" + input + "\x1b[0m";
}

View File

@ -2,38 +2,38 @@
#include <string> #include <string>
std::string black(std::string input); static std::string black(const std::string& input);
std::string red(std::string input); static std::string red(const std::string& input);
std::string green(std::string input); static std::string green(const std::string& input);
std::string yellow(std::string input); static std::string yellow(const std::string& input);
std::string blue(std::string input); static std::string blue(const std::string& input);
std::string magenta(std::string input); static std::string magenta(const std::string& input);
std::string cyan(std::string input); static std::string cyan(const std::string& input);
std::string white(std::string input); static std::string white(const std::string& input);
std::string bright_black(std::string input); static std::string bright_black(const std::string& input);
std::string bright_red(std::string input); static std::string bright_red(const std::string& input);
std::string bright_green(std::string input); static std::string bright_green(const std::string& input);
std::string bright_yellow(std::string input); static std::string bright_yellow(const std::string& input);
std::string bright_blue(std::string input); static std::string bright_blue(const std::string& input);
std::string bright_magenta(std::string input); static std::string bright_magenta(const std::string& input);
std::string bright_cyan(std::string input); static std::string bright_cyan(const std::string& input);
std::string bright_white(std::string input); static std::string bright_white(const std::string& input);
std::string bg_black(std::string input); static std::string bg_black(const std::string& input);
std::string bg_red(std::string input); static std::string bg_red(const std::string& input);
std::string bg_green(std::string input); static std::string bg_green(const std::string& input);
std::string bg_yellow(std::string input); static std::string bg_yellow(const std::string& input);
std::string bg_blue(std::string input); static std::string bg_blue(const std::string& input);
std::string bg_magenta(std::string input); static std::string bg_magenta(const std::string& input);
std::string bg_cyan(std::string input); static std::string bg_cyan(const std::string& input);
std::string bg_white(std::string input); static std::string bg_white(const std::string& input);
std::string bg_bright_black(std::string input); static std::string bg_bright_black(const std::string& input);
std::string bg_bright_red(std::string input); static std::string bg_bright_red(const std::string& input);
std::string bg_bright_green(std::string input); static std::string bg_bright_green(const std::string& input);
std::string bg_bright_yellow(std::string input); static std::string bg_bright_yellow(const std::string& input);
std::string bg_bright_blue(std::string input); static std::string bg_bright_blue(const std::string& input);
std::string bg_bright_magenta(std::string input); static std::string bg_bright_magenta(const std::string& input);
std::string bg_bright_cyan(std::string input); static std::string bg_bright_cyan(const std::string& input);
std::string bg_bright_white(std::string input); static std::string bg_bright_white(const std::string& input);
std::string bold(std::string input); static std::string bold(const std::string&& input);
std::string underline(std::string input); static std::string underline(const std::string& input);
std::string reverse(std::string input); static std::string reverse(const std::string& input);

View File

@ -1,63 +1,25 @@
#include "lang.h" #include "lang.h"
int read_file(std::deque<std::string> args) { int read_file(std::deque<std::string> args) {
if (args.empty()) { if (args.empty()) {
std::cout << bg_red(bold("ERROR")) << ": No file input" << std::endl; std::cout << bg_red(bold("ERROR")) << ": No file input" << std::endl;
return 1; return 1;
} }
fs::path filename = args[0]; fs::path filename = args[0];
args.pop_front(); args.pop_front();
std::ifstream file(filename); std::ifstream file(filename);
if (!file) { if (!file) {
std::cout << bg_red(bold("ERROR")) << ": Could not find file" << std::endl; std::cout << bg_red(bold("ERROR")) << ": Could not find file"
return 1; << std::endl;
} return 1;
std::string line; }
while (std::getline(file, line)) { std::string line;
std::cout << line << std::endl; while (std::getline(file, line)) {
} std::cout << line << std::endl;
return 0; }
return 0;
} }
int parse_line(std::string line) { int parse_line(std::string line) {
struct parsed_token parsed { return 0;
empty_token, empty_token
};
if (int sub = line.find("//"))
line = line.substr(sub);
std::deque<std::string> tokens;
int start = 0;
size_t end = line.find(" ");
while (end != std::string::npos) {
tokens.push_back(line.substr(start, end - start));
start = end + 1;
end = line.find(" ", start);
}
for (std::string &token : tokens) {
try {
Token curr_token = CV_Tokens.at(token);
parsed.lastToken = parsed.currentToken;
if (curr_token == parsed.lastToken && curr_token.type == TokenType::SPACE)
continue;
else {
// TODO: Line number handling for better errors
std::cerr << "Invalid token `" << token << "'." << std::endl;
return 1;
}
parsed.currentToken = curr_token;
} catch (std::out_of_range &oor) {
// this is most likely a variable or a string
if (parsed.lastToken.type == TokenType::INTRINSIC &&
parsed.lastToken.intrinsic == Intrinsic::LET) {
VariableToken var{TokenType::VARIABLE, Intrinsic::EMPTY,
Constant::EMPTY, "", token};
parsed.currentToken = var;
var_tokens.push_back(var);
}
// string parsing
std::cerr << "Not implemented. Found `" << token << "'." << std::endl;
continue;
}
}
return 0;
} }

View File

@ -1,102 +1,12 @@
#pragma once #pragma once
#include "colors.h"
#include <deque> #include <deque>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <map> #include "colors.h"
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
namespace fs = std::filesystem; namespace fs = std::filesystem;
enum class TokenType {
EMPTY,
SPACE,
LEFT_PAREN,
RIGHT_PAREN,
COLONCOLON,
EQ,
COMMA,
STRING,
INTRINSIC,
CONSTANT,
VARIABLE
};
enum class Intrinsic { EMPTY, LET, UNLET, ENTER, EXIT, SHOW, HIDE };
enum class Constant { EMPTY, CHARACTER, LOCATION, IMAGE };
struct Token {
TokenType type;
Intrinsic intrinsic;
Constant constant;
std::string string;
std::string name;
inline bool operator==(const Token &right) {
if (this->type == right.type && this->intrinsic == right.intrinsic &&
this->constant == right.constant && this->string == right.string &&
this->name == right.name)
return true;
return false;
}
inline bool operator!=(const Token &right) { return !(*this == right); }
};
struct VariableToken : Token {
Token value;
inline bool operator==(const VariableToken &right) {
if ((Token) * this == (Token)right && this->value == right.value)
return true;
return false;
}
inline bool operator!=(const VariableToken &right) {
return !(*this == right);
}
};
std::map<std::string, Token> CV_Tokens{
{"", Token{TokenType::EMPTY, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{" ", Token{TokenType::SPACE, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{"(",
Token{TokenType::LEFT_PAREN, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{")",
Token{TokenType::RIGHT_PAREN, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{"::",
Token{TokenType::COLONCOLON, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{"=", Token{TokenType::EQ, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{",", Token{TokenType::COMMA, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{"let",
Token{TokenType::INTRINSIC, Intrinsic::LET, Constant::EMPTY, "", ""}},
{"unlet",
Token{TokenType::INTRINSIC, Intrinsic::UNLET, Constant::EMPTY, "", ""}},
{"enter",
Token{TokenType::INTRINSIC, Intrinsic::ENTER, Constant::EMPTY, "", ""}},
{"exit",
Token{TokenType::INTRINSIC, Intrinsic::EXIT, Constant::EMPTY, "", ""}},
{"show",
Token{TokenType::INTRINSIC, Intrinsic::SHOW, Constant::EMPTY, "", ""}},
{"hide",
Token{TokenType::INTRINSIC, Intrinsic::HIDE, Constant::EMPTY, "", ""}},
{"Character",
Token{TokenType::CONSTANT, Intrinsic::EMPTY, Constant::CHARACTER, "", ""}},
{"Location",
Token{TokenType::CONSTANT, Intrinsic::EMPTY, Constant::LOCATION, "", ""}},
{"Image",
Token{TokenType::CONSTANT, Intrinsic::EMPTY, Constant::IMAGE, "", ""}}};
Token empty_token{TokenType::EMPTY, Intrinsic::EMPTY, Constant::EMPTY, "", ""};
struct parsed_token {
Token lastToken;
Token currentToken;
};
std::vector<VariableToken> var_tokens;
int read_file(std::deque<std::string> args); int read_file(std::deque<std::string> args);
int parse_line(std::string line); int parse_file(std::string file);

27
src_old/README.md 100644
View File

@ -0,0 +1,27 @@
# CeeVLang Documentation
## Includes
```cpp
#include "colors.h"
#include <deque>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
```
## Functions
```cpp
int read_file(std::deque<std::string> args);
```
* Param: std::deque\<std::string\> args - The arguments from main() in ceev.cc, with used
values stripped out.
* Returns: int exit_code
* Reads the file and outputs it.
Currently a work in progress.

37
src_old/colors.cc 100644
View File

@ -0,0 +1,37 @@
#include "colors.h"
std::string black(std::string input) {return "\x1b[30m" + input + "\x1b[0m";}
std::string red(std::string input) {return "\x1b[31m" + input + "\x1b[0m";}
std::string green(std::string input) {return "\x1b[32m" + input + "\x1b[0m";}
std::string yellow(std::string input) {return "\x1b[33m" + input + "\x1b[0m";}
std::string blue(std::string input) {return "\x1b[34m" + input + "\x1b[0m";}
std::string magenta(std::string input) {return "\x1b[35m" + input + "\x1b[0m";}
std::string cyan(std::string input) {return "\x1b[36m" + input + "\x1b[0m";}
std::string white(std::string input) {return "\x1b[37m" + input + "\x1b[0m";}
std::string bright_black(std::string input) {return "\x1b[90m" + input + "\x1b[0m";}
std::string bright_red(std::string input) {return "\x1b[91m" + input + "\x1b[0m";}
std::string bright_green(std::string input) {return "\x1b[92m" + input + "\x1b[0m";}
std::string bright_yellow(std::string input) {return "\x1b[93m" + input + "\x1b[0m";}
std::string bright_blue(std::string input) {return "\x1b[94m" + input + "\x1b[0m";}
std::string bright_magenta(std::string input) {return "\x1b[95m" + input + "\x1b[0m";}
std::string bright_cyan(std::string input) {return "\x1b[96m" + input + "\x1b[0m";}
std::string bright_white(std::string input) {return "\x1b[97m" + input + "\x1b[0m";}
std::string bg_black(std::string input) {return "\x1b[40m" + input + "\x1b[0m";}
std::string bg_red(std::string input) {return "\x1b[41m" + input + "\x1b[0m";}
std::string bg_green(std::string input) {return "\x1b[42m" + input + "\x1b[0m";}
std::string bg_yellow(std::string input) {return "\x1b[43m" + input + "\x1b[0m";}
std::string bg_blue(std::string input) {return "\x1b[44m" + input + "\x1b[0m";}
std::string bg_magenta(std::string input) {return "\x1b[45m" + input + "\x1b[0m";}
std::string bg_cyan(std::string input) {return "\x1b[46m" + input + "\x1b[0m";}
std::string bg_white(std::string input) {return "\x1b[47m" + input + "\x1b[0m";}
std::string bg_bright_black(std::string input) {return "\x1b[100m" + input + "\x1b[0m";}
std::string bg_bright_red(std::string input) {return "\x1b[101m" + input + "\x1b[0m";}
std::string bg_bright_green(std::string input) {return "\x1b[102m" + input + "\x1b[0m";}
std::string bg_bright_yellow(std::string input) {return "\x1b[103m" + input + "\x1b[0m";}
std::string bg_bright_blue(std::string input) {return "\x1b[104m" + input + "\x1b[0m";}
std::string bg_bright_magenta(std::string input) {return "\x1b[105m" + input + "\x1b[0m";}
std::string bg_bright_cyan(std::string input) {return "\x1b[106m" + input + "\x1b[0m";}
std::string bg_bright_white(std::string input) {return "\x1b[107m" + input + "\x1b[0m";}
std::string bold(std::string input) {return "\x1b[1m" + input + "\x1b[0m";}
std::string underline(std::string input) {return "\x1b[4m" + input + "\x1b[0m";}
std::string reverse(std::string input) {return "\x1b[7m" + input + "\x1b[0m";}

39
src_old/colors.h 100644
View File

@ -0,0 +1,39 @@
#pragma once
#include <string>
std::string black(std::string input);
std::string red(std::string input);
std::string green(std::string input);
std::string yellow(std::string input);
std::string blue(std::string input);
std::string magenta(std::string input);
std::string cyan(std::string input);
std::string white(std::string input);
std::string bright_black(std::string input);
std::string bright_red(std::string input);
std::string bright_green(std::string input);
std::string bright_yellow(std::string input);
std::string bright_blue(std::string input);
std::string bright_magenta(std::string input);
std::string bright_cyan(std::string input);
std::string bright_white(std::string input);
std::string bg_black(std::string input);
std::string bg_red(std::string input);
std::string bg_green(std::string input);
std::string bg_yellow(std::string input);
std::string bg_blue(std::string input);
std::string bg_magenta(std::string input);
std::string bg_cyan(std::string input);
std::string bg_white(std::string input);
std::string bg_bright_black(std::string input);
std::string bg_bright_red(std::string input);
std::string bg_bright_green(std::string input);
std::string bg_bright_yellow(std::string input);
std::string bg_bright_blue(std::string input);
std::string bg_bright_magenta(std::string input);
std::string bg_bright_cyan(std::string input);
std::string bg_bright_white(std::string input);
std::string bold(std::string input);
std::string underline(std::string input);
std::string reverse(std::string input);

66
src_old/lang.cc 100644
View File

@ -0,0 +1,66 @@
#include "lang.h"
int read_file(std::deque<std::string> args) {
if (args.empty()) {
std::cout << bg_red(bold("ERROR")) << ": No file input" << std::endl;
return 1;
}
fs::path filename = args[0];
args.pop_front();
std::ifstream file(filename);
if (!file) {
std::cout << bg_red(bold("ERROR")) << ": Could not find file"
<< std::endl;
return 1;
}
std::string line;
while (std::getline(file, line)) {
std::cout << line << std::endl;
}
return 0;
}
int parse_line(std::string line) {
struct parsed_token parsed {
empty_token, empty_token
};
if (int sub = line.find("//"))
line = line.substr(sub);
std::deque<std::string> tokens;
int start = 0;
size_t end = line.find(" ");
while (end != std::string::npos) {
tokens.push_back(line.substr(start, end - start));
start = end + 1;
end = line.find(" ", start);
}
for (std::string& token : tokens) {
try {
Token curr_token = CV_Tokens.at(token);
parsed.lastToken = parsed.currentToken;
if (curr_token == parsed.lastToken &&
curr_token.type == TokenType::SPACE)
continue;
else {
// TODO: Line number handling for better errors
std::cerr << "Invalid token `" << token << "'." << std::endl;
return 1;
}
parsed.currentToken = curr_token;
} catch (std::out_of_range& oor) {
// this is most likely a variable or a string
if (parsed.lastToken.type == TokenType::INTRINSIC &&
parsed.lastToken.intrinsic == Intrinsic::LET) {
VariableToken var{TokenType::VARIABLE, Intrinsic::EMPTY,
Constant::EMPTY, "", token};
parsed.currentToken = var;
var_tokens.push_back(var);
}
// string parsing
std::cerr << "Not implemented. Found `" << token << "'."
<< std::endl;
continue;
}
}
return 0;
}

102
src_old/lang.h 100644
View File

@ -0,0 +1,102 @@
#pragma once
#include "colors.h"
#include <deque>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
namespace fs = std::filesystem;
enum class TokenType {
EMPTY,
SPACE,
LEFT_PAREN,
RIGHT_PAREN,
COLONCOLON,
EQ,
COMMA,
STRING,
INTRINSIC,
CONSTANT,
VARIABLE
};
enum class Intrinsic { EMPTY, LET, UNLET, ENTER, EXIT, SHOW, HIDE };
enum class Constant { EMPTY, CHARACTER, LOCATION, IMAGE };
struct Token {
TokenType type;
Intrinsic intrinsic;
Constant constant;
std::string string;
std::string name;
inline bool operator==(const Token &right) {
if (this->type == right.type && this->intrinsic == right.intrinsic &&
this->constant == right.constant && this->string == right.string &&
this->name == right.name)
return true;
return false;
}
inline bool operator!=(const Token &right) { return !(*this == right); }
};
struct VariableToken : Token {
Token value;
inline bool operator==(const VariableToken &right) {
if ((Token) * this == (Token)right && this->value == right.value)
return true;
return false;
}
inline bool operator!=(const VariableToken &right) {
return !(*this == right);
}
};
std::map<std::string, Token> CV_Tokens{
{"", Token{TokenType::EMPTY, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{" ", Token{TokenType::SPACE, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{"(",
Token{TokenType::LEFT_PAREN, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{")",
Token{TokenType::RIGHT_PAREN, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{"::",
Token{TokenType::COLONCOLON, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{"=", Token{TokenType::EQ, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{",", Token{TokenType::COMMA, Intrinsic::EMPTY, Constant::EMPTY, "", ""}},
{"let",
Token{TokenType::INTRINSIC, Intrinsic::LET, Constant::EMPTY, "", ""}},
{"unlet",
Token{TokenType::INTRINSIC, Intrinsic::UNLET, Constant::EMPTY, "", ""}},
{"enter",
Token{TokenType::INTRINSIC, Intrinsic::ENTER, Constant::EMPTY, "", ""}},
{"exit",
Token{TokenType::INTRINSIC, Intrinsic::EXIT, Constant::EMPTY, "", ""}},
{"show",
Token{TokenType::INTRINSIC, Intrinsic::SHOW, Constant::EMPTY, "", ""}},
{"hide",
Token{TokenType::INTRINSIC, Intrinsic::HIDE, Constant::EMPTY, "", ""}},
{"Character",
Token{TokenType::CONSTANT, Intrinsic::EMPTY, Constant::CHARACTER, "", ""}},
{"Location",
Token{TokenType::CONSTANT, Intrinsic::EMPTY, Constant::LOCATION, "", ""}},
{"Image",
Token{TokenType::CONSTANT, Intrinsic::EMPTY, Constant::IMAGE, "", ""}}};
Token empty_token{TokenType::EMPTY, Intrinsic::EMPTY, Constant::EMPTY, "", ""};
struct parsed_token {
Token lastToken;
Token currentToken;
};
std::vector<VariableToken> var_tokens;
int read_file(std::deque<std::string> args);
int parse_line(std::string line);

View File

@ -2,6 +2,9 @@
if [[ -z $1 ]]; then echo "Expected a file but got nothing"; exit 1; fi if [[ -z $1 ]]; then echo "Expected a file but got nothing"; exit 1; fi
if [[ ! -d ~/.vim/syntax ]]; then mkdir -p ~/.vim/syntax; fi
if [[ ! -d ~/.vim/ftdetect ]]; then mkdir -p ~/.vim/ftdetect; fi
cp $1 ~/.vim/syntax/$1 cp $1 ~/.vim/syntax/$1
cp "${1}.ftd" ~/.vim/ftdetect/$1 cp "${1}.ftd" ~/.vim/ftdetect/$1