summaryrefslogtreecommitdiffstats
path: root/_build/content/articles/xerl-0.4-expression-separator.asciidoc
blob: c137cf1d294c33ba3d4e32293bb9ef36271398df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
+++
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]