jgm/skylighting

Parsing bug with exact Counting

Closed this issue · 2 comments

According to regex101, the regex a{10}b should match exactly 10 copies of a. The cod at link misparses this.

Replacing this by the following should do the trick:

       minn <- option Nothing $ readMay . U.toString <$> A.takeWhile isDig
      comma <- option False (char ',' *> pure True)
      maxn <- case comma of
                False -> pure Nothing
                True -> option Nothing (readMay . U.toString <$> A.takeWhile isDig)
      _ <- char '}'
      case (minn, comma, maxn) of
          (Nothing, _, Nothing) -> mzero
          (Just n, True, Nothing)  -> return $! atleast n re
          (Nothing, True, Just n)  -> return $! atmost n re
          (Just n, False, Nothing) -> return $! between n n re
          (Just m, True, Just n)   -> return $! between m n re
jgm commented

Thanks! I went for a slightly different fix that should do the same thing, but it would be great if you could look it over in case I made a mistake.

This seems to work! Thanks