Method: BabelBridge::PatternElement#parse

Defined in:
lib/babel_bridge/pattern_element.rb

#parse(parent_node) ⇒ Object

attempt to match the pattern defined in self.parser in parent_node.src starting at offset parent_node.next



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/babel_bridge/pattern_element.rb', line 54

def parse(parent_node)

  # run element parser
  begin
    parent_node.parser.matching_negative if negative
    match = parser.call(parent_node)
  ensure
    parent_node.parser.unmatching_negative if negative
  end

  # Negative patterns (PEG: !element)
  match = match ? nil : EmptyNode.new(parent_node) if negative

  # Optional patterns (PEG: element?)
  match = EmptyNode.new(parent_node) if !match && optional

  # Could-match patterns (PEG: &element)
  match.match_length = 0 if match && could_match

  if !match && (terminal || negative)
    # log failures on Terminal patterns for debug output if overall parse fails
    parent_node.parser.log_parsing_failure parent_node.next, :pattern => self.to_s, :node => parent_node
  end

  match.delimiter = delimiter if match

  # return match
  match
end