Parsing bug fix
This commit is contained in:
@@ -92,9 +92,18 @@ std::vector<Instruction> parse(std::string program) {
|
||||
error("Expected '{' for else statement");
|
||||
continue;
|
||||
}
|
||||
size_t else_block_end = remaining_line.find_last_of('}');
|
||||
if (else_block_end == std::string::npos) {
|
||||
error("Expected '}' for else statement");
|
||||
size_t else_block_end = 0;
|
||||
int brace_level = 0;
|
||||
for (size_t i = else_block_start; i < remaining_line.length(); ++i) {
|
||||
if (remaining_line[i] == '{') brace_level++;
|
||||
else if (remaining_line[i] == '}') brace_level--;
|
||||
if (brace_level == 0) {
|
||||
else_block_end = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (else_block_end == 0) {
|
||||
error("Mismatched braces in else statement");
|
||||
continue;
|
||||
}
|
||||
std::string else_content = remaining_line.substr(else_block_start + 1, else_block_end - else_block_start - 1);
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
// Helper to trim whitespace from the start and end of a string
|
||||
std::string trim(const std::string& str) {
|
||||
size_t first = str.find_first_not_of(" \t\n\r");
|
||||
size_t first = str.find_first_not_of(" \t\n");
|
||||
if (std::string::npos == first) {
|
||||
return str;
|
||||
return "";
|
||||
}
|
||||
size_t last = str.find_last_not_of(" \t\n\r");
|
||||
size_t last = str.find_last_not_of(" \t\n");
|
||||
return str.substr(first, (last - first + 1));
|
||||
}
|
||||
|
||||
|
||||
17
test.kyn
Normal file
17
test.kyn
Normal file
@@ -0,0 +1,17 @@
|
||||
fun testFn in {
|
||||
println "Hi!"
|
||||
if compare 1 == 1 {
|
||||
println "1 == 1"
|
||||
|
||||
# This won't work because this is indented
|
||||
}
|
||||
}
|
||||
|
||||
fun testFn in {
|
||||
println "Hi!"
|
||||
if compare 1 == 1 {
|
||||
println "1 == 1"
|
||||
|
||||
# This works now that the indentation is removed
|
||||
}
|
||||
}
|
||||
@@ -9,37 +9,37 @@ fun toInt in {
|
||||
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" {
|
||||
}
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user