Class: Y2R::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/y2r/parser.rb

Defined Under Namespace

Classes: SyntaxError

Constant Summary collapse

SKIPPED_ELEMENTS_PARSING =

The lists of elements skipped during parsing and comment processing need to differ. Currently there are two reasons:

* When parsing, we want to skip <yconst>, because it's just a useless
  wrapper. But when processing comments we don't want to skip it,
  because this is the element to which comments are attached to for
  various literals.

* When parsing, we don't want to skip <element>, because we need to
  handle it specially in case it's inside <map>. But when processing
  comments it's just a useless wrapper.
[
  "arg",
  "cond",
  "else",
  "expr",
  "false",
  "key",
  "lhs",
  "rhs",
  "stmt",
  "then",
  "true",
  "until",
  "value",
  "yconst",
  "ycp"
]
SKIPPED_ELEMENTS_COMMENTS =
[
  "arg",
  "cond",
  "element",
  "else",
  "expr",
  "false",
  "key",
  "lhs",
  "rhs",
  "stmt",
  "then",
  "true",
  "until",
  "value",
  "ycp"
]

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Parser

Returns a new instance of Parser.



61
62
63
# File 'lib/y2r/parser.rb', line 61

def initialize(options = {})
  @options = options
end

Instance Method Details

#parse(input) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/y2r/parser.rb', line 65

def parse(input)
  xml = ycp_to_xml(input)

  if !@options[:xml]
    xml_to_ast(xml)
  else
    xml
  end
end