Commit a2e0cb00 authored by Oleg Grenrus's avatar Oleg Grenrus

Rename Regex to GrammarRegex to avoid confusion

Also regenerate field grammar
parent 7e296257
......@@ -494,8 +494,8 @@ library
Distribution.Types.GivenComponent
Distribution.Types.PackageVersionConstraint
Distribution.Utils.CharSet
Distribution.Utils.Regex
Distribution.Utils.Generic
Distribution.Utils.GrammarRegex
Distribution.Utils.NubList
Distribution.Utils.ShortText
Distribution.Utils.Progress
......
......@@ -4,7 +4,7 @@ module Distribution.FieldGrammar.Described (
Described (..),
describeDoc,
-- * Regular expressions
Regex (..),
GrammarRegex (..),
reEps,
reChar,
reChars,
......@@ -38,7 +38,7 @@ import Prelude ()
import Distribution.Parsec (Parsec)
import Distribution.Pretty (Pretty)
import Distribution.Utils.Regex
import Distribution.Utils.GrammarRegex
import qualified Distribution.Utils.CharSet as CS
import qualified Text.PrettyPrint as PP
......@@ -46,7 +46,7 @@ import qualified Text.PrettyPrint as PP
-- | Class describing the pretty/parsec format of a.
class (Pretty a, Parsec a) => Described a where
-- | A pretty document of "regex" describing the field format
describe :: proxy a -> Regex void
describe :: proxy a -> GrammarRegex void
-- | Pretty-print description.
--
......@@ -66,20 +66,20 @@ instance Described a => Described (Identity a) where
-- Lists
------------------------------------------------------------------------------
reSpacedList :: Regex a -> Regex a
reSpacedList :: GrammarRegex a -> GrammarRegex a
reSpacedList = REMunch RESpaces1
reCommaList :: Regex a -> Regex a
reCommaList :: GrammarRegex a -> GrammarRegex a
reCommaList = RECommaList
reOptCommaList :: Regex a -> Regex a
reOptCommaList :: GrammarRegex a -> GrammarRegex a
reOptCommaList = REOptCommaList
-------------------------------------------------------------------------------
-- Specific grammars
-------------------------------------------------------------------------------
reHsString :: Regex a
reHsString :: GrammarRegex a
reHsString = RENamed "hs-string" impl where
impl = reChar '"' <> REMunch reEps (REUnion [strChar, escChar]) <> reChar '"'
strChar = RECharSet $ CS.difference CS.universe (CS.fromList "\"\\")
......@@ -95,7 +95,7 @@ reHsString = RENamed "hs-string" impl where
, REUnion ["\\NUL", RENamed "ascii" "\\NUL"] -- TODO
]
reUnqualComponent :: Regex a
reUnqualComponent :: GrammarRegex a
reUnqualComponent = RENamed "unqual-name" $
REMunch1 (reChar '-') component
where
......@@ -108,13 +108,13 @@ reUnqualComponent = RENamed "unqual-name" $
<> RECharSet CS.alpha
<> REMunch reEps (RECharSet csAlphaNum)
reDot :: Regex a
reDot :: GrammarRegex a
reDot = reChar '.'
reComma :: Regex a
reComma :: GrammarRegex a
reComma = reChar ','
reSpacedComma :: Regex a
reSpacedComma :: GrammarRegex a
reSpacedComma = RESpaces <> reComma <> RESpaces
-------------------------------------------------------------------------------
......
......@@ -85,7 +85,7 @@ parsecModuleName = state0 DList.empty where
instance Described ModuleName where
describe _ = REMunch1 (reChar '.') component where
component = RECharSet csUpper <> reMunchCS (csAlphaNum <> fromString "_'")
component = RECharSet csUpper <> REMunch reEps (REUnion [RECharSet csAlphaNum, RECharSet (fromString "_'")])
validModuleChar :: Char -> Bool
validModuleChar c = isAlphaNum c || c == '_' || c == '\''
......
......@@ -71,7 +71,7 @@ class Sep sep where
parseSep :: CabalParsing m => Proxy sep -> m a -> m [a]
describeSep :: Proxy sep -> Regex a -> Regex a
describeSep :: Proxy sep -> GrammarRegex a -> GrammarRegex a
instance Sep CommaVCat where
prettySep _ = vcat . punctuate comma
......
......@@ -3,9 +3,9 @@
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Distribution.Utils.Regex (
module Distribution.Utils.GrammarRegex (
-- * Regular expressions
Regex (..),
GrammarRegex (..),
reEps,
reChar,
reChars,
......@@ -26,31 +26,31 @@ import qualified Distribution.Utils.CharSet as CS
import qualified Text.PrettyPrint as PP
-------------------------------------------------------------------------------
-- Regex
-- GrammarRegex
-------------------------------------------------------------------------------
-- | Recursive regular expressions tuned for 'Described' use-case.
data Regex a
= REAppend [Regex a] -- ^ append @ab@
| REUnion [Regex a] -- ^ union @a|b@
data GrammarRegex a
= REAppend [GrammarRegex a] -- ^ append @ab@
| REUnion [GrammarRegex a] -- ^ union @a|b@
-- repetition
| REMunch (Regex a) (Regex a) -- ^ star @a*@, with a separator
| REMunch1 (Regex a) (Regex a) -- ^ plus @a+@, with a separator
| REMunchR Int (Regex a) (Regex a) -- ^ 1-n, with a separator
| REOpt (Regex a) -- ^ optional @r?@
| REMunch (GrammarRegex a) (GrammarRegex a) -- ^ star @a*@, with a separator
| REMunch1 (GrammarRegex a) (GrammarRegex a) -- ^ plus @a+@, with a separator
| REMunchR Int (GrammarRegex a) (GrammarRegex a) -- ^ 1-n, with a separator
| REOpt (GrammarRegex a) -- ^ optional @r?@
| REString String -- ^ literal string @abcd@
| RECharSet CS.CharSet -- ^ charset @[:alnum:]@
| REVar a -- ^ variable
| RENamed String (Regex a) -- ^ named expression
| RERec String (Regex (Maybe a)) -- ^ recursive expressions
| REString String -- ^ literal string @abcd@
| RECharSet CS.CharSet -- ^ charset @[:alnum:]@
| REVar a -- ^ variable
| RENamed String (GrammarRegex a) -- ^ named expression
| RERec String (GrammarRegex (Maybe a)) -- ^ recursive expressions
-- cabal syntax specifics
| RESpaces -- ^ zero-or-more spaces
| RESpaces1 -- ^ one-or-more spaces
| RECommaList (Regex a) -- ^ comma list (note, leading or trailing commas)
| REOptCommaList (Regex a) -- ^ opt comma list
| RECommaList (GrammarRegex a) -- ^ comma list (note, leading or trailing commas)
| REOptCommaList (GrammarRegex a) -- ^ opt comma list
| RETodo -- ^ unspecified
deriving (Eq, Ord, Show, Functor, Foldable, Traversable)
......@@ -59,15 +59,15 @@ data Regex a
-- Instances
-------------------------------------------------------------------------------
instance IsString (Regex a) where
instance IsString (GrammarRegex a) where
fromString = REString
instance Semigroup (Regex a) where
instance Semigroup (GrammarRegex a) where
x <> y = REAppend (unAppend x ++ unAppend y) where
unAppend (REAppend rs) = rs
unAppend r = [r]
instance Monoid (Regex a) where
instance Monoid (GrammarRegex a) where
mempty = REAppend []
mappend = (<>)
......@@ -75,29 +75,29 @@ instance Monoid (Regex a) where
-- Smart constructors
-------------------------------------------------------------------------------
reEps :: Regex a
reEps :: GrammarRegex a
reEps = REAppend []
reChar :: Char -> Regex a
reChar :: Char -> GrammarRegex a
reChar = RECharSet . CS.singleton
reChars :: [Char] -> Regex a
reChars :: [Char] -> GrammarRegex a
reChars = RECharSet . CS.fromList
reMunch1CS :: CS.CharSet -> Regex a
reMunch1CS :: CS.CharSet -> GrammarRegex a
reMunch1CS = REMunch1 reEps . RECharSet
reMunchCS :: CS.CharSet -> Regex a
reMunchCS :: CS.CharSet -> GrammarRegex a
reMunchCS = REMunch reEps . RECharSet
-------------------------------------------------------------------------------
-- Variables
-------------------------------------------------------------------------------
reVar0 :: Regex (Maybe a)
reVar0 :: GrammarRegex (Maybe a)
reVar0 = REVar Nothing
reVar1 :: Regex (Maybe (Maybe a))
reVar1 :: GrammarRegex (Maybe (Maybe a))
reVar1 = REVar (Just Nothing)
-------------------------------------------------------------------------------
......@@ -114,9 +114,9 @@ reVar1 = REVar (Just Nothing)
-- >>> regexDoc $ REString "foo" <> REString "bar"
-- \mathop{\mathord{``}\mathtt{foo}\mathord{"}}\mathop{\mathord{``}\mathtt{bar}\mathord{"}}
--
regexDoc :: Regex Void -> PP.Doc
regexDoc :: GrammarRegex Void -> PP.Doc
regexDoc = go 0 . vacuous where
go :: Int -> Regex PP.Doc -> PP.Doc
go :: Int -> GrammarRegex PP.Doc -> PP.Doc
go _ (REAppend []) = ""
go d (REAppend rs) = parensIf (d > 2) $ PP.hcat (map (go 2) rs)
go d (REUnion [r]) = go d r
......@@ -186,6 +186,7 @@ charsetDoc :: CS.CharSet -> PP.Doc
charsetDoc acs
| acs == CS.alpha = terminalDoc "alpha"
| acs == CS.alphanum = terminalDoc "alpha-num"
| acs == CS.upper = terminalDoc "upper"
charsetDoc acs = case CS.toIntervalList acs of
[] -> "\\emptyset"
[(x,y)] | x == y -> inquotes $ mathtt $ charDoc x
......
......@@ -143,7 +143,7 @@ module-name
Haskell module name as recognized by Cabal parser.
.. math::
\mathsf{\color{red}{TODO}}
{\left(\mathop{\mathit{upper}}{\left\{ \mathop{\mathit{alpha\text{-}num}}\mid[\mathop{\mathord{``}\mathtt{\text{'}}\mathord{"}}\mathop{\mathord{``}\mathtt{\text{_}}\mathord{"}}] \right\}}^\ast_{}\right)}^+_{\mathop{\mathord{``}\mathtt{\text{.}}\mathord{"}}}
version
Version is to first approximation numbers separated by dots, where leading zero is not allowed and each version digit is consists at most of nine characters.
......@@ -190,14 +190,14 @@ autogen-modules
* Documentation of :pkg-field:`autogen-modules`
.. math::
\mathrm{commalist}\mathsf{\color{red}{TODO}}
\mathrm{commalist}\left({\left(\mathop{\mathit{upper}}{\left\{ \mathop{\mathit{alpha\text{-}num}}\mid[\mathop{\mathord{``}\mathtt{\text{'}}\mathord{"}}\mathop{\mathord{``}\mathtt{\text{_}}\mathord{"}}] \right\}}^\ast_{}\right)}^+_{\mathop{\mathord{``}\mathtt{\text{.}}\mathord{"}}}\right)
build-depends
* Monoidal field
* Documentation of :pkg-field:`build-depends`
.. math::
\mathrm{commalist}\left(\mathop{\mathit{pkg\text{-}name}}{\left(\circ\mathop{\mathord{``}\mathtt{\text{:}}\mathord{"}}\circ\left\{ \mathop{\mathit{unqual\text{-}name}}\mid\mathop{\mathord{``}\mathtt{\{}\mathord{"}}\circ\mathrm{commalist}\mathop{\mathit{unqual\text{-}name}}\circ\mathop{\mathord{``}\mathtt{\}}\mathord{"}} \right\}\right)}^?{\left(\circ\mathop{\mathit{version\text{-}range}}\right)}^?\right)
\mathrm{commalist}\left(\mathop{\mathit{pkg\text{-}name}}{\left(\mathop{\mathord{``}\mathtt{\text{:}}\mathord{"}}\left\{ \mathop{\mathit{unqual\text{-}name}}\mid\mathop{\mathord{``}\mathtt{\{}\mathord{"}}\circ{\mathop{\mathit{unqual\text{-}name}}}^\ast_{\left(\circ\mathop{\mathord{``}\mathtt{\text{,}}\mathord{"}}\circ\right)}\circ\mathop{\mathord{``}\mathtt{\}}\mathord{"}} \right\}\right)}^?{\left(\bullet\mathop{\mathit{version\text{-}range}}\right)}^?\right)
build-tool-depends
* Monoidal field
......@@ -473,7 +473,7 @@ other-modules
* Documentation of :pkg-field:`other-modules`
.. math::
\mathrm{commalist}\mathsf{\color{red}{TODO}}
\mathrm{commalist}\left({\left(\mathop{\mathit{upper}}{\left\{ \mathop{\mathit{alpha\text{-}num}}\mid[\mathop{\mathord{``}\mathtt{\text{'}}\mathord{"}}\mathop{\mathord{``}\mathtt{\text{_}}\mathord{"}}] \right\}}^\ast_{}\right)}^+_{\mathop{\mathord{``}\mathtt{\text{.}}\mathord{"}}}\right)
pkgconfig-depends
* Monoidal field
......@@ -488,7 +488,7 @@ virtual-modules
* Documentation of :pkg-field:`virtual-modules`
.. math::
\mathrm{commalist}\mathsf{\color{red}{TODO}}
\mathrm{commalist}\left({\left(\mathop{\mathit{upper}}{\left\{ \mathop{\mathit{alpha\text{-}num}}\mid[\mathop{\mathord{``}\mathtt{\text{'}}\mathord{"}}\mathop{\mathord{``}\mathtt{\text{_}}\mathord{"}}] \right\}}^\ast_{}\right)}^+_{\mathop{\mathord{``}\mathtt{\text{.}}\mathord{"}}}\right)
Package description fields
......@@ -511,7 +511,7 @@ build-type
cabal-version
* Optional field
* Default: ``-any``
* Default: ``>=1.0``
* Documentation of :pkg-field:`cabal-version`
.. math::
......@@ -637,7 +637,7 @@ test-module
* Documentation of :pkg-field:`test-module`
.. math::
\mathsf{\color{red}{TODO}}
{\left(\mathop{\mathit{upper}}{\left\{ \mathop{\mathit{alpha\text{-}num}}\mid[\mathop{\mathord{``}\mathtt{\text{'}}\mathord{"}}\mathop{\mathord{``}\mathtt{\text{_}}\mathord{"}}] \right\}}^\ast_{}\right)}^+_{\mathop{\mathord{``}\mathtt{\text{.}}\mathord{"}}}
type
* Optional field
......
......@@ -11,7 +11,7 @@ import Test.QuickCheck (Arbitrary (..), Gen, Property, choose, counterexam
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Distribution.FieldGrammar.Described (Described (..), Regex (..), reComma, reSpacedComma, reSpacedList)
import Distribution.FieldGrammar.Described (Described (..), GrammarRegex (..), reComma, reSpacedComma, reSpacedList)
import Distribution.Parsec (eitherParsec)
import Distribution.Pretty (prettyShow)
......@@ -101,9 +101,9 @@ genInt lo hi = choose (lo, hi)
-- Conversion
-------------------------------------------------------------------------------
convert :: Regex Void -> RE.RE Void
convert :: GrammarRegex Void -> RE.RE Void
convert = go id . vacuous where
go :: Ord b => (a -> b) -> Regex a -> RE.RE b
go :: Ord b => (a -> b) -> GrammarRegex a -> RE.RE b
go f (REAppend rs) = foldr (\r acc -> go f r <> acc) RE.Eps rs
go f (REUnion rs) = foldr (\r acc -> go f r RE.\/ acc) RE.Null rs
go _ (RECharSet cs) = RE.Ch (convertCS cs)
......@@ -140,17 +140,17 @@ convert = go id . vacuous where
go _ RETodo = RE.Null
expandedCommaList :: Regex a -> Regex a
expandedCommaList :: GrammarRegex a -> GrammarRegex a
expandedCommaList = REUnion . expandedCommaList'
expandedCommaList' :: Regex a -> [Regex a]
expandedCommaList' :: GrammarRegex a -> [GrammarRegex a]
expandedCommaList' r =
[ REMunch reSpacedComma r
, reComma <> RESpaces <> REMunch1 reSpacedComma r
, REMunch1 reSpacedComma r <> RESpaces <> reComma
]
expandedOptCommaList :: Regex a -> Regex a
expandedOptCommaList :: GrammarRegex a -> GrammarRegex a
expandedOptCommaList r = REUnion $ reSpacedList r : expandedCommaList' r
convertCS :: CS.CharSet -> RE.CharSet
......
......@@ -25,7 +25,7 @@ import qualified Text.PrettyPrint as PP
import qualified Zinza as Z
import Distribution.FieldGrammar.Described
import Distribution.Utils.Regex
import Distribution.Utils.GrammarRegex
import Distribution.ModuleName (ModuleName)
import Distribution.Types.Version (Version)
......@@ -78,7 +78,7 @@ main = do
putStrLn "Usage: generator <tmpl>"
exitFailure
zproduction :: String -> Regex Void -> String -> ZProduction
zproduction :: String -> GrammarRegex Void -> String -> ZProduction
zproduction name re desc = ZProduction
{ zprodName = name
, zprodSyntax = show (regexDoc re')
......@@ -90,17 +90,17 @@ zproduction name re desc = ZProduction
_ -> re
-- also in UnitTests.Distribution.Described
expandedCommaList :: Regex a -> Regex a
expandedCommaList :: GrammarRegex a -> GrammarRegex a
expandedCommaList = REUnion . expandedCommaList'
expandedCommaList' :: Regex a -> [Regex a]
expandedCommaList' :: GrammarRegex a -> [GrammarRegex a]
expandedCommaList' r =
[ REMunch reSpacedComma r
, reComma <> RESpaces <> REMunch1 reSpacedComma r
, REMunch1 reSpacedComma r <> RESpaces <> reComma
]
expandedOptCommaList :: Regex a -> Regex a
expandedOptCommaList :: GrammarRegex a -> GrammarRegex a
expandedOptCommaList r = REUnion $ reSpacedList r : expandedCommaList' r
-------------------------------------------------------------------------------
......
.. _buildinfo-field-reference:
==================================================
BuildInfo field reference
==================================================
Field Syntax Reference
======================
Notation
---------------
......
......@@ -7,7 +7,7 @@ module Distribution.Client.Types.RepoName (
import Distribution.Client.Compat.Prelude
import Prelude ()
import Distribution.FieldGrammar.Described (Described (..), Regex (..), csAlpha, csAlphaNum, reMunchCS)
import Distribution.FieldGrammar.Described (Described (..), GrammarRegex (..), csAlpha, csAlphaNum, reMunchCS)
import Distribution.Parsec (Parsec (..))
import Distribution.Pretty (Pretty (..))
......
......@@ -11,7 +11,7 @@ import Test.QuickCheck (Arbitrary (..), Gen, Property, choose, counterexam
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Distribution.FieldGrammar.Described (Described (..), Regex (..), reComma, reSpacedComma, reSpacedList)
import Distribution.FieldGrammar.Described (Described (..), GrammarRegex (..), reComma, reSpacedComma, reSpacedList)
import Distribution.Parsec (eitherParsec)
import Distribution.Pretty (prettyShow)
......@@ -97,9 +97,9 @@ genInt lo hi = choose (lo, hi)
-- Conversion
-------------------------------------------------------------------------------
convert :: Regex Void -> RE.RE Void
convert :: GrammarRegex Void -> RE.RE Void
convert = go id . vacuous where
go :: Ord b => (a -> b) -> Regex a -> RE.RE b
go :: Ord b => (a -> b) -> GrammarRegex a -> RE.RE b
go f (REAppend rs) = foldr (\r acc -> go f r <> acc) RE.Eps rs
go f (REUnion rs) = foldr (\r acc -> go f r RE.\/ acc) RE.Null rs
go _ (RECharSet cs) = RE.Ch (convertCS cs)
......@@ -136,17 +136,17 @@ convert = go id . vacuous where
go _ RETodo = RE.Null
expandedCommaList :: Regex a -> Regex a
expandedCommaList :: GrammarRegex a -> GrammarRegex a
expandedCommaList = REUnion . expandedCommaList'
expandedCommaList' :: Regex a -> [Regex a]
expandedCommaList' :: GrammarRegex a -> [GrammarRegex a]
expandedCommaList' r =
[ REMunch reSpacedComma r
, reComma <> RESpaces <> REMunch1 reSpacedComma r
, REMunch1 reSpacedComma r <> RESpaces <> reComma
]
expandedOptCommaList :: Regex a -> Regex a
expandedOptCommaList :: GrammarRegex a -> GrammarRegex a
expandedOptCommaList r = REUnion $ reSpacedList r : expandedCommaList' r
convertCS :: CS.CharSet -> RE.CharSet
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment