Loading lib/jsduck/lexer.rb +2 −8 Original line number Diff line number Diff line Loading @@ -118,8 +118,8 @@ module JsDuck :type => :operator, :value => @input.scan(/./) } elsif @input.check(/[a-zA-Z_]/) value = @input.scan(/\w+/) elsif @input.check(/[a-zA-Z_$]/) value = @input.scan(/[$\w]+/) return { :type => KEYWORDS[value] ? :keyword : :ident, :value => value Loading Loading @@ -167,12 +167,6 @@ module JsDuck :type => :number, :value => nr } elsif @input.check(/\$/) value = @input.scan(/\$\w*/) return { :type => :ident, :value => value } elsif @input.check(/./) return { :type => :operator, Loading spec/lexer_spec.rb +8 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,14 @@ describe JsDuck::Lexer do ] end it "handles $ in identifiers" do lex("$fo$o").should == [[:ident, "$fo$o"]] end it "handles numbers in identifiers" do lex("x2").should == [[:ident, "x2"]] end describe "differenciates regex from division" do it "when regex after operator" do Loading Loading
lib/jsduck/lexer.rb +2 −8 Original line number Diff line number Diff line Loading @@ -118,8 +118,8 @@ module JsDuck :type => :operator, :value => @input.scan(/./) } elsif @input.check(/[a-zA-Z_]/) value = @input.scan(/\w+/) elsif @input.check(/[a-zA-Z_$]/) value = @input.scan(/[$\w]+/) return { :type => KEYWORDS[value] ? :keyword : :ident, :value => value Loading Loading @@ -167,12 +167,6 @@ module JsDuck :type => :number, :value => nr } elsif @input.check(/\$/) value = @input.scan(/\$\w*/) return { :type => :ident, :value => value } elsif @input.check(/./) return { :type => :operator, Loading
spec/lexer_spec.rb +8 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,14 @@ describe JsDuck::Lexer do ] end it "handles $ in identifiers" do lex("$fo$o").should == [[:ident, "$fo$o"]] end it "handles numbers in identifiers" do lex("x2").should == [[:ident, "x2"]] end describe "differenciates regex from division" do it "when regex after operator" do Loading