A bit more explanation in README
Getty Ritter
8 years ago
160 | 160 | |
161 | 161 | If you are using GHC 7.10, several of these will be powerful |
162 | 162 | bidirectional pattern synonyms that allow both constructing and |
163 |
pattern-match |
|
163 | pattern-matching on s-expressions in non-trivial ways: | |
164 | 164 | |
165 | 165 | ~~~~.haskell |
166 | 166 | >>> import Data.SCargot.Repr.Basic |
220 | 220 | "(0 bar)" |
221 | 221 | ~~~~ |
222 | 222 | |
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 | ||
223 | 232 | ## Carrier Types |
224 | 233 | |
225 | 234 | As pointed out above, there are three different carrier types that are |
290 | 299 | ~~~~.haskell |
291 | 300 | >>> let cppComment = string "//" >> manyTill newline >> return () |
292 | 301 | >>> 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" | |
293 | 323 | Right [SCons (SAtom "a") (SCons (SAtom "b") SNil)] |
294 | 324 | ~~~~ |
295 | 325 |