Class: Fig::Parser

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

Overview

Parses .fig files (wrapping the Treetop-generated parser object) and deals with a few restrictions on them.

Instance Method Summary collapse

Constructor Details

#initialize(application_config, check_include_versions) ⇒ Parser

Returns a new instance of Parser.



17
18
19
20
21
22
# File 'lib/fig/parser.rb', line 17

def initialize(application_config, check_include_versions)
  # Fig::FigParser class is synthesized by Treetop.
  @treetop_parser         = Fig::FigParser.new
  @application_config     = application_config
  @check_include_versions = check_include_versions
end

Instance Method Details

#parse_package(descriptor, directory, source_description, input) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fig/parser.rb', line 24

def parse_package(descriptor, directory, source_description, input)
  # Bye bye comments.
  input = input.gsub(/#.*$/, '')

  # Extra space at the end because most of the rules in the grammar require
  # trailing whitespace.
  result = @treetop_parser.parse(input + ' ')

  extended_description =
    extend_source_description(directory, source_description)

  if result.nil?
    raise_parse_error(extended_description)
  end

  package = result.to_package(
    directory,
    Fig::ParserPackageBuildState.new(descriptor, extended_description)
  )

  check_for_bad_urls(package, descriptor)
  check_for_multiple_command_statements(package)
  check_for_missing_versions_on_include_statements(package)

  return package
end