Add regex postfix flags to javascript grammar

- Refactor statement terminators in javascript grammar
- Reorganize javascript language tests
This commit is contained in:
Max Brunsfeld 2014-06-11 16:43:03 -07:00
parent 082560dd6e
commit bb4d83ce47
9 changed files with 32747 additions and 32747 deletions

View file

@ -17,7 +17,7 @@ namespace tree_sitter {
using std::pair;
using util::join;
using util::indent;
using util::character_code;
using util::escape_char;
namespace generate_code {
string _switch(string condition, string body) {
@ -154,10 +154,10 @@ namespace tree_sitter {
string condition_for_character_range(const rules::CharacterRange &range) {
string lookahead("lookahead");
if (range.min == range.max) {
return lookahead + " == '" + character_code(range.min) + "'";
return lookahead + " == '" + escape_char(range.min) + "'";
} else {
return string("'") + character_code(range.min) + string("' <= ") + lookahead +
" && " + lookahead + " <= '" + character_code(range.max) + "'";
return string("'") + escape_char(range.min) + string("' <= ") + lookahead +
" && " + lookahead + " <= '" + escape_char(range.max) + "'";
}
}

View file

@ -14,11 +14,11 @@ namespace tree_sitter {
namespace prepare_grammar {
class TokenDescription : public rules::RuleFn<string> {
string apply_to(const rules::Pattern *rule) {
return "/" + rule->value + "/";
return "/" + util::escape_string(rule->value) + "/";
}
string apply_to(const rules::String *rule) {
return "'" + rule->value + "'";
return "'" + util::escape_string(rule->value) + "'";
}
string apply_to(const rules::Metadata *rule) {

View file

@ -23,6 +23,27 @@ namespace tree_sitter {
str_replace(&input, "\n", "\\n");
return input;
}
string escape_char(char character) {
switch (character) {
case '\0':
return "\\0";
case '"':
return "\\\"";
case '\'':
return "\\'";
case '\n':
return "\\n";
case '\r':
return "\\r";
case '\t':
return "\\t";
case '\\':
return "\\\\";
default:
return string() + character;
}
}
string join(vector<string> lines, string separator) {
string result;
@ -44,26 +65,5 @@ namespace tree_sitter {
util::str_replace(&input, "\n", "\n" + tab);
return tab + input;
}
string character_code(char character) {
switch (character) {
case '\0':
return "\\0";
case '"':
return "\\\"";
case '\'':
return "\\'";
case '\n':
return "\\n";
case '\r':
return "\\r";
case '\t':
return "\\t";
case '\\':
return "\\\\";
default:
return string() + character;
}
}
}
}

View file

@ -9,10 +9,10 @@ namespace tree_sitter {
namespace util {
void str_replace(std::string *input, const std::string &search, const std::string &replace);
std::string escape_string(std::string input);
std::string escape_char(char character);
std::string indent(std::string input);
std::string join(std::vector<std::string> lines, std::string separator);
std::string join(std::vector<std::string> lines);
std::string character_code(char character);
}
}