Skip to content

Commit 3aadaa3

Browse files
committed
Refactor regex patterns in ParseRules for improved accuracy; remove outdated test case for Python-style array wrapping
1 parent ded2220 commit 3aadaa3

2 files changed

Lines changed: 2 additions & 7 deletions

File tree

cmd/generate/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ func ParseRules(text string) []string {
1414
}
1515
lines := SplitLines(UnBacket(UnXml(Unfence(text))))
1616
itemsRe := regexp.MustCompile(`^\s*(\d+\.|_|-|\*)\s+`) // remove leading item numbers or bullets
17-
rulesRe := regexp.MustCompile(`^\s*(Inverse\s+)?Rules:\s*$`)
18-
pythonWrapRe := regexp.MustCompile(`^\["(.*)"\]$`)
17+
rulesRe := regexp.MustCompile(`^\s*(Inverse\s+(Output\s+)?)?Rules:\s*$`)
18+
pythonWrapRe := regexp.MustCompile(`^\["?(.*?)"?\]$`)
1919
var cleaned []string
2020
for _, line := range lines {
2121
// Remove leading numbering or bullets

cmd/generate/parser_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,6 @@ func TestParseRules(t *testing.T) {
451451
input: "1. Always validate input\n\n2. Handle errors gracefully\n\n\n3. Write clean code",
452452
expected: []string{"Always validate input", "Handle errors gracefully", "Write clean code"},
453453
},
454-
{
455-
name: "rules with python-style array wrapping",
456-
input: `["Always validate input"]`,
457-
expected: []string{"Always validate input"},
458-
},
459454
{
460455
name: "code fenced rules",
461456
input: "```\n1. Always validate input\n2. Handle errors gracefully\n```",

0 commit comments

Comments
 (0)