]> hydra-www.ietfng.org Git - dyna2/commitdiff
Modified default argument disposition (i.e. how operator/functors perfer to
authortimv <timv@herman0.(none)>
Thu, 15 Nov 2012 00:33:23 +0000 (19:33 -0500)
committertimv <timv@herman0.(none)>
Thu, 15 Nov 2012 00:33:23 +0000 (19:33 -0500)
evaluate their arguments). Now we have (b) operators begining with an alphabetic
character do not evaluate (b) a table of exceptions to for logical and
arithmetic connectives (e.g. exp, not).

Parser now allows wider range of names for aggregators, including "max=".

.gitignore [new file with mode: 0644]
src/Dyna/Analysis/NormalizeParse.hs
src/Dyna/ParserHS/Parser.hs

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..6701a67
--- /dev/null
@@ -0,0 +1,4 @@
+*.hs
+*.hi
+*.o
+*.pyc
index 4d7b246a21faccb19db71e6b30bd2a5a796d3a20..8f1344cc6452b2e262289adbd072b542bfe0f719 100644 (file)
@@ -55,6 +55,8 @@ import qualified Dyna.ParserHS.Parser       as P
 import           Dyna.Term.TTerm
 -- import           Dyna.Test.Trifecta         -- XXX
 
+import qualified Data.Char as C
+
 data ANFDict = AD
   { -- | A map from (functor,arity) to a list of bits indicating whether to
     -- (True) or not to (False) evaluate that positional argument.
@@ -63,7 +65,7 @@ data ANFDict = AD
     --
     -- XXX Stronger type desired: we'd like static assurance that the
     -- length of the list matches the arity in the key!
-    ad_arg_dispos  :: M.Map (B.ByteString,Int) [Bool]
+    ad_arg_dispos  :: (B.ByteString,Int) -> [Bool]
 
     -- | The set of functors that prefer not to be evaluated.
   , ad_self_dispos :: S.Set (B.ByteString,Int)
@@ -108,6 +110,7 @@ unspan (P.TNumeric v T.:~ _)    = UTerm $ TNumeric v
 unspan (P.TFunctor a as T.:~ _) = UTerm $ TFunctor a $ map unspan as
 unspan (P.TAnnot a t T.:~ _)    = UTerm $ TAnnot (fmap unspan a) (unspan t)
 
+
 -- | Convert a syntactic term into ANF; while here, move to a
 -- Control.Unification term representation.
 --
@@ -127,7 +130,7 @@ normTerm_ _ _   _  (P.TVar  v)       = return $ UVar v
 
     -- Numerics also get returned in-place.
 normTerm_ _ _   _  (P.TNumeric n)    = return $ UTerm $ TNumeric n
-    
+
     -- Quote simply disappears having converted the context to
     -- a non-evaluation context.
 normTerm_ _ _   ss (P.TFunctor "&" [t T.:~ st]) = do
@@ -149,7 +152,7 @@ normTerm_ c u   ss (P.TAnnot a (t T.:~ st)) = do
     -- Functors have both top-down and bottom-up dispositions on
     -- their handling.
 normTerm_ c u   ss (P.TFunctor f as) = do
-    argdispos <- asks $ maybe (repeat True) (id) . M.lookup (f,length as) . ad_arg_dispos
+    argdispos <- asks $ flip ($) (f,length as) . ad_arg_dispos
     normas <- mapM (\(a T.:~ s,d) -> normTerm_ d True (s:ss) a) (zip as argdispos)
     selfdispos <- getSelfDispos
     (case () of
@@ -161,7 +164,7 @@ normTerm_ c u   ss (P.TFunctor f as) = do
    getSelfDispos = do
     set <- asks $ not . S.member (f,length as) . ad_self_dispos
     return set
-    
+
 
 normTerm :: (MonadState ANFState m, MonadReader ANFDict m)
          => Bool               -- ^ In an evaluation context?
@@ -183,10 +186,18 @@ normRule (P.Rule h a es r T.:~ _) = do
     return $ Rule nh a nes nr
 
     -- XXX
-dynaFunctorArgDispositions :: M.Map (B.ByteString,Int) [Bool]
-dynaFunctorArgDispositions = M.fromList [
-    (("is",2),[False,True])
- ]
+--dynaFunctorArgDispositions :: M.Map (B.ByteString,Int) [Bool]
+dynaFunctorArgDispositions :: (B.ByteString, Int) -> [Bool]
+dynaFunctorArgDispositions x = case x of
+    ("is", 2) -> [False,True]
+    -- evaluate arithmetic / math
+    ("exp", 1) -> [True]
+    ("log", 1) -> [True]
+    -- logic
+    ("and", 2) -> [True, True]
+    ("or", 2)  -> [True, True]
+    ("not", 1) -> [True]
+    (name, arity) -> take arity $ repeat $ C.isAlpha $ head $ BU.toString name
 
     -- XXX
     --
index 7843e1227c2b91dfc758492f59f6b35774e24382..49077718ca973e8746221bb26d44b82de1f9699e 100644 (file)
@@ -1,6 +1,6 @@
 ---------------------------------------------------------------------------
 -- | A parser for some chunk of the Dyna language, using Trifecta
--- 
+--
 -- Based in part on
 -- <https://github.com/ekmett/trifecta/blob/master/examples/RFC2616.hs>
 -- as well as the trifecta code itself
@@ -204,7 +204,7 @@ term  = token $ choice
       , try $ spanned $ flip TFunctor [] <$> atom
                       <* (notFollowedBy $ char '(')
 
-      , try $ spanned $ flip TFunctor [] <$> (bsf $ string "*") 
+      , try $ spanned $ flip TFunctor [] <$> (bsf $ string "*")
       ,       spanned $ parenfunc
       ]
  where
@@ -241,18 +241,19 @@ texpr = buildExpressionParser etable term <?> "Expression"
 
 
 dterm, dtexpr :: DeltaParsing m => m (Spanned Term)
-dterm  = unDL term 
-dtexpr = unDL texpr 
+dterm  = unDL term
+dtexpr = unDL texpr
 
 ------------------------------------------------------------------------}}}
 -- Rules                                                                {{{
 
 -- | Grab the head (term!) and aggregation operator from a line that
--- we hope is a rule.  
+-- we hope is a rule.
 rulepfx :: DeltaParsing f => f ([Spanned Term] -> Spanned Term -> Rule)
 rulepfx = Rule <$> term
                <*  spaces
-               <*> (bsf $ ident dynaOperStyle <?> "Aggregator")
+               <*> ((bsf $ some $ satisfy $ not . isSpace) <?> "Aggregator")  -- XXX probably a better way to do this.. probably want aggregators have suffix =
+               <*  spaces
 
 rule :: DeltaParsing m => m Rule
 rule = choice [
@@ -271,7 +272,7 @@ rule = choice [
               , Fact   <$> term
               ]
  where
-  hrss = highlight ReservedOperator . spanned . symbol 
+  hrss = highlight ReservedOperator . spanned . symbol
 
 drule :: DeltaParsing m => m (Spanned Rule)
 drule = spanned rule