Add unsigned short values to the tok::type enum and move the parseString function to misc.hpp.

This commit is contained in:
Username404 2021-08-06 19:10:28 +02:00
parent fbe8e189d3
commit 2f853fe797
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
5 changed files with 17 additions and 30 deletions

View File

@ -83,7 +83,7 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY "Yerbacon ${CMAKE_PROJECT_VERSION_MAJOR}.${C
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TIME}") set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TIME}")
include_directories(${CMAKE_CURRENT_LIST_DIR}) include_directories(${CMAKE_CURRENT_LIST_DIR})
add_executable(${EXENAME} src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/${PROJECT_NAME}.rc src/parser/MainParse.cpp src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp src/headers/parsing/ParseComponents.hpp src/headers/transpiler/Target.hpp src/headers/transpiler/implementations/Lua.hpp src/headers/transpiler/implementations/Js.hpp src/headers/transpiler/implementations/Py.hpp src/headers/parsing/Parser.hpp src/headers/Yerbacon.hpp src/headers/arguments.hpp) add_executable(${EXENAME} src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/${PROJECT_NAME}.rc src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp src/headers/parsing/ParseComponents.hpp src/headers/transpiler/Target.hpp src/headers/transpiler/implementations/Lua.hpp src/headers/transpiler/implementations/Js.hpp src/headers/transpiler/implementations/Py.hpp src/headers/parsing/Parser.hpp src/headers/Yerbacon.hpp src/headers/arguments.hpp)
target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${CODENAME} ${PROJECT_VERSION}") target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${CODENAME} ${PROJECT_VERSION}")
# lpkg = linux package, wpkg = windows package # lpkg = linux package, wpkg = windows package

View File

@ -14,20 +14,10 @@ vector<tok> lex(const string& in)
for (unsigned int i = 0; i < in.size(); ++i) { for (unsigned int i = 0; i < in.size(); ++i) {
const char& current = in[i]; const char& current = in[i];
switch (current) { switch (current) {
case '#': resVal.emplace_back(tok::TAG, "#"); break; case tok::TAG: case tok::DEFINE: case tok::LPAR: case tok::RPAR:
case '=': resVal.emplace_back(tok::DEFINE, "="); break; case tok::LBRACE: case tok::RBRACE: case tok::LBRACKET: case tok::RBRACKET:
case '(': resVal.emplace_back(tok::LPAR, "("); break; case tok::PLUS: case tok::HYPHEN: case tok::LCOMP: case tok::RCOMP:
case ')': resVal.emplace_back(tok::RPAR, ")"); break; case '$': case '\'': resVal.emplace_back(static_cast<tok::type>(current), string(1, current));
case '{': resVal.emplace_back(tok::LBRACE, "{"); break;
case '}': resVal.emplace_back(tok::RBRACE, "}"); break;
case '[': resVal.emplace_back(tok::LBRACKET, "["); break;
case ']': resVal.emplace_back(tok::RBRACKET, "]"); break;
case '+': resVal.emplace_back(tok::PLUS, "+"); break;
case '-': resVal.emplace_back(tok::HYPHEN, "-"); break;
case '>': resVal.emplace_back(tok::LCOMP, ">"); break;
case '<': resVal.emplace_back(tok::RCOMP, "<"); break;
case '$': resVal.emplace_back(tok::DOLLAR_SIGN, "$"); break;
case '\'': resVal.emplace_back(tok::SQUOTE, "\'"); break;
case ' ': case '\t': case '\r': case ' ': case '\t': case '\r':
case '\n': break; case '\n': break;
default: { default: {

View File

@ -3,18 +3,21 @@
#include <vector> #include <vector>
#include "Yerbacon.hpp" #include "Yerbacon.hpp"
#include <limits>
#include <ostream> #include <ostream>
struct tok { struct tok {
class LexerException: public Yerbacon::Exception { class LexerException: public Yerbacon::Exception {
using Yerbacon::Exception::Exception; using Yerbacon::Exception::Exception;
}; };
enum type { enum type: const unsigned short {
DEFINE, TAG, DOLLAR_SIGN, NUMBER, PLUS, LPAR, LBRACE, LBRACKET, RPAR, RBRACE, RBRACKET, ALPHACHAR, HYPHEN, LCOMP, RCOMP, UNEXPECTED = std::numeric_limits<unsigned char>::max() + 1, IDENTIFIER, NUMBER, ALPHACHAR,
SQUOTE, DEFINE = '=', TAG = '#', DOLLAR_SIGN = '$',
STRING, PLUS = '+', LPAR = '(', LBRACE = '{', LBRACKET = '[', RPAR = ')',
IDENTIFIER, RBRACE = '}', RBRACKET = ']',
UNEXPECTED HYPHEN = '-', LCOMP = '>', RCOMP = '<',
SQUOTE = '\'',
STRING = '"',
}; };
const type toktype; const type toktype;
const std::string toktext; const std::string toktext;

View File

@ -4,7 +4,8 @@
string getFileContent(const string& file); string getFileContent(const string& file);
void outputFileContent(const string& file, string_view content); void outputFileContent(const string& file, string_view content);
#include "src/headers/parsing/ParseComponents.hpp" #include "lex.hpp"
ParseTree parseString(const string& toParse); #include "parsing/Parser.hpp"
inline auto parseString(const string& toParse) { return Parser::parseVector(lex(toParse)); }
#endif //YERBACON_MISC_HPP #endif //YERBACON_MISC_HPP

View File

@ -1,7 +0,0 @@
#include "../headers/parsing/Parser.hpp"
using namespace std;
ParseTree parseString(const string& toParse) {
return Parser::parseVector(lex(toParse));
}