Changeset 3690 for src/Pugs/Internals.hs

Show
Ignore:
Timestamp:
05/23/05 00:47:22 (4 years ago)
Author:
iblech
svk:copy_cache_prev:
5201
Message:

* &::("infix:<[+]>") and &::("prefix:«+<<»") and co. work now.
* Removed a wrong test from operator_overloading.t.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Internals.hs

    r3383 r3690  
    6565    modifyTVar, 
    6666    unsafePerformSTM, 
     67    possiblyFixOperatorName, 
    6768) where 
    6869 
     
    183184-- instance MonadIO STM where 
    184185--     liftIO = unsafeIOToSTM 
     186 
     187{-| 
     188Transform an operator name, for example @&infix:<+>@ or @&prefix:«[+]»@, into 
     189its internal name (@&infix:+@ and @&prefix:[+]@ respectively). 
     190-} 
     191possiblyFixOperatorName :: String -> String 
     192possiblyFixOperatorName name 
     193    -- It doesn't matter if we lookup &foo or &*foo. 
     194    | ('&':'*':rest) <- name = "&*" ++ fixName' rest 
     195    | ('&':rest)     <- name = "&"  ++ fixName' rest 
     196    | otherwise      = name 
     197    where 
     198    -- We've to strip the <>s for &infix:<...>, &prefix:<...>, and 
     199    -- &postfix:<...>. 
     200    -- The other &...:<...> things aren't that simple (e.g. circumfix.). 
     201    fixName' ('i':'n':'f':'i':'x':':':rest)         = "infix:"   ++ dropBrackets rest 
     202    fixName' ('p':'r':'e':'f':'i':'x':':':rest)     = "prefix:"  ++ dropBrackets rest 
     203    fixName' ('p':'o':'s':'t':'f':'i':'x':':':rest) = "postfix:" ++ dropBrackets rest 
     204    fixName' x                                      = x 
     205    -- We have to make sure that the last character(s) match the first one(s), 
     206    -- otherwise 4 <= 4 will stop working. 
     207    -- Kludge. <=> is ambigious. 
     208    dropBrackets "<=>" = "<=>" 
     209    -- «bar» --> bar 
     210    dropBrackets ('\171':(rest@(_:_)))    = if (last rest) == '\187' then init rest else '\171':rest 
     211    -- <<bar>> --> bar 
     212    dropBrackets ('<':'<':(rest@(_:_:_))) = if (last rest) == '>' && (last . init $ rest) == '>' then init . init $ rest else "<<" ++ rest 
     213    -- <bar> --> bar 
     214    dropBrackets ('<':(rest@(_:_)))       = if (last rest) == '>' then init rest else '<':rest 
     215    dropBrackets x                        = x