From e9e428f9e1b995f3e56054401acea7f78c822b4d Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Tue, 22 Oct 2019 19:31:36 +0200 Subject: [PATCH] nilable class contents --- src/andrew.cr | 20 ++++++++++++++++---- src/views/class.ecr | 4 +++- tests/record.yml | 5 +---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/andrew.cr b/src/andrew.cr index 5f8c28c..45b8dc4 100644 --- a/src/andrew.cr +++ b/src/andrew.cr @@ -25,10 +25,22 @@ end class ClassGenerator YAML.mapping( name: String, - bitfields: Array(BitfieldGenerator), - attributes: Array(AttributeGenerator), - repeats: Array(RepeatGenerator), - attributeafters: Array(AttributeAfterGenerator) + bitfields: { + type: Array(BitfieldGenerator), + nilable: true + }, + attributes: { + type: Array(AttributeGenerator), + nilable: true + }, + repeats: { + type: Array(RepeatGenerator), + nilable: true + }, + attributeafters: { + type: Array(AttributeAfterGenerator), + nilable: true + } ) def initialize(@name : String) diff --git a/src/views/class.ecr b/src/views/class.ecr index c45b4e0..626e068 100644 --- a/src/views/class.ecr +++ b/src/views/class.ecr @@ -1,9 +1,11 @@ class <%= @name %> { virtual <%= @name %>() = 0; -<%- @attributes.each do |attr| -%> +<% if !(@attributes.nil?) %> +<%- @attributes.not_nil!.each do |attr| -%> <%= attr.to_s %> <%- end -%> +<% end %> }; diff --git a/tests/record.yml b/tests/record.yml index e1fd38b..264d5b1 100644 --- a/tests/record.yml +++ b/tests/record.yml @@ -45,7 +45,4 @@ classes: name: flags out_type: bitops::regulated start: 40 - class_name: record - bitfields: [] - repeats: [] - attributeafters: [] \ No newline at end of file + class_name: record \ No newline at end of file