Skip to content

Commit

Permalink
Merge pull request #36 from jfacorro/jfacorro.22.colon.parsed.as.atom
Browse files Browse the repository at this point in the history
[Fixes #22] Throw exception when trying to parse a single colon
  • Loading branch information
jfacorro authored Jun 14, 2017
2 parents a863da7 + 59c9ed9 commit f05593d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/eden/lexer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions test/eden/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f05593d

Please sign in to comment.