Class: FixRepeatedTagAs
- Inherits:
-
GrammarTransform
- Object
- GrammarPlugin
- GrammarTransform
- FixRepeatedTagAs
- Defined in:
- lib/ruby_grammar_builder/transforms/fix_repeated_tag_as.rb
Overview
tag_as: inside a quantifier does not work as expected, this fixes it
Class Method Summary collapse
-
.display_options(indent, options) ⇒ String
Displays the state of the options.
-
.options ⇒ Array<Symbol>
Contributes the option :preserve_references?.
Instance Method Summary collapse
-
#pre_transform(pattern, options) ⇒ Object
fixes tag_as when it is inside a quantifier see github.com/jeff-hykin/cpp-textmate-grammar/issues/339#issuecomment-543285390 for an explanation of why and how.
-
#tag_as?(pattern) ⇒ Boolean
Does pattern or any of its children / siblings have a tag_as.
Methods inherited from GrammarTransform
Class Method Details
.display_options(indent, options) ⇒ String
Displays the state of the options
70 71 72 |
# File 'lib/ruby_grammar_builder/transforms/fix_repeated_tag_as.rb', line 70 def self.(indent, ) ",\n#{indent}preserve_references?: #{[:preserve_references?]}" end |
.options ⇒ Array<Symbol>
Contributes the option :preserve_references?
:preserve_references? disables the scrambling of references
61 62 63 |
# File 'lib/ruby_grammar_builder/transforms/fix_repeated_tag_as.rb', line 61 def self. [:preserve_references?] end |
Instance Method Details
#pre_transform(pattern, options) ⇒ Object
fixes tag_as when it is inside a quantifier see github.com/jeff-hykin/cpp-textmate-grammar/issues/339#issuecomment-543285390 for an explanation of why and how
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby_grammar_builder/transforms/fix_repeated_tag_as.rb', line 29 def pre_transform(pattern, ) return pattern.map { |v| pre_transform(v, ) } if pattern.is_a? Array return pattern unless pattern.is_a? PatternBase return pattern if pattern.is_a? PatternRange pattern.map do |pat| next pat unless pat.respond_to? :self_capture_group_rematch next pat unless pat.self_capture_group_rematch next pat unless tag_as?(pat.match) unless pat.arguments[:includes].nil? || pat.arguments[:includes].empty? raise "Cannot transform a Repeated pattern that has non empty includes" end pat.arguments[:includes] = [pat.match.__deep_clone__] pat.match.map! do |pm| pm.arguments.delete(:tag_as) pm.arguments.delete(:includes) next unless [:preserve_references?] || pm.arguments[:preserve_references?] pm.self_scramble_references end end end |
#tag_as?(pattern) ⇒ Boolean
Does pattern or any of its children / siblings have a tag_as
14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby_grammar_builder/transforms/fix_repeated_tag_as.rb', line 14 def tag_as?(pattern) return false unless pattern.is_a? PatternBase pattern.each do |s| return true if s.arguments[:tag_as] end false end |