Class: ABNF::Elt

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

Direct Known Subclasses

Alt, Rep, Seq, Term, Var

Instance Method Summary collapse

Instance Method Details

#*(n) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/abnf/grammar.rb', line 23

def *(n)
  case n
  when Integer
    rep(n, n)
  when Range
    rep(n.first, n.last - (n.exclude_end? ? 1 : 0))
  else
    raise TypeError.new("Integer or Range expected: #{n}")
  end
end

#+(other) ⇒ Object



15
16
17
# File 'lib/abnf/grammar.rb', line 15

def +(other)
  Seq.new(self, other)
end

#empty_sequence?Boolean

A variable is assumed as not empty sequence.

Returns:

  • (Boolean)


11
12
13
# File 'lib/abnf/grammar.rb', line 11

def empty_sequence?
  false
end

#empty_set?Boolean

A variable is assumed as not empty set.

Returns:

  • (Boolean)


6
7
8
# File 'lib/abnf/grammar.rb', line 6

def empty_set?
  false
end

#remove_left_recursion(n) ⇒ Object



168
169
170
171
# File 'lib/abnf/regexp.rb', line 168

def remove_left_recursion(n)
  nonrec, rest = split_left_recursion(n)
  Seq.new(nonrec, rest.rep)
end

#remove_right_recursion(n) ⇒ Object



173
174
175
176
# File 'lib/abnf/regexp.rb', line 173

def remove_right_recursion(n)
  nonrec, rest = split_right_recursion(n)
  Seq.new(rest.rep, nonrec)
end

#rep(min = 0, max = nil, greedy = true) ⇒ Object



34
35
36
# File 'lib/abnf/grammar.rb', line 34

def rep(min=0, max=nil, greedy=true)
  Rep.new(self, min, max, greedy)
end

#|(other) ⇒ Object



19
20
21
# File 'lib/abnf/grammar.rb', line 19

def |(other)
  Alt.new(self, other)
end