Make study a negatable option instead

This commit is contained in:
Flaviu Tamas 2015-01-18 12:49:22 -05:00
commit ca299504d1
3 changed files with 7 additions and 8 deletions

View file

@ -109,7 +109,7 @@ as a key.
Represents the pattern that things are matched against, constructed with Represents the pattern that things are matched against, constructed with
`initRegex(string)` or `re(string)`. Examples: `re"foo"`, `re(r"foo # comment", `initRegex(string)` or `re(string)`. Examples: `re"foo"`, `re(r"foo # comment",
"Sx<anycrlf>")`. "x<anycrlf>")`.
`pattern: string` :: the string that was used to create the pattern. `pattern: string` :: the string that was used to create the pattern.
`captureCount: int` :: the number of captures that the pattern has. `captureCount: int` :: the number of captures that the pattern has.
@ -127,8 +127,6 @@ Represents the pattern that things are matched against, constructed with
subject string subject string
- `N` - turn off auto-capture, `(?foo)` is necessary to capture. - `N` - turn off auto-capture, `(?foo)` is necessary to capture.
- `s` - `.` matches newline - `s` - `.` matches newline
- `S` - study the pattern to hopefully improve performance. JIT is unspported at
the moment.
- `U` - expressions are not greedy by default. `?` can be added to a qualifier - `U` - expressions are not greedy by default. `?` can be added to a qualifier
to make it greedy. to make it greedy.
- `u` - same as `8` - `u` - same as `8`
@ -152,3 +150,4 @@ ____
- `<bsr_anycrlf>` - `\R` matches CR, LF, or CRLF - `<bsr_anycrlf>` - `\R` matches CR, LF, or CRLF
- `<bsr_unicode>` - `\R` matches any unicode newline - `<bsr_unicode>` - `\R` matches any unicode newline
- `<js>` - Javascript compatibility - `<js>` - Javascript compatibility
- `<no_study>` - turn off studying; study is enabled by deafault

View file

@ -4,12 +4,12 @@ include nre
suite "find": suite "find":
test "find text": test "find text":
check("3213a".find(initRegex(r"[a-z]")).match == "a") check("3213a".find(initRegex(r"[a-z]")).match == "a")
check("1 2 3 4 5 6 7 8 ".findAll(initRegex(r" ", "S")).map( check("1 2 3 4 5 6 7 8 ".findAll(re" ").map(
proc (a: RegexMatch): string = a.match proc (a: RegexMatch): string = a.match
) == @[" ", " ", " ", " ", " ", " ", " ", " "]) ) == @[" ", " ", " ", " ", " ", " ", " ", " "])
test "find bounds": test "find bounds":
check("1 2 3 4 5 ".findAll(initRegex(r" ", "S")).map( check("1 2 3 4 5 ".findAll(re" ")).map(
proc (a: RegexMatch): Slice[int] = a.matchBounds proc (a: RegexMatch): Slice[int] = a.matchBounds
) == @[1..2, 3..4, 5..6, 7..8, 9..10]) ) == @[1..2, 3..4, 5..6, 7..8, 9..10])

View file

@ -4,9 +4,9 @@ include nre
suite "string splitting": suite "string splitting":
test "splitting strings": test "splitting strings":
check("12345".split(initRegex("")) == @["1", "2", "3", "4", "5"]) check("12345".split(initRegex("")) == @["1", "2", "3", "4", "5"])
check("1 2 3 4 5 6 ".split(initRegex(" ", "S")) == @["1", "2", "3", "4", "5", "6", ""]) check("1 2 3 4 5 6 ".split(re" ") == @["1", "2", "3", "4", "5", "6", ""])
check("1 2 ".split(initRegex(" ", "S")) == @["1", "", "2", "", ""]) check("1 2 ".split(initRegex(" ")) == @["1", "", "2", "", ""])
check("1 2".split(initRegex(" ", "S")) == @["1", "2"]) check("1 2".split(initRegex(" ")) == @["1", "2"])
check("foo".split(initRegex("foo")) == @["", ""]) check("foo".split(initRegex("foo")) == @["", ""])
test "captured patterns": test "captured patterns":