MixParserState.hs revision 08f8731b34de5dc1ced274594978ad8879c831bd
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaModule : $Header$
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaCopyright : (c) Christian Maeder and Uni Bremen 2003
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaMaintainer : hets@tzi.de
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaStability : experimental
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaPortability : portable
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksaspecial parsing states for the mixfix analysis of terms
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksaimport qualified Common.Lib.Map as Map
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksaimport qualified Common.Lib.Set as Set
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa-- avoid confusion with the variable counter Int
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksanewtype Index = Index Int deriving (Eq, Ord, Show)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa-- deriving Num is also possible
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa-- but the following functions are sufficient
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksastartIndex :: Index
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksastartIndex = Index 0
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa-- (also hiding (==) seems not possible)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaisStartIndex :: Index -> Bool
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaisStartIndex = (== startIndex)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaincrIndex :: Index -> Index
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaincrIndex (Index i) = Index (i + 1)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksadata PState a = PState { ruleId :: Id -- the rule to match
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa , ruleScheme :: TypeScheme -- to make id unique
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa , ruleType :: Type -- type of Id
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa , posList :: [Pos] -- positions of Id tokens
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa , ruleArgs :: [a] -- currently collected arguments
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa -- both in reverse order
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa , restRule :: [Token] -- part of the rule after the "dot"
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa , stateNo :: Index -- index into the ParseMap/input string
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksainstance Eq (PState a) where
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa PState r1 s1 _ _ _ t1 p1 == PState r2 s2 _ _ _ t2 p2 =
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa (r1, s1, t1, p1) == (r2, s2, t2, p2)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksainstance Show (PState a) where
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa showsPrec _ p =
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa let d = restRule p
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa v = getTokenList place (ruleId p)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa first = take (length v - length d) v
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa Index i = stateNo p
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa in showChar '{'
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa . showSepList (showString "") showTok first
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa . showChar '.'
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa . showSepList (showString "") showTok d
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa . shows i . showChar '}'
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa . showChar ':'
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen Kuksa . showPretty (ruleType p)
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksatermStr :: String
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksatermStr = "_"
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksacommaTok, termTok, oParenTok, cParenTok, placeTok :: Token
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksacommaTok = mkSimpleId "," -- for list elements
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksatermTok = mkSimpleId termStr
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaplaceTok = mkSimpleId place
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaoParenTok = mkSimpleId "("
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksacParenTok = mkSimpleId ")"
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaopTok, inTok, caseTok :: Token
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksainTok = mkSimpleId "in"
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksacaseTok = mkSimpleId "case"
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaopTok = mkSimpleId "(o)"
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksamkRuleId :: [Token] -> Id
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksamkRuleId toks = Id toks [] []
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaapplId, parenId, inId, opId, tupleId, unitId :: Id
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaapplId = mkRuleId [placeTok, placeTok]
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaparenId = mkRuleId [oParenTok, placeTok, cParenTok]
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksatupleId = mkRuleId [oParenTok, placeTok, commaTok, cParenTok]
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaunitId = mkRuleId [oParenTok, cParenTok]
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksainId = mkRuleId [inTok]
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksaopId = mkRuleId [opTok]
7bb0a9e92bc7a6f868eaa0b9c3212c0af4f96b7fEugen KuksamkPState :: Index -> Id -> TypeScheme -> Type -> [Token] -> PState a
) $ Set.toList lists
$ Map.toList as