2 Commits

Author SHA1 Message Date
Aadhavan Srinivasan
435588274c WIP - fixing character classes 2025-01-24 17:06:19 -05:00
Aadhavan Srinivasan
a347ebacc4 Added more test cases 2025-01-24 17:06:00 -05:00
2 changed files with 5 additions and 0 deletions

View File

@@ -82,6 +82,7 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
// Also check for non-capturing groups. The LPAREN of a non-capturing group looks like this: '(?:'
// I take this out, and put in a special character - NONCAPLPAREN_CHAR.
//
// Another check is made for unescaped brackets - opening brackets are replaced with LBRACKET and closing brackets are replaced with RBRACKET.
// Finally, check for escaped backslashes. Replace these with the BACKSLASH metacharacter. Later, in thompson(),
// these will be converted back. This avoids confusiuon in detecting whether a character is escaped eg. detecting
// whether '\\[a]' has an escaped opening bracket (it doesn't).
@@ -122,6 +123,9 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
} else if c == '\\' && i < len(re_runes_orig)-1 && re_runes_orig[i+1] == '\\' { // Escaped backslash
re_runes = append(re_runes, ESC_BACKSLASH)
i++
} else if c == '[' && (i == 0 || re_runes_orig[i-1] != '\\')
} else {
re_runes = append(re_runes, c)
}

View File

@@ -236,6 +236,7 @@ var reTests = []struct {
{`abc)`, nil, `-`, nil},
{`(abc`, nil, `-`, nil},
{`a]`, nil, `a]`, []Group{{0, 2}}},
{`a[]]b`, nil, `a]b`, []Group{{0, 3}}},
// Todo - add numeric range tests
}