Skip to content

Commit

Permalink
Fixes and updates for v0.1.0.0 (#14)
Browse files Browse the repository at this point in the history
* Add home page and bug tracker to cabal file
* Fix Text.splitOn example
* Adjust README example
* Link to docs on README
* Don't force inline Text parseSure
* Update changelog
  • Loading branch information
meooow25 authored Mar 4, 2024
1 parent 019543d commit df39d31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 1,3 @@
### 0.1.0.0 -- YYYY-mm-dd
### 0.1.0.0 -- 2024-03-04

* First version.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 1,6 @@
# parser-regex

[![Hackage](https://img.shields.io/hackage/v/parser-regex?logo=haskell&color=blue)](https://hackage.haskell.org/package/parser-regex)
[![Haskell-CI](https://github.com/meooow25/parser-regex/actions/workflows/haskell-ci.yml/badge.svg)](https://github.com/meooow25/parser-regex/actions/workflows/haskell-ci.yml)

Regex based parsers
Expand All @@ -17,14 18,14 @@ Regex based parsers
* Parsing runtime is linear in the length of the sequence being parsed. No
exponential backtracking.

## Usage
## Example

```hs
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative (optional)
import Data.Text (Text)
import qualified Data.Text as T

import Regex.Text (REText)
import qualified Regex.Text as R
import qualified Data.CharSet as CS

Expand All @@ -39,21 40,30 @@ data URI = URI
-- ^(([^:/?#] ):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
-- A non-validating regex to extract parts of a URI, from RFC 3986
-- Translated:
uriRE :: R.REText URI
uriRE :: REText URI
uriRE = URI
<$> optional (R.someTextOf (CS.not ":/?#") <* R.char ':')
<*> optional (R.text "//" *> R.manyTextOf (CS.not "/?#"))
<*> R.manyTextOf (CS.not "?#")
<*> optional (R.char '?' *> R.manyTextOf (CS.not "#"))
<*> optional (R.char '#' *> R.manyText)

-- >>> R.reParse uriRE "https://github.com/meooow25/parser-regex?tab=readme-ov-file#parser-regex"
-- Just (URI { scheme = Just "https"
-- , authority = Just "github.com"
-- , path = "/meooow25/parser-regex"
-- , query = Just "tab=readme-ov-file"
-- , fragment = Just "parser-regex" })
```
```hs
>>> R.reParse uriRE "https://github.com/meooow25/parser-regex?tab=readme-ov-file#parser-regex"
Just (URI { scheme = Just "https"
, authority = Just "github.com"
, path = "/meooow25/parser-regex"
, query = Just "tab=readme-ov-file"
, fragment = Just "parser-regex" })
```

## Documentation

Please find the documentation on Hackage:
[parser-regex](https://hackage.haskell.org/package/parser-regex)

Already familiar with regex patterns? See the
[Regex pattern cheat sheet](https://github.com/meooow25/parser-regex/wiki/Regex-pattern-cheat-sheet).

## Alternatives

Expand Down
2 changes: 2 additions & 0 deletions parser-regex.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,8 @@ name: parser-regex
version: 0.1.0.0
synopsis: Regex based parsers
description: Regex based parsers.
homepage: https://github.com/meooow25/parser-regex
bug-reports: https://github.com/meooow25/parser-regex/issues
license: BSD-3-Clause
license-file: LICENSE
author: Soumik Sarkar
Expand Down
7 changes: 3 additions & 4 deletions src/Regex/Internal/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 401,6 @@ parse = P.parseFoldr tokenFoldr
-- For use with parsers that are known to never fail.
parseSure :: ParserText a -> Text -> a
parseSure p = fromMaybe parseSureError . parse p
{-# INLINE parseSure #-}

parseSureError :: a
parseSureError = errorWithoutStackTrace
Expand Down Expand Up @@ -469,10 468,10 @@ findAll = reParseSure . R.toFindMany
-- >>> splitOn (char ' ' *> oneOf " -=" *> char ' ') "3 - 1 1/2 - 2 = 0"
-- ["3","1","1/2","2","0"]
--
-- If the list starts or ends with a delimiter, the result will contain
-- empty lists at those positions.
-- If the @Text@ starts or ends with a delimiter, the result will contain
-- empty @Text@s at those positions.
--
-- >>> splitOn (single 'a') "ayaya"
-- >>> splitOn (char 'a') "ayaya"
-- ["","y","y",""]
--
splitOn :: REText a -> Text -> [Text]
Expand Down

0 comments on commit df39d31

Please sign in to comment.