Change repeat to mean zero-or-more in lexical rules

Still need to make it work this way in syntactic rules
This commit is contained in:
Max Brunsfeld 2014-02-12 18:35:29 -08:00
parent 70173512f1
commit 7490a7ac94
3 changed files with 10 additions and 2 deletions

View file

@ -84,11 +84,13 @@ static void ts_lex(TSParser *parser) {
if (!((LOOKAHEAD_CHAR() == '\"') ||
(LOOKAHEAD_CHAR() == '\\')))
ADVANCE(11);
if (LOOKAHEAD_CHAR() == '\"')
ADVANCE(12);
if (LOOKAHEAD_CHAR() == '\\')
ADVANCE(13);
if (']' <= LOOKAHEAD_CHAR() && LOOKAHEAD_CHAR() <= '\\')
ADVANCE(15);
LEX_ERROR(2, EXPECT({"<EOF>-!", "#-<MAX>"}));
LEX_ERROR(1, EXPECT({"<ANY>"}));
case 11:
if (!((LOOKAHEAD_CHAR() == '\"') ||
(LOOKAHEAD_CHAR() == '\\')))

View file

@ -14,6 +14,12 @@ describe("json", []() {
});
it("parses strings", [&]() {
TSDocumentSetText(document, "\"\"");
AssertThat(string(TSDocumentToString(document)), Equals("(value (string))"));
TSDocumentSetText(document, "\"simple-string\"");
AssertThat(string(TSDocumentToString(document)), Equals("(value (string))"));
TSDocumentSetText(document, "\"this is a \\\"string\\\" within a string\"");
AssertThat(string(TSDocumentToString(document)), Equals("(value (string))"));
});

View file

@ -26,7 +26,7 @@ namespace tree_sitter {
}
void visit(const Repeat *rule) {
value = rule_can_be_blank(rule->content);
value = true;
}
};