From 953e741b5eb231dbf1e5414203855c124d271e7e Mon Sep 17 00:00:00 2001 From: bootleq Date: Sun, 2 Aug 2015 19:24:39 +0800 Subject: [PATCH 01/27] Describe `ruby_foldable_groups` option usage --- doc/ft-ruby-syntax.txt | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index fdf88a0e..7d1e279b 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -5,7 +5,8 @@ There are a number of options to the Ruby syntax highlighting. 1. Ruby operators |ruby_operators| 2. Whitespace errors |ruby_space_errors| 3. Folds |ruby_fold| -4. Reducing expensive operations |ruby_no_expensive| |ruby_minlines| +4. Foldable groups |ruby_foldable_groups| +5. Reducing expensive operations |ruby_no_expensive| |ruby_minlines| 1. Ruby operators *ruby_operators* @@ -39,7 +40,27 @@ Folds can be enabled by defining "ruby_fold": > This will set the value |foldmethod| to "syntax" locally to the current buffer or window, which will enable syntax-based folding when editing Ruby filetypes. -4. Reducing expensive operations *ruby_no_expensive* +4. Foldable groups *ruby_foldable_groups* + +Default folding is rather detailed, i.e., small syntax units like "if", "do", +"%w[]" may create corresponding fold levels. + +You can set "ruby_foldable_groups" to restrict which groups are foldable: > + + :let ruby_foldable_groups = 'if case %' +< +value is space-separated keywords, known keywords were: + + keyword meaning ~ + -------- ------------------------------------- ~ + ALL Most block syntax (default) + NONE Nothing + if "if" block + case "case" block + do "do" block + % Literal with "%" notation, e.g.: %w(STRING), %!STRING! + +5. Reducing expensive operations *ruby_no_expensive* By default, the "end" keyword is colorized according to the opening statement of the block it closes. While useful, this feature can be expensive; if you From d4bd6f66416019796fe8aa469a30fe21a54418ae Mon Sep 17 00:00:00 2001 From: bootleq Date: Sun, 2 Aug 2015 19:26:09 +0800 Subject: [PATCH 02/27] Helper function for foldable groups --- syntax/ruby.vim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 03d831c3..9486f9d4 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -17,6 +17,29 @@ if has("folding") && exists("ruby_fold") setlocal foldmethod=syntax endif +let s:foldable_groups = split( + \ get( + \ b:, + \ 'ruby_foldable_groups', + \ get(g:, 'ruby_foldable_groups', 'ALL') + \ ) + \ ) + +function! s:foldable(...) abort "{{{ + if index(s:foldable_groups, 'ALL') > -1 + return 1 + endif + + for l:i in a:000 + if index(s:foldable_groups, l:i) > -1 + return 1 + endif + endfor + + return 0 +endfunction "}}} + + syn cluster rubyNotTop contains=@rubyExtendedStringSpecial,@rubyRegexpSpecial,@rubyDeclaration,rubyConditional,rubyExceptional,rubyMethodExceptional,rubyTodo if exists("ruby_space_errors") From 283a970b2145e816300e0e541cd0234cf3b24044 Mon Sep 17 00:00:00 2001 From: bootleq Date: Sun, 2 Aug 2015 20:43:15 +0800 Subject: [PATCH 03/27] Add example file for syntax test Only have manual test for the time being. --- .../generators/syntax/percent_generator.rb | 20 ++ etc/examples/syntax/percent.rb | 179 ++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100755 etc/examples/generators/syntax/percent_generator.rb create mode 100644 etc/examples/syntax/percent.rb diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb new file mode 100755 index 00000000..ce7a87dd --- /dev/null +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby + +puts "# Generated by `../generators/syntax/percent_generator.rb > percent.rb`\n\n" + +%Q[~`!@\#$%^&*_-+=|:;',.?/].split(//).each do |s| + puts <<-END.gsub(/^\s{4}/, '') + %#{s} + foo + \\#{s} + \\\\\\#{s} + bar + #{s} + + + END +end + +puts "#\svim:foldmethod=syntax" + +# vim:foldmethod=syntax diff --git a/etc/examples/syntax/percent.rb b/etc/examples/syntax/percent.rb new file mode 100644 index 00000000..e7e9d8a1 --- /dev/null +++ b/etc/examples/syntax/percent.rb @@ -0,0 +1,179 @@ +# Generated by `../generators/syntax/percent_generator.rb > percent.rb` + +%~ + foo + \~ + \\\~ + bar +~ + + +%` + foo + \` + \\\` + bar +` + + +%! + foo + \! + \\\! + bar +! + + +%@ + foo + \@ + \\\@ + bar +@ + + +%# + foo + \# + \\\# + bar +# + + +%$ + foo + \$ + \\\$ + bar +$ + + +%% + foo + \% + \\\% + bar +% + + +%^ + foo + \^ + \\\^ + bar +^ + + +%& + foo + \& + \\\& + bar +& + + +%* + foo + \* + \\\* + bar +* + + +%_ + foo + \_ + \\\_ + bar +_ + + +%- + foo + \- + \\\- + bar +- + + +%+ + foo + \+ + \\\+ + bar ++ + + +%= + foo + \= + \\\= + bar += + + +%| + foo + \| + \\\| + bar +| + + +%: + foo + \: + \\\: + bar +: + + +%; + foo + \; + \\\; + bar +; + + +%' + foo + \' + \\\' + bar +' + + +%, + foo + \, + \\\, + bar +, + + +%. + foo + \. + \\\. + bar +. + + +%? + foo + \? + \\\? + bar +? + + +%/ + foo + \/ + \\\/ + bar +/ + + +# vim:foldmethod=syntax From 9f93ca9391d6533125efb4e54a0aed7a0d415b16 Mon Sep 17 00:00:00 2001 From: bootleq Date: Mon, 3 Aug 2015 21:09:34 +0800 Subject: [PATCH 04/27] Complete example for %Q %W %! %x Found some existing problems when using space as delimiter: - `%Q foo\ \\\ bar ` is not detected as string. - They can't go across lines, so folding is not needed. --- .../generators/syntax/percent_generator.rb | 75 +- etc/examples/syntax/percent.rb | 179 ---- etc/examples/syntax/percent/Q.rb | 801 ++++++++++++++++++ 3 files changed, 865 insertions(+), 190 deletions(-) delete mode 100644 etc/examples/syntax/percent.rb create mode 100644 etc/examples/syntax/percent/Q.rb diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index ce7a87dd..5d1616f4 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -1,20 +1,73 @@ #!/usr/bin/env ruby -puts "# Generated by `../generators/syntax/percent_generator.rb > percent.rb`\n\n" +args = ARGV -%Q[~`!@\#$%^&*_-+=|:;',.?/].split(//).each do |s| - puts <<-END.gsub(/^\s{4}/, '') - %#{s} - foo - \\#{s} - \\\\\\#{s} - bar - #{s} +# Usage example: +# +# ./etc/examples/generators/syntax/percent_generator.rb %Q > etc/examples/syntax/percent/Q.rb +# +# read this file with foldlevel 0 to see options beside of `%Q` - END +puts "# Generated by `" << + "./etc/examples/generators/syntax/percent_generator.rb %Q" << + " > etc/examples/syntax/percent/Q.rb" << + "`\n\n" + + + +# %Q {{{ +# Generalized Double Quoted String and Array of Strings and Shell Command Output +if args.include?('%Q') + # Note: %= is not matched here as the beginning of a double quoted string + %Q[~`!@\#$%^&*_-+|:;',.?/].split(//).each do |s| + puts <<-END.gsub(/^\s{4}/, '') + %#{s} + foo + \\#{s} + \\\\\\#{s} + bar + #{s} + + + END + end + + %w(Q W x).each do |leading| + %Q[~`!@\#$%^&*_-+=|:;',.?/].split(//).each do |s| + puts <<-END.gsub(/^\s{6}/, '') + %#{leading}#{s} + foo + \\#{s} + \\\\\\#{s} + bar + #{s} + + + END + end + + %w({} <> [] ()).each do |pair| + puts <<-END.gsub(/^\s{6}/, '') + %#{leading}#{pair[0]} + foo + \\#{pair[1]} + \\\\\\#{pair[1]} + bar + #{pair[1]} + + + END + end + + puts " %#{leading} foo\\ \\\\\\ bar \n\n" + end end +# }}} + + puts "#\svim:foldmethod=syntax" -# vim:foldmethod=syntax + +# vim:foldmethod=marker diff --git a/etc/examples/syntax/percent.rb b/etc/examples/syntax/percent.rb deleted file mode 100644 index e7e9d8a1..00000000 --- a/etc/examples/syntax/percent.rb +++ /dev/null @@ -1,179 +0,0 @@ -# Generated by `../generators/syntax/percent_generator.rb > percent.rb` - -%~ - foo - \~ - \\\~ - bar -~ - - -%` - foo - \` - \\\` - bar -` - - -%! - foo - \! - \\\! - bar -! - - -%@ - foo - \@ - \\\@ - bar -@ - - -%# - foo - \# - \\\# - bar -# - - -%$ - foo - \$ - \\\$ - bar -$ - - -%% - foo - \% - \\\% - bar -% - - -%^ - foo - \^ - \\\^ - bar -^ - - -%& - foo - \& - \\\& - bar -& - - -%* - foo - \* - \\\* - bar -* - - -%_ - foo - \_ - \\\_ - bar -_ - - -%- - foo - \- - \\\- - bar -- - - -%+ - foo - \+ - \\\+ - bar -+ - - -%= - foo - \= - \\\= - bar -= - - -%| - foo - \| - \\\| - bar -| - - -%: - foo - \: - \\\: - bar -: - - -%; - foo - \; - \\\; - bar -; - - -%' - foo - \' - \\\' - bar -' - - -%, - foo - \, - \\\, - bar -, - - -%. - foo - \. - \\\. - bar -. - - -%? - foo - \? - \\\? - bar -? - - -%/ - foo - \/ - \\\/ - bar -/ - - -# vim:foldmethod=syntax diff --git a/etc/examples/syntax/percent/Q.rb b/etc/examples/syntax/percent/Q.rb new file mode 100644 index 00000000..4460395f --- /dev/null +++ b/etc/examples/syntax/percent/Q.rb @@ -0,0 +1,801 @@ +# Generated by `./etc/examples/generators/syntax/percent_generator.rb %Q > etc/examples/syntax/percent/Q.rb` + + %~ + foo + \~ + \\\~ + bar + ~ + + + %` + foo + \` + \\\` + bar + ` + + + %! + foo + \! + \\\! + bar + ! + + + %@ + foo + \@ + \\\@ + bar + @ + + + %# + foo + \# + \\\# + bar + # + + + %$ + foo + \$ + \\\$ + bar + $ + + + %% + foo + \% + \\\% + bar + % + + + %^ + foo + \^ + \\\^ + bar + ^ + + + %& + foo + \& + \\\& + bar + & + + + %* + foo + \* + \\\* + bar + * + + + %_ + foo + \_ + \\\_ + bar + _ + + + %- + foo + \- + \\\- + bar + - + + + %+ + foo + \+ + \\\+ + bar + + + + + %| + foo + \| + \\\| + bar + | + + + %: + foo + \: + \\\: + bar + : + + + %; + foo + \; + \\\; + bar + ; + + + %' + foo + \' + \\\' + bar + ' + + + %, + foo + \, + \\\, + bar + , + + + %. + foo + \. + \\\. + bar + . + + + %? + foo + \? + \\\? + bar + ? + + + %/ + foo + \/ + \\\/ + bar + / + + + %Q~ + foo + \~ + \\\~ + bar + ~ + + + %Q` + foo + \` + \\\` + bar + ` + + + %Q! + foo + \! + \\\! + bar + ! + + + %Q@ + foo + \@ + \\\@ + bar + @ + + + %Q# + foo + \# + \\\# + bar + # + + + %Q$ + foo + \$ + \\\$ + bar + $ + + + %Q% + foo + \% + \\\% + bar + % + + + %Q^ + foo + \^ + \\\^ + bar + ^ + + + %Q& + foo + \& + \\\& + bar + & + + + %Q* + foo + \* + \\\* + bar + * + + + %Q_ + foo + \_ + \\\_ + bar + _ + + + %Q- + foo + \- + \\\- + bar + - + + + %Q+ + foo + \+ + \\\+ + bar + + + + + %Q= + foo + \= + \\\= + bar + = + + + %Q| + foo + \| + \\\| + bar + | + + + %Q: + foo + \: + \\\: + bar + : + + + %Q; + foo + \; + \\\; + bar + ; + + + %Q' + foo + \' + \\\' + bar + ' + + + %Q, + foo + \, + \\\, + bar + , + + + %Q. + foo + \. + \\\. + bar + . + + + %Q? + foo + \? + \\\? + bar + ? + + + %Q/ + foo + \/ + \\\/ + bar + / + + + %Q{ + foo + \} + \\\} + bar + } + + + %Q< + foo + \> + \\\> + bar + > + + + %Q[ + foo + \] + \\\] + bar + ] + + + %Q( + foo + \) + \\\) + bar + ) + + + %Q foo\ \\\ bar + + %W~ + foo + \~ + \\\~ + bar + ~ + + + %W` + foo + \` + \\\` + bar + ` + + + %W! + foo + \! + \\\! + bar + ! + + + %W@ + foo + \@ + \\\@ + bar + @ + + + %W# + foo + \# + \\\# + bar + # + + + %W$ + foo + \$ + \\\$ + bar + $ + + + %W% + foo + \% + \\\% + bar + % + + + %W^ + foo + \^ + \\\^ + bar + ^ + + + %W& + foo + \& + \\\& + bar + & + + + %W* + foo + \* + \\\* + bar + * + + + %W_ + foo + \_ + \\\_ + bar + _ + + + %W- + foo + \- + \\\- + bar + - + + + %W+ + foo + \+ + \\\+ + bar + + + + + %W= + foo + \= + \\\= + bar + = + + + %W| + foo + \| + \\\| + bar + | + + + %W: + foo + \: + \\\: + bar + : + + + %W; + foo + \; + \\\; + bar + ; + + + %W' + foo + \' + \\\' + bar + ' + + + %W, + foo + \, + \\\, + bar + , + + + %W. + foo + \. + \\\. + bar + . + + + %W? + foo + \? + \\\? + bar + ? + + + %W/ + foo + \/ + \\\/ + bar + / + + + %W{ + foo + \} + \\\} + bar + } + + + %W< + foo + \> + \\\> + bar + > + + + %W[ + foo + \] + \\\] + bar + ] + + + %W( + foo + \) + \\\) + bar + ) + + + %W foo\ \\\ bar + + %x~ + foo + \~ + \\\~ + bar + ~ + + + %x` + foo + \` + \\\` + bar + ` + + + %x! + foo + \! + \\\! + bar + ! + + + %x@ + foo + \@ + \\\@ + bar + @ + + + %x# + foo + \# + \\\# + bar + # + + + %x$ + foo + \$ + \\\$ + bar + $ + + + %x% + foo + \% + \\\% + bar + % + + + %x^ + foo + \^ + \\\^ + bar + ^ + + + %x& + foo + \& + \\\& + bar + & + + + %x* + foo + \* + \\\* + bar + * + + + %x_ + foo + \_ + \\\_ + bar + _ + + + %x- + foo + \- + \\\- + bar + - + + + %x+ + foo + \+ + \\\+ + bar + + + + + %x= + foo + \= + \\\= + bar + = + + + %x| + foo + \| + \\\| + bar + | + + + %x: + foo + \: + \\\: + bar + : + + + %x; + foo + \; + \\\; + bar + ; + + + %x' + foo + \' + \\\' + bar + ' + + + %x, + foo + \, + \\\, + bar + , + + + %x. + foo + \. + \\\. + bar + . + + + %x? + foo + \? + \\\? + bar + ? + + + %x/ + foo + \/ + \\\/ + bar + / + + + %x{ + foo + \} + \\\} + bar + } + + + %x< + foo + \> + \\\> + bar + > + + + %x[ + foo + \] + \\\] + bar + ] + + + %x( + foo + \) + \\\) + bar + ) + + + %x foo\ \\\ bar + +# vim:foldmethod=syntax From 3aadf4398b2e86e8682bd7d45f18b8e28f11e9cb Mon Sep 17 00:00:00 2001 From: bootleq Date: Mon, 3 Aug 2015 21:20:41 +0800 Subject: [PATCH 05/27] Respect `%` foldable_groups option for %Q %W %! %x --- syntax/ruby.vim | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 9486f9d4..19a27254 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -177,13 +177,22 @@ syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s(" end=")" " Generalized Double Quoted String and Array of Strings and Shell Command Output " Note: %= is not matched here as the beginning of a double quoted string -syn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[Qx] " end=" " skip="\\\\\|\\)" contains=@rubyStringSpecial fold +if s:foldable('%') + syn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold +else + syn region rubyString matchgroup=rubyStringDelimiter start="%\z([~`!@#$%^&*_\-+|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\={" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape + syn region rubyString matchgroup=rubyStringDelimiter start="%[QWx]\=(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape +endif +syn region rubyString matchgroup=rubyStringDelimiter start="%[Qx] " end=" " skip="\\\\\|\\)" contains=@rubyStringSpecial " Array of Symbols syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold From 9d890e76eada25b1346041e0261f89247174847b Mon Sep 17 00:00:00 2001 From: bootleq Date: Mon, 3 Aug 2015 21:38:15 +0800 Subject: [PATCH 06/27] Only accept 1 arg for percent_generator --- etc/examples/generators/syntax/percent_generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index 5d1616f4..c5992ff1 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -args = ARGV +arg = ARGV.pop # Usage example: @@ -18,7 +18,7 @@ # %Q {{{ # Generalized Double Quoted String and Array of Strings and Shell Command Output -if args.include?('%Q') +if arg == '%Q' # Note: %= is not matched here as the beginning of a double quoted string %Q[~`!@\#$%^&*_-+|:;',.?/].split(//).each do |s| puts <<-END.gsub(/^\s{4}/, '') From f6938f63229bca41955240951239048286065d6f Mon Sep 17 00:00:00 2001 From: bootleq Date: Mon, 3 Aug 2015 21:41:23 +0800 Subject: [PATCH 07/27] Fix %Q syntax example - Add back double quote coverage. - Remove invalid `%W foo ` syntax. --- .../generators/syntax/percent_generator.rb | 6 ++-- etc/examples/syntax/percent/Q.rb | 34 +++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index c5992ff1..258ddc1a 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -20,7 +20,7 @@ # Generalized Double Quoted String and Array of Strings and Shell Command Output if arg == '%Q' # Note: %= is not matched here as the beginning of a double quoted string - %Q[~`!@\#$%^&*_-+|:;',.?/].split(//).each do |s| + %Q[~`!@\#$%^&*_-+|:;"',.?/].split(//).each do |s| puts <<-END.gsub(/^\s{4}/, '') %#{s} foo @@ -34,7 +34,7 @@ end %w(Q W x).each do |leading| - %Q[~`!@\#$%^&*_-+=|:;',.?/].split(//).each do |s| + %Q[~`!@\#$%^&*_-+=|:;"',.?/].split(//).each do |s| puts <<-END.gsub(/^\s{6}/, '') %#{leading}#{s} foo @@ -60,7 +60,7 @@ END end - puts " %#{leading} foo\\ \\\\\\ bar \n\n" + puts " %#{leading} foo\\ \\\\\\ bar \n\n" unless leading == 'W' end end # }}} diff --git a/etc/examples/syntax/percent/Q.rb b/etc/examples/syntax/percent/Q.rb index 4460395f..056f8883 100644 --- a/etc/examples/syntax/percent/Q.rb +++ b/etc/examples/syntax/percent/Q.rb @@ -128,6 +128,14 @@ ; + %" + foo + \" + \\\" + bar + " + + %' foo \' @@ -304,6 +312,14 @@ ; + %Q" + foo + \" + \\\" + bar + " + + %Q' foo \' @@ -514,6 +530,14 @@ ; + %W" + foo + \" + \\\" + bar + " + + %W' foo \' @@ -586,8 +610,6 @@ ) - %W foo\ \\\ bar - %x~ foo \~ @@ -724,6 +746,14 @@ ; + %x" + foo + \" + \\\" + bar + " + + %x' foo \' From cea32442ddee165c233a3b18860eb5582c6d857d Mon Sep 17 00:00:00 2001 From: bootleq Date: Tue, 4 Aug 2015 13:47:42 +0800 Subject: [PATCH 08/27] Respect `%` foldable_groups option for %q %w %s --- .../generators/syntax/percent_generator.rb | 41 +- etc/examples/syntax/percent/q.rb | 653 ++++++++++++++++++ syntax/ruby.vim | 35 +- 3 files changed, 716 insertions(+), 13 deletions(-) create mode 100644 etc/examples/syntax/percent/q.rb diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index 258ddc1a..dffcb7b5 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -10,8 +10,8 @@ # read this file with foldlevel 0 to see options beside of `%Q` puts "# Generated by `" << - "./etc/examples/generators/syntax/percent_generator.rb %Q" << - " > etc/examples/syntax/percent/Q.rb" << + "./etc/examples/generators/syntax/percent_generator.rb #{arg}" << + " > etc/examples/syntax/percent/#{arg[/\w+/]}.rb" << "`\n\n" @@ -67,6 +67,43 @@ +# %q {{{ +# Generalized Single Quoted String, Symbol and Array of Strings +if arg == '%q' + %w(q w s).each do |leading| + %Q[~`!@\#$%^&*_-+=|:;"',.?/].split(//).each do |s| + puts <<-END.gsub(/^\s{6}/, '') + %#{leading}#{s} + foo + \\#{s} + \\\\\\#{s} + bar + #{s} + + + END + end + + %w({} <> [] ()).each do |pair| + puts <<-END.gsub(/^\s{6}/, '') + %#{leading}#{pair[0]} + foo + \\#{pair[1]} + \\\\\\#{pair[1]} + bar + #{pair[1]} + + + END + end + + puts " %#{leading} foo\\ \\\\\\ bar \n\n" if leading == 'q' + end +end +# }}} + + + puts "#\svim:foldmethod=syntax" diff --git a/etc/examples/syntax/percent/q.rb b/etc/examples/syntax/percent/q.rb new file mode 100644 index 00000000..459932b4 --- /dev/null +++ b/etc/examples/syntax/percent/q.rb @@ -0,0 +1,653 @@ +# Generated by `./etc/examples/generators/syntax/percent_generator.rb %q > etc/examples/syntax/percent/q.rb` + + %q~ + foo + \~ + \\\~ + bar + ~ + + + %q` + foo + \` + \\\` + bar + ` + + + %q! + foo + \! + \\\! + bar + ! + + + %q@ + foo + \@ + \\\@ + bar + @ + + + %q# + foo + \# + \\\# + bar + # + + + %q$ + foo + \$ + \\\$ + bar + $ + + + %q% + foo + \% + \\\% + bar + % + + + %q^ + foo + \^ + \\\^ + bar + ^ + + + %q& + foo + \& + \\\& + bar + & + + + %q* + foo + \* + \\\* + bar + * + + + %q_ + foo + \_ + \\\_ + bar + _ + + + %q- + foo + \- + \\\- + bar + - + + + %q+ + foo + \+ + \\\+ + bar + + + + + %q= + foo + \= + \\\= + bar + = + + + %q| + foo + \| + \\\| + bar + | + + + %q: + foo + \: + \\\: + bar + : + + + %q; + foo + \; + \\\; + bar + ; + + + %q" + foo + \" + \\\" + bar + " + + + %q' + foo + \' + \\\' + bar + ' + + + %q, + foo + \, + \\\, + bar + , + + + %q. + foo + \. + \\\. + bar + . + + + %q? + foo + \? + \\\? + bar + ? + + + %q/ + foo + \/ + \\\/ + bar + / + + + %q{ + foo + \} + \\\} + bar + } + + + %q< + foo + \> + \\\> + bar + > + + + %q[ + foo + \] + \\\] + bar + ] + + + %q( + foo + \) + \\\) + bar + ) + + + %q foo\ \\\ bar + + %w~ + foo + \~ + \\\~ + bar + ~ + + + %w` + foo + \` + \\\` + bar + ` + + + %w! + foo + \! + \\\! + bar + ! + + + %w@ + foo + \@ + \\\@ + bar + @ + + + %w# + foo + \# + \\\# + bar + # + + + %w$ + foo + \$ + \\\$ + bar + $ + + + %w% + foo + \% + \\\% + bar + % + + + %w^ + foo + \^ + \\\^ + bar + ^ + + + %w& + foo + \& + \\\& + bar + & + + + %w* + foo + \* + \\\* + bar + * + + + %w_ + foo + \_ + \\\_ + bar + _ + + + %w- + foo + \- + \\\- + bar + - + + + %w+ + foo + \+ + \\\+ + bar + + + + + %w= + foo + \= + \\\= + bar + = + + + %w| + foo + \| + \\\| + bar + | + + + %w: + foo + \: + \\\: + bar + : + + + %w; + foo + \; + \\\; + bar + ; + + + %w" + foo + \" + \\\" + bar + " + + + %w' + foo + \' + \\\' + bar + ' + + + %w, + foo + \, + \\\, + bar + , + + + %w. + foo + \. + \\\. + bar + . + + + %w? + foo + \? + \\\? + bar + ? + + + %w/ + foo + \/ + \\\/ + bar + / + + + %w{ + foo + \} + \\\} + bar + } + + + %w< + foo + \> + \\\> + bar + > + + + %w[ + foo + \] + \\\] + bar + ] + + + %w( + foo + \) + \\\) + bar + ) + + + %s~ + foo + \~ + \\\~ + bar + ~ + + + %s` + foo + \` + \\\` + bar + ` + + + %s! + foo + \! + \\\! + bar + ! + + + %s@ + foo + \@ + \\\@ + bar + @ + + + %s# + foo + \# + \\\# + bar + # + + + %s$ + foo + \$ + \\\$ + bar + $ + + + %s% + foo + \% + \\\% + bar + % + + + %s^ + foo + \^ + \\\^ + bar + ^ + + + %s& + foo + \& + \\\& + bar + & + + + %s* + foo + \* + \\\* + bar + * + + + %s_ + foo + \_ + \\\_ + bar + _ + + + %s- + foo + \- + \\\- + bar + - + + + %s+ + foo + \+ + \\\+ + bar + + + + + %s= + foo + \= + \\\= + bar + = + + + %s| + foo + \| + \\\| + bar + | + + + %s: + foo + \: + \\\: + bar + : + + + %s; + foo + \; + \\\; + bar + ; + + + %s" + foo + \" + \\\" + bar + " + + + %s' + foo + \' + \\\' + bar + ' + + + %s, + foo + \, + \\\, + bar + , + + + %s. + foo + \. + \\\. + bar + . + + + %s? + foo + \? + \\\? + bar + ? + + + %s/ + foo + \/ + \\\/ + bar + / + + + %s{ + foo + \} + \\\} + bar + } + + + %s< + foo + \> + \\\> + bar + > + + + %s[ + foo + \] + \\\] + bar + ] + + + %s( + foo + \) + \\\) + bar + ) + + +# vim:foldmethod=syntax diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 19a27254..885b2cc5 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -163,17 +163,30 @@ endif syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial fold " Generalized Single Quoted String, Symbol and Array of Strings -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape -syn region rubyString matchgroup=rubyStringDelimiter start="%[qw](" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape -syn region rubyString matchgroup=rubyStringDelimiter start="%q " end=" " skip="\\\\\|\\)" fold -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\z([~`!@#$%^&*_\-+=|\:;"',.? /]\)" end="\z1" skip="\\\\\|\\\z1" fold -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s(" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape +if s:foldable('%') + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw](" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\z([~`!@#$%^&*_\-+=|\:;"',.? /]\)" end="\z1" skip="\\\\\|\\\z1" fold + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s(" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape +else + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]{" end="}" skip="\\\\\|\\}" contains=rubyNestedCurlyBraces,rubyDelimEscape + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]<" end=">" skip="\\\\\|\\>" contains=rubyNestedAngleBrackets,rubyDelimEscape + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw]\[" end="\]" skip="\\\\\|\\\]" contains=rubyNestedSquareBrackets,rubyDelimEscape + syn region rubyString matchgroup=rubyStringDelimiter start="%[qw](" end=")" skip="\\\\\|\\)" contains=rubyNestedParentheses,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\z([~`!@#$%^&*_\-+=|\:;"',.? /]\)" end="\z1" skip="\\\\\|\\\z1" + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s{" end="}" skip="\\\\\|\\}" contains=rubyNestedCurlyBraces,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s<" end=">" skip="\\\\\|\\>" contains=rubyNestedAngleBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s\[" end="\]" skip="\\\\\|\\\]" contains=rubyNestedSquareBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%s(" end=")" skip="\\\\\|\\)" contains=rubyNestedParentheses,rubyDelimEscape +endif +syn region rubyString matchgroup=rubyStringDelimiter start="%q " end=" " skip="\\\\\|\\)" " Generalized Double Quoted String and Array of Strings and Shell Command Output " Note: %= is not matched here as the beginning of a double quoted string From c9f66b56636bb2b1608a46557c1a34208ca46aa3 Mon Sep 17 00:00:00 2001 From: bootleq Date: Tue, 4 Aug 2015 20:29:00 +0800 Subject: [PATCH 09/27] Respect `%` foldable_groups option for %r --- .../generators/syntax/percent_generator.rb | 33 +++ etc/examples/syntax/percent/r.rb | 219 ++++++++++++++++++ syntax/ruby.vim | 18 +- 3 files changed, 265 insertions(+), 5 deletions(-) create mode 100644 etc/examples/syntax/percent/r.rb diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index dffcb7b5..a58547d8 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -104,6 +104,39 @@ +# %r {{{ +# Generalized Regular Expression +if arg == '%r' + %Q[~`!@\#$%^&*_-+=|:;"',.?/].split(//).each do |s| + puts <<-END.gsub(/^\s{4}/, '') + %r#{s} + foo + \\#{s} + \\\\\\#{s} + bar + #{s} + + + END + end + + %w({} <> [] ()).each do |pair| + puts <<-END.gsub(/^\s{4}/, '') + %r#{pair[0]} + foo + \\#{pair[1]} + \\\\\\#{pair[1]} + bar + #{pair[1]} + + + END + end +end +# }}} + + + puts "#\svim:foldmethod=syntax" diff --git a/etc/examples/syntax/percent/r.rb b/etc/examples/syntax/percent/r.rb new file mode 100644 index 00000000..bed0ab12 --- /dev/null +++ b/etc/examples/syntax/percent/r.rb @@ -0,0 +1,219 @@ +# Generated by `./etc/examples/generators/syntax/percent_generator.rb %r > etc/examples/syntax/percent/r.rb` + + %r~ + foo + \~ + \\\~ + bar + ~ + + + %r` + foo + \` + \\\` + bar + ` + + + %r! + foo + \! + \\\! + bar + ! + + + %r@ + foo + \@ + \\\@ + bar + @ + + + %r# + foo + \# + \\\# + bar + # + + + %r$ + foo + \$ + \\\$ + bar + $ + + + %r% + foo + \% + \\\% + bar + % + + + %r^ + foo + \^ + \\\^ + bar + ^ + + + %r& + foo + \& + \\\& + bar + & + + + %r* + foo + \* + \\\* + bar + * + + + %r_ + foo + \_ + \\\_ + bar + _ + + + %r- + foo + \- + \\\- + bar + - + + + %r+ + foo + \+ + \\\+ + bar + + + + + %r= + foo + \= + \\\= + bar + = + + + %r| + foo + \| + \\\| + bar + | + + + %r: + foo + \: + \\\: + bar + : + + + %r; + foo + \; + \\\; + bar + ; + + + %r" + foo + \" + \\\" + bar + " + + + %r' + foo + \' + \\\' + bar + ' + + + %r, + foo + \, + \\\, + bar + , + + + %r. + foo + \. + \\\. + bar + . + + + %r? + foo + \? + \\\? + bar + ? + + + %r/ + foo + \/ + \\\/ + bar + / + + + %r{ + foo + \} + \\\} + bar + } + + + %r< + foo + \> + \\\> + bar + > + + + %r[ + foo + \] + \\\] + bar + ] + + + %r( + foo + \) + \\\) + bar + ) + + +# vim:foldmethod=syntax diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 885b2cc5..3b802900 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -146,11 +146,19 @@ syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|o syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold " Generalized Regular Expression -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.? /]\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyRegexpSpecial fold -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r{" end="}[iomxneus]*" skip="\\\\\|\\}" contains=@rubyRegexpSpecial fold -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r<" end=">[iomxneus]*" skip="\\\\\|\\>" contains=@rubyRegexpSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\[" end="\][iomxneus]*" skip="\\\\\|\\\]" contains=@rubyRegexpSpecial fold -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r(" end=")[iomxneus]*" skip="\\\\\|\\)" contains=@rubyRegexpSpecial fold +if s:foldable('%') + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.? /]\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyRegexpSpecial fold + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r{" end="}[iomxneus]*" skip="\\\\\|\\}" contains=@rubyRegexpSpecial fold + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r<" end=">[iomxneus]*" skip="\\\\\|\\>" contains=@rubyRegexpSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\[" end="\][iomxneus]*" skip="\\\\\|\\\]" contains=@rubyRegexpSpecial fold + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r(" end=")[iomxneus]*" skip="\\\\\|\\)" contains=@rubyRegexpSpecial fold +else + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\z([~`!@#$%^&*_\-+=|\:;"',.? /]\)" end="\z1[iomxneus]*" skip="\\\\\|\\\z1" contains=@rubyRegexpSpecial + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r{" end="}[iomxneus]*" skip="\\\\\|\\}" contains=@rubyRegexpSpecial + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r<" end=">[iomxneus]*" skip="\\\\\|\\>" contains=@rubyRegexpSpecial,rubyNestedAngleBrackets,rubyDelimEscape + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r\[" end="\][iomxneus]*" skip="\\\\\|\\\]" contains=@rubyRegexpSpecial + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="%r(" end=")[iomxneus]*" skip="\\\\\|\\)" contains=@rubyRegexpSpecial +endif " Normal String and Shell Command Output if exists('ruby_spellcheck_strings') From 05acf3532a69034069a80b56bd9fc009117fc886 Mon Sep 17 00:00:00 2001 From: bootleq Date: Sat, 8 Aug 2015 19:49:43 +0800 Subject: [PATCH 10/27] Respect `%` foldable_groups option for %i %I --- .../generators/syntax/percent_generator.rb | 36 ++ etc/examples/syntax/percent/i.rb | 435 ++++++++++++++++++ syntax/ruby.vim | 42 +- 3 files changed, 500 insertions(+), 13 deletions(-) create mode 100644 etc/examples/syntax/percent/i.rb diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index a58547d8..2fc0000c 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -137,6 +137,42 @@ +# %i / %I {{{ +# Array of Symbols +# Array of interpolated Symbols +if %w(%i %I).include?(arg) + %w(i I).each do |leading| + %Q[~`!@\#$%^&*_-+=|:;"',.?/].split(//).each do |s| + puts <<-END.gsub(/^\s{6}/, '') + %#{leading}#{s} + foo + \\#{s} + \\\\\\#{s} + bar + #{s} + + + END + end + + %w({} <> [] ()).each do |pair| + puts <<-END.gsub(/^\s{6}/, '') + %#{leading}#{pair[0]} + foo + \\#{pair[1]} + \\\\\\#{pair[1]} + bar + #{pair[1]} + + + END + end + end +end +# }}} + + + puts "#\svim:foldmethod=syntax" diff --git a/etc/examples/syntax/percent/i.rb b/etc/examples/syntax/percent/i.rb new file mode 100644 index 00000000..2782f6ac --- /dev/null +++ b/etc/examples/syntax/percent/i.rb @@ -0,0 +1,435 @@ +# Generated by `./etc/examples/generators/syntax/percent_generator.rb %i > etc/examples/syntax/percent/i.rb` + + %i~ + foo + \~ + \\\~ + bar + ~ + + + %i` + foo + \` + \\\` + bar + ` + + + %i! + foo + \! + \\\! + bar + ! + + + %i@ + foo + \@ + \\\@ + bar + @ + + + %i# + foo + \# + \\\# + bar + # + + + %i$ + foo + \$ + \\\$ + bar + $ + + + %i% + foo + \% + \\\% + bar + % + + + %i^ + foo + \^ + \\\^ + bar + ^ + + + %i& + foo + \& + \\\& + bar + & + + + %i* + foo + \* + \\\* + bar + * + + + %i_ + foo + \_ + \\\_ + bar + _ + + + %i- + foo + \- + \\\- + bar + - + + + %i+ + foo + \+ + \\\+ + bar + + + + + %i= + foo + \= + \\\= + bar + = + + + %i| + foo + \| + \\\| + bar + | + + + %i: + foo + \: + \\\: + bar + : + + + %i; + foo + \; + \\\; + bar + ; + + + %i" + foo + \" + \\\" + bar + " + + + %i' + foo + \' + \\\' + bar + ' + + + %i, + foo + \, + \\\, + bar + , + + + %i. + foo + \. + \\\. + bar + . + + + %i? + foo + \? + \\\? + bar + ? + + + %i/ + foo + \/ + \\\/ + bar + / + + + %i{ + foo + \} + \\\} + bar + } + + + %i< + foo + \> + \\\> + bar + > + + + %i[ + foo + \] + \\\] + bar + ] + + + %i( + foo + \) + \\\) + bar + ) + + + %I~ + foo + \~ + \\\~ + bar + ~ + + + %I` + foo + \` + \\\` + bar + ` + + + %I! + foo + \! + \\\! + bar + ! + + + %I@ + foo + \@ + \\\@ + bar + @ + + + %I# + foo + \# + \\\# + bar + # + + + %I$ + foo + \$ + \\\$ + bar + $ + + + %I% + foo + \% + \\\% + bar + % + + + %I^ + foo + \^ + \\\^ + bar + ^ + + + %I& + foo + \& + \\\& + bar + & + + + %I* + foo + \* + \\\* + bar + * + + + %I_ + foo + \_ + \\\_ + bar + _ + + + %I- + foo + \- + \\\- + bar + - + + + %I+ + foo + \+ + \\\+ + bar + + + + + %I= + foo + \= + \\\= + bar + = + + + %I| + foo + \| + \\\| + bar + | + + + %I: + foo + \: + \\\: + bar + : + + + %I; + foo + \; + \\\; + bar + ; + + + %I" + foo + \" + \\\" + bar + " + + + %I' + foo + \' + \\\' + bar + ' + + + %I, + foo + \, + \\\, + bar + , + + + %I. + foo + \. + \\\. + bar + . + + + %I? + foo + \? + \\\? + bar + ? + + + %I/ + foo + \/ + \\\/ + bar + / + + + %I{ + foo + \} + \\\} + bar + } + + + %I< + foo + \> + \\\> + bar + > + + + %I[ + foo + \] + \\\] + bar + ] + + + %I( + foo + \) + \\\) + bar + ) + + +# vim:foldmethod=syntax diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 3b802900..98d8d388 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -215,19 +215,35 @@ else endif syn region rubyString matchgroup=rubyStringDelimiter start="%[Qx] " end=" " skip="\\\\\|\\)" contains=@rubyStringSpecial -" Array of Symbols -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i(" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape - -" Array of interpolated Symbols -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I{" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold -syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold +if s:foldable('%') + " Array of Symbols + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" fold + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i{" end="}" skip="\\\\\|\\}" fold contains=rubyNestedCurlyBraces,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i<" end=">" skip="\\\\\|\\>" fold contains=rubyNestedAngleBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\[" end="\]" skip="\\\\\|\\\]" fold contains=rubyNestedSquareBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i(" end=")" skip="\\\\\|\\)" fold contains=rubyNestedParentheses,rubyDelimEscape + + " Array of interpolated Symbols + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial fold + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I{" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape fold + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape fold + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape fold + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape fold +else + " Array of Symbols + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i{" end="}" skip="\\\\\|\\}" contains=rubyNestedCurlyBraces,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i<" end=">" skip="\\\\\|\\>" contains=rubyNestedAngleBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i\[" end="\]" skip="\\\\\|\\\]" contains=rubyNestedSquareBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%i(" end=")" skip="\\\\\|\\)" contains=rubyNestedParentheses,rubyDelimEscape + + " Array of interpolated Symbols + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\z([~`!@#$%^&*_\-+=|\:;"',.?/]\)" end="\z1" skip="\\\\\|\\\z1" contains=@rubyStringSpecial + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I{" end="}" skip="\\\\\|\\}" contains=@rubyStringSpecial,rubyNestedCurlyBraces,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I<" end=">" skip="\\\\\|\\>" contains=@rubyStringSpecial,rubyNestedAngleBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I\[" end="\]" skip="\\\\\|\\\]" contains=@rubyStringSpecial,rubyNestedSquareBrackets,rubyDelimEscape + syn region rubySymbol matchgroup=rubySymbolDelimiter start="%I(" end=")" skip="\\\\\|\\)" contains=@rubyStringSpecial,rubyNestedParentheses,rubyDelimEscape +endif " Here Document syn region rubyHeredocStart matchgroup=rubyStringDelimiter start=+\%(\%(class\s*\|\%([]})"'.]\|::\)\)\_s*\|\w\)\@ Date: Wed, 16 Sep 2015 21:54:00 +0800 Subject: [PATCH 11/27] Example file for verifying normal regex Aim to test this line: https://github.com/vim-ruby/vim-ruby/blob/8775819/syntax/ruby.vim#L124 Case of ternary operation (8c1c484) doesn't fold with below format: ```ruby / foo \/ \\\/ bar /s ``` so test `?` `:` separately. --- .../generators/syntax/percent_generator.rb | 53 + etc/examples/syntax/percent/regex.rb | 2133 +++++++++++++++++ 2 files changed, 2186 insertions(+) create mode 100644 etc/examples/syntax/percent/regex.rb diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index 2fc0000c..e22e6142 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -173,6 +173,59 @@ +# regex (Normal Regular Expression) {{{ +if arg == 'regexp' + 'iomxneus'.split('').unshift('').each do |option| + puts "\n# Begin test for option '#{option}' {{{\n\n" + + puts <<-END.gsub(/^\s{4}/, '') + / + foo + \\\/ + \\\\\\\/ + bar + /#{option} + + + END + + %w(and or while until unless if elsif when not then else).each do |s| + puts <<-END.gsub(/^\s{6}/, '') + #{s}/ + foo + \\\/ + \\\\\\\/ + bar + /#{option} + + + END + end + + %w(; \ ~ = ! | \( & , { [ < > ? : * + -).each do |s| + puts <<-END.gsub(/^\s{6}/, '') + #{s}/ + foo + \\\/ + \\\\\\\/ + bar + /#{option} + + + END + end + + puts "# }}} End test for option '#{option}'\n" + end + + puts "\n# Test for ternary operation (8c1c484) {{{\n\n" + puts 'yo = 4 ? /quack#{3}/ : /quack/' + puts "\n# }}} End test for ternary operation\n" +end +# }}} + + + puts "#\svim:foldmethod=syntax" diff --git a/etc/examples/syntax/percent/regex.rb b/etc/examples/syntax/percent/regex.rb new file mode 100644 index 00000000..4b80e5db --- /dev/null +++ b/etc/examples/syntax/percent/regex.rb @@ -0,0 +1,2133 @@ +# Generated by `./etc/examples/generators/syntax/percent_generator.rb regexp > etc/examples/syntax/percent/regexp.rb` + + +# Begin test for option '' {{{ + + / + foo + \/ + \\\/ + bar + / + + + and/ + foo + \/ + \\\/ + bar + / + + + or/ + foo + \/ + \\\/ + bar + / + + + while/ + foo + \/ + \\\/ + bar + / + + + until/ + foo + \/ + \\\/ + bar + / + + + unless/ + foo + \/ + \\\/ + bar + / + + + if/ + foo + \/ + \\\/ + bar + / + + + elsif/ + foo + \/ + \\\/ + bar + / + + + when/ + foo + \/ + \\\/ + bar + / + + + not/ + foo + \/ + \\\/ + bar + / + + + then/ + foo + \/ + \\\/ + bar + / + + + else/ + foo + \/ + \\\/ + bar + / + + + ;/ + foo + \/ + \\\/ + bar + / + + + ~/ + foo + \/ + \\\/ + bar + / + + + =/ + foo + \/ + \\\/ + bar + / + + + !/ + foo + \/ + \\\/ + bar + / + + + |/ + foo + \/ + \\\/ + bar + / + + + (/ + foo + \/ + \\\/ + bar + / + + + &/ + foo + \/ + \\\/ + bar + / + + + ,/ + foo + \/ + \\\/ + bar + / + + + {/ + foo + \/ + \\\/ + bar + / + + + [/ + foo + \/ + \\\/ + bar + / + + + / + foo + \/ + \\\/ + bar + / + + + ?/ + foo + \/ + \\\/ + bar + / + + + :/ + foo + \/ + \\\/ + bar + / + + + */ + foo + \/ + \\\/ + bar + / + + + +/ + foo + \/ + \\\/ + bar + / + + + -/ + foo + \/ + \\\/ + bar + / + + +# }}} End test for option '' + +# Begin test for option 'i' {{{ + + / + foo + \/ + \\\/ + bar + /i + + + and/ + foo + \/ + \\\/ + bar + /i + + + or/ + foo + \/ + \\\/ + bar + /i + + + while/ + foo + \/ + \\\/ + bar + /i + + + until/ + foo + \/ + \\\/ + bar + /i + + + unless/ + foo + \/ + \\\/ + bar + /i + + + if/ + foo + \/ + \\\/ + bar + /i + + + elsif/ + foo + \/ + \\\/ + bar + /i + + + when/ + foo + \/ + \\\/ + bar + /i + + + not/ + foo + \/ + \\\/ + bar + /i + + + then/ + foo + \/ + \\\/ + bar + /i + + + else/ + foo + \/ + \\\/ + bar + /i + + + ;/ + foo + \/ + \\\/ + bar + /i + + + ~/ + foo + \/ + \\\/ + bar + /i + + + =/ + foo + \/ + \\\/ + bar + /i + + + !/ + foo + \/ + \\\/ + bar + /i + + + |/ + foo + \/ + \\\/ + bar + /i + + + (/ + foo + \/ + \\\/ + bar + /i + + + &/ + foo + \/ + \\\/ + bar + /i + + + ,/ + foo + \/ + \\\/ + bar + /i + + + {/ + foo + \/ + \\\/ + bar + /i + + + [/ + foo + \/ + \\\/ + bar + /i + + + / + foo + \/ + \\\/ + bar + /i + + + ?/ + foo + \/ + \\\/ + bar + /i + + + :/ + foo + \/ + \\\/ + bar + /i + + + */ + foo + \/ + \\\/ + bar + /i + + + +/ + foo + \/ + \\\/ + bar + /i + + + -/ + foo + \/ + \\\/ + bar + /i + + +# }}} End test for option 'i' + +# Begin test for option 'o' {{{ + + / + foo + \/ + \\\/ + bar + /o + + + and/ + foo + \/ + \\\/ + bar + /o + + + or/ + foo + \/ + \\\/ + bar + /o + + + while/ + foo + \/ + \\\/ + bar + /o + + + until/ + foo + \/ + \\\/ + bar + /o + + + unless/ + foo + \/ + \\\/ + bar + /o + + + if/ + foo + \/ + \\\/ + bar + /o + + + elsif/ + foo + \/ + \\\/ + bar + /o + + + when/ + foo + \/ + \\\/ + bar + /o + + + not/ + foo + \/ + \\\/ + bar + /o + + + then/ + foo + \/ + \\\/ + bar + /o + + + else/ + foo + \/ + \\\/ + bar + /o + + + ;/ + foo + \/ + \\\/ + bar + /o + + + ~/ + foo + \/ + \\\/ + bar + /o + + + =/ + foo + \/ + \\\/ + bar + /o + + + !/ + foo + \/ + \\\/ + bar + /o + + + |/ + foo + \/ + \\\/ + bar + /o + + + (/ + foo + \/ + \\\/ + bar + /o + + + &/ + foo + \/ + \\\/ + bar + /o + + + ,/ + foo + \/ + \\\/ + bar + /o + + + {/ + foo + \/ + \\\/ + bar + /o + + + [/ + foo + \/ + \\\/ + bar + /o + + + / + foo + \/ + \\\/ + bar + /o + + + ?/ + foo + \/ + \\\/ + bar + /o + + + :/ + foo + \/ + \\\/ + bar + /o + + + */ + foo + \/ + \\\/ + bar + /o + + + +/ + foo + \/ + \\\/ + bar + /o + + + -/ + foo + \/ + \\\/ + bar + /o + + +# }}} End test for option 'o' + +# Begin test for option 'm' {{{ + + / + foo + \/ + \\\/ + bar + /m + + + and/ + foo + \/ + \\\/ + bar + /m + + + or/ + foo + \/ + \\\/ + bar + /m + + + while/ + foo + \/ + \\\/ + bar + /m + + + until/ + foo + \/ + \\\/ + bar + /m + + + unless/ + foo + \/ + \\\/ + bar + /m + + + if/ + foo + \/ + \\\/ + bar + /m + + + elsif/ + foo + \/ + \\\/ + bar + /m + + + when/ + foo + \/ + \\\/ + bar + /m + + + not/ + foo + \/ + \\\/ + bar + /m + + + then/ + foo + \/ + \\\/ + bar + /m + + + else/ + foo + \/ + \\\/ + bar + /m + + + ;/ + foo + \/ + \\\/ + bar + /m + + + ~/ + foo + \/ + \\\/ + bar + /m + + + =/ + foo + \/ + \\\/ + bar + /m + + + !/ + foo + \/ + \\\/ + bar + /m + + + |/ + foo + \/ + \\\/ + bar + /m + + + (/ + foo + \/ + \\\/ + bar + /m + + + &/ + foo + \/ + \\\/ + bar + /m + + + ,/ + foo + \/ + \\\/ + bar + /m + + + {/ + foo + \/ + \\\/ + bar + /m + + + [/ + foo + \/ + \\\/ + bar + /m + + + / + foo + \/ + \\\/ + bar + /m + + + ?/ + foo + \/ + \\\/ + bar + /m + + + :/ + foo + \/ + \\\/ + bar + /m + + + */ + foo + \/ + \\\/ + bar + /m + + + +/ + foo + \/ + \\\/ + bar + /m + + + -/ + foo + \/ + \\\/ + bar + /m + + +# }}} End test for option 'm' + +# Begin test for option 'x' {{{ + + / + foo + \/ + \\\/ + bar + /x + + + and/ + foo + \/ + \\\/ + bar + /x + + + or/ + foo + \/ + \\\/ + bar + /x + + + while/ + foo + \/ + \\\/ + bar + /x + + + until/ + foo + \/ + \\\/ + bar + /x + + + unless/ + foo + \/ + \\\/ + bar + /x + + + if/ + foo + \/ + \\\/ + bar + /x + + + elsif/ + foo + \/ + \\\/ + bar + /x + + + when/ + foo + \/ + \\\/ + bar + /x + + + not/ + foo + \/ + \\\/ + bar + /x + + + then/ + foo + \/ + \\\/ + bar + /x + + + else/ + foo + \/ + \\\/ + bar + /x + + + ;/ + foo + \/ + \\\/ + bar + /x + + + ~/ + foo + \/ + \\\/ + bar + /x + + + =/ + foo + \/ + \\\/ + bar + /x + + + !/ + foo + \/ + \\\/ + bar + /x + + + |/ + foo + \/ + \\\/ + bar + /x + + + (/ + foo + \/ + \\\/ + bar + /x + + + &/ + foo + \/ + \\\/ + bar + /x + + + ,/ + foo + \/ + \\\/ + bar + /x + + + {/ + foo + \/ + \\\/ + bar + /x + + + [/ + foo + \/ + \\\/ + bar + /x + + + / + foo + \/ + \\\/ + bar + /x + + + ?/ + foo + \/ + \\\/ + bar + /x + + + :/ + foo + \/ + \\\/ + bar + /x + + + */ + foo + \/ + \\\/ + bar + /x + + + +/ + foo + \/ + \\\/ + bar + /x + + + -/ + foo + \/ + \\\/ + bar + /x + + +# }}} End test for option 'x' + +# Begin test for option 'n' {{{ + + / + foo + \/ + \\\/ + bar + /n + + + and/ + foo + \/ + \\\/ + bar + /n + + + or/ + foo + \/ + \\\/ + bar + /n + + + while/ + foo + \/ + \\\/ + bar + /n + + + until/ + foo + \/ + \\\/ + bar + /n + + + unless/ + foo + \/ + \\\/ + bar + /n + + + if/ + foo + \/ + \\\/ + bar + /n + + + elsif/ + foo + \/ + \\\/ + bar + /n + + + when/ + foo + \/ + \\\/ + bar + /n + + + not/ + foo + \/ + \\\/ + bar + /n + + + then/ + foo + \/ + \\\/ + bar + /n + + + else/ + foo + \/ + \\\/ + bar + /n + + + ;/ + foo + \/ + \\\/ + bar + /n + + + ~/ + foo + \/ + \\\/ + bar + /n + + + =/ + foo + \/ + \\\/ + bar + /n + + + !/ + foo + \/ + \\\/ + bar + /n + + + |/ + foo + \/ + \\\/ + bar + /n + + + (/ + foo + \/ + \\\/ + bar + /n + + + &/ + foo + \/ + \\\/ + bar + /n + + + ,/ + foo + \/ + \\\/ + bar + /n + + + {/ + foo + \/ + \\\/ + bar + /n + + + [/ + foo + \/ + \\\/ + bar + /n + + + / + foo + \/ + \\\/ + bar + /n + + + ?/ + foo + \/ + \\\/ + bar + /n + + + :/ + foo + \/ + \\\/ + bar + /n + + + */ + foo + \/ + \\\/ + bar + /n + + + +/ + foo + \/ + \\\/ + bar + /n + + + -/ + foo + \/ + \\\/ + bar + /n + + +# }}} End test for option 'n' + +# Begin test for option 'e' {{{ + + / + foo + \/ + \\\/ + bar + /e + + + and/ + foo + \/ + \\\/ + bar + /e + + + or/ + foo + \/ + \\\/ + bar + /e + + + while/ + foo + \/ + \\\/ + bar + /e + + + until/ + foo + \/ + \\\/ + bar + /e + + + unless/ + foo + \/ + \\\/ + bar + /e + + + if/ + foo + \/ + \\\/ + bar + /e + + + elsif/ + foo + \/ + \\\/ + bar + /e + + + when/ + foo + \/ + \\\/ + bar + /e + + + not/ + foo + \/ + \\\/ + bar + /e + + + then/ + foo + \/ + \\\/ + bar + /e + + + else/ + foo + \/ + \\\/ + bar + /e + + + ;/ + foo + \/ + \\\/ + bar + /e + + + ~/ + foo + \/ + \\\/ + bar + /e + + + =/ + foo + \/ + \\\/ + bar + /e + + + !/ + foo + \/ + \\\/ + bar + /e + + + |/ + foo + \/ + \\\/ + bar + /e + + + (/ + foo + \/ + \\\/ + bar + /e + + + &/ + foo + \/ + \\\/ + bar + /e + + + ,/ + foo + \/ + \\\/ + bar + /e + + + {/ + foo + \/ + \\\/ + bar + /e + + + [/ + foo + \/ + \\\/ + bar + /e + + + / + foo + \/ + \\\/ + bar + /e + + + ?/ + foo + \/ + \\\/ + bar + /e + + + :/ + foo + \/ + \\\/ + bar + /e + + + */ + foo + \/ + \\\/ + bar + /e + + + +/ + foo + \/ + \\\/ + bar + /e + + + -/ + foo + \/ + \\\/ + bar + /e + + +# }}} End test for option 'e' + +# Begin test for option 'u' {{{ + + / + foo + \/ + \\\/ + bar + /u + + + and/ + foo + \/ + \\\/ + bar + /u + + + or/ + foo + \/ + \\\/ + bar + /u + + + while/ + foo + \/ + \\\/ + bar + /u + + + until/ + foo + \/ + \\\/ + bar + /u + + + unless/ + foo + \/ + \\\/ + bar + /u + + + if/ + foo + \/ + \\\/ + bar + /u + + + elsif/ + foo + \/ + \\\/ + bar + /u + + + when/ + foo + \/ + \\\/ + bar + /u + + + not/ + foo + \/ + \\\/ + bar + /u + + + then/ + foo + \/ + \\\/ + bar + /u + + + else/ + foo + \/ + \\\/ + bar + /u + + + ;/ + foo + \/ + \\\/ + bar + /u + + + ~/ + foo + \/ + \\\/ + bar + /u + + + =/ + foo + \/ + \\\/ + bar + /u + + + !/ + foo + \/ + \\\/ + bar + /u + + + |/ + foo + \/ + \\\/ + bar + /u + + + (/ + foo + \/ + \\\/ + bar + /u + + + &/ + foo + \/ + \\\/ + bar + /u + + + ,/ + foo + \/ + \\\/ + bar + /u + + + {/ + foo + \/ + \\\/ + bar + /u + + + [/ + foo + \/ + \\\/ + bar + /u + + + / + foo + \/ + \\\/ + bar + /u + + + ?/ + foo + \/ + \\\/ + bar + /u + + + :/ + foo + \/ + \\\/ + bar + /u + + + */ + foo + \/ + \\\/ + bar + /u + + + +/ + foo + \/ + \\\/ + bar + /u + + + -/ + foo + \/ + \\\/ + bar + /u + + +# }}} End test for option 'u' + +# Begin test for option 's' {{{ + + / + foo + \/ + \\\/ + bar + /s + + + and/ + foo + \/ + \\\/ + bar + /s + + + or/ + foo + \/ + \\\/ + bar + /s + + + while/ + foo + \/ + \\\/ + bar + /s + + + until/ + foo + \/ + \\\/ + bar + /s + + + unless/ + foo + \/ + \\\/ + bar + /s + + + if/ + foo + \/ + \\\/ + bar + /s + + + elsif/ + foo + \/ + \\\/ + bar + /s + + + when/ + foo + \/ + \\\/ + bar + /s + + + not/ + foo + \/ + \\\/ + bar + /s + + + then/ + foo + \/ + \\\/ + bar + /s + + + else/ + foo + \/ + \\\/ + bar + /s + + + ;/ + foo + \/ + \\\/ + bar + /s + + + ~/ + foo + \/ + \\\/ + bar + /s + + + =/ + foo + \/ + \\\/ + bar + /s + + + !/ + foo + \/ + \\\/ + bar + /s + + + |/ + foo + \/ + \\\/ + bar + /s + + + (/ + foo + \/ + \\\/ + bar + /s + + + &/ + foo + \/ + \\\/ + bar + /s + + + ,/ + foo + \/ + \\\/ + bar + /s + + + {/ + foo + \/ + \\\/ + bar + /s + + + [/ + foo + \/ + \\\/ + bar + /s + + + / + foo + \/ + \\\/ + bar + /s + + + ?/ + foo + \/ + \\\/ + bar + /s + + + :/ + foo + \/ + \\\/ + bar + /s + + + */ + foo + \/ + \\\/ + bar + /s + + + +/ + foo + \/ + \\\/ + bar + /s + + + -/ + foo + \/ + \\\/ + bar + /s + + +# }}} End test for option 's' + +# Test for ternary operation (8c1c484) {{{ + +yo = 4 ? /quack#{3}/ : /quack/ + +# }}} End test for ternary operation +# vim:foldmethod=syntax From f23b02c632dd9c58b684536b0f3bcee20eb44eb2 Mon Sep 17 00:00:00 2001 From: bootleq Date: Sat, 19 Sep 2015 20:56:30 +0800 Subject: [PATCH 12/27] Another part of normal regex example Aim to test this line: https://github.com/vim-ruby/vim-ruby/blob/8775819/syntax/ruby.vim#L125 Not sure the purpose, just write case to reproduce the regex. --- .../generators/syntax/percent_generator.rb | 13 + etc/examples/syntax/percent/regex.rb | 288 ++++++++++++++++++ 2 files changed, 301 insertions(+) diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index e22e6142..36cd3aba 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -215,6 +215,19 @@ END end + [' ', "\t", '=', 'OK'].each do |s| + puts <<-END.gsub(/^\s{6}/, '') + _foo /#{s} + foo + \\\/ + \\\\\\\/ + bar + /#{option} + + + END + end + puts "# }}} End test for option '#{option}'\n" end diff --git a/etc/examples/syntax/percent/regex.rb b/etc/examples/syntax/percent/regex.rb index 4b80e5db..1f48fa24 100644 --- a/etc/examples/syntax/percent/regex.rb +++ b/etc/examples/syntax/percent/regex.rb @@ -235,6 +235,38 @@ / + _foo / + foo + \/ + \\\/ + bar + / + + + _foo / + foo + \/ + \\\/ + bar + / + + + _foo /= + foo + \/ + \\\/ + bar + / + + + _foo /OK + foo + \/ + \\\/ + bar + / + + # }}} End test for option '' # Begin test for option 'i' {{{ @@ -471,6 +503,38 @@ /i + _foo / + foo + \/ + \\\/ + bar + /i + + + _foo / + foo + \/ + \\\/ + bar + /i + + + _foo /= + foo + \/ + \\\/ + bar + /i + + + _foo /OK + foo + \/ + \\\/ + bar + /i + + # }}} End test for option 'i' # Begin test for option 'o' {{{ @@ -707,6 +771,38 @@ /o + _foo / + foo + \/ + \\\/ + bar + /o + + + _foo / + foo + \/ + \\\/ + bar + /o + + + _foo /= + foo + \/ + \\\/ + bar + /o + + + _foo /OK + foo + \/ + \\\/ + bar + /o + + # }}} End test for option 'o' # Begin test for option 'm' {{{ @@ -943,6 +1039,38 @@ /m + _foo / + foo + \/ + \\\/ + bar + /m + + + _foo / + foo + \/ + \\\/ + bar + /m + + + _foo /= + foo + \/ + \\\/ + bar + /m + + + _foo /OK + foo + \/ + \\\/ + bar + /m + + # }}} End test for option 'm' # Begin test for option 'x' {{{ @@ -1179,6 +1307,38 @@ /x + _foo / + foo + \/ + \\\/ + bar + /x + + + _foo / + foo + \/ + \\\/ + bar + /x + + + _foo /= + foo + \/ + \\\/ + bar + /x + + + _foo /OK + foo + \/ + \\\/ + bar + /x + + # }}} End test for option 'x' # Begin test for option 'n' {{{ @@ -1415,6 +1575,38 @@ /n + _foo / + foo + \/ + \\\/ + bar + /n + + + _foo / + foo + \/ + \\\/ + bar + /n + + + _foo /= + foo + \/ + \\\/ + bar + /n + + + _foo /OK + foo + \/ + \\\/ + bar + /n + + # }}} End test for option 'n' # Begin test for option 'e' {{{ @@ -1651,6 +1843,38 @@ /e + _foo / + foo + \/ + \\\/ + bar + /e + + + _foo / + foo + \/ + \\\/ + bar + /e + + + _foo /= + foo + \/ + \\\/ + bar + /e + + + _foo /OK + foo + \/ + \\\/ + bar + /e + + # }}} End test for option 'e' # Begin test for option 'u' {{{ @@ -1887,6 +2111,38 @@ /u + _foo / + foo + \/ + \\\/ + bar + /u + + + _foo / + foo + \/ + \\\/ + bar + /u + + + _foo /= + foo + \/ + \\\/ + bar + /u + + + _foo /OK + foo + \/ + \\\/ + bar + /u + + # }}} End test for option 'u' # Begin test for option 's' {{{ @@ -2123,6 +2379,38 @@ /s + _foo / + foo + \/ + \\\/ + bar + /s + + + _foo / + foo + \/ + \\\/ + bar + /s + + + _foo /= + foo + \/ + \\\/ + bar + /s + + + _foo /OK + foo + \/ + \\\/ + bar + /s + + # }}} End test for option 's' # Test for ternary operation (8c1c484) {{{ From c12d0ffbbc6ac1f6a81e89d76e41d7f583a56bfd Mon Sep 17 00:00:00 2001 From: bootleq Date: Sat, 19 Sep 2015 18:02:12 +0800 Subject: [PATCH 13/27] Add `/` foldable_groups option for normal regexp --- doc/ft-ruby-syntax.txt | 1 + syntax/ruby.vim | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index 7d1e279b..43eeaac5 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -59,6 +59,7 @@ value is space-separated keywords, known keywords were: case "case" block do "do" block % Literal with "%" notation, e.g.: %w(STRING), %!STRING! + / Regexp 5. Reducing expensive operations *ruby_no_expensive* diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 98d8d388..78b8e320 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -142,8 +142,13 @@ syn match rubyPredefinedConstant "\%(\%(^\|[^.]\)\.\s*\)\@\%(\s*(\)\@!" " Normal Regular Expression -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,{[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold -syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold +if s:foldable('/') + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,{[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial fold +else + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,{[<>?:*+-]\)\s*\)\@<=/" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial + syn region rubyRegexp matchgroup=rubyRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/[iomxneus]*" skip="\\\\\|\\/" contains=@rubyRegexpSpecial +endif " Generalized Regular Expression if s:foldable('%') From 040768742ffcf5058fc27cec209915050dd664d7 Mon Sep 17 00:00:00 2001 From: bootleq Date: Sun, 20 Sep 2015 15:29:32 +0800 Subject: [PATCH 14/27] Add `string` foldable_groups option For multiline 'string' "string" and `shell command`. --- doc/ft-ruby-syntax.txt | 1 + .../generators/syntax/percent_generator.rb | 20 ++++++++++++++ etc/examples/syntax/percent/string.rb | 27 +++++++++++++++++++ syntax/ruby.vim | 23 +++++++++++----- 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 etc/examples/syntax/percent/string.rb diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index 43eeaac5..0fcb219f 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -60,6 +60,7 @@ value is space-separated keywords, known keywords were: do "do" block % Literal with "%" notation, e.g.: %w(STRING), %!STRING! / Regexp + string String and shell command output (surrounded by ', ", `) 5. Reducing expensive operations *ruby_no_expensive* diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index 36cd3aba..050f3c96 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -173,6 +173,26 @@ +# string {{{ +# Normal String and Shell Command Output +if arg == 'string' + %w(' " `).each do |quote| + puts <<-END.gsub(/^\s{4}/, '') + #{quote} + foo + \\#{quote} + \\\\\\#{quote} + bar + #{quote} + + + END + end +end +# }}} + + + # regex (Normal Regular Expression) {{{ if arg == 'regexp' 'iomxneus'.split('').unshift('').each do |option| diff --git a/etc/examples/syntax/percent/string.rb b/etc/examples/syntax/percent/string.rb new file mode 100644 index 00000000..778f9e45 --- /dev/null +++ b/etc/examples/syntax/percent/string.rb @@ -0,0 +1,27 @@ +# Generated by `./etc/examples/generators/syntax/percent_generator.rb string > etc/examples/syntax/percent/string.rb` + + ' + foo + \' + \\\' + bar + ' + + + " + foo + \" + \\\" + bar + " + + + ` + foo + \` + \\\` + bar + ` + + +# vim:foldmethod=syntax diff --git a/syntax/ruby.vim b/syntax/ruby.vim index 78b8e320..bba2ed52 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -166,14 +166,25 @@ else endif " Normal String and Shell Command Output -if exists('ruby_spellcheck_strings') - syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial,@Spell fold - syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\\\\|\\'" contains=rubyQuoteEscape,@Spell fold +if s:foldable('%') + if exists('ruby_spellcheck_strings') + syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial,@Spell fold + syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\\\\|\\'" contains=rubyQuoteEscape,@Spell fold + else + syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial fold + syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\\\\|\\'" contains=rubyQuoteEscape fold + endif + syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial fold else - syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial fold - syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\\\\|\\'" contains=rubyQuoteEscape fold + if exists('ruby_spellcheck_strings') + syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial,@Spell + syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\\\\|\\'" contains=rubyQuoteEscape,@Spell + else + syn region rubyString matchgroup=rubyStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@rubyStringSpecial + syn region rubyString matchgroup=rubyStringDelimiter start="'" end="'" skip="\\\\\|\\'" contains=rubyQuoteEscape + endif + syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial endif -syn region rubyString matchgroup=rubyStringDelimiter start="`" end="`" skip="\\\\\|\\`" contains=@rubyStringSpecial fold " Generalized Single Quoted String, Symbol and Array of Strings if s:foldable('%') From 1930020fb9e9ccc58de66ad31c4bbbc85748560c Mon Sep 17 00:00:00 2001 From: bootleq Date: Sun, 20 Sep 2015 16:42:09 +0800 Subject: [PATCH 15/27] Add `:` foldable_groups option for symbol region --- doc/ft-ruby-syntax.txt | 1 + .../generators/syntax/percent_generator.rb | 23 ++++ etc/examples/syntax/percent/symbol.rb | 129 ++++++++++++++++++ syntax/ruby.vim | 10 +- 4 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 etc/examples/syntax/percent/symbol.rb diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index 0fcb219f..57418020 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -61,6 +61,7 @@ value is space-separated keywords, known keywords were: % Literal with "%" notation, e.g.: %w(STRING), %!STRING! / Regexp string String and shell command output (surrounded by ', ", `) + : Symbol 5. Reducing expensive operations *ruby_no_expensive* diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index 050f3c96..ef16767d 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -259,6 +259,29 @@ +# symbol {{{ +# Symbol region +if arg == 'symbol' + %w(' ").each do |quote| + %Q_]})\"':_.split(//).unshift('').each do |s| + puts <<-END.gsub(/^\s{6}/, '') + #{s}:#{quote} + foo + \\#{quote} + \\\\\\#{quote} + bar + #{quote} + #{" #{s} # close string to ensure next case clean" if %w(' ").include?(s) && s != quote } + + + END + end + end +end +# }}} + + + puts "#\svim:foldmethod=syntax" diff --git a/etc/examples/syntax/percent/symbol.rb b/etc/examples/syntax/percent/symbol.rb new file mode 100644 index 00000000..8d8ec607 --- /dev/null +++ b/etc/examples/syntax/percent/symbol.rb @@ -0,0 +1,129 @@ +# Generated by `./etc/examples/generators/syntax/percent_generator.rb symbol > etc/examples/syntax/percent/symbol.rb` + + :' + foo + \' + \\\' + bar + ' + + + + ]:' + foo + \' + \\\' + bar + ' + + + + }:' + foo + \' + \\\' + bar + ' + + + + ):' + foo + \' + \\\' + bar + ' + + + + ":' + foo + \' + \\\' + bar + ' + " # close string to ensure next case clean + + + ':' + foo + \' + \\\' + bar + ' + + + + ::' + foo + \' + \\\' + bar + ' + + + + :" + foo + \" + \\\" + bar + " + + + + ]:" + foo + \" + \\\" + bar + " + + + + }:" + foo + \" + \\\" + bar + " + + + + ):" + foo + \" + \\\" + bar + " + + + + ":" + foo + \" + \\\" + bar + " + + + + ':" + foo + \" + \\\" + bar + " + ' # close string to ensure next case clean + + + ::" + foo + \" + \\\" + bar + " + + + +# vim:foldmethod=syntax diff --git a/syntax/ruby.vim b/syntax/ruby.vim index bba2ed52..caf1ee72 100644 --- a/syntax/ruby.vim +++ b/syntax/ruby.vim @@ -123,8 +123,14 @@ syn match rubySymbol "[]})\"':]\@\|<=\|<\|===\|[=!]=\|[=! syn match rubySymbol "[]})\"':]\@_,;:!?/.'"@$*\&+0]\)" syn match rubySymbol "[]})\"':]\@\@!\)\=" -syn region rubySymbol start="[]})\"':]\@\%(\s*(\)*\s*(\@=" From 3d30d881afd38d384178387788de2aaa6d9e29a9 Mon Sep 17 00:00:00 2001 From: bootleq Date: Tue, 22 Sep 2015 17:28:36 +0800 Subject: [PATCH 16/27] Add `<<` foldable_groups option for here document It's hard to enumerate every case, so just separate to valid/invalid section, see example file for detail. --- doc/ft-ruby-syntax.txt | 1 + .../generators/syntax/percent_generator.rb | 81 ++++++++++ etc/examples/syntax/percent/heredoc.rb | 150 ++++++++++++++++++ syntax/ruby.vim | 30 ++-- 4 files changed, 253 insertions(+), 9 deletions(-) create mode 100644 etc/examples/syntax/percent/heredoc.rb diff --git a/doc/ft-ruby-syntax.txt b/doc/ft-ruby-syntax.txt index 57418020..4ee73bb9 100644 --- a/doc/ft-ruby-syntax.txt +++ b/doc/ft-ruby-syntax.txt @@ -62,6 +62,7 @@ value is space-separated keywords, known keywords were: / Regexp string String and shell command output (surrounded by ', ", `) : Symbol + << Here documents 5. Reducing expensive operations *ruby_no_expensive* diff --git a/etc/examples/generators/syntax/percent_generator.rb b/etc/examples/generators/syntax/percent_generator.rb index ef16767d..3692abe4 100755 --- a/etc/examples/generators/syntax/percent_generator.rb +++ b/etc/examples/generators/syntax/percent_generator.rb @@ -282,6 +282,87 @@ +# heredoc {{{ +# Here Documents +if arg == 'heredoc' + puts "\n# Begin of valid cases {{{\n\n" + + %w(' " `).unshift('').each do |quote| + puts <<-END.gsub(/^\s{6}/, '') + <<#{quote}_LABEL#{quote}.?!, foo + bar baz + _LABEL + \n + + <<-#{quote}_LABEL#{quote}.?!, foo + bar baz + _LABEL + + + END + end + + puts "# }}} End of valid cases'\n\n" + + + puts "\n# Begin of INVALID cases {{{\n\n" + + # NOTE: for simplification, omit test for different quotes " ' `, + # they are all invalid anyway + + %w(class ::).each do |s| + puts <<-END.gsub(/^\s{6}/, '') + #{s}\n <