Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
output
generated-docs
bower_components

node_modules
package.json
package-lock.json
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Breaking changes:
New features:

Bugfixes:
- Issue #69: Fix regex parser to always wrap pattern inside `^(..)` (#80 by @chtenb)

Other improvements:
- Added `purs-tidy` formatter (#76 by @thomashoneyman)
Expand Down
5 changes: 1 addition & 4 deletions src/Text/Parsing/StringParser/CodePoints.purs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ regex pat =
matchRegex r
where
-- ensure the pattern only matches the current position in the parse
pattern =
case stripPrefix (Pattern "^") pat of
Nothing -> "^" <> pat
_ -> pat
pattern = "^(" <> pat <> ")"

matchRegex :: Regex.Regex -> Parser String
matchRegex r = Parser \{ str, pos } -> do
Expand Down
5 changes: 1 addition & 4 deletions src/Text/Parsing/StringParser/CodeUnits.purs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ regex pat =
matchRegex r
where
-- ensure the pattern only matches the current position in the parse
pattern =
case SCU.stripPrefix (Pattern "^") pat of
Nothing -> "^" <> pat
_ -> pat
pattern = "^(" <> pat <> ")"

matchRegex :: Regex.Regex -> Parser String
matchRegex r = Parser \{ str, pos } -> do
Expand Down
2 changes: 2 additions & 0 deletions test/CodePoints.purs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ testCodePoints = do
assert $ expectResult (NonEmptyList ('0' :| '1' : '2' : '3' : '4' : Nil)) (many1 anyDigit) "01234/"
assert $ expectResult (NonEmptyList ('5' :| '6' : '7' : '8' : '9' : Nil)) (many1 anyDigit) "56789:"
assert $ expectResult "aaaa" (regex "a+") "aaaab"
assert $ expectResult "aaaa" (regex "^a+") "aaaab"
assert $ parseFail (regex "a|b") "xb"
assert $ expectResult ("a" : "a" : "a" : Nil) (manyTill (string "a") (string "b")) "aaab"
assert $ expectResult Nil (manyTill (string "a") (string "b")) "b"
assert $ expectResult (NonEmptyList ("a" :| "a" : "a" : Nil)) (many1Till (string "a") (string "b")) "aaab"
Expand Down
2 changes: 2 additions & 0 deletions test/CodeUnits.purs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ testCodeUnits = do
assert $ expectResult (NonEmptyList ('0' :| '1' : '2' : '3' : '4' : Nil)) (many1 anyDigit) "01234/"
assert $ expectResult (NonEmptyList ('5' :| '6' : '7' : '8' : '9' : Nil)) (many1 anyDigit) "56789:"
assert $ expectResult "aaaa" (regex "a+") "aaaab"
assert $ expectResult "aaaa" (regex "^a+") "aaaab"
assert $ parseFail (regex "a|b") "xb"
assert $ expectResult ("a" : "a" : "a" : Nil) (manyTill (string "a") (string "b")) "aaab"
assert $ expectResult Nil (manyTill (string "a") (string "b")) "b"
assert $ expectResult (NonEmptyList ("a" :| "a" : "a" : Nil)) (many1Till (string "a") (string "b")) "aaab"
Expand Down