From bfa8f50ad9c35d99dab6d5ad0c7b5bc6a4ec40f2 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 11 Sep 2021 11:35:22 +0200 Subject: [PATCH] Revert "Add a "SEPARATOR" token type" This reverts commit 47478173 --- src/etc/lexer.cpp | 6 +++--- src/headers/lex.hpp | 6 +++--- src/headers/misc.hpp | 2 +- src/headers/transpiler/Target.hpp | 2 +- src/main.cpp | 9 ++++----- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/etc/lexer.cpp b/src/etc/lexer.cpp index 74bb336..8d26821 100644 --- a/src/etc/lexer.cpp +++ b/src/etc/lexer.cpp @@ -9,7 +9,7 @@ tok::type getIdentifierCharType(const char& Char) { else return UNEXPECTED; } -vector lex(const string& in, const char separatorCharacter) +vector lex(const string& in) { vector resVal; unsigned long lineNumber = 1; @@ -21,9 +21,9 @@ vector lex(const string& in, const char separatorCharacter) case LBRACE: case RBRACE: case LBRACKET: case RBRACKET: case PLUS: case HYPHEN: case LCOMP: case RCOMP: case DOT: case DOLLAR_SIGN: case SQUOTE: - resVal.emplace_back(static_cast(current), string(1, current), lineNumber); break; - [[likely]] case '\n': ++lineNumber; case ';': resVal.emplace_back(SEPARATOR, string(1, separatorCharacter), lineNumber); + resVal.emplace_back(static_cast(current), string(1, current), lineNumber); [[likely]] case ' ': case '\t': [[unlikely]] case '\r': break; + [[likely]] case '\n': ++lineNumber; break; default: { tok::type type = getIdentifierCharType(current); bool isTypeString = (type == STRING); diff --git a/src/headers/lex.hpp b/src/headers/lex.hpp index 503aad7..e485197 100644 --- a/src/headers/lex.hpp +++ b/src/headers/lex.hpp @@ -11,7 +11,7 @@ struct tok { using Yerbacon::Exception::Exception; }; enum type: const unsigned short { - UNEXPECTED = std::numeric_limits::max() + 1, IDENTIFIER, NUMBER, ALPHACHAR, SEPARATOR, + UNEXPECTED = std::numeric_limits::max() + 1, IDENTIFIER, NUMBER, ALPHACHAR, DEFINE = '=', TAG = '#', DOLLAR_SIGN = '$', DOT = '.', PLUS = '+', LPAR = '(', LBRACE = '{', LBRACKET = '[', RPAR = ')', RBRACE = '}', RBRACKET = ']', @@ -22,9 +22,9 @@ struct tok { const type toktype; const std::string toktext; const unsigned long line = 0; - tok(type Type, std::string_view Text, decltype(line) line): toktype(Type), toktext(Text), line(line) {} + tok(type Type, std::string_view Text, auto line): toktype(Type), toktext(Text), line(line) {} friend std::ostream& operator<<(std::ostream& output, const tok& it) { return output << it.toktext; } }; -std::vector lex(const std::string& in, char separatorCharacter); +std::vector lex(const std::string& in); #endif //YERBACON_TEST_H \ No newline at end of file diff --git a/src/headers/misc.hpp b/src/headers/misc.hpp index 3733bfe..0962dee 100644 --- a/src/headers/misc.hpp +++ b/src/headers/misc.hpp @@ -6,6 +6,6 @@ void outputFileContent(const string& file, string_view content); #include "lex.hpp" #include "parsing/Parser.hpp" -inline auto parseString(const string& toParse, const char lineSeparator) { return Parser::parseVector(lex(toParse, lineSeparator)); } +inline auto parseString(const string& toParse) { return Parser::parseVector(lex(toParse)); } #endif //YERBACON_MISC_HPP \ No newline at end of file diff --git a/src/headers/transpiler/Target.hpp b/src/headers/transpiler/Target.hpp index a8bb1cb..d01b9e5 100644 --- a/src/headers/transpiler/Target.hpp +++ b/src/headers/transpiler/Target.hpp @@ -100,7 +100,7 @@ shared_ptr Target::forName(string_view name) { } } shared_ptr target; - #define ADDTARGET(X) target = shared_ptr(new (X)); + #define ADDTARGET(X) target = make_shared(X()); switch (selected) { #ifdef LUA_HPP case LUA: ADDTARGET(LUA_HPP); break; diff --git a/src/main.cpp b/src/main.cpp index b2b7313..3881eeb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,6 @@ int main(int argc, char* argv[]) { string target = ".lua"; bool printResult = false; bool parallel = false; - bool newLinesSeparator = true; if (argc > 0) { vector files; @@ -23,15 +22,15 @@ int main(int argc, char* argv[]) { const string_view currentArg (argv[i]); if (currentArg == ArgumentShort("printresult")) printResult = true; else if (currentArg == ArgumentAssignable("target")) { - const string value = ArgumentAssignable::getValueFor(currentArg.data()); + target.clear(); + string value = ArgumentAssignable::getValueFor(currentArg.data()); if (!value.empty()) (target = '.') += value; } else if (currentArg == Argument("parallel")) parallel = true; else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg); - else if (currentArg == Argument("newlinesoff")) newLinesSeparator = true; } - const auto compile = [&target, &newLinesSeparator](string_view name) { - string transpiledString = transpile(parseString(getFileContent(name.data()), newLinesSeparator ? ';' : '\n'), target); + const auto compile = [&target](string_view name) { + string transpiledString = transpile(parseString(getFileContent(name.data())), target); name.remove_suffix(6); string outputFile; (outputFile = name).append(target);