term :: Parser Cond
term = do
    void $ char '#'
    var@(vtyp,vid) <- variable
    checkVar vid
    opr <- opMatch <|> opNotMatch
    cst@(ctyp,cval) <- constant
    when (vtyp /= ctyp) $ unexpected ": Data type mismatch"
    when (vtyp == DT_Res) $ checkResult vid cval
    return $ var `opr` cst
  where
    variable :: Parser Variable
    variable = var2enum variableNames [minBound..maxBound] variableTypes
    checkVar vid = do
        st <- getState
        let blknm = head $ blocks st
            sanity = fromJust $ lookup blknm varSanity
        unless (vid `elem` sanity) $ unexpected $ ": #" ++ show vid ++ " cannot be used in " ++ show blknm ++ "{}"
    checkResult vid (CV_Result cval) = do
        let sanity = fromJust $ lookup vid resultSanity
        mapM_ (test vid sanity) cval
    checkResult _ _ = return ()
    test vid rs r = unless (r `elem` rs) $ unexpected $ ": '" ++ show r ++ "' cannot be used for #" ++ show vid

----------------------------------------------------------------
term :: Parser Cond
term = do
    void $ char '#'
    var@(vtyp,vid) <- variable
    checkVar vid
    opr <- opMatch <|> opNotMatch
    cst@(ctyp,cval) <- constant
    when (vtyp /= ctyp) $ unexpected ": Data type mismatch"
    when (vtyp == DT_Res) $ checkResult vid cval
    return $ var `opr` cst
  where
    variable :: Parser Variable
    variable = var2enum variableNames [minBound..maxBound] variableTypes
    checkVar vid = do
        st <- getState
        let blknm = head $ blocks st
            sanity = fromJust $ lookup blknm varSanity
        unless (vid `elem` sanity) $ unexpected $ ": #" ++ show vid ++ " cannot be used in " ++ show blknm ++ "{}"
    checkResult vid (CV_Result cval) = do
        let sanity = fromJust $ lookup vid resultSanity
        mapM_ (test vid sanity) cval
    checkResult _ _ = return ()
    test vid rs r = unless (r `elem` rs) $ unexpected $ ": '" ++ show r ++ "' cannot be used for #" ++ show vid

----------------------------------------------------------------
term = do
    void $ char '#'
    var@(vtyp,vid) <- variable
    checkVar vid
    opr <- opMatch <|> opNotMatch
    cst@(ctyp,cval) <- constant
    when (vtyp /= ctyp) $ unexpected ": Data type mismatch"
    when (vtyp == DT_Res) $ checkResult vid cval
    return $ var `opr` cst
  where
    variable :: Parser Variable
    variable = var2enum variableNames [minBound..maxBound] variableTypes
    checkVar vid = do
        st <- getState
        let blknm = head $ blocks st
            sanity = fromJust $ lookup blknm varSanity
        unless (vid `elem` sanity) $ unexpected $ ": #" ++ show vid ++ " cannot be used in " ++ show blknm ++ "{}"
    checkResult vid (CV_Result cval) = do
        let sanity = fromJust $ lookup vid resultSanity
        mapM_ (test vid sanity) cval
    checkResult _ _ = return ()
    test vid rs r = unless (r `elem` rs) $ unexpected $ ": '" ++ show r ++ "' cannot be used for #" ++ show vid

----------------------------------------------------------------