diff options
Diffstat (limited to '_build/content/articles/xerl-0.4-expression-separator.asciidoc')
-rw-r--r-- | _build/content/articles/xerl-0.4-expression-separator.asciidoc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/_build/content/articles/xerl-0.4-expression-separator.asciidoc b/_build/content/articles/xerl-0.4-expression-separator.asciidoc new file mode 100644 index 00000000..c137cf1d --- /dev/null +++ b/_build/content/articles/xerl-0.4-expression-separator.asciidoc @@ -0,0 +1,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] |