[erlang-questions] Writing a DSL in ERlang

Adam Rutkowski hq@REDACTED
Fri Feb 8 12:13:59 CET 2013


On 8 Feb 2013, at 09:59, Christopher Foley wrote:

> Hi,
> 
> I'm am interested in creating an external DSL with Erlang and what are the steps involved. So very basically I want to convert some English like language into running erlang code. My goal is to build up a full erlang source file relative to the dsl file I have as input. I don't necessarily need to print out the source file to the file system, holding it in memory is sufficient and allowing its execution.
> 
> Sample DSL syntax; {createhandler, "TestHandler", {handles, [ {x, {action, printToScreen}}, {y, {action, writeToStorage}} ]} }
> 
> So from above I want to create a gen_event handler with a handle_event function which pattern matches on 'x' and 'y' and performs the actions defined. I have used this to just show what I would like to do, what I'm interested in is the steps and approaches to doing this.
> 
> The steps I see are as follows:
> 	• Parse the dsl text file, create different tokens. I presume that I have to write my own parser as its dependent on the structure of the dsl language itself?
> 	• Match these tokens to chunks of erlang code, is this correct? What is best approach here; create a 'fun' for each chunk of code. How would I then simply put these funs together to represent the overall module?
> 	• Once I have the code combined into one entity(representing a module), then I can presumably use the compile module.
> I am only coming back to writing erlang (ten years since I coded in erlang), so apologies if questions are fairly basic. Any info appreciated.
> Chris.

Take a look at smerl - https://github.com/yariv/erlyweb/blob/master/src/smerl/smerl.erl

--
Adam




More information about the erlang-questions mailing list