Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and updates for v0.1.0.0 #14

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading