Class: ABNF::Compiler::Rule::Repetition
- Inherits:
-
Object
- Object
- ABNF::Compiler::Rule::Repetition
- Includes:
- ABNF::Compiler::Rule
- Defined in:
- lib/abnf/compiler/rule/repetition.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
-
#initialize(range, element) ⇒ Repetition
constructor
A new instance of Repetition.
- #maximum ⇒ Object
- #minimum ⇒ Object
- #parse(stream) ⇒ Object
Methods included from ABNF::Compiler::Rule
Constructor Details
#initialize(range, element) ⇒ Repetition
Returns a new instance of Repetition.
10 11 12 13 |
# File 'lib/abnf/compiler/rule/repetition.rb', line 10 def initialize range, element @element = element @range = range end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
7 8 9 |
# File 'lib/abnf/compiler/rule/repetition.rb', line 7 def element @element end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
8 9 10 |
# File 'lib/abnf/compiler/rule/repetition.rb', line 8 def range @range end |
Instance Method Details
#maximum ⇒ Object
15 16 17 |
# File 'lib/abnf/compiler/rule/repetition.rb', line 15 def maximum range.last end |
#minimum ⇒ Object
19 20 21 |
# File 'lib/abnf/compiler/rule/repetition.rb', line 19 def minimum range.first end |
#parse(stream) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/abnf/compiler/rule/repetition.rb', line 23 def parse stream matches = false nodes = [] stream.branch do until nodes.size == maximum node = element.parse stream break unless node nodes << node end matches = true if nodes.size >= minimum end AST.repetition *nodes if matches end |