Class: Fig::ParserPackageBuildState

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

Overview

The state of a Package while it is being built by a Parser.

Instance Method Summary collapse

Constructor Details

#initialize(grammar_version, descriptor, source_description) ⇒ ParserPackageBuildState

Returns a new instance of ParserPackageBuildState.



22
23
24
25
26
# File 'lib/fig/parser_package_build_state.rb', line 22

def initialize(grammar_version, descriptor, source_description)
  @grammar_version    = grammar_version
  @descriptor         = descriptor
  @source_description = source_description
end

Instance Method Details

#new_asset_statement(statement_class, keyword_node, location_node) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fig/parser_package_build_state.rb', line 91

def new_asset_statement(statement_class, keyword_node, location_node)
  raw_location = location_node.text_value

  tokenized_location =
    statement_class.validate_and_process_escapes_in_location(raw_location) do
      |error_description|

      raise_invalid_value_parse_error(
        keyword_node, location_node, 'URL/path', error_description
      )
    end

  location = tokenized_location.to_expanded_string
  need_to_glob = ! tokenized_location.single_quoted?
  return statement_class.new(
    node_location(keyword_node), @source_description, location, need_to_glob
  )
end

#new_configuration_statement(keyword_node, name_node, statements) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/fig/parser_package_build_state.rb', line 128

def new_configuration_statement(keyword_node, name_node, statements)
  statement_objects = statements.elements.map do
    |statement|

    statement.to_config_statement(self)
  end

  return Fig::Statement::Configuration.new(
    node_location(keyword_node),
    @source_description,
    name_node.text_value,
    statement_objects
  )
end

#new_environment_variable_statement(statement_class, keyword_node, value_node) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/fig/parser_package_build_state.rb', line 204

def new_environment_variable_statement(
  statement_class, keyword_node, value_node
)
  name = value = nil

  if @grammar_version == 0
    name, value = statement_class.parse_v0_name_value(value_node.text_value) {
      |description|
      raise_invalid_statement_parse_error(
        keyword_node, value_node, description
      )
    }
  else
    name, value = statement_class.parse_name_value(value_node.text_value) {
      |description|
      raise_invalid_statement_parse_error(
        keyword_node, value_node, description
      )
    }
  end

  return statement_class.new(
    node_location(keyword_node), @source_description, name, value
  )
end

#new_grammar_version_statement(keyword_node, version_node) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/fig/parser_package_build_state.rb', line 83

def new_grammar_version_statement(keyword_node, version_node)
  return Fig::Statement::GrammarVersion.new(
    node_location(keyword_node),
    @source_description,
    version_node.text_value.to_i
  )
end

#new_include_file_statement(keyword_node, path_node, config_name_node) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/fig/parser_package_build_state.rb', line 160

def new_include_file_statement(keyword_node, path_node, config_name_node)
  path, config_name =
    Fig::Statement::IncludeFile.validate_and_process_raw_path_and_config_name(
      path_node.text_value,
      config_name_node.nil? ? nil : config_name_node.text_value,
    ) do
      |description|

      value_text = path_node.text_value
      if ! config_name_node.nil?
        value_text << ':'
        value_text << config_name_node.text_value
      end

      raise Fig::PackageParseError.new(
        %Q<Invalid include-file statement: "#{value_text}" #{description}#{node_location_description(path_node)}>
      )
    end

  return Fig::Statement::IncludeFile.new(
    node_location(keyword_node),
    @source_description,
    path,
    config_name,
    @descriptor,
  )
end

#new_include_statement(keyword_node, descriptor_node) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/fig/parser_package_build_state.rb', line 143

def new_include_statement(keyword_node, descriptor_node)
  include_descriptor =
    Fig::Statement::Include.parse_descriptor(
      descriptor_node.text_value.strip,
      :source_description => node_location_description(descriptor_node),
      :validation_context => ' for an include statement'
    )

  return Fig::Statement::Include.new(
    node_location(keyword_node),
    @source_description,
    include_descriptor,
    nil,
    @descriptor
  )
