Skip to content

Commit 03f2890

Browse files
committedMay 5, 2015
Fix parsing of paren following '/' operator without space
Fixes #728.
1 parent 6068423 commit 03f2890

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed
 

Diff for: ‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## edge (upcoming 0.8.0)
22

3+
* Parser: Fix parsing of parens following divide operator without a
4+
space.
5+
36
* Parser: Fix bug where keyword arguments could not be parsed if
47
method definition did not have parens around arguments.
58

Diff for: ‎lib/opal/parser/lexer.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -879,13 +879,17 @@ def yylex
879879
elsif scan(/\=/)
880880
@lex_state = :expr_beg
881881
return new_op_asgn('/')
882-
elsif after_operator?
883-
@lex_state = :expr_arg
884-
elsif arg?
882+
end
883+
884+
if arg?
885885
if !check(/\s/) && @space_seen
886886
self.strterm = new_strterm(STR_REGEXP, '/', '/')
887887
return :tREGEXP_BEG
888888
end
889+
end
890+
891+
if after_operator?
892+
@lex_state = :expr_arg
889893
else
890894
@lex_state = :expr_beg
891895
end

Diff for: ‎spec/lib/parser/call_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,12 @@
144144
[:arglist, [:sym, :+]]]
145145
end
146146
end
147+
148+
describe 'Operator calls followed by parens' do
149+
it 'correctly parses parens' do
150+
parsed('1/(2)').should == [:call, [:int, 1], '/'.to_sym, [:arglist, [:paren, [:int, 2]]]]
151+
parsed('1*(2)').should == [:call, [:int, 1], '*'.to_sym, [:arglist, [:paren, [:int, 2]]]]
152+
parsed('1+(2)').should == [:call, [:int, 1], '+'.to_sym, [:arglist, [:paren, [:int, 2]]]]
153+
parsed('1-(2)').should == [:call, [:int, 1], '-'.to_sym, [:arglist, [:paren, [:int, 2]]]]
154+
end
155+
end

0 commit comments

Comments
 (0)
Please sign in to comment.