packages feed

symantic-grammar 0.3.1.20180831 → 0.3.3.20190614

raw patch · 10 files changed

+58/−51 lines, 10 filesdep ~megaparsecPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: megaparsec

API changes (from Hackage documentation)

- Language.Symantic.Grammar.Fixity: [infix_assoc] :: Infix -> Maybe Associativity
- Language.Symantic.Grammar.Fixity: [infix_prece] :: Infix -> Precedence
- Language.Symantic.Grammar.Fixity: [unifix_prece] :: Unifix -> Precedence
- Language.Symantic.Grammar.Fixity: needsParenInfix :: (Infix, Side) -> Infix -> Bool
- Language.Symantic.Grammar.Fixity: parenInfix :: (Semigroup s, IsString s) => (Infix, Side) -> Infix -> s -> s
- Language.Symantic.Grammar.Source: At :: !src -> !a -> At src a
- Language.Symantic.Grammar.Source: [at] :: At src a -> !src
- Language.Symantic.Grammar.Source: [unAt] :: At src a -> !a
- Language.Symantic.Grammar.Source: class Source (SourceOf a) => Sourced a
- Language.Symantic.Grammar.Source: data At src a
- Language.Symantic.Grammar.Source: instance (GHC.Classes.Eq src, GHC.Classes.Eq a) => GHC.Classes.Eq (Language.Symantic.Grammar.Source.At src a)
- Language.Symantic.Grammar.Source: instance (GHC.Classes.Ord src, GHC.Classes.Ord a) => GHC.Classes.Ord (Language.Symantic.Grammar.Source.At src a)
- Language.Symantic.Grammar.Source: instance (GHC.Show.Show src, GHC.Show.Show a) => GHC.Show.Show (Language.Symantic.Grammar.Source.At src a)
- Language.Symantic.Grammar.Source: instance GHC.Base.Functor (Language.Symantic.Grammar.Source.At src)
+ Language.Symantic.Grammar.ContextFree: infixl 4 <&
+ Language.Symantic.Grammar.Fixity: [infix_associativity] :: Infix -> Maybe Associativity
+ Language.Symantic.Grammar.Fixity: [infix_precedence] :: Infix -> Precedence
+ Language.Symantic.Grammar.Fixity: [unifix_precedence] :: Unifix -> Precedence
+ Language.Symantic.Grammar.Fixity: isPairNeeded :: (Infix, Side) -> Infix -> Bool
+ Language.Symantic.Grammar.Fixity: pairBrace :: Pair
+ Language.Symantic.Grammar.Fixity: pairIfNeeded :: Semigroup s => IsString s => Pair -> (Infix, Side) -> Infix -> s -> s
+ Language.Symantic.Grammar.Fixity: pairParen :: Pair
+ Language.Symantic.Grammar.Fixity: type Pair = (String, String)
+ Language.Symantic.Grammar.Regular: infixl 3 <+>
+ Language.Symantic.Grammar.Regular: infixl 4 <*.
+ Language.Symantic.Grammar.Source: Sourced :: !src -> !a -> Sourced src a
+ Language.Symantic.Grammar.Source: [atSource] :: Sourced src a -> !src
+ Language.Symantic.Grammar.Source: [unSourced] :: Sourced src a -> !a
+ Language.Symantic.Grammar.Source: class Source (SourceOf a) => Sourceable a
+ Language.Symantic.Grammar.Source: data Sourced src a
+ Language.Symantic.Grammar.Source: infixl 5 `setSource`
+ Language.Symantic.Grammar.Source: instance (GHC.Classes.Eq src, GHC.Classes.Eq a) => GHC.Classes.Eq (Language.Symantic.Grammar.Source.Sourced src a)
+ Language.Symantic.Grammar.Source: instance (GHC.Classes.Ord src, GHC.Classes.Ord a) => GHC.Classes.Ord (Language.Symantic.Grammar.Source.Sourced src a)
+ Language.Symantic.Grammar.Source: instance (GHC.Show.Show src, GHC.Show.Show a) => GHC.Show.Show (Language.Symantic.Grammar.Source.Sourced src a)
+ Language.Symantic.Grammar.Source: instance GHC.Base.Functor (Language.Symantic.Grammar.Source.Sourced src)
+ Language.Symantic.Grammar.Source: type family Source_Input (src :: *) :: *
- Language.Symantic.Grammar.BinTree: BinTree2 :: (BinTree a) -> (BinTree a) -> BinTree a
+ Language.Symantic.Grammar.BinTree: BinTree2 :: BinTree a -> BinTree a -> BinTree a
- Language.Symantic.Grammar.EBNF: EBNF :: RuleMode -> (Infix, Side) -> Text -> EBNF a
+ Language.Symantic.Grammar.EBNF: EBNF :: (RuleMode -> (Infix, Side) -> Text) -> EBNF a
- Language.Symantic.Grammar.Operators: OpTree1 :: Unifix -> (a -> a) -> (OpTree a) -> OpTree a
+ Language.Symantic.Grammar.Operators: OpTree1 :: Unifix -> (a -> a) -> OpTree a -> OpTree a
- Language.Symantic.Grammar.Operators: OpTree2 :: Infix -> (a -> a -> a) -> (OpTree a) -> (OpTree a) -> OpTree a
+ Language.Symantic.Grammar.Operators: OpTree2 :: Infix -> (a -> a -> a) -> OpTree a -> OpTree a -> OpTree a
- Language.Symantic.Grammar.Source: setSource :: Sourced a => a -> SourceOf a -> a
+ Language.Symantic.Grammar.Source: setSource :: Sourceable a => a -> SourceOf a -> a
- Language.Symantic.Grammar.Source: sourceOf :: Sourced a => a -> SourceOf a
+ Language.Symantic.Grammar.Source: sourceOf :: Sourceable a => a -> SourceOf a
- Language.Symantic.Grammar.Source: withSource :: SourceInj src (SourceOf a) => Sourced a => a -> src -> a
+ Language.Symantic.Grammar.Source: withSource :: SourceInj src (SourceOf a) => Sourceable a => a -> src -> a

