Re: [Haskell-cafe] Re: Scheme in Haskell, Parsec Example, how to add scheme comments
On Nov 18, 2007 8:01 PM, Thomas Schilling [EMAIL PROTECTED] wrote: On Sun, 2007-11-18 at 19:37 -0500, Berlin Brown wrote: On Nov 18, 2007 7:32 PM, Berlin Brown [EMAIL PROTECTED] wrote: I am sure many of you have looked at the scheme in haskell example that is on the web by Jonathan Tang. If you are familiar with the code, I need a little help trying to add scheme style comments: ; This is my comment The preferred way to do that is to use a token helper function: token :: P a - P a token p = do r - p whiteSpace return r -- or, if you add a Control.Applicative instance for your -- parser type, this is just: token p = p * whiteSpace Then you handle comments as whitespace: whiteSpace :: P () whiteSpace = skipMany $ spaces | (char ';' skipMany (satisfy (/='\n'))) Then you just use that like this: symbol :: P String symbol = token $ many1 $ satisfy $ not . (`elem` ()[]; ) See also Parsec's TokenParser. token :: Parser - Parser String token p = do r - p whiteSpace return $ String r I know I am being lazy, but what am I missing in your pseudo code: I tried playing with your example but kept getting these errors: Parsec3.hs:23:13: The last statement in a 'do' construct must be an expression at the token line. -- Berlin Brown http://botspiritcompany.com/botlist/spring/help/about.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Scheme in Haskell, Parsec Example, how to add scheme comments
On Nov 22, 2007, at 0:50 , Berlin Brown wrote: token :: Parser - Parser String token p = do r - p whiteSpace return $ String r You have an indentation problem: whiteSpace and return should be at the level of r, not p. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Scheme in Haskell, Parsec Example, how to add scheme comments
On Nov 18, 2007 7:32 PM, Berlin Brown [EMAIL PROTECTED] wrote: I am sure many of you have looked at the scheme in haskell example that is on the web by Jonathan Tang. If you are familiar with the code, I need a little help trying to add scheme style comments: ; This is my comment I added this code here and I think it works (I replaced the name parseSpaces with his spaces function). But, if I start a line with a comment, it errors out with unbound variable. Anybody have any ideas? -- Added the ';' symbol :: Parser Char symbol = oneOf ;!$%|*+-/:=[EMAIL PROTECTED] -- -- Handle whitespace and comments parseSpaces :: Parser () parseSpaces = (try oneLineComment) | whiteSpace | return () where whiteSpace = do skipMany1 space parseSpaces oneLineComment = do { try (string ;) ; skipMany (satisfy (/= '\n')) ; parseSpaces } http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/overview.html Sorry, I am using the full scheme parser in this example: http://halogen.note.amherst.edu/~jdtang/scheme_in_48/scheme_in_48.zip -- Berlin Brown http://botspiritcompany.com/botlist/spring/help/about.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Scheme in Haskell, Parsec Example, how to add scheme comments
On Sun, 2007-11-18 at 19:37 -0500, Berlin Brown wrote: On Nov 18, 2007 7:32 PM, Berlin Brown [EMAIL PROTECTED] wrote: I am sure many of you have looked at the scheme in haskell example that is on the web by Jonathan Tang. If you are familiar with the code, I need a little help trying to add scheme style comments: ; This is my comment The preferred way to do that is to use a token helper function: token :: P a - P a token p = do r - p whiteSpace return r -- or, if you add a Control.Applicative instance for your -- parser type, this is just: token p = p * whiteSpace Then you handle comments as whitespace: whiteSpace :: P () whiteSpace = skipMany $ spaces | (char ';' skipMany (satisfy (/='\n'))) Then you just use that like this: symbol :: P String symbol = token $ many1 $ satisfy $ not . (`elem` ()[]; ) See also Parsec's TokenParser. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe