chart = chart_indirect()
+
_delete = False
agenda = set()
#aggregator = defaultdict(Counter)
functor/arity, `fn`. Returns the arguments of term as a tuple of intern idxs
and constants (possibly an empty tuple).
"""
+
+ if fn == "true/0" :
+ assert (item is True)
+ return
+ if fn == "false/0" :
+ assert (item is False)
+ return
+
assert isinstance(item, tuple)
(fa, idx) = item
assert fa == fn
def build(fn, *args):
+ if fn == "true/0" : return True
+ if fn == "false/0" : return False
+
idx = chart[fn].lookup(args)
if idx is None:
idx = chart[fn].insert(args, None) # don't know val yet.
-- structured term. None of our as_* fields give us that guarantee. See
-- "Dyna.Backend.Python"'s @findHeadFA@ function.
+-- XXX This module does not use Control.Lens but should.
+
-- FIXME: "str" is the same a constant str.
-- timv: should there ever be more than one side condition? shouldn't it be
import qualified Data.ByteString as B
import qualified Data.Char as C
import qualified Data.Map as M
+-- import qualified Debug.Trace as XT
import qualified Dyna.ParserHS.Parser as P
import Dyna.Analysis.Base
import Dyna.Term.TTerm
(_,ADEval) -> case nt of
NTVar v -> NTVar `fmap` newEval "_s" (Left v)
NTBase b -> do
- newWarn "Ignoring * of literal" ss
- return $ NTBase b
+ newWarn "Ignoring * of literal" ss
+ return $ NTBase b
_ -> return nt
-- "is/2" is sort of exciting. We normalize the second argument in an
-- pass to strip duplicate vars out. We need pattern matching to be
-- linear-with-checks in later pipeline stages so that we can, for
-- example, correctly reject updates that are not the right shape.
- normas' <- let delin (vs,r) x = do
+ normas' <- let delin (vs,r) x =
case x of
NTVar v | not (v `elem` vs) -> do
return (v:vs,v:r)
+ NTVar v -> do
+ v' <- nextVar "_x"
+ doUnif v v'
+ return (vs,v':r)
_ -> do
v' <- newAssign "_x" (Left x)
return (vs,v':r)
, ("<=",2)
, (">",2)
, (">=",2)
+ , ("=",2)
, ("!",1)
, ("mod",1)
, ("abs",1)
( "^", 2) -> infixOp " ** "
( "&", 2) -> infixOp " and " -- note: python's 'and' and 'or' operate on more than bool
( "|", 2) -> infixOp " or "
+ ( "=", 2) -> infixOp " == "
( "<", 2) -> infixOp " < "
( "<=", 2) -> infixOp " <= "
( ">", 2) -> infixOp " > "
-- anywhere else in the pipeline yet)
-- Header material {{{
+{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Rank2Types #-}
+{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Dyna.ParserHS.Parser (
import qualified Data.ByteString as B
-- import Data.Char (isSpace)
import qualified Data.CharSet as CS
+import qualified Data.Data as D
import qualified Data.HashSet as H
import Data.Semigroup ((<>))
import Data.Monoid (mempty)
!(Spanned Term)
| TVar !B.ByteString
| TBase !TBase
- deriving (Eq,Ord,Show)
+ deriving (D.Data,D.Typeable,Eq,Ord,Show)
type RuleIx = Int
-- logical aggregators.
, do
h@(_ :~ s) <- term
- ix <- get
+ ix <- incState
return $ Rule ix h ":-" (TFunctor "true" [] :~ s)
]
<* optional (char '.')
(_tNumeric (Left 1) :~ Span (Columns 8 8) (Columns 10 10) sr)
:~ s1)
:~ s1
- , LRule (Rule 1 (TFunctor "goal" [] :~ Span (Columns 12 12) (Columns 17 17) sr)
- "+="
- (_tNumeric (Left 2) :~ Span (Columns 20 20) (Columns 22 22) sr)
+ , LRule (Rule 1 (TFunctor "laog" [] :~ Span (Columns 12 12) (Columns 17 17) sr)
+ "min="
+ (_tNumeric (Left 2) :~ Span (Columns 22 22) (Columns 24 24) sr)
:~ s2)
:~ s2
]
s1 = Span (Columns 0 0) (Columns 11 11) sr
- s2 = Span (Columns 12 12) (Columns 23 23) sr
- sr = "goal += 1 . goal += 2 ."
+ s2 = Span (Columns 12 12) (Columns 25 25) sr
+ sr = "goal += 1 . laog min= 2 ."
case_rulesWhitespace :: Assertion
case_rulesWhitespace = e @=? (proglines sr)