Module: Pione::Util::ParsletParserExtension

Included in:
Parslet::Atoms::Base, Lang::DocumentParser, PNML::Parser
Defined in:
lib/pione/util/parslet-extension.rb

Overview

ParsletParserExtension provides parser helper methods.

Instance Method Summary collapse

Instance Method Details

#except(exception) ⇒ Object



83
84
85
# File 'lib/pione/util/parslet-extension.rb', line 83

def except(exception)
  ExceptionAtom.new(self, exception)
end

#ignoreObject



79
80
81
# File 'lib/pione/util/parslet-extension.rb', line 79

def ignore
  IgnoreAtom.new(self)
end

#ignore_error(&b) ⇒ Object



108
109
110
111
# File 'lib/pione/util/parslet-extension.rb', line 108

def ignore_error(&b)
  res = yield
  return IgnoreErrorAtom.new(res)
end

#or_error(msg, *expected_elements) ⇒ Object

Create a special atom that raises +ParserError+ when it is tried.



88
89
90
# File 'lib/pione/util/parslet-extension.rb', line 88

def or_error(msg, *expected_elements)
  self | SyntaxErrorAtom.new(msg, expected_elements, $ignore_error)
end

#should(atom, msg, *expected_elements) ⇒ Object



104
105
106
# File 'lib/pione/util/parslet-extension.rb', line 104

def should(atom, msg, *expected_elements)
  atom | syntax_error(msg, *expected_elements)
end

#syntax_error(msg, *expected_elements) ⇒ SyntaxErrorAtom

Raises syntax error. This method returns a dummy atom and the parser evaluates it as error.

Parameters:

  • msg (String)

    error message

  • expected_elements (Array<String>)

    expected name list

Returns:



100
101
102
# File 'lib/pione/util/parslet-extension.rb', line 100

def syntax_error(msg, *expected_elements)
  SyntaxErrorAtom.new(msg, expected_elements, $ignore_error)
end