Give better symbol names to generated tokens

This should make debugging easier
This commit is contained in:
Max Brunsfeld 2014-03-27 12:54:54 -07:00
parent 2226234924
commit e1ac62edc5
14 changed files with 1017 additions and 842 deletions

View file

@ -1,18 +1,11 @@
#include "compiler/generate_code/helpers.h"
#include "compiler/util/string_helpers.h"
namespace tree_sitter {
using std::string;
using std::vector;
namespace generate_code {
static void str_replace(string *input, const string &search, const string &replace) {
size_t pos = 0;
while (1) {
pos = input->find(search, pos);
if (pos == string::npos) break;
input->erase(pos, search.length());
input->insert(pos, replace);
pos += replace.length();
}
}
string join(vector<string> lines, string separator) {
string result;
bool started = false;
@ -30,13 +23,23 @@ namespace tree_sitter {
string indent(string input) {
string tab = " ";
str_replace(&input, "\n", "\n" + tab);
util::str_replace(&input, "\n", "\n" + tab);
return tab + input;
}
string escape_string(string input) {
str_replace(&input, "\"", "\\\"");
return input;
string character_code(char character) {
switch (character) {
case '\0':
return "\\0";
case '"':
return "\\\"";
case '\n':
return "\\n";
case '\\':
return "\\\\";
default:
return string() + character;
}
}
}
}