diff --git a/ds_generator.anubis b/ds_generator.anubis new file mode 100644 index 0000000..f31cc74 --- /dev/null +++ b/ds_generator.anubis @@ -0,0 +1,33 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 22/01/2017 + * Time: 21:50 + * © Calexium + */ + + +read tools/basis.anubis +transmit types/densaku.anubis + +public type DS_Generator_API: + ds_api( + ((List(DS_Type), String) -> Maybe(One)) generate_type_files). + +public define Maybe(DS_Generator_API) + load_ds_generator + = + with file_name = "ds_gen.adm", + if (LoadAdm(DS_Generator_API))load_adm(file_name) is + { + file_not_found then print("File '"+file_name+"' not found.\n\n");failure, + read_error then print("Error reading file '"+file_name+"'.\n\n");failure, + timeout then print("Timeout when loading '"+file_name+"'.\n\n");failure, + file_damaged then print("File '"+file_name+"' is damaged.\n\n");failure, + bad_version(expected,found) then print("Secondary module '"+file_name+"' doesn't have the same\n"+ + " version ("+found+") as primary module ("+expected+").\n\n");failure, + wrong_type(expected,found) then print("Secondary module '"+file_name+"' has type:\n"+ + found+" while primary module expected:\n"+ + expected+"\n\n");failure, + ok(ds_gen_api) then println("Densaku generator loaded ");success(ds_gen_api) + }. diff --git a/types/densaku.anubis b/types/densaku.anubis new file mode 100644 index 0000000..908a777 --- /dev/null +++ b/types/densaku.anubis @@ -0,0 +1,11 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 22/01/2017 + * Time: 21:51 + * © Calexium + */ + + +transmit ds_message.anubis +transmit ds_types.anubis diff --git a/types/ds_message.anubis b/types/ds_message.anubis new file mode 100644 index 0000000..8dbb2aa --- /dev/null +++ b/types/ds_message.anubis @@ -0,0 +1,45 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 15/01/2017 + * Time: 23:45 + * © Calexium + */ + +transmit densaku_lib/types/ds_types.anubis + + +public type DS_Field: + field( + String field_name, + DS_Anubis_Type field_type, + DS_Comment comment + ). + +public type DS_Message: + ds_message( + Word32 what_code, //if what_code is not provided, it's considered as value 0 + String message_name, //if message_name is not provided, it's consired as empty "" + List(DS_Field) fields + ), + ds_message( + Word32 what_code, + String message_name, + DS_Anubis_Type from_type + ). + + ds_message(what(_HK_APP), from_type(ds_type("HK_App"))). //this is the same as below definition + + ds_message(what(_HK_APP), + [ + field(field_name("name"), field_type(string), comment("Name of the application")), + field(field_name("icon"), field_type(ds_type("HK_Icon")), comment("Icon description, contained in message id _HK_ICON")), + field(field_name("help"), field_type(ds_type("HK_Help_Text")), comment("Help string, contained in message id _HK_HELP_TEXT")), + field(field_name("tables"), field_type(ds_type("HK_Table")), list, comment("List of tables of that application contained in message id _HK_TABLE")) + ]). + +public define List(DS_Message) the_message_list = + [ + ds_message((Word32)0, "_HK_APP", ds_type("HK_App")) + ]. + diff --git a/types/ds_types.anubis b/types/ds_types.anubis new file mode 100644 index 0000000..a59eb99 --- /dev/null +++ b/types/ds_types.anubis @@ -0,0 +1,360 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 15/01/2017 + * Time: 23:44 + * © Calexium + */ + +read system/string.anubis +read tools/list.anubis +read tools/basis.anubis +read system/lists.anubis + +public type DS_Anubis_Type: + one, + bool, + int, + string, + float, + ds_type (String type_name), + extern_type (String type_name, String read). //external type. No need to check + +public type Bool_List: + none, + list. + +public type DS_Comment: + none, + comment(String comment). + +public type DS_Component: + component( + Bool_List list, //'list' if the component is a list, otherwise 'none' + DS_Anubis_Type anb_type, //Anubis type (primitive or user defined) + String name, //name of the component + DS_Comment comment // + ). + +public define DS_Component +/* Default constructor helper without Bool_List means 'none' +*/ + component + ( + DS_Anubis_Type anb_type, + String name, + DS_Comment comment + )= + component(none, anb_type, name, comment). + +public define DS_Component +/* Default constructor helper without Bool_List means 'none' +*/ + component + ( + Bool_List list, + DS_Anubis_Type anb_type, + String name + )= + component(list, anb_type, name, none). + +public define DS_Component +/* Default constructor helper without Bool_List means 'none' +*/ + component + ( + DS_Anubis_Type anb_type, + String name + )= + component(none, anb_type, name, none). + + +public type DS_Alternative: + //alternative as enumeration, + enum( + String alt_name, //Name of the alternative + DS_Comment comment + ), + //alternative + alternative( + String alt_name, //Name of the alternative + List(DS_Component) components //list of components of that alternative + ). + +public define DS_Alternative +/* enum without comment helper + */ + enum + ( + String alt_name + )= + enum(alt_name, none). + +public type DS_Type: + ds_type( + String type_name, + List(DS_Alternative) ds_alts + ). + +public type Extern_type: + extern(String type_name, String ext_read) +. + +define List(Extern_type) + extract_extern_type + ( + List(DS_Component) components, + List(Extern_type) so_far + )= + if components is + { + [] then so_far, + [h . t] then + since h is component(_b_list, _anb_type, _name, _comment), + if _anb_type is ds_type(_type_name) then + extract_extern_type( + t, append_once(so_far, extern(_type_name, "types/generated/"+to_lower(_type_name)+".anubis"))) + else if _anb_type is extern_type(_type_name, read_file) then + extract_extern_type( + t, append_once(so_far, extern(_type_name, read_file))) + else + extract_extern_type(t, so_far) + } +. + +define List(Extern_type) + extract_extern_type + ( + List(DS_Alternative) alt, + List(Extern_type) so_far + )= + if alt is + { + [] then so_far, + [h . t] then + if h is + { + enum(_ , _) then extract_extern_type(t, so_far) + alternative(_, components) then + extract_extern_type(t, extract_extern_type(components, so_far)) + } + } +. + +public define List(Extern_type) + get_all_extern_type + ( + DS_Type ds_type + )= + since ds_type is ds_type(_, ds_alternatives), + extract_extern_type(ds_alternatives, []) +. + + /******************* DUMP function *****************************/ + +public define String + dump + ( + DS_Anubis_Type anb_type + )= + if anb_type is + { + one then "One", + bool then "Bool", + int then "Int", + string then "String", + float then "Float", + ds_type(type_name) then type_name, + extern_type(type_name, read) then type_name, + } +. + +public define String + dump + ( + DS_Comment comment + )= + if comment is + { + none then "", + comment(_str) then "//"+_str + } +. + +public define String + dump_component_type + ( + DS_Component _component, + )= + since _component is component(b_list, anb_type, name, _comment), + if b_list is list then + "List("+dump(anb_type)+")" + else + dump(anb_type) +. + +public define String + dump + ( + List(DS_Component) components, + Bool first_time, + Int type_length, //type max length + Int name_length //name max length + )= + with prefix = "\n ", + if components is + { + [] then "\n )", + [h . t] then + since h is component(b_list, anb_type, name, _comment), + + with line = if b_list is list then + // <- TYPE -> <- NAME -> <- comment -> + prefix+fill("List("+dump(anb_type)+")",type_length) + fill(name+(if is_empty(t) then "" else ","), name_length) + dump(_comment) + else + prefix+fill(dump(anb_type), type_length) + fill(name+(if is_empty(t) then "" else ","), name_length) + dump(_comment), +// "\n type len "+type_length+" name len "+name_length + + line + dump(t, false, type_length, name_length) + } +. +define Int + alternative_name_max_length + ( + List(DS_Alternative) ds_alts, + Int current_length + )= + if ds_alts is + { + [] then current_length, + [h . t] then + with name = if h is + { + enum(name, _) then name, + alternative(name, _) then name + }, + alternative_name_max_length(t, max(current_length, length(name))) + } +. + +define Int + component_type_max_length + ( + List(DS_Component) components, + Int so_far_length + )= + if components is + { + [] then so_far_length, + [h . t] then + with str = dump_component_type(h), + length = length(str), + //println("string ["+str+"] size = "+length+" so_far = "+so_far_length); + component_type_max_length(t, max(so_far_length, length)) + } +. + +define Int + alternative_type_max_length + ( + List(DS_Alternative) ds_alts, + Int so_far_length + )= + if ds_alts is + { + [] then so_far_length, + [h . t] then + with current = if h is + { + enum(name, _) then length(name), + alternative(name, components) then component_type_max_length(components, 0) + }, + alternative_type_max_length(t, max(current, so_far_length)) + } +. + +define Int + component_name_max_length + ( + List(DS_Component) components, + Int so_far_length + )= + if components is + { + [] then so_far_length, + [h . t] then + since h is component(_, _, name, _), + with length = length(name), + //println("string ["+str+"] size = "+length+" so_far = "+so_far_length); + component_type_max_length(t, max(so_far_length, length)) + } +. + +define Int + alternative_type_name_max_length + ( + List(DS_Alternative) ds_alts, + Int so_far_length + )= + if ds_alts is + { + [] then so_far_length, + [h . t] then + with current = if h is + { + enum(_, _) then 0, + alternative(_, components) then component_name_max_length(components, 0) + }, + alternative_type_name_max_length(t, max(current, so_far_length)) + } +. + +public define String + dump_DS_Alternative_list + ( + List(DS_Alternative) ds_alts, + Int type_length, //max type length + Int alt_name_length, //max length of an alternative name + Int name_length //max length of the name of the type + )= + with prefix = "\n ", + if ds_alts is + { + [] then println("empty");"\n.\n", + [h . t] then + if h is + { + enum(name, _comment) then prefix + fill(name+(if is_empty(t) then "" else ","), type_length + name_length+2) + dump(_comment) + + dump_DS_Alternative_list(t, type_length, alt_name_length, name_length), + + alternative(name, components) then prefix + name+"("+ + dump(components, true, type_length, name_length)+(if is_empty(t) then "" else ",")+ + dump_DS_Alternative_list(t, type_length, alt_name_length, name_length) + } + } +. + +public define String + dump_DS_Type + ( + DS_Type _ds_type + )= + since _ds_type is ds_type(type_name, ds_alts), + with type_length = alternative_type_max_length(ds_alts,0)+2, + alt_name_length = alternative_name_max_length(ds_alts, 0), + type_name_length = alternative_type_name_max_length(ds_alts,0), + "public type "+type_name+":"+ + dump_DS_Alternative_list(ds_alts, type_length, alt_name_length, type_name_length) +. + +public define String + dump_DS_Type_list + ( + List(DS_Type) types + )= + if types is + { + [] then "", + [h . t] then "\n\n"+dump_DS_Type(h)+dump_DS_Type_list(t) + + } +. -- libgit2 0.21.4