Class: ABNF::Rep
- Inherits:
-
Elt
show all
- Defined in:
- lib/abnf/abnf.rb,
lib/abnf/regexp.rb,
lib/abnf/regexp.rb,
lib/abnf/grammar.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Elt
#*, #+, #empty_sequence?, #empty_set?, #remove_left_recursion, #remove_right_recursion, #rep, #|
Constructor Details
#initialize(elt, min = 0, max = nil, greedy = true) ⇒ Rep
Returns a new instance of Rep.
136
137
138
139
140
141
|
# File 'lib/abnf/grammar.rb', line 136
def initialize(elt, min=0, max=nil, greedy=true)
@elt = elt
@min = min
@max = max
@greedy = greedy
end
|
Instance Attribute Details
#elt ⇒ Object
Returns the value of attribute elt.
142
143
144
|
# File 'lib/abnf/grammar.rb', line 142
def elt
@elt
end
|
#greedy ⇒ Object
Returns the value of attribute greedy.
142
143
144
|
# File 'lib/abnf/grammar.rb', line 142
def greedy
@greedy
end
|
#max ⇒ Object
Returns the value of attribute max.
142
143
144
|
# File 'lib/abnf/grammar.rb', line 142
def max
@max
end
|
#min ⇒ Object
Returns the value of attribute min.
142
143
144
|
# File 'lib/abnf/grammar.rb', line 142
def min
@min
end
|
Class Method Details
._new ⇒ Object
123
|
# File 'lib/abnf/grammar.rb', line 123
alias _new new
|
.new(elt, min = 0, max = nil, greedy = true) ⇒ Object
126
127
128
129
130
131
132
133
134
|
# File 'lib/abnf/grammar.rb', line 126
def Rep.new(elt, min=0, max=nil, greedy=true)
return EmptySequence if min == 0 && max == 0
return elt if min == 1 && max == 1
return EmptySequence if elt.empty_sequence?
if elt.empty_set?
return min == 0 ? EmptySequence : EmptySet
end
Rep._new(elt, min, max, greedy)
end
|
Instance Method Details
#each_var(&block) ⇒ Object
144
|
# File 'lib/abnf/grammar.rb', line 144
def each_var(&block) @elt.each_var(&block) end
|
#recursion(syms, lhs) ⇒ Object
316
317
318
|
# File 'lib/abnf/regexp.rb', line 316
def recursion(syms, lhs)
@elt.recursion(syms, lhs) == NonRecursion ? NonRecursion : OtherRecursion
end
|
#regexp_tree ⇒ Object
392
|
# File 'lib/abnf/regexp.rb', line 392
def regexp_tree() @elt.regexp_tree.rep(min, max, greedy) end
|
#remove_just_recursion(n) ⇒ Object
320
321
322
|
# File 'lib/abnf/regexp.rb', line 320
def remove_just_recursion(n)
self
end
|
#split_left_recursion(n) ⇒ Object
Also known as:
split_right_recursion
324
325
326
|
# File 'lib/abnf/regexp.rb', line 324
def split_left_recursion(n)
[self, EmptySet]
end
|
#split_recursion(n) ⇒ Object
329
330
331
|
# File 'lib/abnf/regexp.rb', line 329
def split_recursion(n)
[EmptySet, self, EmptySet]
end
|
#subst_var(&block) ⇒ Object
145
|
# File 'lib/abnf/grammar.rb', line 145
def subst_var(&block) Rep.new(@elt.subst_var(&block), min, max, greedy) end
|
#useful?(useful_names) ⇒ Boolean
122
|
# File 'lib/abnf/abnf.rb', line 122
def useful?(useful_names) @min == 0 ? true : @elt.useful?(useful_names) end
|