Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 323
Functions: -% 0 / 1 / 1
Branches: 0.0% 0 / 0 / 92

OMCompiler/Compiler/Template/TplMain.mo
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 encapsulated package TplMain
37 "
38 file: TplMain.mo
39 package: TplMain
40 description: Susan Main Module
41
42 $Id$
43
44 This is the main module of Susan language.
45 It only calls the other parts of the compiler
46 and contains some tests for basic parts of Susan.
47 "
48
49 protected import Debug;
50 protected import Flags;
51 protected import FlagsUtil;
52 protected import Print;
53 protected import System;
54 protected import Error;
55
56 public import Tpl;
57 public import TplParser;
58 public import TplAbsyn;
59 public import TplCodegen;
60
61 protected
62 constant Tpl.Text emptyTxt = Tpl.emptyTxt;
63 constant SourceInfo dsi = TplAbsyn.dummySourceInfo;
64
65 public function main
66 input String inFile;
67 input String inOutputDir = "";
68 input String inInterfaceDir = "";
69
70 algorithm
71 ✗ if inInterfaceDir <> "" then
72 ✗ FlagsUtil.setConfigString(Flags.TPL_INTERFACE_DIR, inInterfaceDir);
73 end if;
74 () := match inFile
75 local
76 String file, strErrBuf;
77
78 case "SusanTest.tpl"
79 algorithm
80 ✗ tplMainTest("a");
81 then ();
82
83 case file
84 algorithm
85 ✗ Print.clearBuf();
86 ✗ translateFile(file, inOutputDir);
87 ✗ strErrBuf := Print.getErrorString();
88 ✗ strErrBuf := if strErrBuf == "" then "" else ("### Error Buffer ###\n"+strErrBuf+"\n### End of Error Buffer ###\n");
89 ✗ print(strErrBuf);
90 then ();
91
92 end match;
93 end main;
94
95
96 public function transformFile
97 "Parses and elaborates a template for Susan's Rust backend. Fails when that
98 adds an error."
99 input String inFile;
100 input String inInterfaceDir = "";
101 output TplAbsyn.TemplPackage outTplPackage;
102 output TplAbsyn.MMPackage outMMPackage;
103 protected
104 Integer nErrors;
105 algorithm
106 ✗ if inInterfaceDir <> "" then
107 ✗ FlagsUtil.setConfigString(Flags.TPL_INTERFACE_DIR, inInterfaceDir);
108 end if;
109 ✗ nErrors := Error.getNumErrorMessages();
110 ✗ outTplPackage := TplParser.templPackageFromFile(inFile);
111 ✗ outMMPackage := TplAbsyn.transformAST(outTplPackage);
112 ✗ outTplPackage := TplAbsyn.fullyQualifyTemplatePackage(outTplPackage);
113 ✗ true := nErrors == Error.getNumErrorMessages();
114 end transformFile;
115
116 public function translateFile
117 input String inFile;
118 input String inOutputDir = "";
119
120 algorithm
121 () := matchcontinue inFile
122 local
123 String file, destFile, res;
124 Tpl.Text txt;
125 TplAbsyn.TemplPackage tplPackage;
126 TplAbsyn.MMPackage mmPckg;
127 Integer nErrors;
128 Boolean wasError;
129
130 case file
131 algorithm
132 ✗ print("\nProcessing file '" + file + "'\n");
133 ✗ nErrors := Error.getNumErrorMessages();
134
135 ✗ destFile := System.stringReplace(file + "*", ".tpl*", ".mo");
136 ✗ false := stringEq(file, destFile);
137 ✗ if inOutputDir <> "" then
138 ✗ destFile := inOutputDir + "/" + System.basename(destFile);
139 end if;
140
141 //print(destFile);
142 ✗ tplPackage := TplParser.templPackageFromFile(file);
143
144 ✗ mmPckg := TplAbsyn.transformAST(tplPackage);
145 txt := emptyTxt;
146 ✗ txt := TplCodegen.mmPackage(txt, mmPckg);
147 //res = "/* generated on " + System.getCurrentTimeStr() + "*/\n" + Tpl.textString(txt);
148 ✗ res := Tpl.textString(txt);
149 ✗ wasError := nErrors < Error.getNumErrorMessages();
150 //prevent overriding the previously generated .mo without errors
151 ✗ destFile := destFile + (if wasError then ".err.mo" else "");
152 ✗ print("\nWriting result to file '" + destFile + "'\n");
153
154 ✗ System.writeFile(destFile, res);
155 //print("\nReamining characters:\n" + stringCharListString(chars) + "\n<<");
156 //Error.addMessage(Error.INTERNAL_ERROR, {"Pokus"});
157 //fail when a new error
158 ✗ false := wasError;
159 then ();
160
161 case file
162 algorithm
163 ✗ print("\n### translation of file '"+ file + "' failed! ###\n" );
164 ✗ print("### Error Buffer ###\n");
165 ✗ print(Print.getErrorString());
166 ✗ print("\n### End of Error Buffer ###\n");
167 ✗ Print.clearErrorBuf();
168 ✗ then fail();
169
170 end matchcontinue;
171 end translateFile;
172
173
174 // ********** Tests ****************
175
176
177
178 public function testStringEquality
179 input String inStringReturned;
180 input String inStringShouldBe;
181 input Boolean inPrintResult;
182 input Boolean inPrintErrorBuffer;
183 input String inTestLabel;
184 input Integer inNotPassedCnt;
185
186 output Integer outNotPassedCnt;
187 algorithm
188 outNotPassedCnt := matchcontinue (inStringReturned, inStringShouldBe, inPrintResult, inPrintErrorBuffer, inTestLabel, inNotPassedCnt)
189 local
190 // Tpl.Tokens toks, txttoks;
191 String strRet, strShouldBe, strLabel, strRes, strErrBuf;
192 Boolean printResult, printErrBuf;
193 Integer notPassedCnt;
194
195 case ( strRet, strShouldBe, printResult, printErrBuf, strLabel, notPassedCnt)
196 algorithm
197 ✗ true := stringEq(strRet, strShouldBe);
198 ✗ print("\n**************************************************\n" + strLabel);
199
200 ✗ strRes := if printResult then (" returned <<\n" + strRet + ">>\n") else "\n result not shown \n";
201 ✗ print(strRes);
202
203 ✗ strErrBuf := Print.getErrorString();
204 ✗ strErrBuf := if strErrBuf == "" then "" else
205 (if printErrBuf then ("### Error Buffer ###\n"+strErrBuf+"\n### End of Error Buffer ###\n") else
206 "### Error Buffer is NOT empty - not shown ###\n");
207 ✗ print(strErrBuf);
208 ✗ print("*** OK ***\n");
209 ✗ Print.clearErrorBuf();
210 then
211 notPassedCnt;
212
213 case ( strRet, strShouldBe, printResult,printErrBuf, strLabel, notPassedCnt)
214 algorithm
215 ✗ false := stringEq(strRet, strShouldBe);
216 ✗ print("\n##################################################\n"
217 + strLabel );
218
219 ✗ strRes := if printResult then
220 (" returned <<\n" + strRet + ">>\nshould be <<\n" + strShouldBe + ">>\n")
221 else "\n result not shown \n";
222 ✗ print(strRes);
223
224 ✗ strErrBuf := Print.getErrorString();
225 ✗ strErrBuf := if strErrBuf == "" then "" else
226 (if printErrBuf then ("### Error Buffer ###\n"+strErrBuf+"\n### End of Error Buffer ###\n") else
227 "### Error Buffer is NOT empty - not shown ###\n");
228 ✗ print(strErrBuf);
229
230 ✗ print("### NOT Passed ###\n");
231 ✗ Print.clearErrorBuf();
232 ✗ then
233 (notPassedCnt + 1);
234
235 //should not ever happen
236 else
237 algorithm
238 ✗ true := Flags.isSet(Flags.FAILTRACE); Debug.trace("-!!!Tpl.tplMainTest failed.\n");
239 ✗ then
240 fail();
241 end matchcontinue;
242 end testStringEquality;
243
244
245 public function testTranslateTplFile
246 input String inFile;
247 input Boolean inPrintResult;
248 input Boolean inPrintErrorBuffer;
249 input Integer inNotPassedCnt;
250
251 output Integer outNotPassedCnt;
252 algorithm
253 outNotPassedCnt := matchcontinue (inFile, inPrintResult, inPrintErrorBuffer, inNotPassedCnt)
254 local
255 String file, res, resToBe;
256 Boolean printRes, printErrBuf;
257 Integer notPassedCnt;
258
259 case ( file, printRes, printErrBuf, notPassedCnt)
260 algorithm
261 ✗ System.writeFile(file + ".mo", "Test failed.");
262 ✗ translateFile(file + ".tpl");
263 ✗ res := System.stringReplace(System.readFile(file + ".mo"), intStringChar(13), "");
264 ✗ resToBe := System.stringReplace(System.readFile(file + "__testShouldBe.mo"), intStringChar(13), "");
265 ✗ notPassedCnt := testStringEquality(res,resToBe, printRes, printErrBuf,
266 "translateFile "+ file + ".tpl", notPassedCnt);
267 then notPassedCnt;
268
269 //failed
270 case ( file, printRes, printErrBuf, notPassedCnt)
271 algorithm
272 ✗ System.writeFile(file + ".mo", "Test failed.");
273 //failure( translateFile(file + ".tpl") );
274 ✗ res := System.stringReplace(System.readFile(file + ".mo"), intStringChar(13), "");
275 ✗ resToBe := System.stringReplace(System.readFile(file + "__testShouldBe.mo"), intStringChar(13), "");
276 ✗ notPassedCnt := testStringEquality(res,resToBe, printRes, printErrBuf,
277 "translateFile "+ file + ".tpl", notPassedCnt);
278 then notPassedCnt;
279
280 end matchcontinue;
281 end testTranslateTplFile;
282
283
284
285 public function tplMainTest
286 input String inFile;
287 algorithm
288
289 () := match inFile
290 local
291 //Tpl.Tokens toks, txttoks;
292 String str, strOut, ident, cval;
293 list<String> chars;
294 Tpl.Text txt;
295 Boolean tequal;
296 TplAbsyn.TemplPackage tplPackage;
297 TplAbsyn.MMPackage mmPckg;
298 TplAbsyn.PathIdent pid;
299 TplAbsyn.TypeSignature ts;
300 list<TplAbsyn.ASTDef> astDefs;
301 TplAbsyn.ExpressionBase expB;
302 Tpl.StringToken tok;
303 Real tstart;
304 Integer lnum,colnum, llen, notPassedCnt;
305 case "a"
306 algorithm
307 notPassedCnt := 0;
308 ✗ Print.clearErrorBuf();
309 ✗ print("\n A Test:\n" );
310 ✗ tstart := clock();
311
312 //*************
313 ✗ txt := Tpl.writeStr(emptyTxt, "Ahoj Susan");
314 //txt = newLine(txt);
315 ✗ txt := Tpl.pushBlock(txt,Tpl.BT_ANCHOR(0));
316 ✗ txt := Tpl.writeStr(txt, "Ahoj Susan");
317 ✗ txt := Tpl.newLine(txt);
318 ✗ txt := Tpl.writeStr(txt, "Ahoj Susan");
319 ✗ txt := Tpl.popBlock(txt);
320 ✗ str := Tpl.textString(txt);
321 ✗ notPassedCnt := testStringEquality(str,
322 "Ahoj SusanAhoj Susan
323 Ahoj Susan", true, true, "Anchor", notPassedCnt);
324
325 //*************
326 txt := emptyTxt;
327 ✗ txt := TplCodegen.pathIdent(txt, TplAbsyn.IDENT("Susan"));
328 ✗ str := Tpl.textString(txt);
329 ✗ notPassedCnt := testStringEquality(str,
330 "Susan", true, true, "PathIdent IDENT", notPassedCnt);
331
332 //*************
333 txt := emptyTxt;
334 ✗ txt := TplCodegen.pathIdent(txt, TplAbsyn.PATH_IDENT("Hej", TplAbsyn.IDENT("Susan")));
335 ✗ str := Tpl.textString(txt);
336 ✗ notPassedCnt := testStringEquality(str,
337 "Hej.Susan", true, true, "PathIdent PATH_IDENT", notPassedCnt);
338
339 //*************
340 txt := emptyTxt;
341 ✗ txt := TplCodegen.typedIdents(txt, {
342 ("Hej", TplAbsyn.TEXT_TYPE()),
343 ("Susan", TplAbsyn.LIST_TYPE(TplAbsyn.NAMED_TYPE(TplAbsyn.PATH_IDENT("Pa",TplAbsyn.IDENT("Li")))))} );
344 ✗ str := Tpl.textString(txt);
345 ✗ notPassedCnt := testStringEquality(str,
346 "Tpl.Text Hej;
347 list<Pa.Li> Susan;", true, true, "typedIdents", notPassedCnt);
348
349 //*************
350 txt := emptyTxt;
351 ✗ txt := TplCodegen.typedIdentsEx(txt, {
352 ("Hej", TplAbsyn.TEXT_TYPE()),
353 ("Susan", TplAbsyn.NAMED_TYPE(TplAbsyn.PATH_IDENT("Pa",TplAbsyn.IDENT("Li"))))},
354 "input","in" );
355 ✗ str := Tpl.textString(txt);
356 ✗ notPassedCnt := testStringEquality(str,
357 "input Tpl.Text inHej;
358 input Pa.Li inSusan;", true, true, "typedIdentsEx", notPassedCnt);
359
360 //*************
361 txt := emptyTxt;
362 ✗ txt := TplCodegen.mmPackage(txt,
363 TplAbsyn.MM_PACKAGE(
364 TplAbsyn.IDENT("Susan"),
365 {
366 TplAbsyn.MM_IMPORT(true, TplAbsyn.PATH_IDENT("Pa",TplAbsyn.PATH_IDENT("Li",TplAbsyn.IDENT("Ko"))))
367 ,TplAbsyn.MM_STR_TOKEN_DECL(true, "strTokConst", Tpl.ST_STRING_LIST({"Susan","is","beautiful\n"},true))
368 ,TplAbsyn.MM_LITERAL_DECL(false, "c_literalValueConst", "123", TplAbsyn.INTEGER_TYPE())
369 ,TplAbsyn.MM_FUN(true,"MuchFun",
370 { ("txt",TplAbsyn.TEXT_TYPE()), ("laughLevel",TplAbsyn.INTEGER_TYPE()), ("jokes",TplAbsyn.LIST_TYPE(TplAbsyn.STRING_TYPE())) },
371 { ("txt",TplAbsyn.TEXT_TYPE()) },
372 { ("txt",TplAbsyn.TEXT_TYPE()), ("laughLevel",TplAbsyn.INTEGER_TYPE()), ("jokes",TplAbsyn.LIST_TYPE(TplAbsyn.STRING_TYPE())) },
373 {
374 TplAbsyn.MM_ASSIGN({"out_txt"},
375 TplAbsyn.MM_FN_CALL(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("writeStr")),
376 { TplAbsyn.MM_IDENT(TplAbsyn.IDENT("txt")),
377 TplAbsyn.MM_STRING("Susan")
378 } )),
379 TplAbsyn.MM_ASSIGN({"out_txt"},
380 TplAbsyn.MM_FN_CALL(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("writeTok")),
381 { TplAbsyn.MM_IDENT(TplAbsyn.IDENT("out_txt")),
382 TplAbsyn.MM_STR_TOKEN(Tpl.ST_LINE("Susan is cosmic!\n"))
383 } ))
384 },
385 TplAbsyn.GI_TEMPL_FUN()
386
387 )
388 ,TplAbsyn.MM_FUN(true,"MoreFun",
389 { ("txt",TplAbsyn.TEXT_TYPE()),
390 ("v_laughLevel",TplAbsyn.OPTION_TYPE(TplAbsyn.STRING_TYPE())),
391 ("v_jokes",TplAbsyn.LIST_TYPE(TplAbsyn.STRING_TYPE())) },
392 { ("txt",TplAbsyn.TEXT_TYPE()) },
393 { ("txt",TplAbsyn.TEXT_TYPE()) },
394 {
395 TplAbsyn.MM_MATCH({
396 ({ TplAbsyn.BIND_MATCH("txt"),
397 TplAbsyn.SOME_MATCH(TplAbsyn.BIND_AS_MATCH("v_hej",TplAbsyn.STRING_MATCH("Hej"))),
398 TplAbsyn.BIND_MATCH("v_jokes")
399 },
400 //{ ("v_hej",TplAbsyn.STRING_TYPE()),
401 // ("v_jokes",TplAbsyn.LIST_TYPE(TplAbsyn.STRING_TYPE()))
402 //},
403 {
404 TplAbsyn.MM_ASSIGN({"txt"},
405 TplAbsyn.MM_FN_CALL(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("writeStr")),
406 { TplAbsyn.MM_IDENT(TplAbsyn.IDENT("txt")),
407 TplAbsyn.MM_IDENT(TplAbsyn.IDENT("v_hej"))
408 } ))
409 }),
410 ({ TplAbsyn.BIND_MATCH("txt"),
411 TplAbsyn.SOME_MATCH(TplAbsyn.BIND_MATCH("v_hej")),
412 TplAbsyn.REST_MATCH()
413 },
414 //{ ("v_hej",TplAbsyn.STRING_TYPE())
415 //},
416 {
417 TplAbsyn.MM_ASSIGN({"txt"},
418 TplAbsyn.MM_FN_CALL(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("writeStr")),
419 { TplAbsyn.MM_IDENT(TplAbsyn.IDENT("txt")),
420 TplAbsyn.MM_STRING("Not hej:")
421 } )),
422 TplAbsyn.MM_ASSIGN({"txt"},
423 TplAbsyn.MM_FN_CALL(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("writeStr")),
424 { TplAbsyn.MM_IDENT(TplAbsyn.IDENT("txt")),
425 TplAbsyn.MM_IDENT(TplAbsyn.IDENT("v_hej"))
426 } ))
427 }),
428 ({ TplAbsyn.BIND_MATCH("txt"),
429 TplAbsyn.NONE_MATCH(),
430 TplAbsyn.REST_MATCH()
431 },
432 //{ },
433 {
434 TplAbsyn.MM_ASSIGN({"txt"},
435 TplAbsyn.MM_FN_CALL(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("writeStr")),
436 { TplAbsyn.MM_IDENT(TplAbsyn.IDENT("txt")),
437 TplAbsyn.MM_STRING("NONE at all")
438 } ))
439 })
440 })
441 },
442 TplAbsyn.GI_TEMPL_FUN()
443 )
444 },
445 ""
446 )
447 );
448 ✗ str := Tpl.textString(txt);
449 ✗ notPassedCnt := testStringEquality(str,
450 "package Susan
451
452 public import Tpl;
453
454 public import Pa.Li.Ko;
455
456 public constant Tpl.StringToken strTokConst = Tpl.ST_STRING_LIST({
457 \"Susan\",
458 \"is\",
459 \"beautiful\\n\"
460 }, true);
461
462 protected constant Integer c_literalValueConst = 123;
463
464 public function MuchFun
465 input Tpl.Text txt;
466 input Integer laughLevel;
467 input list<String> jokes;
468
469 output Tpl.Text out_txt;
470 algorithm
471 out_txt := Tpl.writeStr(txt, \"Susan\");
472 out_txt := Tpl.writeTok(out_txt, Tpl.ST_LINE(\"Susan is cosmic!\\n\"));
473 end MuchFun;
474
475 public function MoreFun
476 input Tpl.Text in_txt;
477 input Option<String> in_v_laughLevel;
478 input list<String> in_v_jokes;
479
480 output Tpl.Text out_txt;
481 algorithm
482 out_txt :=
483 matchcontinue(in_txt, in_v_laughLevel, in_v_jokes)
484 local
485 Tpl.Text txt;
486
487 case ( txt,
488 SOME((v_hej as \"Hej\")),
489 v_jokes )
490 local
491 String v_hej;
492 list<String> v_jokes;
493 algorithm
494 txt = Tpl.writeStr(txt, v_hej);
495 then txt;
496
497 case ( txt,
498 SOME(v_hej),
499 _ )
500 local
501 String v_hej;
502 algorithm
503 txt = Tpl.writeStr(txt, \"Not hej:\");
504 txt = Tpl.writeStr(txt, v_hej);
505 then txt;
506
507 case ( txt,
508 NONE(),
509 _ )
510 algorithm
511 txt = Tpl.writeStr(txt, \"NONE at all\");
512 then txt;
513 end matchcontinue;
514 end MoreFun;
515
516 end Susan;", false, false, "mmPackage", notPassedCnt);
517
518
519
520 //*************
521 /*
522 type Ident = String;
523 type TypedIdents = list<tuple<Ident, PathIdent>>;
524
525 uniontype PathIdent
526 record IDENT
527 Ident ident;
528 end IDENT;
529
530 record PATH_IDENT
531 Ident ident;
532 PathIdent path;
533 end PATH_IDENT;
534 end PathIdent;
535
536 pathIdent(PathIdent) <>=
537 case IDENT then ident
538 case PATH_IDENT then ident &'.'& pathIdent(path) //"<ident>.<pathIdent(path)>"
539
540 typedIdents(TypedIdents decls) <>=
541 <decls of (id,pid) :
542 "<pathIdent(pid)> <id>;"
543 \n
544 >
545
546 */
547 tplPackage := TplAbsyn.TEMPL_PACKAGE(
548 TplAbsyn.IDENT("Susan"),
549 { TplAbsyn.AST_DEF(TplAbsyn.IDENT("TplAbsyn"), true, true,
550 { ("Ident", TplAbsyn.TI_ALIAS_TYPE(TplAbsyn.STRING_TYPE())),
551 ("TypedIdents", TplAbsyn.TI_ALIAS_TYPE(TplAbsyn.LIST_TYPE(TplAbsyn.TUPLE_TYPE({TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("Ident")), TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("PathIdent"))})))),
552 ("PathIdent", TplAbsyn.TI_UNION_TYPE({
553 ("IDENT",{("ident", TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("Ident")))}),
554 ("PATH_IDENT",{ ("ident", TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("Ident"))),
555 ("path", TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("PathIdent"))) })
556 }) )
557 } )
558 },
559 { ("pathIdent", TplAbsyn.TEMPLATE_DEF({("it",TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("PathIdent")))}, "", "",
560 (TplAbsyn.MATCH((TplAbsyn.BOUND_VALUE(TplAbsyn.IDENT("it")),dsi) ,
561 { (TplAbsyn.RECORD_MATCH(TplAbsyn.IDENT("IDENT"),{}), (TplAbsyn.BOUND_VALUE(TplAbsyn.IDENT("ident")),dsi) ),
562 (TplAbsyn.RECORD_MATCH(TplAbsyn.IDENT("PATH_IDENT"),{}),
563 (TplAbsyn.TEMPLATE({
564 (TplAbsyn.BOUND_VALUE(TplAbsyn.IDENT("ident")),dsi),
565 (TplAbsyn.STR_TOKEN(Tpl.ST_STRING(".")),dsi),
566 (TplAbsyn.FUN_CALL(TplAbsyn.IDENT("pathIdent"), {(TplAbsyn.BOUND_VALUE(TplAbsyn.IDENT("path")),dsi)}),dsi)
567 },"\"","\""),dsi) )
568 }
569 ),dsi)
570 )
571 ),
572 ("typedIdents", TplAbsyn.TEMPLATE_DEF({("decls",TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("TypedIdents")))}, "", "",
573 (TplAbsyn.ESCAPED(
574 (TplAbsyn.MAP(
575 (TplAbsyn.BOUND_VALUE(TplAbsyn.IDENT("decls")),dsi),
576 TplAbsyn.TUPLE_MATCH({TplAbsyn.BIND_MATCH("id"), TplAbsyn.BIND_MATCH("pid")}),
577 (TplAbsyn.TEMPLATE({
578 (TplAbsyn.FUN_CALL(TplAbsyn.IDENT("pathIdent"), {(TplAbsyn.BOUND_VALUE(TplAbsyn.IDENT("pid")),dsi)}),dsi),
579 (TplAbsyn.STR_TOKEN(Tpl.ST_STRING(" ")),dsi),
580 (TplAbsyn.BOUND_VALUE(TplAbsyn.IDENT("id")),dsi),
581 (TplAbsyn.STR_TOKEN(Tpl.ST_STRING(";")),dsi)
582 },"\"","\""
583 ),dsi),
584 NONE()
585 ),dsi),
586 { ("separator", SOME((TplAbsyn.STR_TOKEN(Tpl.ST_NEW_LINE()),dsi) ))
587 }
588 ),dsi)
589 )
590 )
591
592 },
593 ""
594 );
595 ✗ mmPckg := TplAbsyn.transformAST(tplPackage);
596 txt := emptyTxt;
597 ✗ txt := TplCodegen.mmPackage(txt, mmPckg);
598 ✗ str := Tpl.textString(txt);
599 ✗ notPassedCnt := testStringEquality(str,
600 "package Susan
601
602 public import Tpl;
603
604 public import TplAbsyn;
605
606 public function pathIdent
607 input Tpl.Text in_txt;
608 input TplAbsyn.PathIdent in_i_it;
609
610 output Tpl.Text out_txt;
611 algorithm
612 out_txt :=
613 matchcontinue(in_txt, in_i_it)
614 local
615 Tpl.Text txt;
616
617 case ( txt,
618 TplAbsyn.IDENT(ident = i_ident) )
619 local
620 TplAbsyn.Ident i_ident;
621 algorithm
622 txt = Tpl.writeStr(txt, i_ident);
623 then txt;
624
625 case ( txt,
626 TplAbsyn.PATH_IDENT(ident = i_ident, path = i_path) )
627 local
628 TplAbsyn.PathIdent i_path;
629 TplAbsyn.Ident i_ident;
630 algorithm
631 txt = Tpl.writeStr(txt, i_ident);
632 txt = Tpl.writeTok(txt, Tpl.ST_STRING(\".\"));
633 txt = pathIdent(txt, i_path);
634 then txt;
635
636 else in_txt;
637 end matchcontinue;
638 end pathIdent;
639
640 protected function lm_2
641 input Tpl.Text in_txt;
642 input TplAbsyn.TypedIdents in_items;
643
644 output Tpl.Text out_txt;
645 algorithm
646 out_txt :=
647 matchcontinue(in_txt, in_items)
648 local
649 Tpl.Text txt;
650
651 case ( txt,
652 {} )
653 then txt;
654
655 case ( txt,
656 (i_id, i_pid) :: rest )
657 local
658 TplAbsyn.TypedIdents rest;
659 TplAbsyn.PathIdent i_pid;
660 TplAbsyn.Ident i_id;
661 algorithm
662 txt = pathIdent(txt, i_pid);
663 txt = Tpl.writeTok(txt, Tpl.ST_STRING(\" \"));
664 txt = Tpl.writeStr(txt, i_id);
665 txt = Tpl.writeTok(txt, Tpl.ST_STRING(\";\"));
666 txt = Tpl.nextIter(txt);
667 txt = lm_2(txt, rest);
668 then txt;
669
670 case ( txt,
671 _ :: rest )
672 local
673 TplAbsyn.TypedIdents rest;
674 algorithm
675 txt = lm_2(txt, rest);
676 then txt;
677 end matchcontinue;
678 end lm_2;
679
680 public function typedIdents
681 input Tpl.Text txt;
682 input TplAbsyn.TypedIdents i_decls;
683
684 output Tpl.Text out_txt;
685 algorithm
686 out_txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE()));
687 out_txt := lm_2(out_txt, i_decls);
688 out_txt := Tpl.popIter(out_txt);
689 end typedIdents;
690
691 end Susan;", false, false, "transformAST - pathIdent() + typedIdents()", notPassedCnt);
692
693 //*************
694 str := "// Hej Susan
695 /*this is another dance with Susan */
696 /* event I will /*nest*/ into */ //and still comment
697 Susan lives!";
698 ✗ chars := stringListStringChar( str );
699
700 ✗ (chars, _) := TplParser.interleave(chars, TplParser.makeStartLineInfo(chars, "in memory test"));
701 ✗ strOut := stringCharListString(chars);
702 ✗ notPassedCnt := testStringEquality(strOut,
703 "Susan lives!", true, true, "TplParser.interleave \n\""+ str +"\"\n", notPassedCnt);
704
705 //*************
706 str := "(Susan)";
707 ✗ chars := stringListStringChar( str );
708
709 ✗ TplParser.afterKeyword(chars); //not fail
710 ✗ strOut := stringCharListString(chars);
711 ✗ notPassedCnt := testStringEquality(strOut,
712 "(Susan)", true, true, "TplParser.afterKeyword \n\""+ str +"\"\n", notPassedCnt);
713
714 //*************
715 str := "Susan2:)";
716 ✗ chars := stringListStringChar( str );
717
718 ✗ (chars, ident) := TplParser.identifier(chars);
719 ✗ strOut := "*" + ident + "*" + stringCharListString(chars);
720 ✗ notPassedCnt := testStringEquality(strOut,
721 "*Susan2*:)", true, true, "TplParser.identifier \n\""+ str +"\"\n", notPassedCnt);
722
723 //*************
724 str := "Susan:)";
725 ✗ chars := stringListStringChar( str );
726
727 ✗ (chars,_, pid) := TplParser.pathIdent(chars, TplParser.makeStartLineInfo(chars, "in memory test"));
728 txt := emptyTxt;
729 ✗ txt := TplCodegen.pathIdent(txt, pid);
730 ✗ ident := Tpl.textString(txt);
731 ✗ strOut := "*" + ident + "*" + stringCharListString(chars);
732 ✗ notPassedCnt := testStringEquality(strOut,
733 "*Susan*:)", true, true, "TplParser.pathIdent \n\""+ str +"\"\n", notPassedCnt);
734
735 //*************
736 str := "Susan./*comment*/ Susan2 . tpl3_h4:)";
737 ✗ chars := stringListStringChar( str );
738
739 ✗ (chars,_, pid) := TplParser.pathIdent(chars, TplParser.makeStartLineInfo(chars, "in memory test"));
740 txt := emptyTxt;
741 ✗ txt := TplCodegen.pathIdent(txt, pid);
742 ✗ ident := Tpl.textString(txt);
743 ✗ strOut := "*" + ident + "*" + stringCharListString(chars);
744 ✗ notPassedCnt := testStringEquality(strOut,
745 "*Susan.Susan2.tpl3_h4*:)", true, true, "TplParser.pathIdent \n\""+ str +"\"\n", notPassedCnt);
746
747 //*************
748 str := "Tpl.Susan:)";
749 ✗ chars := stringListStringChar( str );
750
751 ✗ (chars,_, ts) := TplParser.typeSig(chars, TplParser.makeStartLineInfo(chars, "in memory test"));
752 ✗ tequal := valueEq(ts, TplAbsyn.NAMED_TYPE(TplAbsyn.PATH_IDENT("Tpl", TplAbsyn.IDENT("Susan"))));
753 txt := emptyTxt;
754 ✗ txt := TplCodegen.typeSig(txt, ts);
755 ✗ ident := Tpl.textString(txt);
756 ✗ strOut := Tpl.booleanString(tequal) + "*" + ident + "*" + stringCharListString(chars);
757 ✗ notPassedCnt := testStringEquality(strOut,
758 "true*Tpl.Susan*:)", true, true, "TplParser.typeSig \n\""+ str +"\"\n", notPassedCnt);
759
760 //*************
761 str := "list< tuple<Hej.Susan,list <String>,Option< /*uáá*/Integer>> >:)";
762 ✗ chars := stringListStringChar( str );
763
764 ✗ (chars,_, ts) := TplParser.typeSig(chars, TplParser.makeStartLineInfo(chars, "in memory test"));
765 ✗ tequal := valueEq(ts, TplAbsyn.LIST_TYPE(TplAbsyn.TUPLE_TYPE({
766 TplAbsyn.NAMED_TYPE(TplAbsyn.PATH_IDENT("Hej", TplAbsyn.IDENT("Susan"))),
767 TplAbsyn.LIST_TYPE(TplAbsyn.STRING_TYPE()),
768 TplAbsyn.OPTION_TYPE(TplAbsyn.INTEGER_TYPE())})));
769 txt := emptyTxt;
770 ✗ txt := TplCodegen.typeSig(txt, ts);
771 ✗ ident := Tpl.textString(txt);
772 ✗ strOut := Tpl.booleanString(tequal) +"*" + ident + "*" + stringCharListString(chars);
773 ✗ notPassedCnt := testStringEquality(strOut,
774 "true*list<tuple<Hej.Susan, list<String>, Option<Integer>>>*:)", true, true, "TplParser.typeSig \n\""+ str +"\"\n", notPassedCnt);
775
776 //*************
777 str := "
778 interface package Susan
779 package TplAbsyn
780 type Ident = String;
781 type TypedIdents = list<tuple<Ident, PathIdent>>;
782
783 uniontype PathIdent
784 record IDENT
785 Ident ident;
786 end IDENT;
787
788 record PATH_IDENT
789 Ident ident;
790 PathIdent path;
791 end PATH_IDENT;
792 end PathIdent;
793 end TplAbsyn;
794 end Susan;:)";
795 ✗ chars := stringListStringChar( str );
796
797 ✗ (chars,_, pid, astDefs) := TplParser.interfacePackage(chars, TplParser.makeStartLineInfo(chars, "in memory test"),{});
798 /*{ TplAbsyn.AST_DEF(TplAbsyn.IDENT("TplAbsyn"), true, types) } = astDefs;
799 (("Ident", TplAbsyn.TI_ALIAS_TYPE(TplAbsyn.STRING_TYPE()))
800 :: ("TypedIdents", TplAbsyn.TI_ALIAS_TYPE(TplAbsyn.LIST_TYPE(TplAbsyn.TUPLE_TYPE({TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("Ident")), TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("PathIdent"))}))))
801 :: ("PathIdent", TplAbsyn.TI_UNION_TYPE({
802 ("IDENT",{("ident", TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("Ident")))}),
803 ("PATH_IDENT",{ ("ident", TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("Ident"))),
804 ("path", TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("PathIdent"))) })
805 }) )
806 ::_) = types;*/
807
808 ✗ tequal := valueEq(astDefs,
809 { TplAbsyn.AST_DEF(TplAbsyn.IDENT("TplAbsyn"), true, true,
810 { ("Ident", TplAbsyn.TI_ALIAS_TYPE(TplAbsyn.STRING_TYPE())),
811 ("TypedIdents", TplAbsyn.TI_ALIAS_TYPE(TplAbsyn.LIST_TYPE(TplAbsyn.TUPLE_TYPE({TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("Ident")), TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("PathIdent"))})))),
812 ("PathIdent", TplAbsyn.TI_UNION_TYPE({
813 ("IDENT",{("ident", TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("Ident")))}),
814 ("PATH_IDENT",{ ("ident", TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("Ident"))),
815 ("path", TplAbsyn.NAMED_TYPE(TplAbsyn.IDENT("PathIdent"))) })
816 }) )
817 } )
818 });
819
820 txt := emptyTxt;
821 ✗ txt := TplCodegen.pathIdent(txt, pid);
822 ✗ ident := Tpl.textString(txt);
823 ✗ strOut := Tpl.booleanString(tequal) +"*" + ident + "*" + stringCharListString(chars);
824 ✗ notPassedCnt := testStringEquality(strOut,
825 "true*Susan*:)", true, true, "TplParser.templPackage - absyn - type Ident, TypedIdents, PathIdent \n", notPassedCnt);
826
827
828 //*************
829 str := "
830 interface package Susan
831 package builtin
832 function stringListStringChar
833 input String inString;
834 output list<String> outStringList;
835 end stringListStringChar;
836 end builtin;
837 end Susan;:)";
838 ✗ chars := stringListStringChar( str );
839
840 ✗ (chars,_, pid, astDefs) := TplParser.interfacePackage(chars, TplParser.makeStartLineInfo(chars, "in memory test"),{});
841
842 ✗ tequal := valueEq(astDefs,
843 { TplAbsyn.AST_DEF(TplAbsyn.IDENT("builtin"), true, true,
844 { ("stringListStringChar",
845 TplAbsyn.TI_FUN_TYPE(
846 { ("inString", TplAbsyn.STRING_TYPE()) },
847 { ("outStringList", TplAbsyn.LIST_TYPE(TplAbsyn.STRING_TYPE())) },
848 {} )
849 )
850 } )
851 } )
852 and valueEq(pid, TplAbsyn.IDENT("Susan"));
853
854 txt := emptyTxt;
855 ✗ txt := TplCodegen.pathIdent(txt, pid);
856 ✗ Tpl.textString(txt);
857 ✗ strOut := Tpl.booleanString(tequal) +"*" + stringCharListString(chars);
858 ✗ notPassedCnt := testStringEquality(strOut,
859 "true*:)", true, true, "TplParser.templPackage - function stringListStringChar\n", notPassedCnt);
860
861
862 //*************
863 str := "
864 interface package Susan
865 package builtin
866 function stringListStringChar
867 input String inString;
868 output list<String> outStringList;
869 end stringListStringChar;
870 end builtin;
871
872
873 protected package Tpl
874 uniontype StringToken
875 record ST_NEW_LINE \"Always outputs the new-line char.\" end ST_NEW_LINE;
876
877 record ST_STRING \"A string without new-lines in it.\"
878 String value;
879 end ST_STRING;
880
881 record ST_LINE \"A (non-empty) string with new-line at the end.\"
882 String line;
883 end ST_LINE;
884
885 record ST_STRING_LIST \"Every string in the list can have a new-line at its end (but does not have to).\"
886 list<String> strList;
887 Boolean lastHasNewLine \"True when the last string in the list has new-line at the end.\";
888 end ST_STRING_LIST;
889 end StringToken;
890 end Tpl;
891
892
893 package TplAbsyn
894 type Ident = String;
895 type TypedIdents = list<tuple<Ident, TypeSignature>>;
896 type StringToken = Tpl.StringToken;
897
898 uniontype PathIdent
899 record IDENT
900 Ident ident;
901 end IDENT;
902
903 record PATH_IDENT
904 Ident ident;
905 PathIdent path;
906 end PATH_IDENT;
907 end PathIdent;
908
909 uniontype TypeSignature
910 record LIST_TYPE
911 TypeSignature ofType;
912 end LIST_TYPE;
913
914 record ARRAY_TYPE // one-dimensional arrays --> with only (safe) list behaviour
915 TypeSignature ofType;
916 end ARRAY_TYPE;
917
918 record OPTION_TYPE
919 TypeSignature ofType;
920 end OPTION_TYPE;
921
922 record TUPLE_TYPE
923 list<TypeSignature> ofTypes;
924 end TUPLE_TYPE;
925
926 record NAMED_TYPE \"key/path to a TypeInfo list from an AST definition\"
927 PathIdent name;
928 end NAMED_TYPE;
929
930 record STRING_TYPE end STRING_TYPE;
931 record TEXT_TYPE end TEXT_TYPE;
932 record STRING_TOKEN_TYPE \"Used only for internal string constants.\" end STRING_TOKEN_TYPE;
933
934 record INTEGER_TYPE end INTEGER_TYPE;
935 record REAL_TYPE end REAL_TYPE;
936 record BOOLEAN_TYPE end BOOLEAN_TYPE;
937
938 record UNRESOLVED_TYPE \"Errorneous resolving type. Only used during elaboration phase.\"
939 String reason;
940 end UNRESOLVED_TYPE;
941 end TypeSignature;
942
943
944 uniontype MatchingExp
945 record BIND_AS_MATCH
946 Ident bindIdent;
947 MatchingExp matchingExp;
948 end BIND_AS_MATCH;
949
950 record BIND_MATCH
951 Ident bindIdent;
952 end BIND_MATCH;
953
954 record RECORD_MATCH
955 PathIdent tagName;
956 list<tuple<Ident, MatchingExp>> fieldMatchings;
957 end RECORD_MATCH;
958
959 record SOME_MATCH
960 MatchingExp value;
961 end SOME_MATCH;
962
963 record NONE_MATCH end NONE_MATCH;
964
965 record TUPLE_MATCH
966 list<MatchingExp> tupleArgs;
967 end TUPLE_MATCH;
968
969 record LIST_MATCH //non-empty list
970 list<MatchingExp> listElts;
971 end LIST_MATCH;
972
973 record LIST_CONS_MATCH
974 MatchingExp head;
975 MatchingExp rest;
976 end LIST_CONS_MATCH;
977
978 record STRING_MATCH
979 String value;
980 end STRING_MATCH;
981
982 record LITERAL_MATCH
983 String value;
984 TypeSignature litType; // only INTEGER_TYPE, REAL_TYPE or BOOLEAN_TYPE
985 end LITERAL_MATCH;
986
987 record REST_MATCH end REST_MATCH;
988 end MatchingExp;
989
990
991 // **** the (core) output AST
992
993 uniontype MMPackage
994 record MM_PACKAGE
995 PathIdent name;
996 list<MMDeclaration> mmDeclarations;
997 end MM_PACKAGE;
998 end MMPackage;
999
1000 type MMMatchCase = tuple<list<MatchingExp>, TypedIdents, list<MMExp>>;
1001
1002 uniontype MMDeclaration
1003 record MM_IMPORT
1004 Boolean isPublic;
1005 PathIdent packageName;
1006 end MM_IMPORT;
1007
1008 record MM_STR_TOKEN_DECL
1009 Boolean isPublic;
1010 Ident name;
1011 StringToken value;
1012 end MM_STR_TOKEN_DECL;
1013
1014 record MM_LITERAL_DECL
1015 Boolean isPublic;
1016 Ident name;
1017 String value;
1018 TypeSignature litType;
1019 end MM_LITERAL_DECL;
1020
1021
1022 record MM_FUN
1023 Boolean isPublic;
1024 Ident name;
1025 TypedIdents inArgs; //inTxt inclusive
1026 TypedIdents outArgs; // outTxt + extra Texts
1027 TypedIdents locals;
1028 list<MMExp> statements;
1029 end MM_FUN;
1030 end MMDeclaration;
1031
1032 uniontype MMExp
1033 record MM_ASSIGN
1034 list<Ident> lhsArgs;
1035 MMExp rhs;
1036 end MM_ASSIGN;
1037
1038 record MM_FN_CALL
1039 PathIdent fnName;
1040 list<MMExp> args;
1041 end MM_FN_CALL;
1042
1043 record MM_IDENT
1044 PathIdent ident;
1045 end MM_IDENT;
1046
1047 record MM_STR_TOKEN \"constructor of type StringToken\"
1048 StringToken value;
1049 end MM_STR_TOKEN;
1050
1051 record MM_STRING \"to pass a string constant as parameter of type String\"
1052 String value;
1053 end MM_STRING;
1054
1055 record MM_LITERAL \"to pass a literal constant as parameter of type Integer, Real or Boolean\"
1056 String value;
1057 end MM_LITERAL;
1058
1059 record MM_MATCH
1060 list<MMMatchCase> matchCases;
1061 end MM_MATCH;
1062 end MMExp;
1063 end TplAbsyn;
1064 end Susan;:)";
1065 ✗ chars := stringListStringChar( str );
1066
1067 ✗ (chars,_, pid,_) := TplParser.interfacePackage(chars, TplParser.makeStartLineInfo(chars, "in memory test"),{});
1068
1069 txt := emptyTxt;
1070 ✗ txt := TplCodegen.pathIdent(txt, pid);
1071 ✗ Tpl.textString(txt);
1072 ✗ strOut := "parsed*" + stringCharListString(chars);
1073 ✗ notPassedCnt := testStringEquality(strOut,
1074 "parsed*:)", true, true, "TplParser.templPackage - all types for Susan's backend\n", notPassedCnt);
1075
1076 //*************
1077 str := "\"Susan\"~:)";
1078 ✗ chars := stringListStringChar( str );
1079
1080 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1081
1082 ✗ tequal := valueEq(
1083 expB,
1084 TplAbsyn.STR_TOKEN(Tpl.ST_STRING("Susan"))
1085 );
1086
1087 ✗ TplAbsyn.STR_TOKEN(tok) := expB;
1088 txt := emptyTxt;
1089 ✗ txt := Tpl.writeTok(txt, tok);
1090 ✗ strOut := Tpl.textString(txt);
1091 ✗ strOut := Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1092 ✗ notPassedCnt := testStringEquality(strOut,
1093 "true*Susan*~:)", true, true, "TplParser.expression \n>"+ str +"<\n", notPassedCnt);
1094
1095 //*************
1096 str := "\"\\n\"~:)";
1097 ✗ chars := stringListStringChar( str );
1098
1099 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1100
1101 ✗ tequal := valueEq(
1102 expB,
1103 TplAbsyn.STR_TOKEN(Tpl.ST_NEW_LINE())
1104 );
1105
1106 ✗ TplAbsyn.STR_TOKEN(tok) := expB;
1107 //Tpl.ST_STRING_LIST({"\n",""},false) = tok;
1108 txt := emptyTxt;
1109 ✗ txt := Tpl.writeTok(txt, tok);
1110 ✗ strOut := Tpl.textString(txt);
1111 ✗ strOut := Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1112 ✗ notPassedCnt := testStringEquality(strOut,
1113 "true*\n*~:)", true, true, "TplParser.expression \n>"+ str +"<\n", notPassedCnt);
1114
1115 //*************
1116 str := "\",\\n\"~:)";
1117 ✗ chars := stringListStringChar( str );
1118
1119 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1120
1121 ✗ tequal := valueEq(
1122 expB,
1123 TplAbsyn.STR_TOKEN(Tpl.ST_LINE(",\n"))
1124 );
1125
1126 ✗ TplAbsyn.STR_TOKEN(tok) := expB;
1127 //Tpl.ST_STRING_LIST({"\n",""},false) = tok;
1128 txt := emptyTxt;
1129 ✗ txt := Tpl.writeTok(txt, tok);
1130 ✗ strOut := Tpl.textString(txt);
1131 ✗ strOut := Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1132 ✗ notPassedCnt := testStringEquality(strOut,
1133 "true*,\n*~:)", true, true, "TplParser.expression \n>"+ str +"<\n", notPassedCnt);
1134
1135 //*************
1136 str := "\"Susan
1137 is\\nfantastic!\"~:)";
1138 ✗ chars := stringListStringChar( str );
1139
1140 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1141
1142 ✗ tequal := valueEq(
1143 expB,
1144 TplAbsyn.STR_TOKEN(Tpl.ST_STRING_LIST({"Susan\n", "is\n", "fantastic!"}, false))
1145 );
1146
1147 ✗ TplAbsyn.STR_TOKEN(tok) := expB;
1148 txt := emptyTxt;
1149 ✗ txt := Tpl.writeTok(txt, tok);
1150 ✗ strOut := Tpl.textString(txt);
1151 ✗ strOut := Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1152 ✗ notPassedCnt := testStringEquality(strOut,
1153 "true*Susan\nis\nfantastic!*~:)", true, true, "TplParser.expression \n>"+ str +"<\n", notPassedCnt);
1154
1155 //*************
1156 str := "\"
1157 Susan
1158 is\\n new lined!
1159 \"~:)";
1160 ✗ chars := stringListStringChar( str );
1161
1162 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1163
1164 ✗ tequal := valueEq(
1165 expB,
1166 TplAbsyn.STR_TOKEN(Tpl.ST_STRING_LIST({"\n","Susan\n", "is\n", " new lined!\n"}, true))
1167 );
1168
1169 ✗ TplAbsyn.STR_TOKEN(tok) := expB;
1170 txt := emptyTxt;
1171 ✗ txt := Tpl.writeTok(txt, tok);
1172 ✗ strOut := Tpl.textString(txt);
1173 ✗ strOut := Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1174 ✗ notPassedCnt := testStringEquality(strOut,
1175 "true*\nSusan\nis\n new lined!\n*~:)", true, true, "TplParser.expression \n>"+ str +"<\n", notPassedCnt);
1176
1177 //*************
1178 /*
1179 str = "%(Susan)%~:)";
1180 chars = stringListStringChar( str );
1181
1182 (chars,_, exp) = TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1183
1184 tequal = valueEq(
1185 exp,
1186 TplAbsyn.STR_TOKEN(Tpl.ST_STRING("Susan"))
1187 );
1188
1189 TplAbsyn.STR_TOKEN(tok) = exp;
1190 txt = emptyTxt;
1191 txt = Tpl.writeTok(txt, tok);
1192 strOut = Tpl.textString(txt);
1193 strOut = Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1194 notPassedCnt = testStringEquality(strOut,
1195 "true*Susan*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1196 */
1197 //*************
1198 /*
1199 str = "%/
1200 Susan
1201 is\\n verbatim!
1202 /%~:)";
1203 chars = stringListStringChar( str );
1204
1205 (chars,_, exp) = TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1206
1207 tequal = valueEq(
1208 exp,
1209 TplAbsyn.STR_TOKEN(Tpl.ST_STRING_LIST({"Susan\n", "is\\n verbatim!"}, false))
1210 );
1211
1212 TplAbsyn.STR_TOKEN(tok) = exp;
1213 txt = emptyTxt;
1214 txt = Tpl.writeTok(txt, tok);
1215 strOut = Tpl.textString(txt);
1216 strOut = Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1217 notPassedCnt = testStringEquality(strOut,
1218 "true*Susan\nis\\n verbatim!*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1219 */
1220 //*************
1221 str := "1234567~:)";
1222 ✗ chars := stringListStringChar( str );
1223
1224 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1225
1226 ✗ tequal := valueEq(
1227 expB,
1228 TplAbsyn.LITERAL("1234567", TplAbsyn.INTEGER_TYPE())
1229 );
1230
1231 ✗ TplAbsyn.LITERAL(cval,_) := expB;
1232 ✗ strOut := Tpl.booleanString(tequal) + "*" + cval + "*" + stringCharListString(chars);
1233 ✗ notPassedCnt := testStringEquality(strOut,
1234 "true*1234567*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1235
1236 //*************
1237 str := "- 1234567~:)";
1238 ✗ chars := stringListStringChar( str );
1239
1240 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1241
1242 ✗ tequal := valueEq(
1243 expB,
1244 TplAbsyn.LITERAL("-1234567", TplAbsyn.INTEGER_TYPE())
1245 );
1246
1247 ✗ TplAbsyn.LITERAL(cval,_) := expB;
1248 ✗ strOut := Tpl.booleanString(tequal) + "*" + cval + "*" + stringCharListString(chars);
1249 ✗ notPassedCnt := testStringEquality(strOut,
1250 "true*-1234567*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1251
1252 //*************
1253 str := "- 1234567.0123e-12~:)";
1254 ✗ chars := stringListStringChar( str );
1255
1256 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1257
1258 ✗ tequal := valueEq(
1259 expB,
1260 TplAbsyn.LITERAL("-1234567.0123e-12", TplAbsyn.REAL_TYPE())
1261 );
1262
1263 ✗ TplAbsyn.LITERAL(cval,_) := expB;
1264 ✗ strOut := Tpl.booleanString(tequal) + "*" + cval + "*" + stringCharListString(chars);
1265 ✗ notPassedCnt := testStringEquality(strOut,
1266 "true*-1234567.0123e-12*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1267
1268 //*************
1269 str := ".0123E12~:)";
1270 ✗ chars := stringListStringChar( str );
1271
1272 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1273
1274 ✗ tequal := valueEq(
1275 expB,
1276 TplAbsyn.LITERAL(".0123E12", TplAbsyn.REAL_TYPE())
1277 );
1278
1279 ✗ TplAbsyn.LITERAL(cval,_) := expB;
1280 ✗ strOut := Tpl.booleanString(tequal) + "*" + cval + "*" + stringCharListString(chars);
1281 ✗ notPassedCnt := testStringEquality(strOut,
1282 "true*.0123E12*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1283
1284 //*************
1285 str := "true~:)";
1286 ✗ chars := stringListStringChar( str );
1287
1288 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1289
1290 ✗ tequal := valueEq(
1291 expB,
1292 TplAbsyn.LITERAL("true", TplAbsyn.BOOLEAN_TYPE())
1293 );
1294
1295 ✗ TplAbsyn.LITERAL(cval,_) := expB;
1296 ✗ strOut := Tpl.booleanString(tequal) + "*" + cval + "*" + stringCharListString(chars);
1297 ✗ notPassedCnt := testStringEquality(strOut,
1298 "true*true*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1299
1300 //*************
1301 str := "false~:)";
1302 ✗ chars := stringListStringChar( str );
1303
1304 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1305
1306 ✗ tequal := valueEq(
1307 expB,
1308 TplAbsyn.LITERAL("false", TplAbsyn.BOOLEAN_TYPE())
1309 );
1310
1311 ✗ TplAbsyn.LITERAL(cval,_) := expB;
1312 ✗ strOut := Tpl.booleanString(tequal) + "*" + cval + "*" + stringCharListString(chars);
1313 ✗ notPassedCnt := testStringEquality(strOut,
1314 "true*false*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1315
1316 //*************
1317 str := "\\n~:)";
1318 ✗ chars := stringListStringChar( str );
1319
1320 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1321
1322 ✗ tequal := valueEq(
1323 expB,
1324 TplAbsyn.STR_TOKEN(Tpl.ST_NEW_LINE())
1325 );
1326
1327 ✗ TplAbsyn.STR_TOKEN(tok) := expB;
1328 //Tpl.ST_STRING_LIST({"\n",""},false) = tok;
1329 txt := emptyTxt;
1330 ✗ txt := Tpl.writeTok(txt, tok);
1331 ✗ strOut := Tpl.textString(txt);
1332 ✗ strOut := Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1333 ✗ notPassedCnt := testStringEquality(strOut,
1334 "true*\n*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1335
1336 //*************
1337 str := "\\\"\\n\\n\\ ~:)";
1338 ✗ chars := stringListStringChar( str );
1339
1340 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1341
1342 ✗ tequal := valueEq(
1343 expB,
1344 TplAbsyn.STR_TOKEN(Tpl.ST_STRING_LIST({"\"\n", "\n"," "}, false))
1345 );
1346
1347 ✗ TplAbsyn.STR_TOKEN(tok) := expB;
1348 txt := emptyTxt;
1349 ✗ txt := Tpl.writeTok(txt, tok);
1350 ✗ strOut := Tpl.textString(txt);
1351 ✗ strOut := Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1352 ✗ notPassedCnt := testStringEquality(strOut,
1353 "true*\"\n\n *~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1354
1355 //*************
1356 str := "'Susan'~:)";
1357 ✗ chars := stringListStringChar( str );
1358
1359 ✗ (chars,_, (expB,_)) := TplParser.expression(chars, TplParser.makeStartLineInfo(chars, "in memory test"),"<",">", false);
1360
1361 ✗ tequal := valueEq(
1362 expB,
1363 TplAbsyn.STR_TOKEN(Tpl.ST_STRING("Susan"))
1364 );
1365
1366 ✗ TplAbsyn.STR_TOKEN(tok) := expB; //dangerous, can fail fatally here
1367 txt := emptyTxt;
1368 ✗ txt := Tpl.writeTok(txt, tok);
1369 ✗ strOut := Tpl.textString(txt);
1370 ✗ strOut := Tpl.booleanString(tequal) + "*" + strOut + "*" + stringCharListString(chars);
1371 ✗ notPassedCnt := testStringEquality(strOut,
1372 "true*Susan*~:)", true, true, "TplParser.expression \n\""+ str +"\"\n", notPassedCnt);
1373
1374
1375 //*************
1376 str := "Susan:)";
1377 ✗ chars := stringListStringChar( str );
1378 ✗ llen := TplParser.charsTillEndOfLine(chars, 1);
1379 ✗ _ :: _ :: chars := chars;
1380 ✗ (lnum,colnum) := TplParser.getPosition(chars, TplParser.LINE_INFO(TplParser.PARSE_INFO("test - no file",{},false), 11, llen, chars));
1381 ✗ notPassedCnt := testStringEquality(intString(lnum) + "," + intString(colnum) + " of " + intString(llen),
1382 "11,3 of 8", true, true, "TplParser.charsTillEndOfLine and getPosition \n", notPassedCnt);
1383
1384
1385
1386 //*************
1387 txt := emptyTxt;
1388 ✗ txt := statement(txt,
1389 WHILE( BINARY( VARIABLE("x"), LESS(), ICONST(20) ),
1390 {ASSIGN(
1391 VARIABLE("x"),
1392 BINARY( VARIABLE("x"), PLUS(),
1393 BINARY( VARIABLE("y"), TIMES(), ICONST(2) )
1394 )
1395 )}
1396 )
1397
1398 );
1399 ✗ str := Tpl.textString(txt);
1400 ✗ notPassedCnt := testStringEquality(str,
1401 "while((x < 20)) {
1402 x = (x + (y * 2));
1403 }", true, true, "Paper Example statement()", notPassedCnt);
1404
1405 //*************
1406 txt := emptyTxt;
1407 ✗ txt := intMatrix(txt,
1408 { { 1, 2, 3, 4, 5 },
1409 { 6, 7, 8, 9, 10 },
1410 { 11, 12, 13, 14, 15 }
1411 }
1412 );
1413 ✗ str := Tpl.textString(txt);
1414 ✗ notPassedCnt := testStringEquality(str,
1415 "[ 1, 2, 3, 4, 5;
1416 6, 7, 8, 9, 10;
1417 11, 12, 13, 14, 15 ]", true, true, "intMatrix() from test.tpl", notPassedCnt);
1418
1419 //*************
1420 ✗ notPassedCnt := testTranslateTplFile("TplCodegen", false, false, notPassedCnt);
1421
1422 //*************
1423 ✗ notPassedCnt := testTranslateTplFile("paper", false, false, notPassedCnt);
1424
1425 //*************
1426 ✗ notPassedCnt := testTranslateTplFile("test", false, true, notPassedCnt);
1427
1428 //*************
1429 //notPassedCnt = testTranslateTplFile("SimCodeC", false, true, notPassedCnt);
1430
1431
1432 ✗ print("All tests took " + realString(clock() - tstart) + " seconds.\n");
1433 ✗ str := if notPassedCnt == 0 then
1434 "\n ***** All a) tests OK *****\n\n" else
1435 ("\n #### " + intString(notPassedCnt) + " test" + (if notPassedCnt > 1 then "s" else"") + " DID NOT passed ####\n\n");
1436 ✗ print(str);
1437 //print("TplCodegen.tpl:258.1-259.1 Error: Toto je uff!\n");
1438 //print("TplCodegen.tpl:263.1-263.3 Error: Toto je algor uff!\n");
1439 //print("Hej!\n");
1440 then
1441 ();
1442
1443
1444 //should not ever happen - a badly designed test ?
1445 case str
1446 algorithm
1447 ✗ print("\n######## tplMainTest '"+ str + "' (fatally) failed! ########\n" );
1448 ✗ print("### Error Buffer ###\n");
1449 ✗ print(Print.getErrorString());
1450 ✗ print("\n### End of Error Buffer ###\n");
1451 ✗ Print.clearErrorBuf();
1452 then
1453 ();
1454
1455 end match;
1456 end tplMainTest;
1457
1458
1459 /* the paper example */
1460
1461 uniontype Statement "Algorithmic stmts"
1462 record ASSIGN "An assignment stmt"
1463 Exp lhs; Exp rhs;
1464 end ASSIGN;
1465
1466 record WHILE "A while statement"
1467 Exp condition;
1468 list<Statement> statements;
1469 end WHILE;
1470 end Statement;
1471
1472 uniontype Exp "Expression nodes"
1473 record ICONST "Integer constant value"
1474 Integer value;
1475 end ICONST;
1476
1477 record VARIABLE "Variable reference"
1478 String name;
1479 end VARIABLE;
1480
1481 record BINARY "Binary ops"
1482 Exp lhs;
1483 Operator op;
1484 Exp rhs;
1485 end BINARY;
1486 end Exp;
1487
1488 uniontype Operator
1489 record PLUS end PLUS;
1490 record TIMES end TIMES;
1491 record LESS end LESS;
1492 end Operator;
1493
1494
1495
1496 protected function lm_1
1497 input Tpl.Text in_txt;
1498 input list<Statement> in_items;
1499
1500 output Tpl.Text out_txt;
1501 algorithm
1502 out_txt :=
1503 matchcontinue(in_txt, in_items)
1504 local
1505 Tpl.Text txt;
1506 list<Statement> rest;
1507 Statement i_it;
1508
1509 case ( txt,
1510 {} )
1511 then txt;
1512
1513 case ( txt,
1514 i_it :: rest )
1515 algorithm
1516 ✗ txt := statement(txt, i_it);
1517 ✗ txt := Tpl.nextIter(txt);
1518 ✗ txt := lm_1(txt, rest);
1519 then txt;
1520
1521 case ( txt,
1522 _ :: rest )
1523 algorithm
1524 ✗ txt := lm_1(txt, rest);
1525 then txt;
1526 end matchcontinue;
1527 end lm_1;
1528
1529 public function statement
1530 input Tpl.Text in_txt;
1531 input Statement in_i_it;
1532
1533 output Tpl.Text out_txt;
1534 algorithm
1535 out_txt :=
1536 matchcontinue(in_txt, in_i_it)
1537 local
1538 Tpl.Text txt;
1539 list<Statement> i_statements;
1540 Exp i_condition;
1541 Exp i_rhs;
1542 Exp i_lhs;
1543
1544 case ( txt,
1545 ASSIGN(lhs = i_lhs, rhs = i_rhs) )
1546 algorithm
1547 ✗ txt := exp(txt, i_lhs);
1548 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING(" = "));
1549 ✗ txt := exp(txt, i_rhs);
1550 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING(";"));
1551 then txt;
1552
1553 case ( txt,
1554 WHILE(condition = i_condition, statements = i_statements) )
1555 algorithm
1556 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING("while("));
1557 ✗ txt := exp(txt, i_condition);
1558 ✗ txt := Tpl.writeTok(txt, Tpl.ST_LINE(") {\n"));
1559 ✗ txt := Tpl.pushBlock(txt, Tpl.BT_INDENT(2));
1560 ✗ txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0,NONE(), SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE()));
1561 ✗ txt := lm_1(txt, i_statements);
1562 ✗ txt := Tpl.popIter(txt);
1563 ✗ txt := Tpl.softNewLine(txt);
1564 ✗ txt := Tpl.popBlock(txt);
1565 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING("}"));
1566 then txt;
1567
1568 case ( txt,
1569 _ )
1570 then txt;
1571 end matchcontinue;
1572 end statement;
1573
1574 public function exp
1575 input Tpl.Text in_txt;
1576 input Exp in_i_it;
1577
1578 output Tpl.Text out_txt;
1579 algorithm
1580 out_txt :=
1581 matchcontinue(in_txt, in_i_it)
1582 local
1583 Tpl.Text txt;
1584 Integer i_value;
1585 String i_name;
1586 Exp i_rhs;
1587 Operator i_op;
1588 Exp i_lhs;
1589
1590 case ( txt,
1591 ICONST(value = i_value) )
1592 algorithm
1593 ✗ txt := Tpl.writeStr(txt, intString(i_value));
1594 then txt;
1595
1596 case ( txt,
1597 VARIABLE(name = i_name) )
1598 algorithm
1599 ✗ txt := Tpl.writeStr(txt, i_name);
1600 then txt;
1601
1602 case ( txt,
1603 BINARY(lhs = i_lhs, op = i_op, rhs = i_rhs) )
1604 algorithm
1605 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING("("));
1606 ✗ txt := exp(txt, i_lhs);
1607 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING(" "));
1608 ✗ txt := oper(txt, i_op);
1609 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING(" "));
1610 ✗ txt := exp(txt, i_rhs);
1611 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING(")"));
1612 then txt;
1613
1614 else in_txt;
1615 end matchcontinue;
1616 end exp;
1617
1618 public function oper
1619 input Tpl.Text in_txt;
1620 input Operator in_i_it;
1621
1622 output Tpl.Text out_txt;
1623 algorithm
1624 out_txt :=
1625 matchcontinue(in_txt, in_i_it)
1626 local
1627 Tpl.Text txt;
1628
1629 case ( txt,
1630 PLUS() )
1631 algorithm
1632 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING("+"));
1633 then txt;
1634
1635 case ( txt,
1636 TIMES() )
1637 algorithm
1638 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING("*"));
1639 then txt;
1640
1641 case ( txt,
1642 LESS() )
1643 algorithm
1644 ✗ txt := Tpl.writeTok(txt, Tpl.ST_STRING("<"));
1645 then txt;
1646
1647 else in_txt;
1648 end matchcontinue;
1649 end oper;
1650
1651 /***************************/
1652 /* intMatrix from test.tpl */
1653 /***************************/
1654
1655 protected function lm_54
1656 input Tpl.Text in_txt;
1657 input list<Integer> in_items;
1658
1659 output Tpl.Text out_txt;
1660 algorithm
1661 out_txt :=
1662 matchcontinue(in_txt, in_items)
1663 local
1664 Tpl.Text txt;
1665 list<Integer> rest;
1666 Integer i_it;
1667
1668 case ( txt,
1669 {} )
1670 then txt;
1671
1672 case ( txt,
1673 i_it :: rest )
1674 algorithm
1675 ✗ txt := Tpl.writeStr(txt, intString(i_it));
1676 ✗ txt := Tpl.nextIter(txt);
1677 ✗ txt := lm_54(txt, rest);
1678 then txt;
1679
1680 case ( txt,
1681 _ :: rest )
1682 algorithm
1683 ✗ txt := lm_54(txt, rest);
1684 then txt;
1685 end matchcontinue;
1686 end lm_54;
1687
1688 protected function lm_55
1689 input Tpl.Text in_txt;
1690 input list<list<Integer>> in_items;
1691
1692 output Tpl.Text out_txt;
1693 algorithm
1694 out_txt :=
1695 matchcontinue(in_txt, in_items)
1696 local
1697 Tpl.Text txt;
1698 list<list<Integer>> rest;
1699 list<Integer> i_intLst;
1700
1701 case ( txt,
1702 {} )
1703 then txt;
1704
1705 case ( txt,
1706 i_intLst :: rest )
1707 algorithm
1708 ✗ txt := Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0,NONE(), SOME(Tpl.ST_STRING(", ")), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE()));
1709 ✗ txt := lm_54(txt, i_intLst);
1710 ✗ txt := Tpl.popIter(txt);
1711 ✗ txt := Tpl.nextIter(txt);
1712 ✗ txt := lm_55(txt, rest);
1713 then txt;
1714
1715 case ( txt,
1716 _ :: rest )
1717 algorithm
1718 ✗ txt := lm_55(txt, rest);
1719 then txt;
1720 end matchcontinue;
1721 end lm_55;
1722
1723 public function intMatrix
1724 input Tpl.Text txt;
1725 input list<list<Integer>> i_lstOfLst;
1726
1727 output Tpl.Text out_txt;
1728 algorithm
1729 ✗ out_txt := Tpl.writeTok(txt, Tpl.ST_STRING("[ "));
1730 ✗ out_txt := Tpl.pushBlock(out_txt, Tpl.BT_ANCHOR(0));
1731 ✗ out_txt := Tpl.pushIter(out_txt, Tpl.ITER_OPTIONS(0,NONE(), SOME(Tpl.ST_LINE(";\n")), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE()));
1732 ✗ out_txt := lm_55(out_txt, i_lstOfLst);
1733 ✗ out_txt := Tpl.popIter(out_txt);
1734 ✗ out_txt := Tpl.popBlock(out_txt);
1735 ✗ out_txt := Tpl.writeTok(out_txt, Tpl.ST_STRING(" ]"));
1736 end intMatrix;
1737 /***************************/
1738 /* end of intMatrix from test.tpl */
1739 /***************************/
1740
1741
1742
1743 //!!! weird type behavior of MM
1744 /*
1745 public
1746 function MuchFun2
1747 input Tpl.Text txt;
1748 input Integer inlaughLevel;
1749 input list<String> injokes;
1750
1751 output Integer txt;
1752
1753 Tpl.Text txt1;
1754 Integer laughLevel;
1755 list<String> jokes;
1756 algorithm
1757 (txt) := Tpl.writeStr(txt, "Susan");
1758 txt := 1;
1759 //(txt1) := Tpl.writeStr(txt, "Susan");
1760
1761 //(txt) := Tpl.writeTok(txt, Tpl.ST_LINE("Susan is cosmic!\n"));
1762 end MuchFun2;
1763 */
1764
1765 annotation(__OpenModelica_Interface="susan");
1766 end TplMain;
1767