gdritter repos s-cargot / dafe1ce
A bit more explanation in README Getty Ritter 7 years ago
1 changed file(s) with 31 addition(s) and 1 deletion(s). Collapse all Expand all
160160
161161 If you are using GHC 7.10, several of these will be powerful
162162 bidirectional pattern synonyms that allow both constructing and
163 pattern-matchhing on s-expressions in non-trivial ways:
163 pattern-matching on s-expressions in non-trivial ways:
164164
165165 ~~~~.haskell
166166 >>> import Data.SCargot.Repr.Basic
220220 "(0 bar)"
221221 ~~~~
222222
223 Several common atom types appear in the module
224 [`Data.SCargot.Common`](https://hackage.haskell.org/package/s-cargot-0.1.0.0/docs/Data-SCargot-Common.html),
225 including various kinds of identifiers and number literals. The
226 long-term plan for S-Cargot is to include more and more kinds of
227 built-in atoms, in order to make putting together an S-Expression
228 parser even easier. If you have a common syntax for an atom type
229 that you think should be represented there, please
230 [suggest it in an issue](https://github.com/aisamanra/s-cargot/issues)!
231
223232 ## Carrier Types
224233
225234 As pointed out above, there are three different carrier types that are
290299 ~~~~.haskell
291300 >>> let cppComment = string "//" >> manyTill newline >> return ()
292301 >>> decode (setComment cppComment basicParser) "(a //comment\n b)\n"
302 Right [SCons (SAtom "a") (SCons (SAtom "b") SNil)]
303 ~~~~
304
305 The
306 [`Data.SCargot.Comments`](https://hackage.haskell.org/package/s-cargot/docs/Data-SCargot-Comments.html)
307 module defines some helper functions for creating comment syntaxes, so the
308 `cppComment` parser above could be defined as simply
309
310 ~~~~.haskell
311 >>> let cppComment = lineComment "//"
312 >>> decode (setComment cppComment basicParser) "(a //comment\n b)\n"
313 Right [SCons (SAtom "a") (SCons (SAtom "b") SNil)]
314 ~~~~
315
316 Additionally, a handful of common comment syntaxes are defined in
317 [`Data.SCargot.Comments`](https://hackage.haskell.org/package/s-cargot/docs/Data-SCargot-Comments.html),
318 including C-style, Haskell-style, and generic scripting-language-style
319 comments, so in practice, we could write the above example as
320
321 ~~~~.haskell
322 >>> decode (withCLikeLineComments basicParser) "(a //comment\n b)\n"
293323 Right [SCons (SAtom "a") (SCons (SAtom "b") SNil)]
294324 ~~~~
295325