Skip to content

Commit

Permalink
endlines delimit expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
marianoguerra committed Mar 23, 2016
1 parent 412bfd2 commit c04c56b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
12 changes: 11 additions & 1 deletion examples/trues.otl
@@ -1 +1,11 @@
true true true

true

false

12



13.4

6 changes: 5 additions & 1 deletion src/otl_lexer.xrl
Expand Up @@ -16,7 +16,8 @@ Rules.
{Float} : make_token(float, TokenLine, TokenChars, fun erlang:list_to_float/1).

% spaces, tabs and new lines
{Endls} : skip_token.
{Endls}+ : make_token(nl, TokenLine, endls(TokenChars)).

{Whites} : skip_token.
{Tabs} : skip_token.

Expand All @@ -29,3 +30,6 @@ make_token(Name, Line, Chars) ->

make_token(Name, Line, Chars, Fun) ->
{token, {Name, Line, Fun(Chars)}}.

endls(Chars) ->
lists:filter(fun (C) -> C == $\n end, Chars).
6 changes: 4 additions & 2 deletions src/otl_parser.yrl
Expand Up @@ -3,15 +3,17 @@ Nonterminals
program tl_exprs tl_expr.

Terminals
float integer boolean.
float integer boolean nl.

Rootsymbol
program.

program -> nl tl_exprs : '$2'.
program -> tl_exprs : '$1'.

tl_exprs -> tl_expr : ['$1'].
tl_exprs -> tl_expr tl_exprs : ['$1'|'$2'].
tl_exprs -> tl_expr nl: ['$1'].
tl_exprs -> tl_expr nl tl_exprs : ['$1'|'$3'].

tl_expr -> boolean : {atom, line('$1'), unwrap('$1')}.
tl_expr -> integer: '$1'.
Expand Down

0 comments on commit c04c56b

Please sign in to comment.