Class: Pray::PackageSpecParser::BlockParser
- Inherits:
-
Object
- Object
- Pray::PackageSpecParser::BlockParser
show all
- Includes:
- ParserHelpers
- Defined in:
- lib/pray/package_spec.rb
Instance Method Summary
collapse
#array_of_strings, #map_string, #map_string_array, #parse_dependency, #parse_exports, #parse_skills, #parse_string_map, #parse_templates, #string_from_literal, #string_from_value
apply_target_statement, infer_source_kind, keyword_array, keyword_bool, keyword_string, package_constraint, package_exports, parse_call, parse_group_header, parse_keyword_segment, parse_local_decl, parse_package_decl, parse_render_policy, parse_source, parse_target_header, source_kind_and_url, string_from_literal, string_from_value
Constructor Details
Returns a new instance of BlockParser.
162
163
164
165
|
# File 'lib/pray/package_spec.rb', line 162
def initialize(lines)
@lines = lines
@cursor = 0
end
|
Instance Method Details
#apply_assignment(spec, field, value) ⇒ Object
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/pray/package_spec.rb', line 199
def apply_assignment(spec, field, value)
case field
when "name" then spec.name = string_from_literal(value)
when "version" then spec.version = string_from_literal(value)
when "summary" then spec.summary = string_from_literal(value)
when "description" then spec.description = string_from_literal(value)
when "authors" then spec.authors = array_of_strings(value)
when "license" then spec.license = string_from_literal(value)
when "homepage" then spec.homepage = string_from_literal(value)
when "source_code_uri" then spec.source_code_uri = string_from_literal(value)
when "changelog_uri" then spec.changelog_uri = string_from_literal(value)
when "prayfile_version" then spec.prayfile_version = string_from_literal(value)
when "files" then spec.files = array_of_strings(value)
when "targets" then spec.targets = array_of_strings(value)
when "exports" then spec.exports = parse_exports(value)
when "skills" then spec.skills = parse_skills(value)
when "templates" then spec.templates = parse_templates(value)
when "adapters" then spec.adapters = parse_string_map(value)
when "metadata" then spec.metadata = Literal.parse_literal_map(value)
else
raise Error.parse("prayspec", "unsupported assignment: #{field}")
end
end
|
#apply_statement(spec, statement) ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/pray/package_spec.rb', line 186
def apply_statement(spec, statement)
case statement
when /\Aspec\.add_dependency (.+)\z/
spec.dependencies << parse_dependency(Regexp.last_match(1), false)
when /\Aspec\.add_optional_dependency (.+)\z/
spec.dependencies << parse_dependency(Regexp.last_match(1), true)
when /\Aspec\.(.+) = (.+)\z/
apply_assignment(spec, Regexp.last_match(1).strip, Regexp.last_match(2).strip)
else
raise Error.parse("prayspec", "unrecognized statement: #{statement}")
end
end
|
#expect_start! ⇒ Object
178
179
180
181
182
183
184
|
# File 'lib/pray/package_spec.rb', line 178
def expect_start!
statement = next_statement
raise Error.parse("prayspec", "empty package spec") unless statement
unless statement.start_with?("Package::Specification.new")
raise Error.parse("prayspec", "expected Package::Specification.new")
end
end
|
#next_statement ⇒ Object
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
# File 'lib/pray/package_spec.rb', line 223
def next_statement
while @cursor < @lines.length
statement = @lines[@cursor].strip
@cursor += 1
next if statement.empty?
while !statement.end_with?(" do") && statement != "end" && @cursor < @lines.length &&
(statement.rstrip.end_with?(",") || !Literal.is_balanced?(statement))
next_line = @lines[@cursor].strip
@cursor += 1
next if next_line.empty?
statement = "#{statement} #{next_line}"
end
return statement
end
nil
end
|
#parse_root ⇒ Object
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/pray/package_spec.rb', line 167
def parse_root
expect_start!
spec = PackageSpec.new
while (statement = next_statement)
return spec.canonicalized if statement == "end"
apply_statement(spec, statement)
end
raise Error.parse("prayspec", "missing 'end'")
end
|