Add repeat rules
This commit is contained in:
parent
80acabb03e
commit
92e73a9e70
8 changed files with 96 additions and 12 deletions
|
|
@ -41,21 +41,25 @@ namespace tree_sitter {
|
|||
case '(':
|
||||
next();
|
||||
result = rule();
|
||||
if (peek() == ')') {
|
||||
if (peek() != ')')
|
||||
error("mismatched parens");
|
||||
else
|
||||
next();
|
||||
return result;
|
||||
} else {
|
||||
throw std::string("Invalid regex pattern: ") + input;
|
||||
}
|
||||
break;
|
||||
case ')':
|
||||
error("mismatched parens");
|
||||
break;
|
||||
case '\\':
|
||||
next();
|
||||
result = character(peek());
|
||||
next();
|
||||
break;
|
||||
default:
|
||||
result = character(peek());
|
||||
next();
|
||||
return result;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void next() {
|
||||
|
|
@ -70,6 +74,10 @@ namespace tree_sitter {
|
|||
return position < length;
|
||||
}
|
||||
|
||||
void error(const char *message) {
|
||||
throw std::string("Invalid regex pattern '") + input + "': " + message;
|
||||
}
|
||||
|
||||
const std::string input;
|
||||
const size_t length;
|
||||
int position;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue