Class: ABNF::Compiler::Grammar::Repetition
- Inherits:
-
Object
- Object
- ABNF::Compiler::Grammar::Repetition
- Includes:
- Compiler
- Defined in:
- lib/abnf/compiler/grammar/repetition.rb
Constant Summary collapse
- PATTERN =
%r{\A (?: (?<range>(?<minimum>[[:digit:]]*)\*(?<maximum>[[:digit:]]*)) | (?<fixed_number>[[:digit:]]+) )? }nx
Instance Attribute Summary
Attributes included from Compiler
Instance Method Summary collapse
- #call ⇒ Object
- #fixed_number ⇒ Object
- #maximum ⇒ Object
- #minimum ⇒ Object
- #no_repeat? ⇒ Boolean
- #range? ⇒ Boolean
Methods included from Compiler
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/abnf/compiler/grammar/repetition.rb', line 15 def call element = Element.compile stream return unless element if no_repeat? min = 1 max = 1 elsif fixed_number min = fixed_number.to_i max = min else min = minimum.to_i max = if maximum.empty? then Float::INFINITY else maximum.to_i end end return element if min == 1 and max == 1 return if min > max ABNF::Compiler::Rule::Repetition.new min..max, element end |
#fixed_number ⇒ Object
36 37 38 |
# File 'lib/abnf/compiler/grammar/repetition.rb', line 36 def fixed_number match_data['fixed_number'.freeze] end |
#maximum ⇒ Object
40 41 42 |
# File 'lib/abnf/compiler/grammar/repetition.rb', line 40 def maximum match_data['maximum'.freeze] end |
#minimum ⇒ Object
44 45 46 |
# File 'lib/abnf/compiler/grammar/repetition.rb', line 44 def minimum match_data['minimum'.freeze] end |
#no_repeat? ⇒ Boolean
48 49 50 |
# File 'lib/abnf/compiler/grammar/repetition.rb', line 48 def no_repeat? not fixed_number and not range? end |
#range? ⇒ Boolean
52 53 54 |
# File 'lib/abnf/compiler/grammar/repetition.rb', line 52 def range? match_data['range'.freeze] end |