Files

Language/Symantic/Grammar/ContextFree.hs view
@@ -32,15 +32,15 @@ deriving instance Gram_RuleEBNF g => Gram_RuleEBNF (CF g) instance Gram_CF EBNF where 	CF (EBNF f) <& Reg (EBNF g) =-		CF $ EBNF $ \bo po -> parenInfix po op $+		CF $ EBNF $ \bo po -> pairIfNeeded pairParen po op $ 		f bo (op, SideL) <> " & " <> g bo (op, SideR) 		where op = infixB SideL 4 	Reg (EBNF f) &> CF (EBNF g) =-		CF $ EBNF $ \bo po -> parenInfix po op $+		CF $ EBNF $ \bo po -> pairIfNeeded pairParen po op $ 		f bo (op, SideL) <> " & " <> g bo (op, SideR) 		where op = infixB SideL 4 	CF (EBNF f) `minus` Reg (EBNF g) =-		CF $ EBNF $ \bo po -> parenInfix po op $+		CF $ EBNF $ \bo po -> pairIfNeeded pairParen po op $ 		f bo (op, SideL) <> " - " <> g bo (op, SideR) 		where op = infixL 6 
Language/Symantic/Grammar/EBNF.hs view
@@ -56,7 +56,7 @@  -- | 'EBNF' which adds an argument to be applied. ebnf_arg :: EBNF a -> EBNF b -> EBNF ()-ebnf_arg (EBNF a) (EBNF b) = EBNF $ \bo po -> parenInfix po op $+ebnf_arg (EBNF a) (EBNF b) = EBNF $ \bo po -> pairIfNeeded pairParen po op $ 	a bo (op, SideL) <> " " <> b bo (op, SideR) 	where op = infixL 11 infixl 5 `ebnf_arg`@@ -111,7 +111,7 @@ 	fmap _f (EBNF x) = EBNF x instance Applicative EBNF where 	pure _ = ebnf_const $ "\"\""-	EBNF f <*> EBNF x = EBNF $ \bo po -> parenInfix po op $+	EBNF f <*> EBNF x = EBNF $ \bo po -> pairIfNeeded pairParen po op $ 		f bo (op, SideL) <> ", " <> x bo (op, SideR) 		where op = infixB SideL 10 instance Gram_Rule EBNF where
Language/Symantic/Grammar/Fixity.hs view
@@ -1,14 +1,14 @@ module Language.Symantic.Grammar.Fixity where -import Data.Bool as Bool+import Data.Bool import Data.Eq (Eq(..)) import Data.Function ((.)) import Data.Int (Int) import Data.Maybe (Maybe(..)) import Data.Ord (Ord(..)) import Data.Semigroup-import Data.String (IsString(..))-import Text.Show (Show)+import Data.String (String, IsString(..))+import Text.Show (Show(..))  -- * Type 'Fixity' data Fixity@@ -18,15 +18,15 @@  -- ** Type 'Unifix' data Unifix- =   Prefix  { unifix_prece :: Precedence }- |   Postfix { unifix_prece :: Precedence }+ =   Prefix  { unifix_precedence :: Precedence }+ |   Postfix { unifix_precedence :: Precedence }  deriving (Eq, Show)  -- ** Type 'Infix' data Infix  =   Infix- {   infix_assoc :: Maybe Associativity- ,   infix_prece :: Precedence+ {   infix_associativity :: Maybe Associativity+ ,   infix_precedence    :: Precedence  } deriving (Eq, Show)  infixL :: Precedence -> Infix@@ -50,29 +50,30 @@ -- | Given 'Precedence' and 'Associativity' of its parent operator, -- and the operand 'Side' it is in, -- return whether an 'Infix' operator--- needs to be enclosed by parenthesis.-needsParenInfix :: (Infix, Side) -> Infix -> Bool-needsParenInfix (po, lr) op =-	infix_prece op < infix_prece po-	|| infix_prece op == infix_prece po-	&& Bool.not associate+-- needs to be enclosed by a 'Pair'.+isPairNeeded :: (Infix, Side) -> Infix -> Bool+isPairNeeded (po, lr) op =+	infix_precedence op < infix_precedence po+	|| infix_precedence op == infix_precedence po+	&& not associate 	where 	associate =-		case (lr, infix_assoc po) of+		case (lr, infix_associativity po) of 		 (_, Just AssocB{})   -> True 		 (SideL, Just AssocL) -> True 		 (SideR, Just AssocR) -> True 		 _ -> False --- | If 'needsParenInfix' is 'True',--- enclose the given 'IsString' by parenthesis,+-- | If 'isPairNeeded' is 'True',+-- enclose the given 'IsString' by given 'Pair', -- otherwise returns the same 'IsString'.-parenInfix- :: (Semigroup s, IsString s)- => (Infix, Side) -> Infix -> s -> s-parenInfix po op s =-	if needsParenInfix po op-	then fromString "(" <> s <> fromString ")"+pairIfNeeded ::+ Semigroup s => IsString s =>+ Pair -> (Infix, Side) -> Infix ->+ s -> s+pairIfNeeded (o,c) po op s =+	if isPairNeeded po op+	then fromString o <> s <> fromString c 	else s  -- * Type 'Precedence'@@ -85,9 +86,9 @@ 	precedence (Fixity1 uni) = precedence uni 	precedence (Fixity2 inf) = precedence inf instance PrecedenceOf Unifix where-	precedence = unifix_prece+	precedence = unifix_precedence instance PrecedenceOf Infix where-	precedence = infix_prece+	precedence = infix_precedence  -- * Type 'Associativity' data Associativity@@ -101,3 +102,9 @@  =   SideL -- ^ Left  |   SideR -- ^ Right  deriving (Eq, Show)++-- ** Type 'Pair'+type Pair = (String, String)+pairParen, pairBrace :: Pair+pairParen = ("(",")")+pairBrace = ("{","}")
Language/Symantic/Grammar/Operators.hs view
@@ -130,7 +130,7 @@ 		 EQ -> OpTree1 uni_a op_a nod_b 		 LT -> OpTree1 uni_b op_b $ insertUnifix a nod 	 OpTree2 inf_b op_b l r ->-		case infix_prece inf_b `compare` prece_a of+		case infix_precedence inf_b `compare` prece_a of 		 GT -> OpTree1 uni_a op_a nod_b 		 EQ -> OpTree1 uni_a op_a nod_b 		 LT -> OpTree2 inf_b op_b (insertUnifix a l) r@@ -144,7 +144,7 @@ 		 LT -> OpTree1 uni_b op_b $ insertUnifix a nod 	 OpTree1 Postfix{} _op_b _nod -> OpTree1 uni_a op_a nod_b 	 OpTree2 inf_b op_b l r ->-		case infix_prece inf_b `compare` prece_a of+		case infix_precedence inf_b `compare` prece_a of 		 GT -> OpTree1 uni_a op_a nod_b 		 EQ -> OpTree1 uni_a op_a nod_b 		 LT -> OpTree2 inf_b op_b l (insertUnifix a r)@@ -160,14 +160,14 @@ 	case nod_b of 	 OpTree0{} -> Right $ OpTree2 inf_a op_a nod_a nod_b 	 OpTree1 uni_b op_b nod ->-		case unifix_prece uni_b `compare` infix_prece inf_a of+		case unifix_precedence uni_b `compare` infix_precedence inf_a of 		 EQ -> Right $ OpTree2 inf_a op_a nod_a nod_b 		 GT -> Right $ OpTree2 inf_a op_a nod_a nod_b 		 LT -> do 			n <- insertInfix nod_a in_ (Right nod) 			Right $ OpTree1 uni_b op_b n 	 OpTree2 inf_b op_b l r ->-		case infix_prece inf_b `compare` infix_prece inf_a of+		case infix_precedence inf_b `compare` infix_precedence inf_a of 		 GT -> Right $ OpTree2 inf_a op_a nod_a nod_b 		 LT -> do 			n <- insertInfix nod_a in_ (Right l)@@ -177,7 +177,7 @@ 				 AssocL -> SideL 				 AssocR -> SideR 				 AssocB lr -> lr in-			case (ass <$> infix_assoc inf_b, ass <$> infix_assoc inf_a) of+			case (ass <$> infix_associativity inf_b, ass <$> infix_associativity inf_a) of 			 (Just SideL, Just SideL) -> do 				n <- insertInfix nod_a in_ (Right l) 				Right $ OpTree2 inf_b op_b n r
Language/Symantic/Grammar/Regular.hs view
@@ -52,13 +52,13 @@ instance Gram_Alt EBNF where 	empty = ebnf_const $ "empty" 	EBNF g <+> EBNF q =-		EBNF $ \bo po -> parenInfix po op $+		EBNF $ \bo po -> pairIfNeeded pairParen po op $ 		g bo (op, SideL) <> " | " <> q bo (op, SideR) 		where op = infixB SideL 2 	choice [] = empty 	choice [g] = g 	choice l@(_:_) =-		EBNF $ \bo po -> parenInfix po op $+		EBNF $ \bo po -> pairIfNeeded pairParen po op $ 		Text.intercalate " | " $ 		(unEBNF <$> l) <*> pure bo <*> pure (op, SideL) 		where op = infixB SideL 2
Language/Symantic/Grammar/Source.hs view
@@ -23,13 +23,13 @@ -- ** Type family 'SourceOf' type family SourceOf a --- ** Type 'Sourced'-class Source (SourceOf a) => Sourced a where+-- ** Type 'Sourceable'+class Source (SourceOf a) => Sourceable a where 	sourceOf  :: a -> SourceOf a 	setSource :: a -> SourceOf a -> a infixl 5 `setSource` -withSource :: SourceInj src (SourceOf a) => Sourced a => a -> src -> a+withSource :: SourceInj src (SourceOf a) => Sourceable a => a -> src -> a withSource a src = a `setSource` sourceInj src  -- ** Type 'Source_Input'@@ -43,10 +43,10 @@  ,   spanEnd   :: !src  } deriving (Eq, Ord, Show, Typeable) --- ** Type 'At'+-- ** Type 'Sourced' -- | Attach a 'Source' to something.-data At src a- =   At- {   at   :: !src- ,   unAt :: !a+data Sourced src a+ =   Sourced+ {   atSource  :: !src+ ,   unSourced :: !a  } deriving (Eq, Functor, Ord, Show, Typeable)
Language/Symantic/Grammar/Terminal.hs view
@@ -44,7 +44,7 @@ instance Gram_Char EBNF where 	any  = ebnf_const "_" 	Terminal (EBNF f) `but` Terminal (EBNF g) =-		Terminal $ EBNF $ \bo po -> parenInfix po op $+		Terminal $ EBNF $ \bo po -> pairIfNeeded pairParen po op $ 			f bo (op, SideL) <> " - " <> g bo (op, SideR) 		where op = infixL 6 	eoi   = ebnf_const "eoi"
stack.yaml view
@@ -1,3 +1,3 @@-resolver: lts-12.8+resolver: lts-13.19 packages: - '.'
symantic-grammar.cabal view
@@ -2,7 +2,7 @@ -- PVP:  +-+------- breaking API changes --       | | +----- non-breaking API additions --       | | | +--- code changes with no API change-version: 0.3.1.20180831+version: 0.3.3.20190614 category: Language synopsis: Library for symantic grammars. description: This library defines an embedded DSL for regular or context-free grammars,@@ -20,8 +20,8 @@ -- homepage:  build-type: Simple-cabal-version: >= 1.24-tested-with: GHC==8.4.3+cabal-version: 1.24+tested-with: GHC==8.4.4 extra-source-files:   stack.yaml extra-tmp-files:@@ -89,7 +89,7 @@   build-depends:       symantic-grammar     , base         >= 4.6 && < 5-    , megaparsec   >= 6.3+    , megaparsec   >= 7.0     , tasty        >= 0.11     , tasty-hunit  >= 0.9     , text         >= 1.2
test/HUnit.hs view
@@ -24,7 +24,7 @@ instance ParsecC e s => Gram_Rule (P.ParsecT e s m) where 	rule = P.label . Text.unpack instance ParsecC e s => Gram_Char (P.ParsecT e s m) where-	any          = P.anyChar+	any          = P.anySingle 	eoi          = P.eof 	char         = P.char 	unicat cat   = P.satisfy $ (`elem` cats) . Char.generalCategory