minor refactor
This commit is contained in:
+3
-27
@@ -1,5 +1,7 @@
|
||||
#include "commons.h"
|
||||
|
||||
#include "../util/stringutil.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <math.h>
|
||||
@@ -38,32 +40,6 @@ std::string parsing_error::errorLog() const {
|
||||
}
|
||||
ss << "^";
|
||||
return ss.str();
|
||||
|
||||
}
|
||||
|
||||
std::string escape_string(std::string s) {
|
||||
std::stringstream ss;
|
||||
ss << '"';
|
||||
for (char c : s) {
|
||||
switch (c) {
|
||||
case '\n': ss << "\\n"; break;
|
||||
case '\r': ss << "\\r"; break;
|
||||
case '\t': ss << "\\t"; break;
|
||||
case '\f': ss << "\\f"; break;
|
||||
case '\b': ss << "\\b"; break;
|
||||
case '"': ss << "\\\""; break;
|
||||
case '\\': ss << "\\\\"; break;
|
||||
default:
|
||||
if (c < ' ') {
|
||||
ss << "\\" << std::oct << uint(ubyte(c));
|
||||
break;
|
||||
}
|
||||
ss << c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ss << '"';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
BasicParser::BasicParser(std::string file, std::string source) : filename(file), source(source) {
|
||||
@@ -151,7 +127,7 @@ void BasicParser::expect(const std::string& substring) {
|
||||
return;
|
||||
for (uint i = 0; i < substring.length(); i++) {
|
||||
if (source.length() <= pos + i || source[pos+i] != substring[i]) {
|
||||
throw error(escape_string(substring)+" expected");
|
||||
throw error(util::quote(substring)+" expected");
|
||||
}
|
||||
}
|
||||
pos += substring.length();
|
||||
|
||||
Reference in New Issue
Block a user