Class: ABNF::Alt
- 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?, #remove_left_recursion, #remove_right_recursion, #rep, #|
Constructor Details
#initialize(*elts) ⇒ Alt
Returns a new instance of Alt.
68
69
70
|
# File 'lib/abnf/grammar.rb', line 68
def initialize(*elts)
@elts = elts
end
|
Instance Attribute Details
#elts ⇒ Object
Returns the value of attribute elts.
71
72
73
|
# File 'lib/abnf/grammar.rb', line 71
def elts
@elts
end
|
Class Method Details
._new ⇒ Object
41
|
# File 'lib/abnf/grammar.rb', line 41
alias _new new
|
.new(*elts) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/abnf/grammar.rb', line 44
def Alt.new(*elts)
elts2 = []
elts.each {|e|
if e.empty_set?
next
elsif Alt === e
elts2.concat e.elts
elsif Term === e
if Term === elts2.last
elts2[-1] = Term.new(elts2.last.natset + e.natset)
else
elts2 << e
end
else
elts2 << e
end
}
case elts2.length
when 0; EmptySet
when 1; elts2.first
else; Alt._new(*elts2)
end
end
|
Instance Method Details
#each_var(&block) ⇒ Object
77
|
# File 'lib/abnf/grammar.rb', line 77
def each_var(&block) @elts.each {|elt| elt.each_var(&block)} end
|
#empty_set? ⇒ Boolean
73
74
75
|
# File 'lib/abnf/grammar.rb', line 73
def empty_set?
@elts.empty?
end
|
#recursion(syms, lhs) ⇒ Object
180
181
182
|
# File 'lib/abnf/regexp.rb', line 180
def recursion(syms, lhs)
@elts.inject(0) {|r, e| r | e.recursion(syms, lhs)}
end
|
#regexp_tree ⇒ Object
390
|
# File 'lib/abnf/regexp.rb', line 390
def regexp_tree() RegexpTree.alt(*@elts.map {|e| e.regexp_tree}) end
|
#remove_just_recursion(n) ⇒ Object
184
185
186
|
# File 'lib/abnf/regexp.rb', line 184
def remove_just_recursion(n)
Alt.new(*@elts.map {|e| e.remove_just_recursion(n)})
end
|
#split_left_recursion(n) ⇒ Object
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/abnf/regexp.rb', line 188
def split_left_recursion(n)
nonrec = EmptySet
rest = EmptySet
@elts.each {|e|
nonrec1, rest1 = e.split_left_recursion(n)
nonrec |= nonrec1
rest |= rest1
}
[nonrec, rest]
end
|
#split_recursion(n) ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/abnf/regexp.rb', line 210
def split_recursion(n)
rest_left = EmptySet
nonrec = EmptySet
rest_right = EmptySet
@elts.each {|e|
rest_left1, nonrec1, rest_right1 = e.split_recursion(n)
rest_left |= rest_left1
nonrec |= nonrec1
rest_right |= rest_right1
}
[rest_left, nonrec, rest_right]
end
|
#split_right_recursion(n) ⇒ Object
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/abnf/regexp.rb', line 199
def split_right_recursion(n)
nonrec = EmptySet
rest = EmptySet
@elts.each {|e|
nonrec1, rest1 = e.split_right_recursion(n)
nonrec |= nonrec1
rest |= rest1
}
[nonrec, rest]
end
|
#subst_var(&block) ⇒ Object
78
|
# File 'lib/abnf/grammar.rb', line 78
def subst_var(&block) Alt.new(*@elts.map {|elt| elt.subst_var(&block)}) end
|
#useful?(useful_names) ⇒ Boolean
120
|
# File 'lib/abnf/abnf.rb', line 120
def useful?(useful_names) @elts.any? {|e| e.useful?(useful_names)} end
|