Class: Regexp::Syntax::Base
- Inherits:
-
Object
- Object
- Regexp::Syntax::Base
- Defined in:
- lib/regexp_parser/syntax.rb
Overview
A lookup map of supported types and tokens in a given syntax
Direct Known Subclasses
Instance Method Summary collapse
-
#excludes(type, tokens) ⇒ Object
removes.
- #implementation ⇒ Object
- #implements(type, tokens) ⇒ Object
- #implements!(type, token) ⇒ Object (also: #check!)
- #implements?(type, token) ⇒ Boolean (also: #check?)
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #normalize(type, token) ⇒ Object
- #normalize_backref(type, token) ⇒ Object
- #normalize_group(type, token) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
87 88 89 90 91 |
# File 'lib/regexp_parser/syntax.rb', line 87 def initialize @implements = {} implements :literal, [:literal] end |
Instance Method Details
#excludes(type, tokens) ⇒ Object
removes
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/regexp_parser/syntax.rb', line 106 def excludes(type, tokens) if tokens tokens = [tokens] unless tokens.is_a?(Array) end if @implements[type] if tokens @implements[type] = @implements[type] - tokens @implements[type] = nil if @implements[type].empty? else @implements[type] = nil end end end |
#implementation ⇒ Object
93 94 95 |
# File 'lib/regexp_parser/syntax.rb', line 93 def implementation @implements end |
#implements(type, tokens) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/regexp_parser/syntax.rb', line 97 def implements(type, tokens) if @implements[type] @implements[type] = (@implements[type] + tokens).uniq else @implements[type] = tokens end end |
#implements!(type, token) ⇒ Object Also known as: check!
127 128 129 130 |
# File 'lib/regexp_parser/syntax.rb', line 127 def implements!(type, token) raise NotImplementedError.new(self, type, token) unless implements?(type, token) end |
#implements?(type, token) ⇒ Boolean Also known as: check?
121 122 123 124 |
# File 'lib/regexp_parser/syntax.rb', line 121 def implements?(type, token) return true if @implements[type] and @implements[type].include?(token) false end |
#normalize(type, token) ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/regexp_parser/syntax.rb', line 133 def normalize(type, token) case type when :group normalize_group(type, token) when :backref normalize_backref(type, token) else [type, token] end end |
#normalize_backref(type, token) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/regexp_parser/syntax.rb', line 153 def normalize_backref(type, token) case token when :name_ref_ab, :name_ref_sq [:backref, :name_ref] when :name_call_ab, :name_call_sq [:backref, :name_call] when :name_nest_ref_ab, :name_nest_ref_sq [:backref, :name_nest_ref] when :number_ref_ab, :number_ref_sq [:backref, :number_ref] when :number_call_ab, :number_call_sq [:backref, :number_call] when :number_rel_ref_ab, :number_rel_ref_sq [:backref, :number_rel_ref] when :number_rel_call_ab, :number_rel_call_sq [:backref, :number_rel_call] when :number_nest_ref_ab, :number_nest_ref_sq [:backref, :number_nest_ref] else [type, token] end end |
#normalize_group(type, token) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/regexp_parser/syntax.rb', line 144 def normalize_group(type, token) case token when :named_ab, :named_sq [:group, :named] else [type, token] end end |