Add rule precedence construct
Still need to add some way of expressing left and right associativity
This commit is contained in:
parent
e23604ac52
commit
a437d39773
23 changed files with 750 additions and 1504 deletions
|
|
@ -1,7 +1,10 @@
|
|||
#include "compiler/util/string_helpers.h"
|
||||
#include <vector>
|
||||
|
||||
namespace tree_sitter {
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::set;
|
||||
|
||||
namespace util {
|
||||
void str_replace(string *input, const string &search, const string &replace) {
|
||||
|
|
@ -20,5 +23,45 @@ namespace tree_sitter {
|
|||
str_replace(&input, "\n", "\\n");
|
||||
return input;
|
||||
}
|
||||
|
||||
string join(vector<string> lines, string separator) {
|
||||
string result;
|
||||
bool started = false;
|
||||
for (auto line : lines) {
|
||||
if (started) result += separator;
|
||||
started = true;
|
||||
result += line;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
string join(vector<string> lines) {
|
||||
return join(lines, "\n");
|
||||
}
|
||||
|
||||
string indent(string input) {
|
||||
string tab = " ";
|
||||
util::str_replace(&input, "\n", "\n" + tab);
|
||||
return tab + input;
|
||||
}
|
||||
|
||||
string character_code(char character) {
|
||||
switch (character) {
|
||||
case '\0':
|
||||
return "\\0";
|
||||
case '"':
|
||||
return "\\\"";
|
||||
case '\n':
|
||||
return "\\n";
|
||||
case '\r':
|
||||
return "\\r";
|
||||
case '\t':
|
||||
return "\\t";
|
||||
case '\\':
|
||||
return "\\\\";
|
||||
default:
|
||||
return string() + character;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue