Skip to content

Commit

Permalink
+ Added tLABEL. (brynary)
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 6728]
  • Loading branch information
zenspider committed Nov 3, 2011
1 parent 8c54563 commit 18c757e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ruby19_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
kREDO kRETRY kIN kDO kDO_COND kDO_BLOCK kDO_LAMBDA kRETURN kYIELD kSUPER
kSELF kNIL kTRUE kFALSE kAND kOR kNOT kIF_MOD kUNLESS_MOD kWHILE_MOD
kUNTIL_MOD kRESCUE_MOD kALIAS kDEFINED klBEGIN klEND k__LINE__
k__FILE__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tNTH_REF
k__FILE__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tLABEL tCVAR tNTH_REF
tBACK_REF tSTRING_CONTENT tINTEGER tFLOAT tREGEXP_END tUPLUS
tUMINUS tUMINUS_NUM tPOW tCMP tEQ tEQQ tNEQ tGEQ tLEQ tANDOP
tOROP tMATCH tNMATCH tDOT tDOT2 tDOT3 tAREF tASET tLSHFT tRSHFT
Expand Down Expand Up @@ -1845,9 +1845,9 @@ xstring_contents: none
{
result = s(:array, val[0], val[2])
}
| variable tCOLON arg_value
| tLABEL arg_value
{
result = s(:array, s(:lit, val[0].to_sym), val[2])
result = s(:array, s(:lit, val[0][0].to_sym), val[1])
}

operation: tIDENTIFIER | tCONSTANT | tFID
Expand Down
14 changes: 14 additions & 0 deletions lib/ruby_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,20 @@ def process_token(command_state)
end
end

if lex_state == :expr_beg || lex_state == :expr_arg || lex_state == :expr_cmdarg
colon = src.scan(/:/)

if colon && src.peek(1) != ":"
src.unscan
self.lex_state == :expr_beg
src.scan(/:/)
self.yacc_value = [token, src.lineno]
return :tLABEL
end

src.unscan if colon
end

unless lex_state == :expr_dot then
# See if it is a reserved word.
keyword = RubyParser::Keyword.keyword token
Expand Down
11 changes: 11 additions & 0 deletions test/test_ruby_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ def test_yylex_assoc
util_lex_token "=>", :tASSOC, "=>"
end

def test_yylex_label
util_lex_token "{a:", :tLBRACE, "{", :tLABEL, "a"
end

def test_yylex_label_in_params
util_lex_token "foo(a:",
:tIDENTIFIER, "foo",
:tLPAREN2, "(",
:tLABEL, "a"
end

def test_yylex_back_ref
util_lex_token("[$&, $`, $', $+]",
:tLBRACK, "[",
Expand Down

0 comments on commit 18c757e

Please sign in to comment.