forked from solstice/solstice
Proper string parsing
This commit is contained in:
21
src/main.cpp
21
src/main.cpp
@@ -212,7 +212,6 @@ namespace HighGround {
|
||||
GroundInstruction gi3 = groundCreateInstruction(CREATELABEL);
|
||||
groundAddReferenceToInstruction(&gi3, groundCreateReference(LABEL, labelId.data()));
|
||||
codeBlock.code.push_back(gi3);
|
||||
codeBlock.code.push_back(groundCreateInstruction(PAUSE));
|
||||
code.push_back(codeBlock);
|
||||
break;
|
||||
}
|
||||
@@ -525,9 +524,29 @@ namespace HighGround {
|
||||
current = 0;
|
||||
std::vector<std::string> tokens;
|
||||
std::string buf;
|
||||
bool inString = false;
|
||||
while (auto copt = consume()) {
|
||||
char c = copt.value();
|
||||
if (inString) {
|
||||
buf.push_back(c);
|
||||
if (c == '"') {
|
||||
tokens.push_back(buf);
|
||||
buf.clear();
|
||||
inString = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
switch (c) {
|
||||
// double quotes are special
|
||||
case '"': {
|
||||
if (!buf.empty()) {
|
||||
tokens.push_back(buf);
|
||||
buf.clear();
|
||||
}
|
||||
buf.push_back(c);
|
||||
inString = true;
|
||||
break;
|
||||
}
|
||||
// tokens which are not followed by anything
|
||||
case '\n':
|
||||
case '(':
|
||||
|
||||
@@ -3,3 +3,5 @@ puts 432
|
||||
puts 3.141
|
||||
puts 'c'
|
||||
puts true
|
||||
|
||||
puts "now we have proper string lexing!!!!!11!!@!2!1@1@12!!!112!@"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if true {
|
||||
if 1 == 1 {
|
||||
puts "huzzah"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user