Now I am thinking of writing a Parser for variable. My thought is:
variable::Parser String variable = do s<-identifier if not (s=="define") then return s else --let parser fail
You forgot to tell which parser library you use. If you use ParseLib (or Parsec) you can use the monadic zero function "mzero".
Now, if you are using Parsec, you can also use "fail :: String -> Parser a" to add some error message.
variable = do s<-identifier when (s=="define") (fail "define is a keyword") return s
Or better:
variable = do s<-identifier when (s=="define") (unexpected "keyword") return s <?> "variable"
Or even better, use the standard "identifier" parser from the "ParsecToken" module to handle this for you automatically. The user guide describes this in detail: http://www.cs.uu.nl/~daan/parsec.html
All the best,
Daan.I will be very happy if there is some mechanism to implement the "else" branch, for I have thought of it for long. :)
__________________________________________________ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/ _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
_______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
