Rename source -> withSource, and g_*.
authorJulien Moutinho <julm+symantic@autogeree.net>
Tue, 27 Jun 2017 06:27:09 +0000 (08:27 +0200)
committerJulien Moutinho <julm+symantic@autogeree.net>
Tue, 27 Jun 2017 06:27:09 +0000 (08:27 +0200)
22 files changed:
symantic-document/Language/Symantic/Document/Sym.hs
symantic-grammar/Language/Symantic/Grammar.hs
symantic-grammar/Language/Symantic/Grammar/ContextFree.hs
symantic-grammar/Language/Symantic/Grammar/EBNF.hs
symantic-grammar/Language/Symantic/Grammar/Error.hs [new file with mode: 0644]
symantic-grammar/Language/Symantic/Grammar/Meta.hs
symantic-grammar/Language/Symantic/Grammar/Source.hs [new file with mode: 0644]
symantic-grammar/symantic-grammar.cabal
symantic-lib/Language/Symantic/Grammar/Megaparsec.hs
symantic-lib/Language/Symantic/Lib/Char.hs
symantic-lib/Language/Symantic/Lib/Integer.hs
symantic-lib/Language/Symantic/Lib/List.hs
symantic-lib/Language/Symantic/Lib/Tuple2.hs
symantic-lib/Language/Symantic/Lib/Unit.hs
symantic/Language/Symantic.hs
symantic/Language/Symantic/Compiling/Grammar.hs
symantic/Language/Symantic/Compiling/Term.hs
symantic/Language/Symantic/Typing/Grammar.hs
symantic/Language/Symantic/Typing/Kind.hs
symantic/Language/Symantic/Typing/Type.hs
symantic/Language/Symantic/Typing/Unify.hs
symantic/Language/Symantic/Typing/Variable.hs

index c90bf451bdc102420ee476f224233b7bcc449c05..2fe28634173fd3d8ec262b3825522c58826867b8 100644 (file)
@@ -1,14 +1,11 @@
 {-# LANGUAGE PolyKinds #-}
-{-# LANGUAGE ViewPatterns #-}
 module Language.Symantic.Document.Sym where
 
 import Data.Char (Char)
-import Data.Eq (Eq(..))
 import Data.Foldable (Foldable(..))
 import Data.Function ((.))
 import Data.Functor (Functor(..))
 import Data.Int (Int, Int64)
-import Data.Maybe (Maybe(..))
 import Data.Semigroup (Semigroup(..))
 import Data.String (String, IsString)
 import Data.Text (Text)
@@ -63,9 +60,9 @@ class (IsString d, Semigroup d) => Doc_Text d where
        spaces i  = replicate i space
        int       = integer . toInteger
        char      = \case '\n' -> eol; c -> charH c
-       string    = catV . fmap stringH . lines
-       text      = catV . fmap textH   . lines
-       ltext     = catV . fmap ltextH  . lines
+       string    = catV . fmap stringH . L.lines
+       text      = catV . fmap textH   . T.lines
+       ltext     = catV . fmap ltextH  . TL.lines
        catH      = foldr (<>) empty
        catV l    = if null l then empty else foldr1 (\a acc -> a <> eol <> acc) l
        paren   d = charH '('   <> d <> charH ')'
@@ -232,56 +229,5 @@ class Trans tr where
         -> (tr -> tr -> tr -> tr)
        trans3 f t1 t2 t3 = trans (f (unTrans t1) (unTrans t2) (unTrans t3))
 
-
--- * Class 'SplitOnCharWithEmpty'
-class SplitOnCharWithEmpty t where
-       splitOnCharWithEmpty :: Char -> t -> [t]
-instance SplitOnCharWithEmpty Text where
-       splitOnCharWithEmpty sep t =
-               case T.break (== sep) t of
-                (chunk, T.uncons -> Just (_, rest)) -> chunk : splitOnCharWithEmpty sep rest
-                (chunk, _) -> [chunk]
-instance SplitOnCharWithEmpty TL.Text where
-       splitOnCharWithEmpty sep t =
-               case TL.break (== sep) t of
-                (chunk, TL.uncons -> Just (_, rest)) -> chunk : splitOnCharWithEmpty sep rest
-                (chunk, _) -> [chunk]
-instance SplitOnCharWithEmpty String where
-       splitOnCharWithEmpty sep t =
-               case L.break (== sep) t of
-                (chunk, _:rest) -> chunk : splitOnCharWithEmpty sep rest
-                (chunk, []) -> [chunk]
-
-lines :: SplitOnCharWithEmpty t => t -> [t]
-lines = splitOnCharWithEmpty '\n'
-
 int64OfInt :: Int -> Int64
 int64OfInt = fromInteger . toInteger
-
-
-{-
--- * Class 'SplitOnChar'
-
-class SplitOnChar t where
-       splitOnChar :: Char -> t -> [t]
-instance SplitOnChar Text where
-       splitOnChar sep t =
-               case Text.uncons t of
-                Nothing -> []
-                Just (x, xs) ->
-                       if x == sep
-                       then splitOnChar sep xs
-                       else
-                               let (chunk, rest) = Text.break (== sep) t in
-                               chunk:splitOnChar sep rest
-instance SplitOnChar String where
-       splitOnChar sep t =
-               case t of
-                [] -> []
-                x:xs ->
-                       if x == sep
-                       then splitOnChar sep xs
-                       else
-                               let (chunk, rest) = List.break (== sep) t in
-                               chunk:splitOnChar sep rest
--}
index 50974d9ef69db8534fac582d6fa4b93099bfd64d..222717853bceaf1e85b3d3be4e819f22538ba52d 100644 (file)
@@ -6,6 +6,8 @@ module Language.Symantic.Grammar
  , module Language.Symantic.Grammar.ContextFree
  , module Language.Symantic.Grammar.Operators
  , module Language.Symantic.Grammar.Meta
+ , module Language.Symantic.Grammar.Error
+ , module Language.Symantic.Grammar.Source
  , module Language.Symantic.Grammar.BinTree
  ) where
 
@@ -16,4 +18,6 @@ import Language.Symantic.Grammar.Regular
 import Language.Symantic.Grammar.ContextFree
 import Language.Symantic.Grammar.Operators
 import Language.Symantic.Grammar.Meta
+import Language.Symantic.Grammar.Error
+import Language.Symantic.Grammar.Source
 import Language.Symantic.Grammar.BinTree
index 5a247ff6746a1ae2c28822ba7d69ffada00cd50f..b2403a0801a81624b4ffe6672644c1826234410a 100644 (file)
@@ -43,11 +43,12 @@ instance Gram_CF EBNF where
                f bo (op, SideL) <> " - " <> g bo (op, SideR)
                where op = infixL 6
 
-cf_of_Terminal :: Terminal g a -> CF g a
-cf_of_Terminal (Terminal g) = CF g
-
-cf_of_Reg :: Reg lr g a -> CF g a
-cf_of_Reg (Reg g) = CF g
+class ContextFreeOf gram where
+       cfOf :: gram g a -> CF g a
+instance ContextFreeOf Terminal where
+       cfOf (Terminal g) = CF g
+instance ContextFreeOf (Reg lr) where
+       cfOf (Reg g) = CF g
 
 -- ** Class 'Gram_CF'
 -- | Symantics for context-free grammars.
@@ -118,7 +119,7 @@ class
                prefix *> many (any `minus` (void (char '\n') <+> eoi))
        comment_block :: CF g String -> Reg lr g String -> CF g String
        comment_block begin end = rule "comment_block" $
-               begin *> many (any `minus` end) <* cf_of_Reg end
+               begin *> many (any `minus` end) <* cfOf end
        lexeme :: CF g a -> CF g a
        lexeme = rule1 "lexeme" $ \g ->
                g <* commentable
index a33c536575d88294886a65e7ff7f9a521d76d1ca..50cb2c8218119df16f940c121917248933bab83f 100644 (file)
@@ -32,13 +32,13 @@ import Language.Symantic.Grammar.Fixity
 -- * 'Text' of the 'EBNF' rendition.
 newtype EBNF a = EBNF { unEBNF :: RuleMode -> (Infix, Side) -> Text }
 instance Gram_Reader st EBNF where
-       g_ask_before (EBNF e) = EBNF e
-       g_ask_after  (EBNF e) = EBNF e
+       askBefore (EBNF e) = EBNF e
+       askAfter  (EBNF e) = EBNF e
 instance Gram_State st EBNF where
-       g_state_before (EBNF e) = EBNF e
-       g_state_after  (EBNF e) = EBNF e
+       stateBefore (EBNF e) = EBNF e
+       stateAfter  (EBNF e) = EBNF e
 instance Gram_Error err EBNF where
-       g_catch (EBNF e) = EBNF e
+       catch (EBNF e) = EBNF e
 
 -- | Get textual rendition of given 'EBNF'.
 runEBNF :: EBNF a -> Text
diff --git a/symantic-grammar/Language/Symantic/Grammar/Error.hs b/symantic-grammar/Language/Symantic/Grammar/Error.hs
new file mode 100644 (file)
index 0000000..2b34343
--- /dev/null
@@ -0,0 +1,18 @@
+{-# LANGUAGE TypeApplications #-}
+module Language.Symantic.Grammar.Error where
+
+import Data.Proxy (Proxy)
+
+-- * Class 'Inj_Error'
+class Inj_Error a b where
+       inj_Error :: a -> b
+instance Inj_Error err e => Inj_Error err (Either e a) where
+       inj_Error = Left . inj_Error
+
+liftError ::
+ forall e0 err e1 a.
+ Inj_Error e0 e1 =>
+ Inj_Error e1 err =>
+ Proxy e1 -> Either e0 a -> Either err a
+liftError _e1 (Right a) = Right a
+liftError _e1 (Left e)  = Left $ inj_Error @e1 @err $ inj_Error @e0 @e1 e
index 12b529a2ca19d85df7a1b99b864158e39d79fc16..0f86b13cd4ac6e2632a94156fd3b0b3d367e88a2 100644 (file)
@@ -1,95 +1,41 @@
 {-# LANGUAGE DefaultSignatures #-}
-{-# LANGUAGE DeriveFunctor #-}
-{-# LANGUAGE TypeApplications #-}
-{-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE UndecidableInstances #-}
 module Language.Symantic.Grammar.Meta where
 
-import Data.Function (const)
-import Data.Proxy (Proxy(..))
-import Data.Typeable (Typeable)
+import Language.Symantic.Grammar.Source
 
 -- * Type 'Gram_Reader'
 class Gram_Reader st g where
-       g_ask_before :: g (st -> a) -> g a
-       g_ask_after  :: g (st -> a) -> g a
+       askBefore :: g (st -> a) -> g a
+       askAfter  :: g (st -> a) -> g a
 
 -- * Type 'Gram_State'
 class Gram_State st g where
-       g_state_before :: g (st -> (st, a)) -> g a
-       g_state_after  :: g (st -> (st, a)) -> g a
-       g_get_before   :: g (st -> a) -> g a
-       g_get_after    :: g (st -> a) -> g a
-       g_put          :: g (st, a) -> g a
-       default g_get_before :: Functor g => g (st -> a) -> g a
-       default g_get_after  :: Functor g => g (st -> a) -> g a
-       default g_put        :: Functor g => g (st, a) -> g a
-       g_get_before g = g_state_before ((\f st -> (st, f st)) <$> g)
-       g_get_after  g = g_state_after ((\f st -> (st, f st)) <$> g)
-       g_put        g = g_state_after ((\(st, a) -> const (st, a)) <$> g)
+       stateBefore :: g (st -> (st, a)) -> g a
+       stateAfter  :: g (st -> (st, a)) -> g a
+       getBefore   :: g (st -> a) -> g a
+       getAfter    :: g (st -> a) -> g a
+       put         :: g (st, a) -> g a
+       default getBefore :: Functor g => g (st -> a) -> g a
+       default getAfter  :: Functor g => g (st -> a) -> g a
+       default put       :: Functor g => g (st, a) -> g a
+       getBefore g = stateBefore ((\f st -> (st, f st)) <$> g)
+       getAfter  g = stateAfter ((\f st -> (st, f st)) <$> g)
+       put       g = stateAfter ((\(st, a) -> const (st, a)) <$> g)
 
 -- * Class 'Gram_Error'
 -- | Symantics for handling errors at the semantic level (not the syntaxic one).
 class Gram_Error err g where
-       g_catch :: g (Either err a) -> g a
+       catch :: g (Either err a) -> g a
 
--- * Class 'Inj_Error'
-class Inj_Error a b where
-       inj_Error :: a -> b
-instance Inj_Error err e => Inj_Error err (Either e a) where
-       inj_Error = Left . inj_Error
-
-lift_Error ::
- forall e0 err e1 a.
- Inj_Error e0 e1 =>
- Inj_Error e1 err =>
- Proxy e1 -> Either e0 a -> Either err a
-lift_Error _e1 (Right a) = Right a
-lift_Error _e1 (Left e)  = Left $ inj_Error @e1 @err $ inj_Error @e0 @e1 e
-
--- * Class 'Source'
-class Source src where
-       noSource :: src
-instance Source () where
-       noSource = ()
-
--- ** Class 'Inj_Source'
-class Source src => Inj_Source a src where
-       inj_Source :: a -> src
-instance Inj_Source a () where
-       inj_Source _ = ()
-
--- ** Type family 'SourceOf'
-type family SourceOf a
-
--- ** Type 'Sourced'
-class Source (SourceOf a) => Sourced a where
-       sourceOf  :: a -> SourceOf a
-       setSource :: a -> SourceOf a -> a
-infixl 5 `setSource`
-
-source :: Inj_Source src (SourceOf a) => Sourced a => a -> src -> a
-source a src = a `setSource` inj_Source src
-
--- ** Type 'Source_Input'
-type family Source_Input (src :: *) :: *
-type instance Source_Input () = ()
-
--- ** Type 'Span'
-data Span src
- =   Span
- {   spanBegin :: !src
- ,   spanEnd   :: !src
- } deriving (Eq, Ord, Show, Typeable)
-
--- ** Class 'Gram_Source'
+-- * Class 'Gram_Source'
 class
  ( Gram_Reader (Source_Input src) g
  , Inj_Source (Span (Source_Input src)) src
  ) => Gram_Source src g where
-       g_source :: Functor g => g (src -> a) -> g a
-       g_source g =
-               g_ask_after $ g_ask_before $
+       source :: Functor g => g (src -> a) -> g a
+       source g =
+               askAfter $ askBefore $
                 (\f (beg::Source_Input src) (end::Source_Input src) ->
                        f (inj_Source $ Span beg end::src))
                 <$> g
@@ -97,11 +43,3 @@ instance
  ( Gram_Reader (Source_Input src) g
  , Inj_Source (Span (Source_Input src)) src
  ) => Gram_Source src g
-
--- ** Type 'At'
--- | Attach a 'Source' to something.
-data At src a
- =   At
- {   at   :: !src
- ,   unAt :: !a
- } deriving (Eq, Functor, Ord, Show, Typeable)
diff --git a/symantic-grammar/Language/Symantic/Grammar/Source.hs b/symantic-grammar/Language/Symantic/Grammar/Source.hs
new file mode 100644 (file)
index 0000000..4dcbab2
--- /dev/null
@@ -0,0 +1,49 @@
+{-# LANGUAGE DeriveFunctor #-}
+{-# LANGUAGE TypeFamilies #-}
+module Language.Symantic.Grammar.Source where
+
+import Data.Functor (Functor)
+import Data.Typeable (Typeable)
+
+-- * Class 'Source'
+class Source src where
+       noSource :: src
+instance Source () where
+       noSource = ()
+
+-- ** Class 'Inj_Source'
+class Source src => Inj_Source a src where
+       inj_Source :: a -> src
+instance Inj_Source a () where
+       inj_Source _ = ()
+
+-- ** Type family 'SourceOf'
+type family SourceOf a
+
+-- ** Type 'Sourced'
+class Source (SourceOf a) => Sourced a where
+       sourceOf  :: a -> SourceOf a
+       setSource :: a -> SourceOf a -> a
+infixl 5 `setSource`
+
+withSource :: Inj_Source src (SourceOf a) => Sourced a => a -> src -> a
+withSource a src = a `setSource` inj_Source src
+
+-- ** Type 'Source_Input'
+type family Source_Input (src :: *) :: *
+type instance Source_Input () = ()
+
+-- ** Type 'Span'
+data Span src
+ =   Span
+ {   spanBegin :: !src
+ ,   spanEnd   :: !src
+ } deriving (Eq, Ord, Show, Typeable)
+
+-- ** Type 'At'
+-- | Attach a 'Source' to something.
+data At src a
+ =   At
+ {   at   :: !src
+ ,   unAt :: !a
+ } deriving (Eq, Functor, Ord, Show, Typeable)
index ae244cdb736401aace576ff52c9223b6c576eacf..cf433f04cff9f320f1fe2bec1abc93056a9b04b2 100644 (file)
@@ -55,6 +55,8 @@ Library
     Language.Symantic.Grammar.Operators
     Language.Symantic.Grammar.Regular
     Language.Symantic.Grammar.Terminal
+    Language.Symantic.Grammar.Source
+    Language.Symantic.Grammar.Error
   build-depends:
     base >= 4.6 && < 5
     , text
index 466db9b9a37f508383395e5cc927ca329353ab9f..0c7dc002242856d8b9eb07467993af2f45712a12 100644 (file)
@@ -30,10 +30,10 @@ import qualified Language.Symantic as Sym
 
 -- NonEmpty P.SourcePos
 instance ParsecC e s => Sym.Gram_Reader (NonEmpty P.SourcePos) (P.ParsecT e s m) where
-       g_ask_before g = do
+       askBefore g = do
                s <- P.statePos <$> P.getParserState
                ($ s) <$> g
-       g_ask_after g = do
+       askAfter g = do
                f <- g
                f . P.statePos <$> P.getParserState
 type instance MC.CanDo (P.ParsecT e s m) (MC.EffReader (NonEmpty P.SourcePos)) = 'True
@@ -41,10 +41,10 @@ instance ParsecC e s => MC.MonadReaderN 'MC.Zero (NonEmpty P.SourcePos) (P.Parse
        askN _n = P.statePos <$> P.getParserState
 -- P.SourcePos
 instance ParsecC e s => Sym.Gram_Reader P.SourcePos (P.ParsecT e s m) where
-       g_ask_before g = do
+       askBefore g = do
                s <- P.getPosition
                ($ s) <$> g
-       g_ask_after g = do
+       askAfter g = do
                f <- g
                f <$> P.getPosition
 type instance MC.CanDo (P.ParsecT e s m) (MC.EffReader P.SourcePos) = 'True
@@ -52,8 +52,8 @@ instance ParsecC e s => MC.MonadReaderN 'MC.Zero P.SourcePos (P.ParsecT e s m) w
        askN _n = P.getPosition
 -- ()
 instance ParsecC e s => Sym.Gram_Reader () (P.ParsecT e s m) where
-       g_ask_before = fmap ($ ())
-       g_ask_after  = fmap ($ ())
+       askBefore = fmap ($ ())
+       askAfter  = fmap ($ ())
 
 --
 -- States
@@ -62,27 +62,27 @@ instance ParsecC e s => Sym.Gram_Reader () (P.ParsecT e s m) where
 -- st
 type instance MC.CanDo (P.ParsecT e s m) (MC.EffState st) = 'False
 instance (Monad m, MC.MonadState st m) => Sym.Gram_State st m where
-       g_state_before g = do
+       stateBefore g = do
                s <- MC.get
                f <- g
                let (s', a) = f s
                MC.put s'
                return a
-       g_state_after g = do
+       stateAfter g = do
                f <- g
                s <- MC.get
                let (s_, a) = f s
                MC.put s_
                return a
-       g_get_before g = do
+       getBefore g = do
                s <- MC.get
                f <- g
                return (f s)
-       g_get_after g = do
+       getAfter g = do
                f <- g
                s <- MC.get
                return (f s)
-       g_put g = do
+       put g = do
                (s, a) <- g
                MC.put s
                return a
@@ -97,7 +97,7 @@ instance ParsecC e s => IsString (P.ParsecT e s m [Char]) where
 -- Sym instances
 --
 instance (ParsecC e s, Show err) => Sym.Gram_Error err (P.ParsecT e s m) where
-       g_catch me = do
+       catch me {- if you can :-} = do
                e <- me
                case e of
                 Left err -> fail $ show err
index 83e8b0edf5d01f551b2ce3de9183058f8b5b9f1d..03e8c2209cf02bb5bbd2854c529e4d7cc0882b31 100644 (file)
@@ -7,7 +7,7 @@ import qualified Data.Char as Char
 import qualified Data.Text as Text
 
 import Language.Symantic.Grammar hiding (char, any)
-import qualified Language.Symantic.Grammar as Gram
+import qualified Language.Symantic.Grammar as G
 import Language.Symantic
 import Language.Symantic.Lib.List (tyList)
 
@@ -68,16 +68,16 @@ instance
  ) => Gram_Term_AtomsFor src ss g Char where
        g_term_atomsFor =
         [ rule "teChar" $
-               lexeme $ g_source $
+               lexeme $ source $
                (\c src -> BinTree0 $ Token_Term $ TermAVT $ (`setSource` src) $ teChar c)
                 <$> between tickG tickG (
-                       cf_of_Terminal (Gram.any `but` tickG) <+>
+                       cfOf (G.any `but` tickG) <+>
                        '\'' <$ string "\\'"
                 )
         ]
                where
                tickG :: Gram_Terminal g' => g' Char
-               tickG = Gram.char '\''
+               tickG = G.char '\''
 instance (Source src, Inj_Sym ss Char) => ModuleFor src ss Char where
        moduleFor = ["Char"] `moduleWhere`
         [ "toLower" := teChar_toLower
index e53a4995e1a9875ebb5902e4372af7f7dc80f2ee..a8451831e4dadd9f1ec1171504f5eb3f5548c00f 100644 (file)
@@ -54,7 +54,7 @@ instance
  ) => Gram_Term_AtomsFor src ss g Integer where
        g_term_atomsFor =
         [ rule "teinteger" $
-               lexeme $ g_source $
+               lexeme $ source $
                (\i src -> BinTree0 $ Token_Term $ TermAVT $ (`setSource` src) $ teInteger $ read i)
                 <$> some (choice $ char <$> ['0'..'9'])
         ]
index 25a6de7921ce6ebb1c3c66d1287226f994d9561a..4491017ac7a23831abb39e813e8d0f32ea1bc86f 100644 (file)
@@ -13,7 +13,7 @@ import qualified Data.Text as Text
 import qualified Data.Traversable as Traversable
 
 import Language.Symantic
-import Language.Symantic.Grammar
+import Language.Symantic.Grammar as G
 import Language.Symantic.Lib.Function (a0, b1, c2)
 import Language.Symantic.Lib.MonoFunctor (Element)
 
@@ -108,7 +108,7 @@ instance
         [ rule "teList_list" $
                between (symbol "[") (symbol "]") listG
         , rule "teList_empty" $
-               g_source $
+               G.source $
                (\src -> BinTree0 $ Token_Term $ TermAVT teList_empty `setSource` src)
                 <$ symbol "["
                 <* symbol "]"
@@ -116,7 +116,7 @@ instance
                where
                listG :: CF g (AST_Term src ss)
                listG = rule "list" $
-                       g_source $
+                       G.source $
                        (\a mb src ->
                                case mb of
                                 Just b  -> BinTree2 (BinTree2 (BinTree0 $ Token_Term $ TermAVT $ (`setSource` src) $ teList_cons) a) b
index ed62a9dc195972879693f2d843b0cacab19383a0..6bcb7151a51991c2e6579970a1aa163064a62b35 100644 (file)
@@ -105,14 +105,14 @@ instance
        g_term_atomsFor =
         -- TODO: proper TupleSections
         [ rule "teTuple2_2" $
-               g_source $ parens $
+               source $ parens $
                (\a b src ->
                        BinTree2 (BinTree2 (BinTree0 $ Token_Term $ TermAVT $ (`setSource` src) $ teTuple2) a) b)
                 <$> g_term
                 <*  symbol ","
                 <*> g_term
         , rule "teTuple2" $
-               g_source $
+               source $
                (\src -> BinTree0 $ Token_Term $ TermAVT $ (`setSource` src) $ teTuple2)
                 <$ symbol "(,)"
         ]
index 3b07c400c37ff9f3b16699f052a1687cbb823902..93f58e365d33895f124f50d8687caa3de89973f5 100644 (file)
@@ -50,7 +50,7 @@ instance
  ) => Gram_Term_AtomsFor src ss g () where
        g_term_atomsFor =
         [ rule "teUnit" $
-               g_source $
+               source $
                (\src -> BinTree0 $ Token_Term $ TermAVT $ (`setSource` src) $ teUnit)
                 <$ symbol "("
                 <* symbol ")"
index 0d24784e348bee11e6783fe1db9e91220057df05..5590af231f25ac8796ca2f7a5c7f3bbbbe89ab6e 100644 (file)
@@ -5,7 +5,8 @@ module Language.Symantic
  , module Language.Symantic.Transforming
  -- * Re-exports for convenience.
  , module Language.Symantic.Grammar.Fixity
- , module Language.Symantic.Grammar.Meta
+ , module Language.Symantic.Grammar.Source
+ , module Language.Symantic.Grammar.Error
  ) where
 
 import Language.Symantic.Typing
@@ -14,4 +15,5 @@ import Language.Symantic.Interpreting
 import Language.Symantic.Transforming
 
 import Language.Symantic.Grammar.Fixity
-import Language.Symantic.Grammar.Meta
+import Language.Symantic.Grammar.Source
+import Language.Symantic.Grammar.Error
index e5da2d0e806f968f4c90df11373d6f1ddc56c200..e1cb972f8b036946f89fc67c1901d9bb623e8f95 100644 (file)
@@ -16,7 +16,7 @@ import qualified Data.Function as Fun
 import qualified Data.Map.Strict as Map
 import qualified Data.Text as Text
 
-import Language.Symantic.Grammar
+import Language.Symantic.Grammar as G
 import Language.Symantic.Typing
 import Language.Symantic.Compiling.Module
 
@@ -47,7 +47,7 @@ class
                 <$> g_term_keywords
                 <*. (any `but` g_term_idname_tail)
                where
-               identG = (:) <$> headG <*> many (cf_of_Terminal g_term_idname_tail)
+               identG = (:) <$> headG <*> many (G.cfOf g_term_idname_tail)
                headG  = unicat $ Unicat Char.UppercaseLetter
        
        g_term_mod_name :: CF g (Mod NameTe)
@@ -74,7 +74,7 @@ class
                 <$> g_term_keywords
                 <*. (any `but` g_term_idname_tail)
                where
-               identG = (:) <$> headG <*> many (cf_of_Terminal g_term_idname_tail)
+               identG = (:) <$> headG <*> many (G.cfOf g_term_idname_tail)
                headG  = unicat $ Unicat_Letter
        g_term_idname_tail :: Terminal g Char
        g_term_idname_tail = rule "term_idname_tail" $
@@ -97,7 +97,7 @@ class
                 <$> g_term_keysyms
                 <*. (any `but` g_term_opname_ok)
                where
-               symG = some $ cf_of_Terminal g_term_opname_ok
+               symG = some $ G.cfOf g_term_opname_ok
        g_term_opname_ok :: Terminal g Char
        g_term_opname_ok = rule "term_opname_ok" $
                choice (unicat <$>
@@ -176,7 +176,7 @@ class
                 ]
        g_term_operators :: CF g  (AST_Term src ss)
        g_term_operators = rule "term_operators" $
-               g_catch $
+               G.catch $
                left Error_Term_Gram_Fixity <$>
                g_ops
                where
@@ -185,9 +185,9 @@ class
                g_prefix  :: CF g (Unifix, AST_Term src ss -> AST_Term src ss)
                g_infix   :: CF g (Infix,  AST_Term src ss -> AST_Term src ss -> AST_Term src ss)
                g_postfix :: CF g (Unifix, AST_Term src ss -> AST_Term src ss)
-               g_prefix  = g_catch $ g_source $ g_get_after $ op_prefix  <$> g_prefix_op
-               g_infix   = g_catch $ g_source $ g_get_after $ op_infix   <$> g_infix_op
-               g_postfix = g_catch $ g_source $ g_get_after $ op_postfix <$> g_postfix_op
+               g_prefix  = G.catch $ G.source $ G.getAfter $ op_prefix  <$> g_prefix_op
+               g_infix   = G.catch $ G.source $ G.getAfter $ op_infix   <$> g_infix_op
+               g_postfix = G.catch $ G.source $ G.getAfter $ op_postfix <$> g_postfix_op
                op_infix
                 :: Mod NameTe
                 -> (Imports, Modules src ss)
@@ -219,7 +219,7 @@ class
                g_postfix_op :: CF g (Mod NameTe)
                g_postfix_op = rule "term_op_postfix" $
                        lexeme $
-                               g_backquote *> g_term_mod_idname <+> -- <* (cf_of_Terminal $ Gram.Term (pure ' ') `but` g_backquote)
+                               g_backquote *> g_term_mod_idname <+> -- <* (G.cfOf $ Gram.Term (pure ' ') `but` g_backquote)
                                g_term_mod_opname
                g_infix_op :: CF g (Mod NameTe)
                g_infix_op = rule "term_op_infix" $
@@ -239,13 +239,13 @@ class
        g_term_atom = rule "term_atom" $
                choice $
                 {-(try (
-                       g_source $
+                       G.source $
                        (\typ src -> BinTree0 $ inj_EToken src $ Token_Term_Type typ)
                         <$ char '@' <*> g_type) :) $
                 -}
                 (try <$> g_term_atomsR @_ @_ @ss) <>
                 [ try $
-                       g_catch $ g_source $ g_get_after $
+                       G.catch $ G.source $ G.getAfter $
                        (\m (imps, mods) src ->
                                case lookupDefTerm FixitySing_Infix imps m mods of
                                 Right t -> Right $ BinTree0 $ token_term t src
@@ -260,7 +260,7 @@ class
        g_term_group = rule "term_group" $ parens g_term
        g_term_abst :: CF g (AST_Term src ss)
        g_term_abst = rule "term_abst" $
-               g_source $
+               G.source $
                ((\(xs, te) src ->
                        foldr (\(x, ty_x) ->
                                BinTree0 . Token_Term_Abst src x ty_x) te xs) <$>) $
@@ -273,9 +273,9 @@ class
         -> CF g ([(NameTe, AST_Type src)], AST_Term src ss)
        -- g_term_abst_args_body args body = (,) <$> args <*> body
        g_term_abst_args_body cf_args cf_body =
-               g_state_before $
+               G.stateBefore $
                (\a b (imps::Imports, mods::Modules src ss) -> ((imps, mods), (a, b)))
-                <$> g_state_after ((<$> cf_args) $ \args (imps::Imports, Modules mods) ->
+                <$> G.stateAfter ((<$> cf_args) $ \args (imps::Imports, Modules mods) ->
                        ((imps, Modules $ Map.alter (setArgs args) [] mods), args))
                 <*> cf_body
                where
@@ -296,7 +296,7 @@ class
                         }
        g_term_let :: CF g  (AST_Term src ss)
        g_term_let = rule "term_let" $
-               g_source $
+               G.source $
                (\name args bound body src ->
                        BinTree0 $
                        Token_Term_Let src name
@@ -359,12 +359,12 @@ gram_term =
  , void g_term_mod_name
  , void g_term_name
  , void g_term_idname
- , void $ cf_of_Terminal g_term_idname_tail
- , void $ cf_of_Reg g_term_keywords
+ , void $ G.cfOf g_term_idname_tail
+ , void $ G.cfOf g_term_keywords
  , void g_term_mod_opname
  , void g_term_opname
- , void $ cf_of_Terminal g_term_opname_ok
- , void $ cf_of_Reg g_term_keysyms
+ , void $ G.cfOf g_term_opname_ok
+ , void $ G.cfOf g_term_keysyms
  ] where
        voiD :: CF g (AST_Term () '[Proxy (->), Proxy Integer]) -> CF g ()
        voiD = (() <$)
index 19c62d53b19ba1191fdd38b37352d72b4dfea5a7..1ca8430bc88f572f15b8ce53d19eaabed9a0078b 100644 (file)
@@ -53,7 +53,7 @@ instance ExpandFam (Term src ss ts vs t) where
 
 -- Type
 instance Inj_Source (TermT src ss ts vs) src => TypeOf (Term src ss ts vs) where
-       typeOf t = typeOfTerm t `source` TermT t
+       typeOf t = typeOfTerm t `withSource` TermT t
 
 typeOfTerm :: Source src => Term src ss ts vs t -> Type src vs t
 typeOfTerm (Term q t _) = q #> t
index e4d9efe746301f01f357ca0124dcd3ed63bead34..7e17fed5c94929a881d8125156c68afdac600ef5 100644 (file)
@@ -9,7 +9,7 @@ import Data.String (IsString(..))
 import Data.Text (Text)
 import qualified Data.Char as Char
 
-import Language.Symantic.Grammar
+import Language.Symantic.Grammar as G
 import Language.Symantic.Typing.Variable
 
 -- * Type 'NameTy'
@@ -65,12 +65,12 @@ class
        g_type = rule "type" $ g_type_fun
        g_type_fun :: CF g (AST_Type src)
        g_type_fun = rule "type_fun" $
-               infixrG g_type_list (g_source $ op <$ symbol "->")
+               infixrG g_type_list (G.source $ op <$ symbol "->")
                where op src = BinTree2 . BinTree2 (BinTree0 $ Token_Type_Const $ At src "(->)")
        -- TODO: maybe not harcoding g_type_list and g_type_tuple2
        g_type_list :: CF g (AST_Type src)
        g_type_list = rule "type_list" $
-               g_source $ inside mk
+               G.source $ inside mk
                 (symbol "[") (optional g_type) (symbol "]")
                 (const <$> g_type_tuple2)
                where
@@ -79,7 +79,7 @@ class
                tok src = BinTree0 $ Token_Type_Const $ At src "[]"
        g_type_tuple2 :: CF g (AST_Type src)
        g_type_tuple2 = rule "type_tuple2" $
-               try (parens (infixrG (g_type) (g_source $ op <$ symbol ","))) <+> (g_type_app)
+               try (parens (infixrG (g_type) (G.source $ op <$ symbol ","))) <+> (g_type_app)
                where op src = BinTree2 . BinTree2 (BinTree0 $ Token_Type_Const $ At src "(,)")
        g_type_app :: CF g (AST_Type src)
        g_type_app = rule "type_app" $
@@ -92,20 +92,20 @@ class
                g_type_symbol
        g_type_name_const :: CF g (AST_Type src)
        g_type_name_const = rule "type_name_const" $
-               lexeme $ g_source $
+               lexeme $ G.source $
                (\n ns src -> BinTree0 $ Token_Type_Const $ At src $ fromString $ n:ns)
                 <$> unicat (Unicat Char.UppercaseLetter)
                 <*> many (choice $ unicat <$> [Unicat_Letter, Unicat_Number])
        g_type_name_var :: CF g (AST_Type src)
        g_type_name_var = rule "type_name_var" $
-               lexeme $ g_source $
+               lexeme $ G.source $
                (\n ns src -> BinTree0 $ Token_Type_Var $ At src $ fromString $ n:ns)
                 <$> unicat (Unicat Char.LowercaseLetter)
                 <*> many (choice $ unicat <$> [Unicat_Letter, Unicat_Number])
        g_type_symbol :: CF g (AST_Type src)
        g_type_symbol = rule "type_symbol" $
-               g_source $ (mk <$>) $
-               parens $ many $ cf_of_Terminal $ choice g_ok `but` choice g_ko
+               G.source $ (mk <$>) $
+               parens $ many $ G.cfOf $ choice g_ok `but` choice g_ko
                where
                mk s src = BinTree0 $ Token_Type_Const $ At src (fromString $ "(" ++ s ++ ")")
                g_ok = unicat <$>
index 7f08c8c3f6abb308b029b3da791789a1225f0b7e..212d09320c58ca3fc73bd2c8da21fbc5142a285c 100644 (file)
@@ -138,5 +138,5 @@ when_KiFun ::
  Either err ret
 when_KiFun x k =
        case x of
-        KiFun _src a b -> k Refl (a `source` KindK x) (b `source` KindK x)
+        KiFun _src a b -> k Refl (a `withSource` KindK x) (b `withSource` KindK x)
         _ -> Left $ inj_Error $ Con_Kind_Arrow (KindK x)
index 9043fb7f0b6dc94b378c0c1463070e70c0ae63c0..734d32fbc7e14837f37640e1ce4a1eeab1c50536 100644 (file)
@@ -80,7 +80,7 @@ instance Source src => Sourced (Type src vs t) where
        setSource (TyFam   _src l f as) src = TyFam   src l f as
 
 instance Inj_Source (TypeVT src) src => KindOf (Type src vs) where
-       kindOf t = kindOfType t `source` TypeVT t
+       kindOf t = kindOfType t `withSource` TypeVT t
 
 instance ConstsOf (Type src vs t) where
        constsOf (TyConst _src _len c)    = Set.singleton $ ConstC c
@@ -229,7 +229,7 @@ type instance SourceOf (Const src c) = src
 instance ConstsOf (Const src c) where
        constsOf = Set.singleton . ConstC
 instance Inj_Source (ConstC src) src => KindOf (Const src) where
-       kindOf c@(Const kc) = kc `source` ConstC c
+       kindOf c@(Const kc) = kc `withSource` ConstC c
 
 kindOfConst :: Const src (t::kt) -> Kind src kt
 kindOfConst (Const kc) = kc
@@ -318,7 +318,7 @@ unTyFun ty_ini = go ty_ini
               , Type src tys (FunRes x) )
        go (TyApp _ (TyApp _ (TyConst _ _ f) a) b)
         | Just HRefl <- proj_ConstKi @(K (->)) @(->) f
-        = Just ((a `source` TypeVT ty_ini), (b `source` TypeVT ty_ini))
+        = Just ((a `withSource` TypeVT ty_ini), (b `withSource` TypeVT ty_ini))
        go (TyApp _ (TyApp _ (TyConst _ _ f) _a) b)
         | Just HRefl <- proj_ConstKi @(K (#>)) @(#>) f
         = go b
index 14e31b63c8474da183d61769fe8f700c8ae40986..bafa81002b69b85c61ed5b28aa1a22f597bd9e2f 100644 (file)
@@ -150,8 +150,8 @@ spineTy typ = go [] typ
        go ctx (TyApp _ (TyApp _ (TyConst _ _ c) _q) t)
         | Just HRefl <- proj_ConstKi @(K (#>)) @(#>) c
         = go ctx t -- NOTE: skip the constraint @q@.
-       go ctx (TyApp  _src f a) = go (TypeT (a `source` TypeVT typ) : ctx) f
-       go ctx t = (TypeT (t `source` TypeVT typ), ctx)
+       go ctx (TyApp  _src f a) = go (TypeT (a `withSource` TypeVT typ) : ctx) f
+       go ctx t = (TypeT (t `withSource` TypeVT typ), ctx)
 
 {-
 spineTy
index ad89c9ef750aa474d24c424dcb5964d36296b247..9be9483d070b2d135ef926e3de233675f7e138fa 100644 (file)
@@ -35,7 +35,7 @@ type instance SourceOf (Var src vs t) = src
 instance Show (Var src tys v) where
        showsPrec p v = showsPrec p (indexVar v)
 instance Inj_Source (EVar src vs) src => KindOf (Var src vs) where
-       kindOf v = kindOfVar v `source` EVar v
+       kindOf v = kindOfVar v `withSource` EVar v
 instance LenVars (Var src vs v) where
        lenVars (VarZ _k l) = l
        lenVars (VarS v)    = LenS (lenVars v)