Class: Regexp::Expression::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/regexp_parser/expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
17
# File 'lib/regexp_parser/expression.rb', line 10

def initialize(token)
  @type         = token.type
  @token        = token.token
  @text         = token.text
  @ts           = token.ts
  @level        = token.level
  @options      = nil
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



5
6
7
# File 'lib/regexp_parser/expression.rb', line 5

def level
  @level
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/regexp_parser/expression.rb', line 8

def options
  @options
end

#quantifierObject

Returns the value of attribute quantifier.



7
8
9
# File 'lib/regexp_parser/expression.rb', line 7

def quantifier
  @quantifier
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/regexp_parser/expression.rb', line 5

def text
  @text
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/regexp_parser/expression.rb', line 4

def token
  @token
end

#tsObject

Returns the value of attribute ts.



5
6
7
# File 'lib/regexp_parser/expression.rb', line 5

def ts
  @ts
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/regexp_parser/expression.rb', line 4

def type
  @type
end

Instance Method Details

#case_insensitive?Boolean Also known as: i?, ignore_case?

Returns:

  • (Boolean)


98
99
100
# File 'lib/regexp_parser/expression.rb', line 98

def case_insensitive?
  (@options and @options[:i]) ? true : false
end

#cloneObject



19
20
21
22
23
24
25
26
27
# File 'lib/regexp_parser/expression.rb', line 19

def clone
  copy = self.dup

  copy.text       = (self.text        ? self.text.dup         : nil)
  copy.options    = (self.options     ? self.options.dup      : nil)
  copy.quantifier = (self.quantifier  ? self.quantifier.clone : nil)

  copy
end

#coded_offsetObject



45
46
47
# File 'lib/regexp_parser/expression.rb', line 45

def coded_offset
  '@%d+%d' % offset
end

#free_spacing?Boolean Also known as: x?, extended?

Returns:

  • (Boolean)


104
105
106
# File 'lib/regexp_parser/expression.rb', line 104

def free_spacing?
  (@options and @options[:x]) ? true : false
end

#full_lengthObject



37
38
39
# File 'lib/regexp_parser/expression.rb', line 37

def full_length
  to_s.length
end

#greedy?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/regexp_parser/expression.rb', line 80

def greedy?
  quantified? and @quantifier.mode == :greedy
end

#multiline?Boolean Also known as: m?

Returns:

  • (Boolean)


93
94
95
# File 'lib/regexp_parser/expression.rb', line 93

def multiline?
  (@options and @options[:m]) ? true : false
end

#offsetObject



41
42
43
# File 'lib/regexp_parser/expression.rb', line 41

def offset
  [starts_at, full_length]
end

#possessive?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/regexp_parser/expression.rb', line 89

def possessive?
  quantified? and @quantifier.mode == :possessive
end

#quantified?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/regexp_parser/expression.rb', line 71

def quantified?
  not @quantifier.nil?
end

#quantify(token, text, min = nil, max = nil, mode = :greedy) ⇒ Object



67
68
69
# File 'lib/regexp_parser/expression.rb', line 67

def quantify(token, text, min = nil, max = nil, mode = :greedy)
  @quantifier = Quantifier.new(token, text, min, max, mode)
end

#quantityObject



75
76
77
78
# File 'lib/regexp_parser/expression.rb', line 75

def quantity
  return [nil,nil] unless quantified?
  [@quantifier.min, @quantifier.max]
end

#reluctant?Boolean Also known as: lazy?

Returns:

  • (Boolean)


84
85
86
# File 'lib/regexp_parser/expression.rb', line 84

def reluctant?
  quantified? and @quantifier.mode == :reluctant
end

#starts_atObject



33
34
35
# File 'lib/regexp_parser/expression.rb', line 33

def starts_at
  @ts
end

#terminal?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/regexp_parser/expression.rb', line 63

def terminal?
  !respond_to?(:expressions)
end

#to_re(format = :full) ⇒ Object



29
30
31
# File 'lib/regexp_parser/expression.rb', line 29

def to_re(format = :full)
  ::Regexp.new(to_s(format))
end

#to_s(format = :full) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/regexp_parser/expression.rb', line 49

def to_s(format = :full)
  s = ''

  case format
  when :base
    s << @text.dup
  else
    s << @text.dup
    s << @quantifier if quantified?
  end

  s
end