Archived
3
0

Library renaming: Specs => SpecFileParser.

This commit is contained in:
Philippe PITTOLI 2019-08-13 18:11:20 +02:00
parent ad4ac62352
commit be84c7d18b
3 changed files with 13 additions and 13 deletions

View File

@ -1,5 +1,5 @@
name: package name: package
version: 0.1.0 version: 0.1.1
# authors: # authors:
# - name <email@example.com> # - name <email@example.com>
@ -8,7 +8,7 @@ version: 0.1.0
# Short description of package # Short description of package
dependencies: dependencies:
spec: specfileparser:
git: https://git.karchnu.fr/WeirdOS/recipes-parser git: https://git.karchnu.fr/WeirdOS/recipes-parser
# dependencies: # dependencies:

View File

@ -3,7 +3,7 @@ require "uuid"
require "uri" require "uri"
require "file_utils" require "file_utils"
require "spec" require "specfileparser"
require "./context.cr" require "./context.cr"
require "./package.cr" require "./package.cr"
@ -31,7 +31,7 @@ module FileUtils
end end
# FIXME: This could probably be shorter and less stupid with a macro or two. # FIXME: This could probably be shorter and less stupid with a macro or two.
class Specs::StringContainer class SpecFileParser::StringContainer
def as_s : String def as_s : String
value value
end end
@ -44,7 +44,7 @@ class Specs::StringContainer
end end
end end
class Specs::LongStringContainer class SpecFileParser::LongStringContainer
def as_s : String def as_s : String
raise "short string expected, got multiline text section" raise "short string expected, got multiline text section"
end end
@ -56,7 +56,7 @@ class Specs::LongStringContainer
end end
end end
class Specs::ArrayContainer class SpecFileParser::ArrayContainer
def as_s : String def as_s : String
raise "string expected, got list" raise "string expected, got list"
end end
@ -68,7 +68,7 @@ class Specs::ArrayContainer
end end
end end
class Specs::SectionContainer class SpecFileParser::SectionContainer
def as_s : String def as_s : String
raise "string expected, got section" raise "string expected, got section"
end end
@ -128,7 +128,7 @@ class Package::Recipe
end end
def initialize(@context, filename : String) def initialize(@context, filename : String)
specs = Specs.parse filename, { specs = SpecFileParser.parse filename, {
"pkg" => fake_root_directory "pkg" => fake_root_directory
} }

10
test.cr
View File

@ -11,7 +11,7 @@ context.packaging_backend = "apk"
recipes = [] of Package::Recipe recipes = [] of Package::Recipe
class Specs class SpecFileParser
def get_string?(id) : String? def get_string?(id) : String?
entry = self.assignments[id]? entry = self.assignments[id]?
@ -49,9 +49,9 @@ class Specs
entry = assignments[id]? entry = assignments[id]?
case entry case entry
when Specs::ArrayContainer when SpecFileParser::ArrayContainer
entry.value entry.value
when Specs::StringContainer when SpecFileParser::StringContainer
entry.value.split(",") entry.value.split(",")
when Nil when Nil
return nil return nil
@ -62,7 +62,7 @@ class Specs
end end
class Package::Recipe class Package::Recipe
def initialize(@context, specs : Specs) def initialize(@context, specs : SpecFileParser)
pp! specs pp! specs
@name = specs.get_string "name" @name = specs.get_string "name"
@ -120,7 +120,7 @@ end
class Package::Context class Package::Context
def read_recipe(filename : String) def read_recipe(filename : String)
specs = Specs.parse filename specs = SpecFileParser.parse filename
if specs.nil? if specs.nil?
raise Exception.new "file could not be parsed" raise Exception.new "file could not be parsed"