This commit is contained in:
yhirose 2022-05-04 23:26:36 -04:00
parent 2478bd57ab
commit 23436e1fcc
2 changed files with 8 additions and 5 deletions

View File

@ -3132,7 +3132,10 @@ private:
tok(oom(seq(npd(chr(']')), g["Range"]))), chr(']'), tok(oom(seq(npd(chr(']')), g["Range"]))), chr(']'),
g["Spacing"]); g["Spacing"]);
g["Range"] <= cho(seq(g["Char"], chr('-'), g["Char"]), g["Char"]); // NOTE: This is different from The original Brian Ford's paper, and this
// modification allows us to specify `[+-]` as a valid char class.
g["Range"] <= cho(seq(g["Char"], chr('-'), npd(chr(']')), g["Char"]), g["Char"]);
g["Char"] <= g["Char"] <=
cho(seq(chr('\\'), cls("nrt'\"[]\\^")), cho(seq(chr('\\'), cls("nrt'\"[]\\^")),
seq(chr('\\'), cls("0-3"), cls("0-7"), cls("0-7")), seq(chr('\\'), cls("0-3"), cls("0-7"), cls("0-7")),

View File

@ -159,7 +159,7 @@ TEST(LeftRecursiveTest, PEG_Class) {
EXPECT_TRUE(exact(g, "Class", "[az]")); EXPECT_TRUE(exact(g, "Class", "[az]"));
EXPECT_TRUE(exact(g, "Class", "[a-zA-Z-]")); EXPECT_TRUE(exact(g, "Class", "[a-zA-Z-]"));
EXPECT_TRUE(exact(g, "Class", "[a-zA-Z-0-9]")); EXPECT_TRUE(exact(g, "Class", "[a-zA-Z-0-9]"));
EXPECT_FALSE(exact(g, "Class", "[a-]")); EXPECT_TRUE(exact(g, "Class", "[a-]"));
EXPECT_TRUE(exact(g, "Class", "[-a]")); EXPECT_TRUE(exact(g, "Class", "[-a]"));
EXPECT_FALSE(exact(g, "Class", "[")); EXPECT_FALSE(exact(g, "Class", "["));
EXPECT_FALSE(exact(g, "Class", "[a")); EXPECT_FALSE(exact(g, "Class", "[a"));
@ -168,7 +168,7 @@ TEST(LeftRecursiveTest, PEG_Class) {
EXPECT_TRUE(exact(g, "Class", u8"[あ-ん]")); EXPECT_TRUE(exact(g, "Class", u8"[あ-ん]"));
EXPECT_FALSE(exact(g, "Class", u8"あ-ん")); EXPECT_FALSE(exact(g, "Class", u8"あ-ん"));
EXPECT_TRUE(exact(g, "Class", "[-+]")); EXPECT_TRUE(exact(g, "Class", "[-+]"));
EXPECT_FALSE(exact(g, "Class", "[+-]")); EXPECT_TRUE(exact(g, "Class", "[+-]"));
EXPECT_TRUE(exact(g, "Class", "[\\^]")); EXPECT_TRUE(exact(g, "Class", "[\\^]"));
} }
@ -180,7 +180,7 @@ TEST(LeftRecursiveTest, PEG_Negated_Class) {
EXPECT_TRUE(exact(g, "NegatedClass", "[^az]")); EXPECT_TRUE(exact(g, "NegatedClass", "[^az]"));
EXPECT_TRUE(exact(g, "NegatedClass", "[^a-zA-Z-]")); EXPECT_TRUE(exact(g, "NegatedClass", "[^a-zA-Z-]"));
EXPECT_TRUE(exact(g, "NegatedClass", "[^a-zA-Z-0-9]")); EXPECT_TRUE(exact(g, "NegatedClass", "[^a-zA-Z-0-9]"));
EXPECT_FALSE(exact(g, "NegatedClass", "[^a-]")); EXPECT_TRUE(exact(g, "NegatedClass", "[^a-]"));
EXPECT_TRUE(exact(g, "NegatedClass", "[^-a]")); EXPECT_TRUE(exact(g, "NegatedClass", "[^-a]"));
EXPECT_FALSE(exact(g, "NegatedClass", "[^")); EXPECT_FALSE(exact(g, "NegatedClass", "[^"));
EXPECT_FALSE(exact(g, "NegatedClass", "[^a")); EXPECT_FALSE(exact(g, "NegatedClass", "[^a"));
@ -189,7 +189,7 @@ TEST(LeftRecursiveTest, PEG_Negated_Class) {
EXPECT_TRUE(exact(g, "NegatedClass", u8"[^あ-ん]")); EXPECT_TRUE(exact(g, "NegatedClass", u8"[^あ-ん]"));
EXPECT_FALSE(exact(g, "NegatedClass", u8"^あ-ん")); EXPECT_FALSE(exact(g, "NegatedClass", u8"^あ-ん"));
EXPECT_TRUE(exact(g, "NegatedClass", "[^-+]")); EXPECT_TRUE(exact(g, "NegatedClass", "[^-+]"));
EXPECT_FALSE(exact(g, "NegatedClass", "[^+-]")); EXPECT_TRUE(exact(g, "NegatedClass", "[^+-]"));
EXPECT_TRUE(exact(g, "NegatedClass", "[^^]")); EXPECT_TRUE(exact(g, "NegatedClass", "[^^]"));
} }