require "ecr"
|
|
require "yaml"
|
|
|
|
|
|
module Andrew
|
|
VERSION = "0.1.0"
|
|
|
|
# TODO: Put your code here
|
|
end
|
|
|
|
class FileGenerator
|
|
YAML.mapping(
|
|
classes: Array(ClassGenerator),
|
|
includes: Array(String)
|
|
)
|
|
|
|
def initialize
|
|
@classes = Array(ClassGenerator).new
|
|
@includes = Array(String).new
|
|
end
|
|
|
|
ECR.def_to_s "src/views/file.ecr"
|
|
end
|
|
|
|
class ClassGenerator
|
|
YAML.mapping(
|
|
name: String,
|
|
bitfields: Array(BitfieldGenerator),
|
|
attributes: Array(AttributeGenerator),
|
|
repeats: Array(RepeatGenerator),
|
|
attributeafters: Array(AttributeAfterGenerator)
|
|
)
|
|
|
|
def initialize(@name : String)
|
|
@bitfields = Array(BitfieldGenerator).new
|
|
@attributes = Array(AttributeGenerator).new
|
|
@repeats = Array(RepeatGenerator).new
|
|
@attributeafters = Array(AttributeAfterGenerator).new
|
|
end
|
|
|
|
def push(attr : AttributeGenerator)
|
|
attr.class_name = @name
|
|
@attributes.push(attr)
|
|
end
|
|
|
|
def push(bitf : BitfieldGenerator)
|
|
end
|
|
|
|
ECR.def_to_s "src/views/class.ecr"
|
|
end
|
|
|
|
class BitfieldGenerator
|
|
YAML.mapping(
|
|
class_name: String,
|
|
name: String,
|
|
out_type: String,
|
|
start: Int32,
|
|
size: Int32
|
|
)
|
|
|
|
def initialize(@name : String, @out_type : String, @start : Int32, @size : Int32)
|
|
@class_name = "no_class"
|
|
end
|
|
end
|
|
|
|
class AttributeGenerator
|
|
YAML.mapping(
|
|
class_name: String,
|
|
name: String,
|
|
out_type: String,
|
|
start: Int32
|
|
)
|
|
|
|
def initialize(@name : String, @out_type : String, @start : Int32)
|
|
@class_name = "no_class"
|
|
end
|
|
|
|
ECR.def_to_s "src/views/attribute.ecr"
|
|
end
|
|
|
|
class RepeatGenerator
|
|
YAML.mapping(
|
|
class_name: String,
|
|
name: String,
|
|
out_type: String,
|
|
start: Int32,
|
|
count_name: String
|
|
)
|
|
def initialize(@name : String, @out_type : String, @start : Int32, @count_name : String)
|
|
@class_name = "no_class"
|
|
end
|
|
end
|
|
|
|
class AttributeAfterGenerator
|
|
YAML.mapping(
|
|
class_name: String,
|
|
name: String,
|
|
out_type: String,
|
|
start: Int32,
|
|
after_name: String
|
|
)
|
|
def initialize(@name : String, @out_type : String, @start : Int32, @after_name : String)
|
|
@class_name = "no_class"
|
|
end
|
|
end
|
|
|
|
#v = ClassGenerator.new("record")
|
|
#v.push(AttributeGenerator.new("uuid", "std::array<unsigned char, 16>", 0))
|
|
#v.push(AttributeGenerator.new("x", "bitops::regulated<int>", 16))
|
|
#v.push(AttributeGenerator.new("y", "bitops::regulated<int>", 20))
|
|
#f = FileGenerator.new
|
|
#f.classes << v
|
|
#f.includes << "<array>"
|
|
#f.includes << "\"bitops.hpp\""
|
|
#puts f.to_s
|
|
File.open(ARGV[0]) do |file|
|
|
puts FileGenerator.from_yaml(file).to_s
|
|
end
|