1 module dpp2.translation.node; 2 3 4 import dpp.from; 5 6 7 // FIXME - all of the parameters should be const but `match` won't have it 8 9 10 string[] translate(from!"dpp2.sea.node".Node node) 11 @safe pure 12 { 13 import dpp2.sea.node; 14 import sumtype: match; 15 16 return node.match!( 17 translateStruct, 18 ); 19 } 20 21 22 string[] translateStruct(from!"dpp2.sea.node".Struct struct_) 23 @safe pure 24 { 25 import dpp2.sea.node: Node; 26 import std.algorithm: map; 27 import std.array: array, join; 28 29 string[] lines; 30 31 lines ~= "struct " ~ struct_.spelling; 32 lines ~= "{"; 33 34 lines ~= struct_ 35 .fields 36 .map!translateField 37 .join 38 ; 39 40 // FIXME 41 lines ~= struct_ 42 .structs 43 .map!(a => " static" ~ translateStruct(a).map!(l => " " ~ l).array) 44 .join("\n") 45 ; 46 47 lines ~= "}"; 48 49 return lines; 50 } 51 52 53 string[] translateField(from!"dpp2.sea.node".Field field) 54 @safe pure 55 { 56 import dpp2.translation.type: translate; 57 return [" " ~ translate(field.type) ~ " " ~ field.spelling ~ ";"]; 58 }