blob: c137cf1d294c33ba3d4e32293bb9ef36271398df (
plain) (
tree)
|
|
+++
date = "2013-03-01T00:00:00+01:00"
title = "Xerl: expression separator"
+++
As promised we are adding an expression separator this time.
This will be short and easy.
In the tokenizer we only need to add a line recognizing the
comma as a valid token.
[source,erlang]
, : {token, {',', TokenLine}}.
Then we need to change the following lines in the parser:
[source,erlang]
exprs -> expr : ['$1'].
exprs -> expr exprs : ['$1' | '$2'].
And add a comma between the expressions on the second line:
[source,erlang]
exprs -> expr : ['$1'].
exprs -> expr ',' exprs : ['$1' | '$3'].
That takes care of everything except the optional trailing
comma at the end of our lists of expressions. We just need an
additional rule to take care of this.
[source,erlang]
exprs -> expr ',' : ['$1'].
That's it.
Wondering why we don't have this optional trailing comma in
Erlang considering how easy it was and the number of people
complaining about it? Yeah, me too. But that's for someone else
to answer.
Another change I want to talk about is a simple modification
of the compiler code to use an `#env{}` record for
tracking state instead of passing around individual variables.
This will be required later on when we make modules into proper
expressions so I thought it was a good idea to anticipate.
* https://github.com/extend/xerl/blob/0.4/[View the source]
|