Changeset 14640 for src/Pugs/Parser

Show
Ignore:
Timestamp:
11/05/06 18:52:06 (2 years ago)
Author:
audreyt
svk:copy_cache_prev:
41990
Message:

* Pugs.Parser.Operator: Generalize decl+assign hack so we

can deal with "constant=" in a similar way later.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Parser/Operator.hs

    r14625 r14640  
    390390makeOp2Assign prec _ con = (`Infix` prec) $ do 
    391391    symbol "=" 
    392     return $ \invExp argExp -> stateAssignHack (con "=" [invExp, argExp]) 
     392    return $ \invExp argExp -> declAssignHack (con "=" [invExp, argExp]) 
    393393 
    394394-- Rewrite "EXP ~~ .meth" into "?(EXP.meth)" 
     
    403403        _ -> con (sigil ++ name) [x,y] 
    404404 
    405 stateAssignHack :: Exp -> Exp 
    406 stateAssignHack exp@(Syn "=" [lhs, _]) | isStateAssign lhs =  
    407     let pad = unsafePerformSTM $! do 
    408             state_first_run <- newTVar =<< (fmap scalarRef $! newTVar (VInt 0)) 
    409             state_fresh     <- newTVar False 
    410             return $! mkPad [(cast "$?STATE_START_RUN", [(state_fresh, state_first_run)])] in 
    411     Syn "block" 
    412         [ Pad SState pad $! 
    413             Syn "if" 
    414                 [ App (_Var "&postfix:++") Nothing [_Var "$?STATE_START_RUN"] 
    415                 , lhs 
    416                 , exp 
    417                 ] 
    418         ] 
    419     where 
    420     isStateAssign (Ann (Decl SState) _) = True 
    421     isStateAssign (Ann _ exp)           = isStateAssign exp 
    422     isStateAssign _                     = False 
    423 stateAssignHack others = others 
     405declAssignHack :: Exp -> Exp 
     406declAssignHack exp@(Syn "=" [lhs, _]) 
     407    | isDecl SState lhs =  
     408        let pad = unsafePerformSTM $! do 
     409                state_first_run <- newTVar =<< (fmap scalarRef $! newTVar (VInt 0)) 
     410                state_fresh     <- newTVar False 
     411                return $! mkPad [(cast "$?STATE_START_RUN", [(state_fresh, state_first_run)])] in 
     412        Syn "block" 
     413            [ Pad SState pad $! 
     414                Syn "if" 
     415                    [ App (_Var "&postfix:++") Nothing [_Var "$?STATE_START_RUN"] 
     416                    , lhs 
     417                    , exp 
     418                    ] 
     419            ] 
     420    where 
     421    isDecl s (Ann (Decl d) _)    = s == d 
     422    isDecl s (Ann _ exp)         = isDecl s exp 
     423    isDecl _ _                   = False 
     424declAssignHack others = others 
    424425 
    425426-- Just for the ".=" rewriting 
     
    429430    insertIntoPosition "." -- "$x .= foo" becomes "$x .= .foo" 
    430431    return $ \invExp argExp -> case argExp of 
    431         -- XXX - App meth _ args -> stateAssignHack (con ".=" [invExp, App meth Nothing args]) 
    432         App meth _ args -> stateAssignHack (con "=" [invExp, App meth (Just invExp) args]) 
     432        -- XXX - App meth _ args -> declAssignHack (con ".=" [invExp, App meth Nothing args]) 
     433        App meth _ args -> declAssignHack (con "=" [invExp, App meth (Just invExp) args]) 
    433434        _               -> Val (VError (VStr "the right-hand-side of .= must be a function application") []) 
    434435