Class: Regexp::Expression::Base
- Inherits:
-
Object
- Object
- Regexp::Expression::Base
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
#level ⇒ Object
Returns the value of attribute level.
5
6
7
|
# File 'lib/regexp_parser/expression.rb', line 5
def level
@level
end
|
#options ⇒ Object
Returns the value of attribute options.
8
9
10
|
# File 'lib/regexp_parser/expression.rb', line 8
def options
@options
end
|
#quantifier ⇒ Object
Returns the value of attribute quantifier.
7
8
9
|
# File 'lib/regexp_parser/expression.rb', line 7
def quantifier
@quantifier
end
|
#text ⇒ Object
Returns the value of attribute text.
5
6
7
|
# File 'lib/regexp_parser/expression.rb', line 5
def text
@text
end
|
#token ⇒ Object
Returns the value of attribute token.
4
5
6
|
# File 'lib/regexp_parser/expression.rb', line 4
def token
@token
end
|
#ts ⇒ Object
Returns the value of attribute ts.
5
6
7
|
# File 'lib/regexp_parser/expression.rb', line 5
def ts
@ts
end
|
#type ⇒ Object
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?
98
99
100
|
# File 'lib/regexp_parser/expression.rb', line 98
def case_insensitive?
(@options and @options[:i]) ? true : false
end
|
#clone ⇒ Object
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_offset ⇒ Object
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?
104
105
106
|
# File 'lib/regexp_parser/expression.rb', line 104
def free_spacing?
(@options and @options[:x]) ? true : false
end
|
#full_length ⇒ Object
37
38
39
|
# File 'lib/regexp_parser/expression.rb', line 37
def full_length
to_s.length
end
|
#greedy? ⇒ 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?
93
94
95
|
# File 'lib/regexp_parser/expression.rb', line 93
def multiline?
(@options and @options[:m]) ? true : false
end
|
#offset ⇒ Object
41
42
43
|
# File 'lib/regexp_parser/expression.rb', line 41
def offset
[starts_at, full_length]
end
|
#possessive? ⇒ Boolean
89
90
91
|
# File 'lib/regexp_parser/expression.rb', line 89
def possessive?
quantified? and @quantifier.mode == :possessive
end
|
#quantified? ⇒ 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
|
#quantity ⇒ Object
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?
84
85
86
|
# File 'lib/regexp_parser/expression.rb', line 84
def reluctant?
quantified? and @quantifier.mode == :reluctant
end
|
#starts_at ⇒ Object
33
34
35
|
# File 'lib/regexp_parser/expression.rb', line 33
def starts_at
@ts
end
|
#terminal? ⇒ 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
|