1 module extra; 2 3 public import econf.econf; 4 public import econf.tokens; 5 import std.string; 6 import std.array; 7 import std.stdio : writeln; 8 import std.conv : to; 9 10 EToken[int] EConfInitArrays(EToken[int] toks_asnum) { 11 int j=0; 12 EToken[int] temptoks; 13 EToken[int] nulltoks; 14 EToken[int] oldtoks=toks_asnum; 15 EToken[int] newtoks; 16 EToken[int] arrays; 17 int h=0; 18 int z=0; 19 void addTempTok(EToken t) {temptoks[h]=t; h+=1;} 20 21 while(j<toks_asnum.length) { 22 if(toks_asnum[j].getType()==ETokenType.START_ARRAY) { 23 int num_of_array=j; 24 int b=j+1; 25 while(b<toks_asnum.length&&toks_asnum[b].getType()!=ETokenType.END_ARRAY) { 26 if(toks_asnum[b].getType()!=ETokenType.IDENTIFIER) { 27 addTempTok(toks_asnum[b]); 28 oldtoks.remove(b); 29 b+=1;} 30 else { 31 throw new StringException("Error: identifier in array \""~ 32 toks_asnum[b].getString()~"\"!"); 33 } 34 } 35 j=b; 36 arrays[z]=new EToken("[]"); 37 arrays[z].childs=temptoks; 38 temptoks=nulltoks; 39 h=0; 40 z+=1; 41 } 42 else j+=1; 43 } 44 j=0; 45 h=0; 46 z=0; 47 while(h<oldtoks.length) { 48 if(oldtoks[h].getType()!=ETokenType.START_ARRAY 49 &&oldtoks[h].getType()!=ETokenType.END_ARRAY) { 50 newtoks[j]=oldtoks[h]; 51 h+=1; 52 j+=1; 53 } 54 else if(oldtoks[h].getType()==ETokenType.END_ARRAY) { 55 h+=1; 56 } 57 else { 58 newtoks[j]=arrays[z]; 59 newtoks[j].childs=arrays[z].childs; 60 newtoks[j].childsToT(); 61 h+=1; 62 while(h !in oldtoks) {h+=1;} 63 j+=1; 64 z+=1; 65 } 66 } 67 return newtoks; 68 } 69 70 EToken[int] EConfInitObjects(EToken[int] toks_asnum) { 71 int j=0; 72 EToken[int] temptoks; 73 EToken[int] nulltoks; 74 EToken[int] oldtoks=toks_asnum.dup; 75 EToken[int] newtoks; 76 EToken[int] arrays; 77 int h=0; 78 int z=0; 79 void addTempTok(EToken t) {temptoks[h]=t; h+=1;} 80 81 while(j<toks_asnum.length) { 82 if(toks_asnum[j].getType()==ETokenType.START_OBJECT) { 83 int num_of_array=j; 84 int b=j+1; 85 b=j+1; 86 while(b<toks_asnum.length&&toks_asnum[b].getType()!=ETokenType.END_OBJECT) { 87 addTempTok(toks_asnum[b]); 88 oldtoks.remove(b); 89 b+=1; 90 } 91 j=b; 92 arrays[z]=new EToken("{}"); 93 arrays[z].childs=temptoks; 94 temptoks=nulltoks.dup; 95 h=0; 96 z+=1; 97 } 98 else j+=1; 99 } 100 j=0; 101 h=0; 102 z=0; 103 while(h<oldtoks.length) { 104 if(oldtoks[h].getType()!=ETokenType.START_OBJECT 105 &&oldtoks[h].getType()!=ETokenType.END_OBJECT) { 106 newtoks[j]=oldtoks[h]; 107 h+=1; 108 j+=1; 109 } 110 else if(oldtoks[h].getType()==ETokenType.END_OBJECT) { 111 h+=1; 112 } 113 else { 114 newtoks[j]=arrays[z]; 115 newtoks[j].childs=arrays[z].childs; 116 newtoks[j].childsToObj(); 117 h+=1; 118 while(h !in oldtoks) {h+=1;} 119 j+=1; 120 z+=1; 121 } 122 } 123 return newtoks; 124 }