| | 186 | |
| | 187 | {-| |
| | 188 | Transform an operator name, for example @&infix:<+>@ or @&prefix:«[+]»@, into |
| | 189 | its internal name (@&infix:+@ and @&prefix:[+]@ respectively). |
| | 190 | -} |
| | 191 | possiblyFixOperatorName :: String -> String |
| | 192 | possiblyFixOperatorName 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 |