Commit 7e96578325b591652558fe6bdc0364f830f186e3

Authored by totoro
0 parents

first commit

ds_generator.anubis 0 → 100644
  1 +++ a/ds_generator.anubis
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 22/01/2017
  5 + * Time: 21:50
  6 + * © Calexium
  7 + */
  8 +
  9 +
  10 +read tools/basis.anubis
  11 +transmit types/densaku.anubis
  12 +
  13 +public type DS_Generator_API:
  14 + ds_api(
  15 + ((List(DS_Type), String) -> Maybe(One)) generate_type_files).
  16 +
  17 +public define Maybe(DS_Generator_API)
  18 + load_ds_generator
  19 + =
  20 + with file_name = "ds_gen.adm",
  21 + if (LoadAdm(DS_Generator_API))load_adm(file_name) is
  22 + {
  23 + file_not_found then print("File '"+file_name+"' not found.\n\n");failure,
  24 + read_error then print("Error reading file '"+file_name+"'.\n\n");failure,
  25 + timeout then print("Timeout when loading '"+file_name+"'.\n\n");failure,
  26 + file_damaged then print("File '"+file_name+"' is damaged.\n\n");failure,
  27 + bad_version(expected,found) then print("Secondary module '"+file_name+"' doesn't have the same\n"+
  28 + " version ("+found+") as primary module ("+expected+").\n\n");failure,
  29 + wrong_type(expected,found) then print("Secondary module '"+file_name+"' has type:\n"+
  30 + found+" while primary module expected:\n"+
  31 + expected+"\n\n");failure,
  32 + ok(ds_gen_api) then println("Densaku generator loaded ");success(ds_gen_api)
  33 + }.
... ...
types/densaku.anubis 0 → 100644
  1 +++ a/types/densaku.anubis
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 22/01/2017
  5 + * Time: 21:51
  6 + * © Calexium
  7 + */
  8 +
  9 +
  10 +transmit ds_message.anubis
  11 +transmit ds_types.anubis
... ...
types/ds_message.anubis 0 → 100644
  1 +++ a/types/ds_message.anubis
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 15/01/2017
  5 + * Time: 23:45
  6 + * © Calexium
  7 + */
  8 +
  9 +transmit densaku_lib/types/ds_types.anubis
  10 +
  11 +
  12 +public type DS_Field:
  13 + field(
  14 + String field_name,
  15 + DS_Anubis_Type field_type,
  16 + DS_Comment comment
  17 + ).
  18 +
  19 +public type DS_Message:
  20 + ds_message(
  21 + Word32 what_code, //if what_code is not provided, it's considered as value 0
  22 + String message_name, //if message_name is not provided, it's consired as empty ""
  23 + List(DS_Field) fields
  24 + ),
  25 + ds_message(
  26 + Word32 what_code,
  27 + String message_name,
  28 + DS_Anubis_Type from_type
  29 + ).
  30 +
  31 + ds_message(what(_HK_APP), from_type(ds_type("HK_App"))). //this is the same as below definition
  32 +
  33 + ds_message(what(_HK_APP),
  34 + [
  35 + field(field_name("name"), field_type(string), comment("Name of the application")),
  36 + field(field_name("icon"), field_type(ds_type("HK_Icon")), comment("Icon description, contained in message id _HK_ICON")),
  37 + field(field_name("help"), field_type(ds_type("HK_Help_Text")), comment("Help string, contained in message id _HK_HELP_TEXT")),
  38 + field(field_name("tables"), field_type(ds_type("HK_Table")), list, comment("List of tables of that application contained in message id _HK_TABLE"))
  39 + ]).
  40 +
  41 +public define List(DS_Message) the_message_list =
  42 + [
  43 + ds_message((Word32)0, "_HK_APP", ds_type("HK_App"))
  44 + ].
  45 +
