Skip to content

Commit

Permalink
Fix #1 by removing check on dash in regex parser
Browse files Browse the repository at this point in the history
There are no illegal occurrences of `-` in a bracket expression.
Those that are separators of a range (e.g. `a-z`) are simply standing
for themselves.  A dash can even be an start or end point of a range,
as in `[--@]`.
  • Loading branch information
andreasabel committed Jul 16, 2022
1 parent c9f29a9 commit 205d36d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/Text/Regex/TDFA/ReadRegex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ module Text.Regex.TDFA.ReadRegex (parseRegex) where

import Text.Regex.TDFA.Pattern {- all -}
import Text.ParserCombinators.Parsec((<|>), (<?>),
unexpected, try, runParser, many, getState, setState, CharParser, ParseError,
try, runParser, many, getState, setState, CharParser, ParseError,
sepBy1, option, notFollowedBy, many1, lookAhead, eof, between,
string, noneOf, digit, char, anyChar)

import Control.Monad(liftM, when, guard)
import Control.Monad (liftM, guard)

import Data.Foldable (asum)
import qualified Data.Set as Set(fromList)

Expand Down Expand Up @@ -168,9 +169,6 @@ p_set_elem_range = try $ do
p_set_elem_char :: P BracketElement
p_set_elem_char = do
c <- noneOf "]"
when (c == '-') $ do
atEnd <- (lookAhead (char ']') >> return True) <|> (return False)
when (not atEnd) (unexpected "A dash is in the wrong place in a bracket")
return (BEChar c)

-- | Fail when 'BracketElement' is invalid, e.g. empty range @1-0@.
Expand Down

0 comments on commit 205d36d

Please sign in to comment.