[erlang-questions] Adoption of perl/javascript-style regexp syntax

David Mercer dmercer@REDACTED
Thu Jun 4 16:39:08 CEST 2009


Once I get done with translating the Haskell to Erlang, I might create a
parsec-based PEG module.  For me, the "secret sauce" of parsec is the
monadic bind operator, whose use in Erlang is unwieldy, but effective.

Here's how unpretty it is in Erlang, however:

	Haskell:

		do{ tagName <- xmlOpeningTag()
		  ; xmlFragment()
		  ; xmlClosingTag tagName
		  }

	Erlang:

		bind(xmlOpeningTag(),
			fun(TagName) -> bind(xmlFragment(),
			fun(_) -> xmlClosingTag(TagName) end)
			end).

The unprettiness goes beyond having to repeat the bind/2 call and match up
end's and right parens; I didn't even know how to indent it to make it
clear.  However, there is a lot of functionality abstracted into that bind/2
function which would have to be repeated again and again without it.

I suspect a parse transform could be written that would allow a nice
Haskell-like syntax, but I haven't gotten that far yet.


> -----Original Message-----
> From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On
> Behalf Of Richard Carlsson
> Sent: Thursday, June 04, 2009 9:09 AM
> To: David Mercer
> Cc: 'Richard O'Keefe'; 'Tony Finch'; 'Tony Arcieri'; 'Dmitrii Dimandt';
> erlang-questions@REDACTED
> Subject: Re: [erlang-questions] Adoption of perl/javascript-style regexp
> syntax
> 
> David Mercer wrote:
> > For what it's worth, I started working on a PEG-based module in Erlang a
> few
> > weeks ago, but, in the end I started adding all sorts of niceties that
> > parsec already has, so I've instead taken to reading the Haskell source
> code
> > for parsec and translating it to Erlang.  I know there is already an
> Erlang
> > module for parsec, but it is incomplete and undocumented, so I am
> > documenting as I go along (I also like to have tests [I use common
> test],
> > which the Erlang parsec did not have).  Also, this gave me a good excuse
> to
> > learn Haskell.
> 
> That makes at least three known parsec-like implementations; maybe some
> cooperation would be a good idea:
> http://seancribbs.com/tech/2009/05/29/building-a-parser-generator-in-
> erlang-part-2/
> 
>   /Richard
> 
> (who is increasingly glad he postponed writing his own peg library.)
> 
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org



More information about the erlang-questions mailing list