3
0

renaming: Specs => SpecFileParser

This commit is contained in:
Philippe PITTOLI 2019-08-13 18:03:34 +02:00
parent 79ef66292b
commit 2694ecdae1
3 changed files with 17 additions and 17 deletions

View File

@ -1,5 +1,5 @@
require "option_parser" require "option_parser"
require "./src/spec" require "./src/specfileparser"
recipe_file_name = "some-non-existant-file" recipe_file_name = "some-non-existant-file"
@ -18,7 +18,7 @@ end
options = Hash(String,String).new options = Hash(String,String).new
options["someoptionexample"] = "option" options["someoptionexample"] = "option"
specs = Specs.parse recipe_file_name, options specs = SpecFileParser.parse recipe_file_name, options
pp! specs pp! specs
@ -27,30 +27,30 @@ pp! specs
# low level stuff # low level stuff
sectioncontainer = Specs::Section.new "val" sectioncontainer = SpecFileParser::Section.new "val"
begin begin
puts sectioncontainer.as_s puts sectioncontainer.as_s
puts "(NOT OK) Specs::Section should not accept .as_s" puts "(NOT OK) SpecFileParser::Section should not accept .as_s"
rescue e rescue e
puts "(OK) #{e}" puts "(OK) #{e}"
end end
begin begin
pp! sectioncontainer.as_a_or_s pp! sectioncontainer.as_a_or_s
puts "(NOT OK) Specs::Section should not accept .as_a_or_s" puts "(NOT OK) SpecFileParser::Section should not accept .as_a_or_s"
rescue e rescue e
puts "(OK) #{e}" puts "(OK) #{e}"
end end
arraycontainer = Specs::ArrayContainer.new Array(String).new.push "value" arraycontainer = SpecFileParser::ArrayContainer.new Array(String).new.push "value"
begin begin
puts arraycontainer.as_s puts arraycontainer.as_s
puts "(NOT OK) Specs::ArrayContainer should not accept .as_s" puts "(NOT OK) SpecFileParser::ArrayContainer should not accept .as_s"
rescue e rescue e
puts "(OK) #{e}" puts "(OK) #{e}"
end end
begin begin
pp! arraycontainer.as_a_or_s pp! arraycontainer.as_a_or_s
puts "(OK) Specs::ArrayContainer should accept .as_a_or_s" puts "(OK) SpecFileParser::ArrayContainer should accept .as_a_or_s"
rescue e rescue e
puts "(NOT OK) #{e}" puts "(NOT OK) #{e}"
end end

View File

@ -1,11 +1,11 @@
name: spec name: specfileparser
version: 0.4.1 version: 0.4.2
authors: authors:
- Philippe Pittoli <karchnu@karchnu.fr> - Philippe Pittoli <karchnu@karchnu.fr>
description: | description: |
`Spec` is a parsing library for the `Spec` format. `SpecFileParser` is a parsing library for the `Spec` format.
license: ISC license: ISC

View File

@ -1,5 +1,5 @@
class Specs class SpecFileParser
macro incompatible_methods(*names) macro incompatible_methods(*names)
{% for name in names %} {% for name in names %}
@ -40,7 +40,7 @@ class Specs
end end
class LongStringContainer class LongStringContainer
Specs.incompatible_methods as_s, as_a_or_s SpecFileParser.incompatible_methods as_s, as_a_or_s
property value : String property value : String
def as_s_or_ls : String def as_s_or_ls : String
@ -52,7 +52,7 @@ class Specs
end end
class ArrayContainer class ArrayContainer
Specs.incompatible_methods as_s, as_s_or_ls SpecFileParser.incompatible_methods as_s, as_s_or_ls
property value : Array(String) property value : Array(String)
def as_a_or_s : Array(String) def as_a_or_s : Array(String)
@ -64,7 +64,7 @@ class Specs
end end
class Section class Section
Specs.incompatible_methods as_s, as_a_or_s, as_s_or_ls SpecFileParser.incompatible_methods as_s, as_a_or_s, as_s_or_ls
property name : String property name : String
property options : Array(String) property options : Array(String)
property content : Hash(String, StringContainer | ArrayContainer | LongStringContainer) property content : Hash(String, StringContainer | ArrayContainer | LongStringContainer)
@ -367,12 +367,12 @@ class Specs
# The only function to use from outside. # The only function to use from outside.
def self.parse(file_name : String, options : Hash(String, String) | Nil = nil) : Specs | Nil def self.parse(file_name : String, options : Hash(String, String) | Nil = nil) : SpecFileParser | Nil
begin begin
content = File.read(file_name) content = File.read(file_name)
content = content.rchop content = content.rchop
specs = Specs.new specs = SpecFileParser.new
unless options.nil? unless options.nil?
options.each do |opt, val| options.each do |opt, val|
specs.assignments[opt] = StringContainer.new val specs.assignments[opt] = StringContainer.new val