git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1727 from purescript/unicode

Unicode operators

commit65087aa9d5bd2e4236c06d6d48fba8e31ab53d90 authorPhil Freeman <paf31@cantab.net> dateSat 19 Dec 2015, 16:49 (11 years ago) parent71c0a76ea00235
3 files changed+27−7
examples/passing/UnicodeOperators.purs+20 src/Language/PureScript/Parser/Lexer.hs+5−5 src/Language/PureScript/Pretty/Common.hs+2−2
examples/passing/UnicodeOperators.pursnew file+20
@@ -0,0 +1,20 @@
1+module Main where
2+
3+compose :: forall a b c. (b -> c) -> (a -> b) -> a -> c
4+compose f g a = f (g a)
5+
6+infixr 9 compose as ∘
7+
8+test1 = (\x -> x) ∘ \y -> y
9+
10+elem :: forall a b. a -> (a -> Boolean) -> Boolean
11+elem x f = f x
12+
13+infixl 1 elem as ∈
14+
15+emptySet :: forall a. a -> Boolean
16+emptySet _ = true
17+
18+test2 = 1 ∈ emptySet
19+
20+main = Control.Monad.Eff.Console.log "Done"
src/Language/PureScript/Parser/Lexer.hs+5−5
@@ -67,13 +67,13 @@ module Language.PureScript.Parser.Lexer
6767 , natural
6868 , reservedPsNames
6969 , reservedTypeNames
70− , opChars
70+ , isSymbolChar
7171 )
7272 where
7373
7474import Prelude hiding (lex)
7575
76−import Data.Char (isSpace)
76+import Data.Char (isSpace, isAscii, isSymbol)
7777
7878import Control.Monad (void, guard)
7979import Data.Functor.Identity
@@ -233,7 +233,7 @@ parseToken = P.choice
233233 uidentLetter = P.alphaNum <|> P.char '_'
234234
235235 symbolChar :: P.Parsec String u Char
236− symbolChar = P.oneOf opChars
236+ symbolChar = P.satisfy isSymbolChar
237237
238238 parseCharLiteral :: P.Parsec String u Char
239239 parseCharLiteral = PT.charLiteral tokenParser
@@ -516,5 +516,5 @@ reservedTypeNames = [ "forall", "where" ]
516516-- |
517517-- The characters allowed for use in operators
518518--
519−opChars :: [Char]
520−opChars = ":!#$%&*+./<=>?@\\^|-~"
519+isSymbolChar :: Char -> Bool
520+isSymbolChar c = (c `elem` ":!#$%&*+./<=>?@\\^|-~") || (not (isAscii c) && isSymbol c)
src/Language/PureScript/Pretty/Common.hs+2−2
@@ -18,7 +18,7 @@ module Language.PureScript.Pretty.Common where
1818import Control.Monad.State
1919import Data.List (intercalate)
2020
21−import Language.PureScript.Parser.Lexer (reservedPsNames, opChars)
21+import Language.PureScript.Parser.Lexer (reservedPsNames, isSymbolChar)
2222
2323import Text.PrettyPrint.Boxes
2424
@@ -68,7 +68,7 @@ prettyPrintMany f xs = do
6868--
6969prettyPrintObjectKey :: String -> String
7070prettyPrintObjectKey s | s `elem` reservedPsNames = show s
71− | any (`elem` opChars) s = show s
71+ | any isSymbolChar s = show s
7272 | otherwise = s
7373
7474-- | Place a box before another, vertically when the first box takes up multiple lines.