end

#new_override_statement(keyword_node, descriptor_node) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/fig/parser_package_build_state.rb', line 188

def new_override_statement(keyword_node, descriptor_node)
  override_descriptor =
    Fig::Statement::Override.parse_descriptor(
      descriptor_node.text_value.strip,
      :source_description => node_location_description(descriptor_node),
      :validation_context => ' for an override statement'
    )

  return Fig::Statement::Override.new(
    node_location(keyword_node),
    @source_description,
    override_descriptor.name,
    override_descriptor.version
  )
end

#new_package_statement(unparsed_package, grammar_node, statement_nodes) ⇒ Object



49
50
51
52
53
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
# File 'lib/fig/parser_package_build_state.rb', line 49

def new_package_statement(unparsed_package, grammar_node, statement_nodes)
  grammar_statement = nil
  if grammar_node && ! grammar_node.empty?
    grammar_statement = grammar_node.to_package_statement(self)
  else
    grammar_statement = Fig::Statement::GrammarVersion.new(
      nil,
      %Q<[synthetic statement created in #{__FILE__} line #{__LINE__}]>,
      0 # Grammar version
    )
  end
  statement_objects = [grammar_statement]

  statement_nodes.elements.each do
    |node|

    statement_objects << node.to_package_statement(self)
  end

  package = Fig::Package.new(
    @descriptor.name,
    @descriptor.version,
    @descriptor.file_path,
    @descriptor.description,
    unparsed_package.working_directory,
    unparsed_package.include_file_base_directory,
    statement_objects,
    false,
  )
  package.unparsed_text = unparsed_package.unparsed_text

  return package
end

#new_retrieve_statement(keyword_node, variable_name_node, path_node) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fig/parser_package_build_state.rb', line 110

def new_retrieve_statement(keyword_node, variable_name_node, path_node)
  tokenized_path =
    Fig::Statement::Retrieve.tokenize_path(path_node.text_value) do
      |error_description|

      raise_invalid_value_parse_error(
        keyword_node, path_node, 'path', error_description
      )
    end

  return Fig::Statement::Retrieve.new(
    node_location(keyword_node),
    @source_description,
    variable_name_node.text_value,
    tokenized_path
  )
end

#new_v0_command_statement(keyword_node, command_line_node) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/fig/parser_package_build_state.rb', line 230

def new_v0_command_statement(keyword_node, command_line_node)
  tokenized_command =
    Fig::Statement::Command.validate_and_process_escapes_in_argument(
      command_line_node.text_value
    ) {
      |description|
      raise_invalid_statement_parse_error(
        keyword_node, command_line_node, description
      )
    }

  return Fig::Statement::Command.new(
    node_location(keyword_node), @source_description, [tokenized_command]
  )
end

#new_v1_command_statement(keyword_node, command_line) ⇒ Object



246
247
248
249
250
251
252
# File 'lib/fig/parser_package_build_state.rb', line 246

def new_v1_command_statement(keyword_node, command_line)
  return Fig::Statement::Command.new(
    node_location(keyword_node),
    @source_description,
    tokenize_v1_command_line(keyword_node, command_line)
  )
end

#node_location(node) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/fig/parser_package_build_state.rb', line 28

def node_location(node)
  offset_from_start_of_file = node.interval.first
  input = node.input

  return [
    input.line_of(offset_from_start_of_file),
    input.column_of(offset_from_start_of_file)
  ]
end

#node_location_description(node) ⇒ Object

This method is necessary due to ruby v1.8 not allowing array splat notation, i.e. Fig::Statement.position_description(*node_location(node), source_description)



41
42
43
44
45
46
47
# File 'lib/fig/parser_package_build_state.rb', line 41

def node_location_description(node)
  location = node_location(node)

  return Fig::Statement.position_description(
    location[0], location[1], @source_description
  )
end