git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
comment-styles: style comment types differently (#2597)

* comment-styles: style comment types differently closes #2514 In JS output, style single line and block comments differently. * comment-styles: add myself to CONTRIBUTORS.md

commitbc18c54110505323ace1b08b1fd9529ff9faba58 authorMatthew Leon <ml@matthewleon.com> dateSat 28 Jan 2017, 19:05 (10 years ago) parentde550a1
2 files changed+16−9
CONTRIBUTORS.md+1 src/Language/PureScript/Pretty/JS.hs+15−9
CONTRIBUTORS.md+1
@@ -87,6 +87,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
8787- [@bbqbaron](https://github.com/bbqbaron) (Eric Loren) My existing contributions and all future contributions until further notice are Copyright Eric Loren, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
8888- [@RyanGlScott](https://github.com/RyanGlScott) (Ryan Scott) My existing contributions and all future contributions until further notice are Copyright Ryan Scott, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
8989- [@seungha-kim](https://github.com/seungha-kim) (Seungha Kim) My existing contributions and all future contributions until further notice are Copyright Seungha Kim, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
90+- [@matthewleon](https://github.com/matthewleon) (Matthew Leon) My existing contributions and all future contributions until further notice are Copyright Matthew Leon, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
9091
9192### Companies
9293
src/Language/PureScript/Pretty/JS.hs+15−9
@@ -122,22 +122,30 @@ literals = mkPattern' match'
122122 [ return $ emit $ lbl <> ": "
123123 , prettyPrintJS' js
124124 ]
125− match (JSComment _ com js) = fmap mconcat $ sequence $
125+ match (JSComment _ com js) = mconcat <$> sequence
126+ [ mconcat <$> forM com comment
127+ , prettyPrintJS' js
128+ ]
129+ match (JSRaw _ js) = return $ emit js
130+ match _ = mzero
131+
132+ comment :: (Emit gen) => Comment -> StateT PrinterState Maybe gen
133+ comment (LineComment com) = fmap mconcat $ sequence $
134+ [ return $ emit "\n"
135+ , currentIndent
136+ , return $ emit "//" <> emit com <> emit "\n"
137+ ]
138+ comment (BlockComment com) = fmap mconcat $ sequence $
126139 [ return $ emit "\n"
127140 , currentIndent
128141 , return $ emit "/**\n"
129142 ] ++
130− map asLine (concatMap commentLines com) ++
143+ map asLine (T.lines com) ++
131144 [ currentIndent
132145 , return $ emit " */\n"
133146 , currentIndent
134− , prettyPrintJS' js
135147 ]
136148 where
137− commentLines :: Comment -> [Text]
138− commentLines (LineComment s) = [s]
139− commentLines (BlockComment s) = T.lines s
140−
141149 asLine :: (Emit gen) => Text -> StateT PrinterState Maybe gen
142150 asLine s = do
143151 i <- currentIndent
@@ -150,8 +158,6 @@ literals = mkPattern' match'
150158 Nothing -> case T.uncons t of
151159 Just (x, xs) -> x `T.cons` removeComments xs
152160 Nothing -> ""
153− match (JSRaw _ js) = return $ emit js
154− match _ = mzero
155161
156162conditional :: Pattern PrinterState JS ((Maybe SourceSpan, JS, JS), JS)
157163conditional = mkPattern match