diff --git a/src/datatypes/strings/strings.cpp b/src/datatypes/strings/strings.cpp index d28145d..977ac9a 100644 --- a/src/datatypes/strings/strings.cpp +++ b/src/datatypes/strings/strings.cpp @@ -51,7 +51,7 @@ Value handleStringGet(const Value& subject, const std::vector& args) { error("String index out of bounds"); return Value(); } - return Value(std::string(1, subject.string_val.at(index))); + return Value("\"" + std::string(1, subject.string_val.at(index)) + "\""); } void handleStringSet(std::string var_name, Value& subject, const Value& index_val, const Value& new_val) { diff --git a/src/defs/defs.cpp b/src/defs/defs.cpp index 3f9818f..ac77f03 100644 --- a/src/defs/defs.cpp +++ b/src/defs/defs.cpp @@ -77,18 +77,18 @@ Instruction::Instruction(std::vector toks) { Value::Value(std::string stringval) { // This constructor will attempt to parse the string into the most specific type possible. - if (stringval.length() > 2 && stringval.front() == '<' && stringval.back() == '>') { - valtype = ValueType::TypePlaceholder; - type_placeholder_name = stringval.substr(1, stringval.length() - 2); - return; - } - if (stringval.length() >= 2 && stringval.front() == '"' && stringval.back() == '"') { valtype = ValueType::String; string_val = interpretEscapeSequences(stringval.substr(1, stringval.length() - 2)); return; } + if (stringval.length() > 2 && stringval.front() == '<' && stringval.back() == '>') { + valtype = ValueType::TypePlaceholder; + type_placeholder_name = stringval.substr(1, stringval.length() - 2); + return; + } + if (stringval.empty()) { valtype = ValueType::None; string_val = ""; @@ -274,7 +274,7 @@ std::vector split(std::string line) { splitvals.push_back(Value(buf)); } buf = ""; - } else if (chr == '(' || chr == '[') { + } else if ((chr == '(' || chr == '[') && !instring) { if (brackets == 0) { bracket_type = chr; if (!buf.empty()) { @@ -285,7 +285,7 @@ std::vector split(std::string line) { buf += chr; } brackets++; - } else if (chr == ')' || chr == ']') { + } else if ((chr == ')' || chr == ']') && !instring) { brackets--; if (brackets == 0) { if (!buf.empty()) { diff --git a/src/defs/defs.h b/src/defs/defs.h index 342a5f4..f54c3ce 100644 --- a/src/defs/defs.h +++ b/src/defs/defs.h @@ -67,6 +67,7 @@ struct Instruction { InstructionType instruction = InstructionType::None; std::vector args; std::string toString() const; + int lineNum; Instruction() = default; Instruction(std::vector toks); Instruction(std::vector toks); diff --git a/src/modules/concat/concat.cpp b/src/modules/concat/concat.cpp index acb1d84..e54e24a 100644 --- a/src/modules/concat/concat.cpp +++ b/src/modules/concat/concat.cpp @@ -7,6 +7,7 @@ Value modules::concat(std::vector args) { std::string buf; for (Value val : args) { switch (val.valtype) { + case ValueType::Identifier: case ValueType::String: buf += val.string_val; break; @@ -17,7 +18,7 @@ Value modules::concat(std::vector args) { buf += std::to_string(val.double_val); break; default: - error("Can only concatenate String, Int, and Double values"); + error("Can only concatenate String, Int, and Double values. Value given: " + val.toString()); break; } } diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 2196533..27a18d4 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -9,8 +9,10 @@ std::vector parse(std::string program) { std::vector lines; std::string buf; int blockTracker = 0; + int lineNum = 0; for (char chr : program) { + if (chr == '\n') lineNum ++; if (chr == '{') { blockTracker++; } else if (chr == '}') { @@ -23,7 +25,7 @@ std::vector parse(std::string program) { if ((chr == '\n' || chr == ';') && blockTracker == 0) { if (!buf.empty()) { - lines.push_back(buf); + lines.push_back(trim(buf)); buf.clear(); } } else { diff --git a/tests/toInt.kyn b/tests/toInt.kyn new file mode 100644 index 0000000..e9b7d97 --- /dev/null +++ b/tests/toInt.kyn @@ -0,0 +1,47 @@ +fun toInt in { + assert $in is + let retint = 0 + let counter = 0 + let power = ($in size) + let size = ($in size) + while compare $counter < $size { + let char = ($in $counter) + power = (math $power - 1) + if compare $char == "1" { + retint = (math $retint + (math 1 * 10 ^ $power)) +} + if compare $char == "2" { + retint = (math $retint + (math 2 * 10 ^ $power)) +} + if compare $char == "3" { + retint = (math $retint + (math 3 * 10 ^ $power)) +} + if compare $char == "4" { + retint = (math $retint + (math 4 * 10 ^ $power)) +} + if compare $char == "5" { + retint = (math $retint + (math 5 * 10 ^ $power)) +} + if compare $char == "6" { + retint = (math $retint + (math 6 * 10 ^ $power)) +} + if compare $char == "7" { + retint = (math $retint + (math 7 * 10 ^ $power)) +} + if compare $char == "8" { + retint = (math $retint + (math 8 * 10 ^ $power)) +} + if compare $char == "9" { + retint = (math $retint + (math 9 * 10 ^ $power)) +} + if compare $char == "0" { + # whole lotta nothing +} + counter = (math $counter + 1) + +} + return $retint +} +let myInt = (toInt "4738927643289") + +println $myInt