Add SyntaxChar typeclass and decimal, scientific functions.

This commit is contained in:
Paweł Nowak 2014-11-12 22:51:29 +01:00
parent d537ee1e37
commit 262260e664
3 changed files with 17 additions and 6 deletions

View File

@ -79,7 +79,7 @@ class ( SemiIsoAlternative syn
, Eq (Element seq))
=> Syntax syn seq | syn -> seq
where
-- | Any character.
anyChar :: syn (Element seq)

View File

@ -1,5 +1,5 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{- |
Module : Data.Syntax.Char
Description : Char specific combinators.
@ -14,7 +14,7 @@ Common combinators that work with sequences of chars.
There are A LOT of combinators missing.
-}
module Data.Syntax.Char (
SyntaxChar,
SyntaxChar(..),
spaces,
spaces_,
spaces1,
@ -26,12 +26,23 @@ import Control.Lens.SemiIso
import Data.Char
import Data.MonoTraversable
import Data.Monoid
import Data.Scientific (Scientific)
import Data.SemiIsoFunctor
import Data.Syntax (Syntax)
import qualified Data.Syntax as S
-- | Syntax constrainted to sequences of chars.
type SyntaxChar syn seq = (Syntax syn seq, Element seq ~ Char)
--
-- Note: methods of this class do not have default implementations (for now),
-- because their code is quite ugly and already written in most parser libraries.
class (Syntax syn seq, Element seq ~ Char) => SyntaxChar syn seq where
-- | An unsigned decimal number.
decimal :: Integral a => syn a
-- | A scientific number.
scientific :: syn Scientific
{-# MINIMAL decimal, scientific #-}
-- | Accepts zero or more spaces. Generates a single space.
spaces :: SyntaxChar syn seq => syn ()

View File

@ -1,5 +1,5 @@
name: syntax
version: 0.1.1.0
version: 0.2.0.0
synopsis: Abstract syntax descriptions for parsing and pretty-printing.
description: Abstract syntax descriptions for parsing and pretty-printing.
Write a single syntax description, get both a parser and a pretty-printer.
@ -27,5 +27,5 @@ library
exposed-modules: Data.Syntax
Data.Syntax.Char
Data.Syntax.Combinator
build-depends: base >= 4 && < 5, mono-traversable, lens, semi-iso
build-depends: base >= 4 && < 5, mono-traversable, lens >= 4, semi-iso >= 0.3, scientific >= 0.3
default-language: Haskell2010