Class: ABNF::Var

Inherits:
Elt
  • Object
show all
Defined in:
lib/abnf/abnf.rb,
lib/abnf/regexp.rb,
lib/abnf/grammar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Elt

#*, #+, #empty_sequence?, #empty_set?, #remove_left_recursion, #remove_right_recursion, #rep, #|

Constructor Details

#initialize(name) ⇒ Var

Returns a new instance of Var.



149
150
151
# File 'lib/abnf/grammar.rb', line 149

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



152
153
154
# File 'lib/abnf/grammar.rb', line 152

def name
  @name
end

Instance Method Details

#each_var {|@name| ... } ⇒ Object

Yields:



154
# File 'lib/abnf/grammar.rb', line 154

def each_var(&block) yield @name end

#recursion(syms, lhs) ⇒ Object



354
355
356
357
358
359
360
361
362
# File 'lib/abnf/regexp.rb', line 354

def recursion(syms, lhs)
  if lhs == self.name
	JustRecursion | SelfRecursion
  elsif syms.include? self.name
	JustRecursion
  else
    NonRecursion
  end
end

#remove_just_recursion(n) ⇒ Object



364
365
366
367
368
369
370
# File 'lib/abnf/regexp.rb', line 364

def remove_just_recursion(n)
  if n == self.name
    EmptySet
  else
	self
  end
end

#split_left_recursion(n) ⇒ Object Also known as: split_right_recursion



372
373
374
375
376
377
378
# File 'lib/abnf/regexp.rb', line 372

def split_left_recursion(n)
  if n == self.name
	[EmptySet, EmptySequence]
  else
	[self, EmptySet]
  end
end

#split_recursion(n) ⇒ Object



381
382
383
384
385
386
387
# File 'lib/abnf/regexp.rb', line 381

def split_recursion(n)
  if n == self.name
	[EmptySet, EmptySet, EmptySet]
  else
	[EmptySet, self, EmptySet]
  end
end

#subst_var(&block) ⇒ Object



155
# File 'lib/abnf/grammar.rb', line 155

def subst_var(&block) yield(@name) || self end

#useful?(useful_names) ⇒ Boolean

Returns:

  • (Boolean)


123
# File 'lib/abnf/abnf.rb', line 123

def useful?(useful_names) useful_names[@name] end