Class: Regexgen::Ast::Literal
- Inherits:
-
Object
- Object
- Regexgen::Ast::Literal
- Defined in:
- lib/regexgen/ast.rb
Overview
Represents a literal (e.g. a string)
Instance Attribute Summary collapse
-
#precedence ⇒ Object
readonly
Returns the value of attribute precedence.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #char_class ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(value) ⇒ Literal
constructor
A new instance of Literal.
- #length ⇒ Object
- #literal(_side = nil) ⇒ Object
- #remove_substring(side, len) ⇒ Object
- #single_character? ⇒ Boolean
- #single_codepoint? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ Literal
Returns a new instance of Literal.
147 148 149 150 |
# File 'lib/regexgen/ast.rb', line 147 def initialize(value) @precedence = 2 @value = value end |
Instance Attribute Details
#precedence ⇒ Object (readonly)
Returns the value of attribute precedence.
145 146 147 |
# File 'lib/regexgen/ast.rb', line 145 def precedence @precedence end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
145 146 147 |
# File 'lib/regexgen/ast.rb', line 145 def value @value end |
Instance Method Details
#char_class ⇒ Object
172 173 174 |
# File 'lib/regexgen/ast.rb', line 172 def char_class @value if single_codepoint? end |
#empty? ⇒ Boolean
152 153 154 |
# File 'lib/regexgen/ast.rb', line 152 def empty? @value.empty? end |
#length ⇒ Object
164 165 166 |
# File 'lib/regexgen/ast.rb', line 164 def length @value.length end |
#literal(_side = nil) ⇒ Object
176 177 178 |
# File 'lib/regexgen/ast.rb', line 176 def literal(_side = nil) @value end |
#remove_substring(side, len) ⇒ Object
180 181 182 183 184 185 186 |
# File 'lib/regexgen/ast.rb', line 180 def remove_substring(side, len) case side when :start then Literal.new(@value[len...@value.length]) when :end then Literal.new(@value[0...(@value.length - len)]) else raise "Unknown side: #{side}" end end |
#single_character? ⇒ Boolean
156 157 158 |
# File 'lib/regexgen/ast.rb', line 156 def single_character? length == 1 end |
#single_codepoint? ⇒ Boolean
160 161 162 |
# File 'lib/regexgen/ast.rb', line 160 def single_codepoint? @value.codepoints.length == 1 end |
#to_s ⇒ Object
168 169 170 |
# File 'lib/regexgen/ast.rb', line 168 def to_s Regexp.escape(@value) end |