diff --git a/src/etc/lexer.cpp b/src/etc/lexer.cpp index fa6389c..3d6b0f7 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) +vector lex(const string& in, const char separatorCharacter) { vector resVal; unsigned long lineNumber = 1; @@ -21,9 +21,9 @@ vector lex(const string& in) 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); + resVal.emplace_back(static_cast(current), string(1, current), lineNumber); break; + [[likely]] case '\n': ++lineNumber; case ';': resVal.emplace_back(SEPARATOR, string(1, separatorCharacter), lineNumber); [[likely]] case ' ': case '\t': case '\r': break; - [[likely]] case '\n': ++lineNumber; break; default: { tok::type type = getIdentifierCharType(current); bool isTypeString = (type == STRING); @@ -32,8 +32,8 @@ vector lex(const string& in) case IDENTIFIER: case NUMBER: { string formedString; for (;i < in.size(); ++i) { - tok::type currentCharType = getIdentifierCharType(in[i]); - bool isString = currentCharType == STRING; + const tok::type currentCharType = getIdentifierCharType(in[i]); + const bool isString = currentCharType == STRING; if (i == in.size() - 1 && not isString) throw tok::LexerException("A never ending string was found", lineNumber); if ((currentCharType == type || isTypeString) && !isString) { formedString += string(1, in[i]); diff --git a/src/headers/lex.hpp b/src/headers/lex.hpp index e485197..503aad7 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, + UNEXPECTED = std::numeric_limits::max() + 1, IDENTIFIER, NUMBER, ALPHACHAR, SEPARATOR, 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, auto line): toktype(Type), toktext(Text), line(line) {} + tok(type Type, std::string_view Text, decltype(line) 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); +std::vector lex(const std::string& in, char separatorCharacter); #endif //YERBACON_TEST_H \ No newline at end of file diff --git a/src/headers/misc.hpp b/src/headers/misc.hpp index 0962dee..3733bfe 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) { return Parser::parseVector(lex(toParse)); } +inline auto parseString(const string& toParse, const char lineSeparator) { return Parser::parseVector(lex(toParse, lineSeparator)); } #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 d01b9e5..a8bb1cb 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 = make_shared(X()); + #define ADDTARGET(X) target = shared_ptr(new (X)); switch (selected) { #ifdef LUA_HPP case LUA: ADDTARGET(LUA_HPP); break; diff --git a/src/main.cpp b/src/main.cpp index 3881eeb..b2b7313 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ int main(int argc, char* argv[]) { string target = ".lua"; bool printResult = false; bool parallel = false; + bool newLinesSeparator = true; if (argc > 0) { vector files; @@ -22,15 +23,15 @@ int main(int argc, char* argv[]) { const string_view currentArg (argv[i]); if (currentArg == ArgumentShort("printresult")) printResult = true; else if (currentArg == ArgumentAssignable("target")) { - target.clear(); - string value = ArgumentAssignable::getValueFor(currentArg.data()); + const 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](string_view name) { - string transpiledString = transpile(parseString(getFileContent(name.data())), target); + const auto compile = [&target, &newLinesSeparator](string_view name) { + string transpiledString = transpile(parseString(getFileContent(name.data()), newLinesSeparator ? ';' : '\n'), target); name.remove_suffix(6); string outputFile; (outputFile = name).append(target);