mirror of
https://github.com/ilyakooo0/syntax.git
synced 2024-09-11 16:26:27 +03:00
Reversed 'exact', added 'SyntaxChar'.
This commit is contained in:
parent
bc482d85de
commit
9e6fa12e31
@ -54,7 +54,7 @@ class ( SemiIsoAlternative syn
|
||||
|
||||
-- | A specific character.
|
||||
char :: Element seq -> syn ()
|
||||
char c = exact c /$/ anyChar
|
||||
char c = rev (exact c) /$/ anyChar
|
||||
|
||||
-- | Any character except the given one.
|
||||
notChar :: Element seq -> syn (Element seq)
|
||||
@ -71,7 +71,7 @@ class ( SemiIsoAlternative syn
|
||||
|
||||
-- | A specific string.
|
||||
string :: seq -> syn ()
|
||||
string s = exact s /$/ take (olength s)
|
||||
string s = rev (exact s) /$/ take (olength s)
|
||||
|
||||
-- | A string of length @n@.
|
||||
take :: Int -> syn seq
|
||||
|
@ -1,4 +1,5 @@
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE ConstraintKinds #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{- |
|
||||
Module : Data.Syntax.Char
|
||||
@ -14,6 +15,7 @@ Common combinators that work with sequences of chars.
|
||||
-}
|
||||
module Data.Syntax.Char (
|
||||
SyntaxChar(..),
|
||||
SyntaxText,
|
||||
signed,
|
||||
spaces,
|
||||
spaces_,
|
||||
@ -28,6 +30,7 @@ import Data.Scientific (Scientific)
|
||||
import Data.SemiIsoFunctor
|
||||
import Data.Syntax
|
||||
import Data.Syntax.Combinator
|
||||
import Data.Text (Text)
|
||||
|
||||
-- | Syntax constrainted to sequences of chars.
|
||||
--
|
||||
@ -42,6 +45,9 @@ class (Syntax syn seq, Element seq ~ Char) => SyntaxChar syn seq where
|
||||
|
||||
{-# MINIMAL decimal, scientific #-}
|
||||
|
||||
-- | An useful synonym for SyntaxChars with Text sequences.
|
||||
type SyntaxText syn = SyntaxChar syn Text
|
||||
|
||||
-- | A number with an optional leading '+' or '-' sign character.
|
||||
signed :: (Real a, SyntaxChar syn seq) => syn a -> syn a
|
||||
signed n = _Negative /$/ char '-' */ n
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: syntax
|
||||
version: 0.2.1.0
|
||||
version: 0.3.0.0
|
||||
synopsis: Syntax descriptions for unified parsing and pretty-printing.
|
||||
description:
|
||||
'syntax' allows you to write a single syntax description and instantiate is both as a parser and a pretty printer.
|
||||
@ -43,5 +43,6 @@ library
|
||||
exposed-modules: Data.Syntax
|
||||
Data.Syntax.Char
|
||||
Data.Syntax.Combinator
|
||||
build-depends: base >= 4 && < 5, mono-traversable, lens >= 4, semi-iso >= 0.4.1, scientific >= 0.3
|
||||
Data.Syntax.Indent
|
||||
build-depends: base >= 4 && < 5, mono-traversable, lens >= 4, semi-iso >= 0.5.0, scientific >= 0.3, text
|
||||
default-language: Haskell2010
|
||||
|
Loading…
Reference in New Issue
Block a user