Skip to content

Commit

Permalink
Added compare18 and compare19 tasks to help me diff and compare again…
Browse files Browse the repository at this point in the history
…st MRI

- Renamed awords to qwords to match stupid MRI naming. (1.8, 1.9) :(
- Fixed reswords to match MRI (1.8, 1.9)
- Entirely reworked block arg handling. (1.8)
- Added missing gvar arg error. (1.8)
- Split block_var from for_var. (1.8, 1.9)
- Made lambda w/o arg list zero out the arg slot.
- Split 1.8 from 1.9 open paren lexer. Gawd that's ugly code.
Refactored both 1.8 and 1.9 open paren lexing code into separate methods.
Added d method to help debugging output inline with debugging racc output.
Added block_var to handle generating all block_var nodes

[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 7324]
  • Loading branch information
zenspider committed Apr 12, 2012
1 parent 49c0c95 commit feebfe8
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 55 deletions.
16 changes: 16 additions & 0 deletions Rakefile
Expand Up @@ -122,4 +122,20 @@ task :isolate => :phony
file "lib/ruby18_parser.rb" => :isolate
file "lib/ruby19_parser.rb" => :isolate

task :compare18 do
sh "./yack.rb lib/ruby18_parser.output > racc18.txt"
sh "./yack.rb parse18.output > yacc18.txt"
sh "diff -du racc18.txt yacc18.txt || true"
puts
sh "diff -du racc18.txt yacc18.txt | wc -l"
end

task :compare19 do
sh "./yack.rb lib/ruby19_parser.output > racc19.txt"
sh "./yack.rb parse19.output > yacc19.txt"
sh "diff -du racc19.txt yacc19.txt || true"
puts
sh "diff -du racc19.txt yacc19.txt | wc -l"
end

# vim: syntax=Ruby
83 changes: 72 additions & 11 deletions lib/ruby18_parser.y
Expand Up @@ -15,7 +15,7 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
tLBRACK tRBRACK tLBRACE tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2
tTILDE tPERCENT tDIVIDE tPLUS tMINUS tLT tGT tPIPE tBANG tCARET
tLCURLY tRCURLY tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
tWORDS_BEG tAWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END tSTRING
tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END tSTRING
tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAST_TOKEN

prechigh
Expand Down Expand Up @@ -495,7 +495,7 @@ rule
| kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
| kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF
| kSUPER | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
| kIF_MOD | kUNLESS_MOD | kWHILE_MOD | kUNTIL_MOD | kRESCUE_MOD
| kIF | kUNLESS | kWHILE | kUNTIL
arg: lhs tEQL arg
{
Expand Down Expand Up @@ -881,7 +881,7 @@ rule
{
result = val[1]
}
| none_block_pass
| none

args: arg_value
{
Expand Down Expand Up @@ -910,7 +910,7 @@ rule
| xstring
| regexp
| words
| awords
| qwords
| var_ref
| backref
| tFID
Expand Down Expand Up @@ -1044,7 +1044,7 @@ rule
{
result = new_case nil, val[3]
}
| kFOR block_var kIN
| kFOR for_var kIN
{
lexer.cond.push true
}
Expand Down Expand Up @@ -1184,12 +1184,71 @@ rule
result = val[1]
}

block_var: lhs
for_var: lhs
| mlhs
{
val[0].delete_at 1 if val[0][1].nil? # HACK
}

block_par: mlhs_item
{
result = s(:array, val[0])
}
| block_par tCOMMA mlhs_item
{
result = self.list_append val[0], val[2]
}

block_var: block_par
{
result = block_var val[0], nil, nil
}
| block_par tCOMMA
{
result = block_var val[0], nil, nil
}
| block_par tCOMMA tAMPER lhs
{
result = block_var val[0], nil, val[3]
}
| block_par tCOMMA tSTAR lhs tCOMMA tAMPER lhs
{
result = block_var val[0], val[3], val[6]
}
| block_par tCOMMA tSTAR tCOMMA tAMPER lhs
{
result = block_var val[0], s(:splat), val[5]
}
| block_par tCOMMA tSTAR lhs
{
result = block_var val[0], val[3], nil
}
| block_par tCOMMA tSTAR
{
result = block_var val[0], s(:splat), nil
}
| tSTAR lhs tCOMMA tAMPER lhs
{
result = block_var nil, val[1], val[4]
}
| tSTAR tCOMMA tAMPER lhs
{
result = block_var nil, s(:splat), val[3]
}
| tSTAR lhs
{
result = block_var nil, val[1], nil
}
| tSTAR
{
result = block_var nil, s(:splat), nil
}
| tAMPER lhs
{
result = block_var nil, nil, val[1]
}
;

opt_block_var: none
| tPIPE tPIPE
{
Expand Down Expand Up @@ -1429,11 +1488,11 @@ rule
result = self.literal_concat val[0], val[1]
}

awords: tAWORDS_BEG tSPACE tSTRING_END
qwords: tQWORDS_BEG tSPACE tSTRING_END
{
result = s(:array)
}
| tAWORDS_BEG qword_list tSTRING_END
| tQWORDS_BEG qword_list tSTRING_END
{
result = val[1]
}
Expand Down Expand Up @@ -1650,12 +1709,16 @@ xstring_contents: none

f_norm_arg: tCONSTANT
{
yyerror "formal argument cannot be a constant: #{val[0]}"
yyerror "formal argument cannot be a constant"
}
| tIVAR
{
yyerror "formal argument cannot be an instance variable"
}
| tGVAR
{
yyerror "formal argument cannot be a global variable"
}
| tCVAR
{
yyerror "formal argument cannot be a class variable"
Expand Down Expand Up @@ -1788,8 +1851,6 @@ xstring_contents: none

none: { result = nil }

none_block_pass: { result = nil }

end

---- inner
Expand Down
75 changes: 67 additions & 8 deletions lib/ruby19_parser.y
Expand Up @@ -15,7 +15,7 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
tLBRACK tRBRACK tLBRACE tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2
tTILDE tPERCENT tDIVIDE tPLUS tMINUS tLT tGT tPIPE tBANG tCARET
tLCURLY tRCURLY tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
tWORDS_BEG tAWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END tSTRING
tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END tSTRING
tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAST_TOKEN tLAMBDA tLAMBEG

prechigh
Expand Down Expand Up @@ -495,7 +495,7 @@ rule
| kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
| kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF
| kSUPER | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
| kIF_MOD | kUNLESS_MOD | kWHILE_MOD | kUNTIL_MOD | kRESCUE_MOD
| kIF | kUNLESS | kWHILE | kUNTIL
arg: lhs tEQL arg
{
Expand Down Expand Up @@ -925,7 +925,7 @@ rule
| xstring
| regexp
| words
| awords
| qwords
| var_ref
| backref
| tFID
Expand Down Expand Up @@ -1063,7 +1063,7 @@ rule
{
result = new_case nil, val[3]
}
| kFOR block_var kIN
| kFOR for_var kIN
{
lexer.cond.push true
}
Expand Down Expand Up @@ -1203,12 +1203,71 @@ rule
result = val[1]
}
block_var: lhs
for_var: lhs
| mlhs
{
val[0].delete_at 1 if val[0][1].nil? # HACK
}
block_par: mlhs_item
{
result = s(:array, val[0])
}
| block_par tCOMMA mlhs_item
{
result = self.list_append val[0], val[2]
}
block_var: block_par
{
result = block_var val[0], nil, nil
}
| block_par tCOMMA
{
result = block_var val[0], nil, nil
}
| block_par tCOMMA tAMPER lhs
{
result = block_var val[0], nil, val[3]
}
| block_par tCOMMA tSTAR lhs tCOMMA tAMPER lhs
{
result = block_var val[0], val[3], val[6]
}
| block_par tCOMMA tSTAR tCOMMA tAMPER lhs
{
result = block_var val[0], s(:splat), val[5]
}
| block_par tCOMMA tSTAR lhs
{
result = block_var val[0], val[3], nil
}
| block_par tCOMMA tSTAR
{
result = block_var val[0], s(:splat), nil
}
| tSTAR lhs tCOMMA tAMPER lhs
{
result = block_var nil, val[1], val[4]
}
| tSTAR tCOMMA tAMPER lhs
{
result = block_var nil, s(:splat), val[3]
}
| tSTAR lhs
{
result = block_var nil, val[1], nil
}
| tSTAR
{
result = block_var nil, s(:splat), nil
}
| tAMPER lhs
{
result = block_var nil, nil, val[1]
}
;
opt_block_var: none
| tPIPE tPIPE
{
Expand Down Expand Up @@ -1299,7 +1358,7 @@ rule
lambda: lambda_body
{
call = s(:call, nil, :lambda, s(:arglist))
result = s(:iter, call, nil, val[0])
result = s(:iter, call, 0, val[0])
}
| f_larglist lambda_body
{
Expand Down Expand Up @@ -1492,11 +1551,11 @@ rule
result = self.literal_concat val[0], val[1]
}
awords: tAWORDS_BEG tSPACE tSTRING_END
qwords: tQWORDS_BEG tSPACE tSTRING_END
{
result = s(:array)
}
| tAWORDS_BEG qword_list tSTRING_END
| tQWORDS_BEG qword_list tSTRING_END
{
result = val[1]
}
Expand Down

0 comments on commit feebfe8

Please sign in to comment.