[erlang-questions] Parser combinators

Joel Reymont <>
Wed Oct 17 23:11:08 CEST 2007


Folks,

Any suggestions on how parser combinators can be elegantly and  
cleanly implemented in Erlang?

State needs to be threaded from combinator to combinator and I don't  
see an option apart from either keeping the state in the process  
dictionary or keeping it in a process launched at the beginning of  
the parsing run.

How could the following bits of Haskell without having to deal with  
state returned from each of reschoice, symbol, commaSep, etc.?

	Thanks, Joel

---

varDeclarations = do
   reschoice [ "Variable", "Variables", "Vars", "Var" ]
   symbol ":"
   decs <- commaSep varDeclaration
   return $ VarDecs decs

whileStatement = do
   reserved "While"
   e <- expr
   reserved "Begin"
   xs <- statements
   reserved "End"
   return $ While e (Compound xs)

ident = do
   c <- identStart
   cs <- many (identLetter)
   return (c:cs)

sign = (char '-' >> return (0-1))
        <|> (char '+' >> return 1)
        <|> return 1


--
http://wagerlabs.com








More information about the erlang-questions mailing list