class Hercules::UptimeMonitor::Parser

Public Class Methods

parse(data, parser, description = false) click to toggle source
# File lib/uptime_monitor/parser.rb, line 6
def self.parse(data, parser, description = false)
  if data.respond_to? :read
    data = data.read
  end

  ast = parser.parse data

  if ast
    return (description ? ast.description : ast.content)
  else
    parser.failure_reason =~ /^(Expected .+) after/m
    raise(Hercules::UptimeMonitor::ParserSyntaxError.new(error: "syntax error"), "syntax error") if $1.nil?
    message =
    "#{$1.gsub("\n", '$NEWLINE')}:" << "\n" <<
    data.lines.to_a[parser.failure_line - 1] << "\n" <<
    "#{'~' * (parser.failure_column - 1)}^"
    raise(Hercules::UptimeMonitor::ParserSyntaxError.new(error: message), message)
  end
end