Module: ABNF::Parser::Node

Included in:
Alternation, PatternMatch, Sequence, Single
Defined in:
lib/abnf/parser/node.rb

Defined Under Namespace

Classes: Alternation, PatternMatch, Sequence, Single

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.alternation(node, abnf) ⇒ Object



4
5
6
# File 'lib/abnf/parser/node.rb', line 4

def self.alternation node, abnf
  Alternation.new node, abnf
end

.concatenation(children = nil, abnf) ⇒ Object



8
9
10
11
# File 'lib/abnf/parser/node.rb', line 8

def self.concatenation children=nil, abnf
  children ||= Array(children)
  Sequence.new children, abnf
end

.pattern_match(match_data, abnf) ⇒ Object



18
19
20
# File 'lib/abnf/parser/node.rb', line 18

def self.pattern_match match_data, abnf
  PatternMatch.new match_data, abnf
end

.repetition(children = nil, abnf) ⇒ Object



13
14
15
16
# File 'lib/abnf/parser/node.rb', line 13

def self.repetition children=nil, abnf
  children ||= Array(children)
  Sequence.new children, abnf
end

.terminal(text, abnf) ⇒ Object



22
23
24
# File 'lib/abnf/parser/node.rb', line 22

def self.terminal text, abnf
  Single.new text, abnf
end

Instance Method Details

#==(other_node) ⇒ Object



26
27
28
29
# File 'lib/abnf/parser/node.rb', line 26

def == other_node
  return false unless other_node.is_a? Node
  self.text == other_node.text and self.abnf == other_node.abnf
end

#[](index) ⇒ Object



31
32
33
# File 'lib/abnf/parser/node.rb', line 31

def [] index
  children[index]
end

#child_countObject



39
40
41
# File 'lib/abnf/parser/node.rb', line 39

def child_count
  children.size
end

#childrenObject



35
36
37
# File 'lib/abnf/parser/node.rb', line 35

def children
  []
end

#each(&block) ⇒ Object



43
44
45
# File 'lib/abnf/parser/node.rb', line 43

def each &block
  children.each &block
end

#octetsObject



47
48
49
# File 'lib/abnf/parser/node.rb', line 47

def octets
  text.bytesize
end