|
|
- 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),
- namespace: {
- type: String,
- nilable: true
- }
- )
-
- 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: {
- type: Array(BitfieldGenerator),
- nilable: true
- },
- attributes: {
- type: Array(AttributeGenerator),
- nilable: true
- },
- repeats: {
- type: Array(RepeatGenerator),
- nilable: true
- },
- attributeafters: {
- type: Array(AttributeAfterGenerator),
- nilable: true
- },
- size: {
- type: Int32,
- nilable: true
- }
- )
-
- def initialize(@name : String)
- @bitfields = Array(BitfieldGenerator).new
- @attributes = Array(AttributeGenerator).new
- @repeats = Array(RepeatGenerator).new
- @attributeafters = Array(AttributeAfterGenerator).new
- end
-
- ECR.def_to_s "src/views/class.ecr"
- end
-
- class BitfieldGenerator
- YAML.mapping(
- class_name: {
- type: String,
- default: "no_class"
- },
- name: String,
- out_type: String,
- start: Int32,
- mask: String
- )
-
- def initialize(@name : String, @out_type : String, @start : Int32, @mask : String)
- @class_name = "no_class"
- end
-
- ECR.def_to_s "src/views/bitfield_generator.ecr"
- end
-
- class AttributeGenerator
- YAML.mapping(
- class_name: {
- type: String,
- default: "no_class"
- },
- 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: {
- type: String,
- default: "no_class"
- },
- 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
-
- ECR.def_to_s "src/views/repeat.ecr"
- end
-
- class AttributeAfterGenerator
- YAML.mapping(
- class_name: {
- type: String,
- default: "no_class"
- },
- name: String,
- out_type: String,
- after_name: String
- )
- def initialize(@name : String, @out_type : String, @after_name : String)
- @class_name = "no_class"
- end
-
- ECR.def_to_s "src/views/attribute_after.ecr"
- end
-
- if(ARGV.size != 0)
- File.open(ARGV[0]) do |file|
- puts FileGenerator.from_yaml(file).to_s
- end
- else
- puts "Andrew code generator\n\tExpects a single YAML file as argument"
- end
|