class Regexgen::Ast::Literal
Represents a literal (e.g. a string)
Attributes
precedence[R]
value[R]
Public Class Methods
new(value)
click to toggle source
# File lib/regexgen/ast.rb, line 147 def initialize(value) @precedence = 2 @value = value end
Public Instance Methods
char_class()
click to toggle source
# File lib/regexgen/ast.rb, line 172 def char_class @value if single_codepoint? end
empty?()
click to toggle source
# File lib/regexgen/ast.rb, line 152 def empty? @value.empty? end
length()
click to toggle source
# File lib/regexgen/ast.rb, line 164 def length @value.length end
literal(_side = nil)
click to toggle source
# File lib/regexgen/ast.rb, line 176 def literal(_side = nil) @value end
remove_substring(side, len)
click to toggle source
# File lib/regexgen/ast.rb, line 180 def remove_substring(side, len) return Literal.new(@value[len..]) if side == :start return Literal.new(@value[0...(@value.length - len)]) if side == :end end
single_character?()
click to toggle source
# File lib/regexgen/ast.rb, line 156 def single_character? length == 1 end
single_codepoint?()
click to toggle source
# File lib/regexgen/ast.rb, line 160 def single_codepoint? @value.codepoints.length == 1 end
to_s()
click to toggle source
# File lib/regexgen/ast.rb, line 168 def to_s Regexp.escape(@value) end