git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'master' into pure11
commit24fdff2b93c94532e7a5495585a69aa5a08d3130 authorAndy Arvanitis <andyarvanitis@gmail.com> dateThu 12 Nov 2015, 21:40 (11 years ago) parentd0af8780b66f36
6 files changed+60−14
examples/passing/FieldConsPuns.purs+10 examples/passing/OperatorSections.purs+6 examples/passing/StringEscapes.purs+15 src/Language/PureScript/Parser/Declarations.hs+20−11 src/Language/PureScript/Pretty/JS.hs+6 src/Language/PureScript/Publish/ErrorsWarnings.hs+3−3
examples/passing/FieldConsPuns.pursnew file+10
@@ -0,0 +1,10 @@
1+module Main where
2+
3+import Prelude
4+import Control.Monad.Eff.Console
5+
6+greet { greeting, name } = log $ greeting <> ", " <> name <> "."
7+
8+main = greet { greeting, name} where
9+ greeting = "Hello"
10+ name = "World"
examples/passing/OperatorSections.purs+6
@@ -8,4 +8,10 @@ main = do
88 assert $ (2.0 /) 4.0 == 0.5
99 assert $ (`const` 1.0) 2.0 == 2.0
1010 assert $ (1.0 `const`) 2.0 == 1.0
11+ let foo = { x: 2.0 }
12+ assert $ (/ foo.x) 4.0 == 2.0
13+ assert $ (foo.x /) 4.0 == 0.5
14+ let (//) x y = x.x / y.x
15+ assert $ (// foo { x = 4.0 }) { x: 4.0 } == 1.0
16+ assert $ (foo { x = 4.0 } //) { x: 4.0 } == 1.0
1117 Control.Monad.Eff.Console.log "Done!"
examples/passing/StringEscapes.pursnew file+15
@@ -0,0 +1,15 @@
1+module Main where
2+
3+import Prelude ((==), bind)
4+import Test.Assert (assert)
5+
6+singleCharacter = "\0\b\t\n\v\f\r\"\\" == "\x0\x8\x9\xA\xB\xC\xD\x22\x5C"
7+hex = "\x1D306\x2603\x3C6\xE0\x0" == "𝌆☃φà\0"
8+decimal = "\119558\9731\966\224\0" == "𝌆☃φà\0"
9+surrogatePair = "\xD834\xDF06" == "\x1D306"
10+
11+main = do
12+ assert singleCharacter
13+ assert hex
14+ assert decimal
15+ assert surrogatePair
src/Language/PureScript/Parser/Declarations.hs+20−11
@@ -334,9 +334,14 @@ parseObjectLiteral :: TokenParser Expr
334334parseObjectLiteral = ObjectConstructor <$> braces (commaSep parseIdentifierAndValue)
335335
336336parseIdentifierAndValue :: TokenParser (String, Maybe Expr)
337−parseIdentifierAndValue = (,) <$> (C.indented *> (lname <|> stringLiteral) <* C.indented <* colon)
338− <*> (C.indented *> val)
337+parseIdentifierAndValue =
338+ do
339+ name <- C.indented *> lname
340+ b <- P.option (Just $ Var $ Qualified Nothing (Ident name)) rest
341+ return (name, b)
342+ <|> (,) <$> (C.indented *> stringLiteral) <*> rest
339343 where
344+ rest = C.indented *> colon *> C.indented *> val
340345 val = (Just <$> parseValue) <|> (underscore *> pure Nothing)
341346
342347parseAbs :: TokenParser Expr
@@ -414,8 +419,8 @@ parseInfixExpr = P.between tick tick parseValue
414419parseOperatorSection :: TokenParser Expr
415420parseOperatorSection = parens $ left <|> right
416421 where
417− right = OperatorSection <$> parseInfixExpr <* indented <*> (Right <$> parseValueAtom)
418− left = flip OperatorSection <$> (Left <$> parseValueAtom) <* indented <*> parseInfixExpr
422+ right = OperatorSection <$> parseInfixExpr <* indented <*> (Right <$> indexersAndAccessors)
423+ left = flip OperatorSection <$> (Left <$> indexersAndAccessors) <* indented <*> parseInfixExpr
419424
420425parsePropertyUpdate :: TokenParser (String, Maybe Expr)
421426parsePropertyUpdate = do
@@ -449,21 +454,25 @@ parseDoNotationElement = P.choice
449454parseObjectGetter :: TokenParser Expr
450455parseObjectGetter = ObjectGetter <$> (underscore *> C.indented *> dot *> C.indented *> (lname <|> stringLiteral))
451456
457+-- | Expressions including indexers and record updates
458+indexersAndAccessors :: TokenParser Expr
459+indexersAndAccessors = C.buildPostfixParser postfixTable parseValueAtom
460+ where
461+ postfixTable = [ parseAccessor
462+ , P.try . parseUpdaterBody . Just ]
463+
452464-- |
453465-- Parse a value
454466--
455467parseValue :: TokenParser Expr
456468parseValue = withSourceSpan PositionedValue
457469 (P.buildExpressionParser operators
458− . C.buildPostfixParser postfixTable2
470+ . C.buildPostfixParser postfixTable
459471 $ indexersAndAccessors) P.<?> "expression"
460472 where
461− indexersAndAccessors = C.buildPostfixParser postfixTable1 parseValueAtom
462− postfixTable1 = [ parseAccessor
463− , P.try . parseUpdaterBody . Just ]
464− postfixTable2 = [ \v -> P.try (flip App <$> (C.indented *> indexersAndAccessors)) <*> pure v
465− , \v -> flip (TypedValue True) <$> (P.try (C.indented *> doubleColon) *> parsePolyType) <*> pure v
466− ]
473+ postfixTable = [ \v -> P.try (flip App <$> (C.indented *> indexersAndAccessors)) <*> pure v
474+ , \v -> flip (TypedValue True) <$> (P.try (C.indented *> doubleColon) *> parsePolyType) <*> pure v
475+ ]
467476 operators = [ [ P.Prefix (P.try (C.indented *> symbol' "-") >> return UnaryMinus)
468477 ]
469478 , [ P.Infix (P.try (C.indented *> parseInfixExpr P.<?> "infix expression") >>= \ident ->
src/Language/PureScript/Pretty/JS.hs+6
@@ -164,8 +164,14 @@ string s = '"' : concatMap encodeChar s ++ "\""
164164 encodeChar '\r' = "\\r"
165165 encodeChar '"' = "\\\""
166166 encodeChar '\\' = "\\\\"
167+ encodeChar c | fromEnum c > 0xFFFF = "\\u" ++ showHex highSurrogate ("\\u" ++ showHex lowSurrogate "")
168+ where
169+ (h, l) = divMod (fromEnum c - 0x10000) 0x400
170+ highSurrogate = h + 0xD800
171+ lowSurrogate = l + 0xDC00
167172 encodeChar c | fromEnum c > 0xFFF = "\\u" ++ showHex (fromEnum c) ""
168173 encodeChar c | fromEnum c > 0xFF = "\\u0" ++ showHex (fromEnum c) ""
174+ encodeChar c | fromEnum c < 0x10 = "\\x0" ++ showHex (fromEnum c) ""
169175 encodeChar c | fromEnum c > 0x7E || fromEnum c < 0x20 = "\\x" ++ showHex (fromEnum c) ""
170176 encodeChar c = [c]
171177
src/Language/PureScript/Publish/ErrorsWarnings.hs+3−3
@@ -160,9 +160,9 @@ displayUserError e = case e of
160160 , indented (para "* {MAJOR}.{MINOR}.{PATCH} (example: \"1.6.2\")")
161161 , spacer
162162 , para (concat
163− [ "If the version you are publishing is not yet tagged, you might want to use"
164− , "the --dry-run flag instead, which removes this requirement. Run"
165− , "psc-publish --help for more details."
163+ [ "If the version you are publishing is not yet tagged, you might "
164+ , "want to use the --dry-run flag instead, which removes this "
165+ , "requirement. Run psc-publish --help for more details."
166166 ])
167167 ]
168168 AmbiguousVersions vs ->