... ...
types/ds_types.anubis 0 → 100644
  1 +++ a/types/ds_types.anubis
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 15/01/2017
  5 + * Time: 23:44
  6 + * © Calexium
  7 + */
  8 +
  9 +read system/string.anubis
  10 +read tools/list.anubis
  11 +read tools/basis.anubis
  12 +read system/lists.anubis
  13 +
  14 +public type DS_Anubis_Type:
  15 + one,
  16 + bool,
  17 + int,
  18 + string,
  19 + float,
  20 + ds_type (String type_name),
  21 + extern_type (String type_name, String read). //external type. No need to check
  22 +
  23 +public type Bool_List:
  24 + none,
  25 + list.
  26 +
  27 +public type DS_Comment:
  28 + none,
  29 + comment(String comment).
  30 +
  31 +public type DS_Component:
  32 + component(
  33 + Bool_List list, //'list' if the component is a list, otherwise 'none'
  34 + DS_Anubis_Type anb_type, //Anubis type (primitive or user defined)
  35 + String name, //name of the component
  36 + DS_Comment comment //
  37 + ).
  38 +
  39 +public define DS_Component
  40 +/* Default constructor helper without Bool_List means 'none'
  41 +*/
  42 + component
  43 + (
  44 + DS_Anubis_Type anb_type,
  45 + String name,
  46 + DS_Comment comment
  47 + )=
  48 + component(none, anb_type, name, comment).
  49 +
  50 +public define DS_Component
  51 +/* Default constructor helper without Bool_List means 'none'
  52 +*/
  53 + component
  54 + (
  55 + Bool_List list,
  56 + DS_Anubis_Type anb_type,
  57 + String name
  58 + )=
  59 + component(list, anb_type, name, none).
  60 +
  61 +public define DS_Component
  62 +/* Default constructor helper without Bool_List means 'none'
  63 +*/
  64 + component
  65 + (
  66 + DS_Anubis_Type anb_type,
  67 + String name
  68 + )=
  69 + component(none, anb_type, name, none).
  70 +
  71 +
  72 +public type DS_Alternative:
  73 + //alternative as enumeration,
  74 + enum(
  75 + String alt_name, //Name of the alternative
  76 + DS_Comment comment
  77 + ),
  78 + //alternative
  79 + alternative(
  80 + String alt_name, //Name of the alternative
  81 + List(DS_Component) components //list of components of that alternative
  82 + ).
  83 +
  84 +public define DS_Alternative
  85 +/* enum without comment helper
  86 + */
  87 + enum
  88 + (
  89 + String alt_name
  90 + )=
  91 + enum(alt_name, none).
  92 +
  93 +public type DS_Type:
  94 + ds_type(
  95 + String type_name,
  96 + List(DS_Alternative) ds_alts
  97 + ).
  98 +
  99 +public type Extern_type:
  100 + extern(String type_name, String ext_read)
  101 +.
  102 +
  103 +define List(Extern_type)
  104 + extract_extern_type
  105 + (
  106 + List(DS_Component) components,
  107 + List(Extern_type) so_far
  108 + )=
  109 + if components is
  110 + {
  111 + [] then so_far,
  112 + [h . t] then
  113 + since h is component(_b_list, _anb_type, _name, _comment),
  114 + if _anb_type is ds_type(_type_name) then
  115 + extract_extern_type(
  116 + t, append_once(so_far, extern(_type_name, "types/generated/"+to_lower(_type_name)+".anubis")))
  117 + else if _anb_type is extern_type(_type_name, read_file) then
  118 + extract_extern_type(
  119 + t, append_once(so_far, extern(_type_name, read_file)))
  120 + else
  121 + extract_extern_type(t, so_far)
  122 + }
  123 +.
  124 +
  125 +define List(Extern_type)
  126 + extract_extern_type
  127 + (
  128 + List(DS_Alternative) alt,
  129 + List(Extern_type) so_far
  130 + )=
  131 + if alt is
  132 + {
  133 + [] then so_far,
  134 + [h . t] then
  135 + if h is
  136 + {
  137 + enum(_ , _) then extract_extern_type(t, so_far)
  138 + alternative(_, components) then
  139 + extract_extern_type(t, extract_extern_type(components, so_far))
  140 + }
  141 + }
  142 +.
  143 +
  144 +public define List(Extern_type)
  145 + get_all_extern_type
  146 + (
  147 + DS_Type ds_type
  148 + )=
  149 + since ds_type is ds_type(_, ds_alternatives),
  150 + extract_extern_type(ds_alternatives, [])
  151 +.
  152 +
  153 + /******************* DUMP function *****************************/
  154 +
  155 +public define String
  156 + dump
  157 + (
  158 + DS_Anubis_Type anb_type
  159 + )=
  160 + if anb_type is
  161 + {
  162 + one then "One",
  163 + bool then "Bool",
  164 + int then "Int",
  165 + string then "String",
  166 + float then "Float",
  167 + ds_type(type_name) then type_name,
  168 + extern_type(type_name, read) then type_name,
  169 + }
  170 +.
  171 +
  172 +public define String
  173 + dump
  174 + (
  175 + DS_Comment comment
  176 + )=
  177 + if comment is
  178 + {
  179 + none then "",
  180 + comment(_str) then "//"+_str
  181 + }
  182 +.
  183 +
  184 +public define String
  185 + dump_component_type
  186 + (
  187 + DS_Component _component,
  188 + )=
  189 + since _component is component(b_list, anb_type, name, _comment),
  190 + if b_list is list then
  191 + "List("+dump(anb_type)+")"
  192 + else
  193 + dump(anb_type)
  194 +.
  195 +
  196 +public define String
  197 + dump
  198 + (
  199 + List(DS_Component) components,
  200 + Bool first_time,
  201 + Int type_length, //type max length
  202 + Int name_length //name max length
  203 + )=
  204 + with prefix = "\n ",
  205 + if components is
  206 + {
  207 + [] then "\n )",
  208 + [h . t] then
  209 + since h is component(b_list, anb_type, name, _comment),
  210 +
  211 + with line = if b_list is list then
  212 + // <- TYPE -> <- NAME -> <- comment ->
  213 + prefix+fill("List("+dump(anb_type)+")",type_length) + fill(name+(if is_empty(t) then "" else ","), name_length) + dump(_comment)
  214 + else
  215 + prefix+fill(dump(anb_type), type_length) + fill(name+(if is_empty(t) then "" else ","), name_length) + dump(_comment),
  216 +// "\n type len "+type_length+" name len "+name_length +
  217 + line + dump(t, false, type_length, name_length)
  218 + }
  219 +.
  220 +define Int
  221 + alternative_name_max_length
  222 + (
  223 + List(DS_Alternative) ds_alts,
  224 + Int current_length
  225 + )=
  226 + if ds_alts is
  227 + {
  228 + [] then current_length,
  229 + [h . t] then
  230 + with name = if h is
  231 + {
  232 + enum(name, _) then name,
  233 + alternative(name, _) then name
  234 + },
  235 + alternative_name_max_length(t, max(current_length, length(name)))
  236 + }
  237 +.
  238 +
  239 +define Int
  240 + component_type_max_length
  241 + (
  242 + List(DS_Component) components,
  243 + Int so_far_length
  244 + )=
  245 + if components is
  246 + {
  247 + [] then so_far_length,
  248 + [h . t] then
  249 + with str = dump_component_type(h),
  250 + length = length(str),
  251 + //println("string ["+str+"] size = "+length+" so_far = "+so_far_length);
  252 + component_type_max_length(t, max(so_far_length, length))
  253 + }
  254 +.
  255 +
  256 +define Int
  257 + alternative_type_max_length
  258 + (
  259 + List(DS_Alternative) ds_alts,
  260 + Int so_far_length
  261 + )=
  262 + if ds_alts is
  263 + {
  264 + [] then so_far_length,
  265 + [h . t] then
  266 + with current = if h is
  267 + {
  268 + enum(name, _) then length(name),
  269 + alternative(name, components) then component_type_max_length(components, 0)
  270 + },
  271 + alternative_type_max_length(t, max(current, so_far_length))
  272 + }
  273 +.
  274 +
  275 +define Int
  276 + component_name_max_length
  277 + (
  278 + List(DS_Component) components,
  279 + Int so_far_length
  280 + )=
  281 + if components is
  282 + {
  283 + [] then so_far_length,
  284 + [h . t] then
  285 + since h is component(_, _, name, _),
  286 + with length = length(name),
  287 + //println("string ["+str+"] size = "+length+" so_far = "+so_far_length);
  288 + component_type_max_length(t, max(so_far_length, length))
  289 + }
  290 +.
  291 +
  292 +define Int
  293 + alternative_type_name_max_length
  294 + (
  295 + List(DS_Alternative) ds_alts,
  296 + Int so_far_length
  297 + )=
  298 + if ds_alts is
  299 + {
  300 + [] then so_far_length,
  301 + [h . t] then
  302 + with current = if h is
  303 + {
  304 + enum(_, _) then 0,
  305 + alternative(_, components) then component_name_max_length(components, 0)
  306 + },
  307 + alternative_type_name_max_length(t, max(current, so_far_length))
  308 + }
  309 +.
  310 +
  311 +public define String
  312 + dump_DS_Alternative_list
  313 + (
  314 + List(DS_Alternative) ds_alts,
  315 + Int type_length, //max type length
  316 + Int alt_name_length, //max length of an alternative name
  317 + Int name_length //max length of the name of the type
  318 + )=
  319 + with prefix = "\n ",
  320 + if ds_alts is
  321 + {
  322 + [] then println("empty");"\n.\n",
  323 + [h . t] then
  324 + if h is
  325 + {
  326 + enum(name, _comment) then prefix + fill(name+(if is_empty(t) then "" else ","), type_length + name_length+2) + dump(_comment) +
  327 + dump_DS_Alternative_list(t, type_length, alt_name_length, name_length),
  328 +
  329 + alternative(name, components) then prefix + name+"("+
  330 + dump(components, true, type_length, name_length)+(if is_empty(t) then "" else ",")+
  331 + dump_DS_Alternative_list(t, type_length, alt_name_length, name_length)
  332 + }
  333 + }
  334 +.
  335 +
  336 +public define String
  337 + dump_DS_Type
  338 + (
  339 + DS_Type _ds_type
  340 + )=
  341 + since _ds_type is ds_type(type_name, ds_alts),
  342 + with type_length = alternative_type_max_length(ds_alts,0)+2,
  343 + alt_name_length = alternative_name_max_length(ds_alts, 0),
  344 + type_name_length = alternative_type_name_max_length(ds_alts,0),
  345 + "public type "+type_name+":"+
  346 + dump_DS_Alternative_list(ds_alts, type_length, alt_name_length, type_name_length)
  347 +.
  348 +
  349 +public define String
  350 + dump_DS_Type_list
  351 + (
  352 + List(DS_Type) types
  353 + )=
  354 + if types is
  355 + {
  356 + [] then "",
  357 + [h . t] then "\n\n"+dump_DS_Type(h)+dump_DS_Type_list(t)
  358 +
  359 + }
  360 +.
... ...