Skip to content

Commit

Permalink
Fixed #4549: Parser chokes on x ** -y
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jun 11, 2017
1 parent 4a9b867 commit 9db7b50
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Expand Up @@ -1278,6 +1278,8 @@ describe "Parser" do

it_parses "x.y=(1).to_s", Call.new("x".call, "y=", Call.new(Expressions.new([1.int32] of ASTNode), "to_s"))

it_parses "1 ** -x", Call.new(1.int32, "**", Call.new("x".call, "-"))

assert_syntax_error "return do\nend", "unexpected token: do"

%w(def macro class struct module fun alias abstract include extend lib).each do |keyword|
Expand Down
7 changes: 3 additions & 4 deletions src/compiler/crystal/syntax/parser.cr
Expand Up @@ -529,7 +529,8 @@ module Crystal
end
end

parse_operator :mul_or_div, :prefix, "Call.new left, method, [right] of ASTNode, name_column_number: method_column_number", ":\"*\", :\"/\", :\"%\""
parse_operator :mul_or_div, :pow, "Call.new left, method, [right] of ASTNode, name_column_number: method_column_number", ":\"*\", :\"/\", :\"%\""
parse_operator :pow, :prefix, "Call.new left, method, [right] of ASTNode, name_column_number: method_column_number", ":\"**\""

def parse_prefix
column_number = @token.column_number
Expand All @@ -545,12 +546,10 @@ module Crystal
Call.new(arg, token_type.to_s, name_column_number: column_number).at(location).at_end(arg)
end
else
parse_pow
parse_atomic_with_method
end
end

parse_operator :pow, :atomic_with_method, "Call.new left, method, [right] of ASTNode, name_column_number: method_column_number", ":\"**\""

AtomicWithMethodCheck = [:IDENT, :"+", :"-", :"*", :"/", :"%", :"|", :"&", :"^", :"**", :"<<", :"<", :"<=", :"==", :"!=", :"=~", :"!~", :">>", :">", :">=", :"<=>", :"===", :"[]", :"[]=", :"[]?", :"["]

def parse_atomic_with_method
Expand Down

0 comments on commit 9db7b50

Please sign in to comment.