Changeset 6682

Show
Ignore:
Timestamp:
09/04/05 09:32:39 (3 years ago)
Author:
luqui
Message:

Created a warning that warns when you try to export an operator. The problem
came up with Set that exported &infix:<->, thus *overriding* the default
numeric minus, and causing wacky infinite loops all over the place!

Location:
src/Pugs
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Compile.hs

    r6594 r6682  
    1818    TParam(..), 
    1919    EnterClass(..), 
    20     die, varText, 
     20    die, varText 
    2121) where 
    2222import Pugs.AST 
     
    390390    compile val = return $ PVal val 
    391391 
    392 die :: (MonadIO m, Show a) => String -> a -> m b 
    393 die x y = do 
    394     warn x y 
    395     liftIO $ exitFailure 
    396  
    397 warn :: (MonadIO m, Show a) => String -> a -> m () 
    398 warn str val = liftIO $ do 
    399     hPutStrLn stderr $ "*** " ++ str ++ ":\n    " ++ show val 
    400  
    401392-- utility functions 
    402393padSort :: (Var, [(TVar Bool, TVar VRef)]) -> (String, [(a, b)]) -> Ordering 
  • src/Pugs/Internals.hs

    r5963 r6682  
    7272    maybeM, 
    7373    safeMode, 
     74    warn, 
     75    die, 
    7476) where 
    7577 
     
    147149    "Internal error:\n    " ++ s ++ "\nPlease file a bug report." 
    148150 
     151die :: (MonadIO m, Show a) => String -> a -> m b 
     152die x y = do 
     153    warn x y 
     154    liftIO $ exitFailure 
     155 
     156warn :: (MonadIO m, Show a) => String -> a -> m () 
     157warn str val = liftIO $ do 
     158    hPutStrLn stderr $ "*** " ++ str ++ ":\n    " ++ show val 
     159 
    149160split :: (Eq a) => [a] -> [a] -> [[a]] 
    150161split []  _   = internalError "splitting by an empty list" 
  • src/Pugs/Parser.hs

    r6673 r6682  
    3434import Pugs.Parser.Number 
    3535import Pugs.Parser.Unsafe 
     36 
     37fixities :: [String] 
     38fixities = words " prefix: postfix: infix: circumfix: coerce: self: term: postcircumfix: rule_modifier: trait_verb: trait_auxiliary: scope_declarator: statement_control: infix_postfix_meta_operator: postfix_prefix_meta_operator: prefix_postfix_meta_operator: infix_circumfix_meta_operator: " 
     39 
     40isOperatorName :: String -> Bool 
     41isOperatorName ('&':opa@(_:opb)) = isOperatorName' opa || isOperatorName' opb 
     42    where 
     43    isOperatorName' :: String -> Bool 
     44    isOperatorName' oper = or (map (flip isPrefixOf oper) fixities) 
     45isOperatorName _ = False 
    3646 
    3747-- Lexical units -------------------------------------------------- 
     
    369379ruleSubDeclaration :: RuleParser Exp 
    370380ruleSubDeclaration = rule "subroutine declaration" $ do 
    371     -- namePos <- getPosition 
     381    namePos <- getPosition 
    372382    (scope, typ, isMulti, styp, name) <- tryChoice 
    373383        [ ruleSubScopedWithContext 
     
    421431        isBuiltin = ("builtin" `elem` traits) 
    422432        isExported = ("export" `elem` traits) 
     433         
     434    -- XXX this belongs in semantic analysis, not in the parser 
     435    -- also, maybe we should only warn when you try to export an 
     436    -- operator that is "standard" 
     437    -- XXX I can't figure out how to do this without trace 
     438    when (isExported && isOperatorName name) $ 
     439        trace  
     440            ("You probably don't want to export an operator name; instead\n\ 
     441  define a new variant on the new operator (eg. multi sub *infix:<+>):"  
     442                ++ show name ++ " at " ++ show namePos) 
     443            (return ()) 
     444             
    423445    -- Don't add the sub if it's unsafe and we're in safemode. 
    424446    if "unsafe" `elem` traits && safeMode then return emptyExp else case scope of 
     
    464486            <|> between (char '\171') (char '\187') (many1 $ satisfy (/= '\187')) 
    465487    return $ fixity ++ name 
    466     where 
    467     fixities = words " prefix: postfix: infix: circumfix: coerce: self: term: postcircumfix: rule_modifier: trait_verb: trait_auxiliary: scope_declarator: statement_control: infix_postfix_meta_operator: postfix_prefix_meta_operator: prefix_postfix_meta_operator: infix_circumfix_meta_operator: " 
    468488     
    469489