Skip to content

Commit

Permalink
Merge pull request #402 from Shopify/at-fix-parse
Browse files Browse the repository at this point in the history
Do not raise unnecessarily during parsing
  • Loading branch information
Morriar authored Jan 21, 2025
2 parents aca32f2 + 0038e4c commit b16c86e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
7 changes: 0 additions & 7 deletions lib/rbi/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,6 @@ def visit_call_node(node)
loc: node_loc(node),
comments: node_comments(node),
)
else
raise ParseError.new(
"Unexpected token `#{node.message}` before `#{last_node&.string&.strip}`",
node_loc(node),
)
end
else
current_scope << parse_visibility(node.name.to_s, node)
Expand Down Expand Up @@ -722,8 +717,6 @@ def parse_struct(node)

keyword_init = val == "true" if key == "keyword_init:"
end
else
raise ParseError.new("Unexpected node type `#{arg.class}`", node_loc(arg))
end
end
end
Expand Down
38 changes: 0 additions & 38 deletions test/rbi/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1019,44 +1019,6 @@ def foo(
RBI
end

def test_parse_errors
e = assert_raises(ParseError) do
Parser.parse_string(<<~RBI)
def bar
RBI
end
assert_equal(
"unexpected end-of-input, assuming it is closing the parent top level context. expected an `end` " \
"to close the `def` statement.",
e.message,
)
assert_equal("-:1:7", e.location.to_s)

e = assert_raises(ParseError) do
Parser.parse_string(<<~RBI)
private include Foo
RBI
end
assert_equal("Unexpected token `private` before `include Foo`", e.message)
assert_equal("-:1:0-1:19", e.location.to_s)

e = assert_raises(ParseError) do
Parser.parse_string(<<~RBI)
private class Foo; end
RBI
end
assert_equal("Unexpected token `private` before `class Foo; end`", e.message)
assert_equal("-:1:0-1:22", e.location.to_s)

e = assert_raises(ParseError) do
Parser.parse_string(<<~RBI)
private CST = 42
RBI
end
assert_equal("Unexpected token `private` before `CST = 42`", e.message)
assert_equal("-:1:0-1:16", e.location.to_s)
end

def test_parse_strings
trees = Parser.parse_strings([
"class Foo; end",
Expand Down

0 comments on commit b16c86e

Please sign in to comment.