Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/spitfire.ex
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,12 @@ defmodule Spitfire do
token = encode_literal(parser, token, meta)
parser = parser |> next_token() |> eat_eol()

dbg(parser)
{expr, parser} = parse_expression(parser, @kw_identifier, false, false, false)

dbg(expr)
dbg(parser)

{{token, expr}, parser}
end

Expand Down Expand Up @@ -1711,6 +1715,9 @@ defmodule Spitfire do
old_nesting = parser.nesting
parser = Map.put(parser, :nesting, 0)

dbg(orig_parser)
dbg(parser)

cond do
current_token(parser) == :"]" ->
parser = Map.put(parser, :nesting, old_nesting)
Expand Down
29 changes: 29 additions & 0 deletions test/spitfire_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,35 @@ defmodule SpitfireTest do
assert Spitfire.parse(code) == {:error, {:foo, :baz}, [{[line: 1, column: 7], "syntax error"}]}
end

test "incomplete keyword list" do
code = "[foo: ]"

assert Spitfire.parse(code) ==
{:error, [{:foo, {:__block__, [error: true, line: 1, column: 7], []}}],
[{[line: 1, column: 7], "unknown token: ]"}, {[line: 1, column: 1], "missing closing bracket for list"}]}
end

# FIXME: https://github.com/elixir-tools/spitfire/issues/31
@tag :skip
test "incomplete keyword list with invalid tokeh" do
code = "[foo:]"

assert Spitfire.parse(code) ==
{:error, [{:foo, {:__block__, [error: true, line: 1, column: 7], []}}],
[{[line: 1, column: 7], "unknown token: ]"}, {[line: 1, column: 1], "missing closing bracket for list"}]}
end

test "keyword list in module attr" do
code = ~S'''
@tag foo: bar,
foo
'''

assert Spitfire.parse(code) ==
{:error, [{:foo, {:__block__, [error: true, line: 1, column: 7], []}}],
[{[line: 1, column: 7], "unknown token: ]"}, {[line: 1, column: 1], "missing closing bracket for list"}]}
end

test "missing end in block" do
code = ~S'''
foo do
Expand Down