todesking / ruby_hl_lvar.vim

Highlight Ruby local variables
MIT License
53 stars 10 forks source link

Separates extractor for each S-expression version #23

Open chiastolite opened 4 years ago

chiastolite commented 4 years ago

massign structure patterns changed for Ruby 2.5 or later. So I propose to separate RubyHlLvar::Extractor by Ruby's version. This makes easier to introduce pattern matching for Ruby 2.7.

$ docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4 ./all-ruby -rpp -rripper -e 'pp Ripper.sexp("a, (b, c) = foo")'
ruby-2.4.0          [:program,
                     [[:massign,
                       [[:@ident, "a", [1, 0]],
                        [:mlhs_paren, [[:@ident, "b", [1, 4]], [:@ident, "c", [1, 7]]]]],
                       [:vcall, [:@ident, "foo", [1, 12]]]]]]
...
ruby-2.4.9          [:program,
                     [[:massign,
                       [[:@ident, "a", [1, 0]],
                        [:mlhs_paren, [[:@ident, "b", [1, 4]], [:@ident, "c", [1, 7]]]]],
                       [:vcall, [:@ident, "foo", [1, 12]]]]]]
ruby-2.5.0-preview1 [:program,
                     [[:massign,
                       [[:var_field, [:@ident, "a", [1, 0]]],
                        [:mlhs,
                         [:var_field, [:@ident, "b", [1, 4]]],
                         [:var_field, [:@ident, "c", [1, 7]]]]],
                       [:vcall, [:@ident, "foo", [1, 12]]]]]]
...
ruby-2.7.0-rc2      [:program,
                     [[:massign,
                       [[:var_field, [:@ident, "a", [1, 0]]],
                        [:mlhs,
                         [:var_field, [:@ident, "b", [1, 4]]],
                         [:var_field, [:@ident, "c", [1, 7]]]]],
                       [:vcall, [:@ident, "foo", [1, 12]]]]]]
$ docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4 ./all-ruby -rpp -rripper -e 'pp Ripper.sexp("a,*b=1,2")'

ruby-2.4.0          [:program,
                     [[:massign,
                       [:mlhs_add_star, [[:@ident, "a", [1, 0]]], [:@ident, "b", [1, 3]]],
                       [:mrhs_new_from_args, [[:@int, "1", [1, 5]]], [:@int, "2", [1, 7]]]]]]
...
ruby-2.4.9          [:program,
                     [[:massign,
                       [:mlhs_add_star, [[:@ident, "a", [1, 0]]], [:@ident, "b", [1, 3]]],
                       [:mrhs_new_from_args, [[:@int, "1", [1, 5]]], [:@int, "2", [1, 7]]]]]]
ruby-2.5.0-preview1 [:program,
                     [[:massign,
                       [[:var_field, [:@ident, "a", [1, 0]]],
                        [:rest_param, [:var_field, [:@ident, "b", [1, 3]]]]],
                       [:mrhs_new_from_args, [[:@int, "1", [1, 5]]], [:@int, "2", [1, 7]]]]]]
...
ruby-2.7.0-rc2      [:program,
                     [[:massign,
                       [[:var_field, [:@ident, "a", [1, 0]]],
                        [:rest_param, [:var_field, [:@ident, "b", [1, 3]]]]],
                       [:mrhs_new_from_args, [[:@int, "1", [1, 5]]], [:@int, "2", [1, 7]]]]]]
$ docker run -it --rm rubylang/all-ruby env ALL_RUBY_SINCE=ruby-2.4 ./all-ruby -rpp -rripper -e 'pp Ripper.sexp("a,b=1,2")'
ruby-2.4.0          [:program,
                     [[:massign,
                       [[:@ident, "a", [1, 0]], [:@ident, "b", [1, 2]]],
                       [:mrhs_new_from_args, [[:@int, "1", [1, 4]]], [:@int, "2", [1, 6]]]]]]
...
ruby-2.4.9          [:program,
                     [[:massign,
                       [[:@ident, "a", [1, 0]], [:@ident, "b", [1, 2]]],
                       [:mrhs_new_from_args, [[:@int, "1", [1, 4]]], [:@int, "2", [1, 6]]]]]]
ruby-2.5.0-preview1 [:program,
                     [[:massign,
                       [[:var_field, [:@ident, "a", [1, 0]]],
                        [:var_field, [:@ident, "b", [1, 2]]]],
                       [:mrhs_new_from_args, [[:@int, "1", [1, 4]]], [:@int, "2", [1, 6]]]]]]
...
ruby-2.7.0-preview1 [:program,
                     [[:massign,
                       [[:var_field, [:@ident, "a", [1, 0]]],
                        [:var_field, [:@ident, "b", [1, 2]]]],
                       [:mrhs_new_from_args, [[:@int, "1", [1, 4]]], [:@int, "2", [1, 6]]]]]]
pocke commented 4 years ago

Thank you for your pull request, and sorry for my absence. I'll review this pull request, but I do not use this plugin. So probably I do not review it sooner. If someone reviews it, it will be helpful.

chiastolite commented 4 years ago

This PR contains updating todesking/patm for Named capture which supported from 2.0.