From 59c9ed9aa65f149df20fb039e4d733dccc4658c7 Mon Sep 17 00:00:00 2001 From: Juan Facorro Date: Thu, 15 Jun 2017 00:29:28 +0200 Subject: [PATCH] [#22] Throw exception when trying to parse a single colon --- lib/eden/lexer.ex | 7 ++++++- test/eden/parser_test.exs | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/eden/lexer.ex b/lib/eden/lexer.ex index 7628ff3..293b4dc 100644 --- a/lib/eden/lexer.ex +++ b/lib/eden/lexer.ex @@ -18,7 +18,9 @@ defmodule Eden.Lexer do Options: - - `:location` - a `boolean` that determines wether the location information should be included with each token. Columns are one-based and columns are zero-based. The default value for `:location` is `false`. + - `:location` - a `boolean` that determines wether the location information + should be included with each token. Lines are one-based and columns are + zero-based. The default value for `:location` is `false`. ## Examples @@ -324,6 +326,9 @@ defmodule Eden.Lexer do state end defp add_token(state, token) do + if token.type == :keyword and token.value == "" do + raise Ex.UnfinishedTokenError, token + end %{state | tokens: [token | state.tokens]} end diff --git a/test/eden/parser_test.exs b/test/eden/parser_test.exs index 3c6074c..9117092 100644 --- a/test/eden/parser_test.exs +++ b/test/eden/parser_test.exs @@ -45,6 +45,14 @@ defmodule Eden.ParserTest do root = node(:root, nil, [node(:string, "Thaïlande")]) assert parse("\"Thaïlande\"") == root + + assert_raise Ex.UnfinishedTokenError, fn -> + parse(":") + end + + assert_raise Ex.UnfinishedTokenError, fn -> + parse(": :a") + end end test "Map" do