diff --git a/Compiler/TplCodegen.mo b/Compiler/TplCodegen.mo index d3e1f919036..5a3896e0f68 100644 --- a/Compiler/TplCodegen.mo +++ b/Compiler/TplCodegen.mo @@ -195,9 +195,9 @@ algorithm txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); txt = typedIdentsEx(txt, i_mf_outArgs, "output", "out_"); txt = Tpl.softNewLine(txt); + txt = Tpl.popBlock(txt); txt = fun_5(txt, i_mf_locals); txt = Tpl.softNewLine(txt); - txt = Tpl.popBlock(txt); txt = Tpl.writeTok(txt, Tpl.ST_LINE("algorithm\n")); txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); 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())); @@ -467,8 +467,8 @@ algorithm local TplAbsyn.TypedIdents i_locals; equation - txt = Tpl.writeTok(txt, Tpl.ST_LINE(" local\n")); - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(8)); + txt = Tpl.writeTok(txt, Tpl.ST_LINE(" local\n")); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(4)); txt = typedIdents(txt, i_locals); txt = Tpl.popBlock(txt); then txt; @@ -532,8 +532,8 @@ algorithm local list i_statements; equation - txt = Tpl.writeTok(txt, Tpl.ST_LINE(" equation\n")); - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(8)); + txt = Tpl.writeTok(txt, Tpl.ST_LINE(" equation\n")); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(4)); 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())); txt = lm_14(txt, i_statements); txt = Tpl.popIter(txt); @@ -639,7 +639,7 @@ algorithm list i_mexps; equation txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(4)); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); txt = Tpl.writeTok(txt, Tpl.ST_STRING("case ( ")); txt = Tpl.pushBlock(txt, Tpl.BT_ANCHOR(0)); txt = Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE, SOME(Tpl.ST_LINE(",\n")), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); @@ -647,16 +647,16 @@ algorithm txt = Tpl.popIter(txt); txt = Tpl.popBlock(txt); txt = Tpl.writeTok(txt, Tpl.ST_LINE(" )\n")); - txt = Tpl.popBlock(txt); txt = fun_13(txt, i_locals); txt = Tpl.softNewLine(txt); txt = fun_15(txt, i_statements); txt = Tpl.softNewLine(txt); - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(6)); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); txt = Tpl.writeTok(txt, Tpl.ST_STRING("then ")); txt = fun_17(txt, i_outArgs); txt = Tpl.writeTok(txt, Tpl.ST_STRING(";")); txt = Tpl.popBlock(txt); + txt = Tpl.popBlock(txt); txt = Tpl.nextIter(txt); txt = lm_18(txt, rest, i_outArgs); then txt; @@ -706,12 +706,12 @@ algorithm out_txt := typedIdents(out_txt, i_locals); out_txt := Tpl.softNewLine(out_txt); out_txt := Tpl.popBlock(out_txt); - out_txt := Tpl.popBlock(out_txt); out_txt := Tpl.pushIter(out_txt, Tpl.ITER_OPTIONS(0, NONE, SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); out_txt := lm_18(out_txt, i_matchCases, i_outArgs); out_txt := Tpl.popIter(out_txt); out_txt := Tpl.softNewLine(out_txt); - out_txt := Tpl.writeTok(out_txt, Tpl.ST_STRING(" end matchcontinue;")); + out_txt := Tpl.writeTok(out_txt, Tpl.ST_STRING("end matchcontinue;")); + out_txt := Tpl.popBlock(out_txt); end mmMatchFunBody; public function pathIdent @@ -1271,8 +1271,8 @@ public function mmEscapeStringConst input Boolean i_escapeNewLine; output Tpl.Text out_txt; - protected - list ret_0; +protected + list ret_0; algorithm ret_0 := stringListStringChar(i_internalValue); out_txt := lm_32(txt, ret_0, i_escapeNewLine); @@ -1846,7 +1846,6 @@ algorithm TplAbsyn.PathIdent i_importPackage; Boolean i_isDefault; equation - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); txt = fun_44(txt, i_isDefault); txt = Tpl.writeTok(txt, Tpl.ST_STRING("absyn ")); txt = pathIdent(txt, i_importPackage); @@ -1864,7 +1863,6 @@ algorithm txt = pathIdent(txt, i_importPackage); txt = Tpl.writeTok(txt, Tpl.ST_STRING(";")); txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); - txt = Tpl.popBlock(txt); txt = Tpl.nextIter(txt); txt = lm_46(txt, rest); then txt; @@ -1937,11 +1935,13 @@ algorithm txt = Tpl.writeTok(txt, Tpl.ST_STRING("spackage ")); txt = pathIdent(txt, i_name); txt = Tpl.softNewLine(txt); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); 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())); txt = lm_46(txt, i_astDefs); txt = Tpl.popIter(txt); txt = Tpl.softNewLine(txt); txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); + txt = Tpl.popBlock(txt); txt = Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE, SOME(Tpl.ST_STRING_LIST({ "\n", "\n" diff --git a/Compiler/TplMain.mo b/Compiler/TplMain.mo index 9173c3c062f..e0b659f4a8f 100644 --- a/Compiler/TplMain.mo +++ b/Compiler/TplMain.mo @@ -394,10 +394,10 @@ public function MuchFun input list jokes; output Tpl.Text out_txt; - protected - Tpl.Text txt; - Integer laughLevel; - list jokes; +protected + Tpl.Text txt; + Integer laughLevel; + list jokes; algorithm out_txt := Tpl.writeStr(txt, \"Susan\"); out_txt := Tpl.writeTok(out_txt, Tpl.ST_LINE(\"Susan is cosmic!\\n\")); diff --git a/Compiler/TplParser.mo b/Compiler/TplParser.mo index 9bd91caa5ff..9392e4f9bea 100644 --- a/Compiler/TplParser.mo +++ b/Compiler/TplParser.mo @@ -2866,7 +2866,7 @@ public function templateExp algorithm (outChars, outLineInfo, outExpression) := matchcontinue (inChars, inLineInfo, inLeftEsc, inRightEsc) local - list chars; + list chars, solChars; LineInfo linfo; String c, lesc, resc; Boolean isD; @@ -2877,48 +2877,45 @@ algorithm Tpl.StringToken st; TplAbsyn.Expression exp, bexp; list expLst; + Integer baseInd, lineInd; case ("'" :: chars, linfo, lesc, resc) equation + //single quotes has no special treatment of indent and new lines + //i.e., it takes O as the base indent, and it counts every new line (chars, linfo, exp) = templateBody(chars, linfo, lesc, resc, true, {},{},0); then (chars, linfo, exp); case ("<"::"<":: chars, linfo, lesc, resc) equation - (chars, linfo) = templStripFirstNewLine(chars, linfo); - (chars, linfo, exp) = templateBody(chars, linfo, lesc, resc, false, {},{},0); + //the base indent is the indent of the line where the << appears + LINE_INFO(startOfLineChars = solChars) = linfo; + (_, baseInd) = lineIndent(solChars,0); + //the case when nothing visible is after << + (chars, linfo) = takeSpaceAndNewLine(chars, linfo); + //(chars, linfo) = templStripFirstNewLine(chars, linfo); + //push the staring indent on the indentStack + (chars, linfo, exp) = templateBody(chars, linfo, lesc, resc, false, {}, {}, baseInd); then (chars, linfo, exp); - + + //special treatment when some non-space is right after << + case ("<"::"<":: chars, linfo, lesc, resc) + equation + //the base indent is the indent of the line where the << appears + LINE_INFO(startOfLineChars = solChars) = linfo; + (_, baseInd) = lineIndent(solChars,0); + //some non-space char(s) is after << + failure( (_,_) = takeSpaceAndNewLine(chars, linfo) ); + (chars, lineInd) = lineIndent(chars,0); + //correct the indent of the line right after << to baseInd + lineInd = lineInd + baseInd; + //push the base indent on the indentStack + (chars, linfo, exp) = restOfTemplLine(chars, linfo, lesc, resc, false, {}, {}, baseInd, lineInd, {}); + then (chars, linfo, exp); end matchcontinue; end templateExp; -/* -templStripFirstNewLine: - takeSpaceAndNewLine - | - _ //just nothing -*/ -public function templStripFirstNewLine - input list inChars; - input LineInfo inLineInfo; - output list outChars; - output LineInfo outLineInfo; -algorithm - (outChars, outLineInfo) := matchcontinue (inChars, inLineInfo) - local - list chars; - LineInfo linfo; - - case (chars, linfo) - equation - (chars, linfo) = takeSpaceAndNewLine(chars, linfo); - then (chars, linfo); - - case (chars, linfo) - then (chars, linfo); - - end matchcontinue; -end templStripFirstNewLine; + /* takeSpaceAndNewLine: @@ -3191,7 +3188,7 @@ algorithm end matchcontinue; end restOfTemplLine; - +/* obsolete public function restOfTemplLineAfterEmptyExp input list inChars; input LineInfo inLineInfo; @@ -3226,8 +3223,8 @@ algorithm //and [space] and newLine() after it case (chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd, _, {}) equation - (chars, _) = lineIndent(chars,0); //try take a space before newLine() - (chars, linfo) = newLine(chars, linfo); + //try take a space and new line + (chars, linfo) = takeSpaceAndNewLine(chars, linfo); (chars, linfo, exp) = templateBody(chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd); then (chars, linfo, exp); @@ -3239,7 +3236,7 @@ algorithm end matchcontinue; end restOfTemplLineAfterEmptyExp; - +*/ public function dropNewLineAfterEmptyExp input list inChars; @@ -3324,7 +3321,7 @@ algorithm list chars, accChars; String c, lesc, resc; Boolean isSQ; - Integer actInd, lineInd; + Integer actInd, lineInd, baseInd; TplAbsyn.Ident id; TplAbsyn.PathIdent name; TplAbsyn.TypedIdents fields,inargs,outargs; @@ -3334,6 +3331,15 @@ algorithm list expLst; list>> indStack; + + //TODO: optimization for <\n> + //we need a flag for having something non-space on the line + //case (TplAbsyn.STR_TOKEN(value = Tpl.ST_NEW_LINE()), expLst, indStack, actInd, lineInd, accChars) + // equation + // //equality( lineInd = actInd); + // expLst = addAccStringChars(expLst, "\n" :: accChars); + // then (expLst, indStack, actInd); + //the same indent level case (exp, expLst, indStack, actInd, lineInd, accChars) equation @@ -3354,8 +3360,17 @@ algorithm expLst = exp :: expLst; then (expLst, indStack, lineInd); - //pop indent level and try again - case (exp, expLst, indStack, actInd, lineInd, accChars) + //if the indent is under the base indent level, warn and make it 0 level + case (exp, expLst, {}, baseInd, lineInd, accChars) + equation + true = ( lineInd < baseInd ); + Debug.fprint("failtrace", "Parse warning onEscapedExp() - indent level is under the level of the '<<' determined level.\n"); + //call again as lineInd = baseInd + (expLst, indStack, actInd) = onEscapedExp(exp, expLst, {}, baseInd, baseInd, accChars); + then (expLst, indStack, actInd); + + //pop indent level and try again (indStack must have at least one pushed indent level) + case (exp, expLst, indStack as (_::_), actInd, lineInd, accChars) equation true = ( lineInd < actInd ); expLst = finalizeLastStringToken(expLst); @@ -3390,7 +3405,7 @@ algorithm list chars, accChars, strLst; String c, lesc, resc; Boolean isSQ; - Integer actInd, lineInd; + Integer actInd, lineInd, baseInd; TplAbsyn.Ident id; TplAbsyn.PathIdent name; TplAbsyn.TypedIdents fields,inargs,outargs; @@ -3425,6 +3440,7 @@ algorithm expLst = addAccStringChars(expLst, {"\n"} ); then (expLst, indStack, actInd); + //TODO: this does not work, because the <\n> finalizes the previous ST to be closed //AccStringChars = {} // expLst = <\n> :: _ -> a forced new line - make permanent - replace with \n // ignore lineInd - must be lineInd = actInd (because the <\n> exp made it so) @@ -3450,7 +3466,7 @@ algorithm expLst = TplAbsyn.SOFT_NEW_LINE() :: expLst; then (expLst, indStack, actInd); - //AccStringChars <> {} + //AccStringChars = (_::_) // lineInd >= actInd // align the string with prefixed space // put a disposable new line - may be disposed by onTemplEnd() or hardened by addAccStringChars() or finalizeLastStringToken() @@ -3464,10 +3480,23 @@ algorithm expLst = TplAbsyn.STR_TOKEN(Tpl.ST_STRING_LIST(strLst, true)) :: expLst; then (expLst, indStack, actInd); - //AccStringChars <> {} + //if the indent is under base indent level, warn and make it 0 level + //AccStringChars = (_::_) + // lineInd < actInd + //pop indent level and try again + case (expLst, {}, baseInd, lineInd, accChars as (_ :: _)) + equation + true = ( lineInd < baseInd ); + Debug.fprint("failtrace", "Parse warning onNewLine() - indent level is under the level of the '<<' determined level.\n"); + //call again as lineInd = baseInd + (expLst, indStack, actInd) = onNewLine(expLst, {}, baseInd, baseInd, accChars); + then (expLst, indStack, actInd); + + //AccStringChars = (_::_) // lineInd < actInd //pop indent level and try again - case (expLst, indStack, actInd, lineInd, accChars as (_ :: _)) + //(indStack must have at least one pushed indent level) + case (expLst, indStack as (_::_), actInd, lineInd, accChars as (_ :: _)) equation true = ( lineInd < actInd ); expLst = finalizeLastStringToken(expLst); @@ -3502,7 +3531,7 @@ algorithm list chars, accChars, strLst; String c, lesc, resc; Boolean dropLastNL; - Integer actInd, lineInd; + Integer actInd, lineInd, baseInd; TplAbsyn.Ident id; TplAbsyn.PathIdent name; TplAbsyn.TypedIdents fields,inargs,outargs; @@ -3515,12 +3544,25 @@ algorithm //AccStringChars = {} // expLst = {} - special case, only space in the template // make the space and take it - case (_, {}, {}, 0, lineInd, {}) + case (_, {}, {}, baseInd, lineInd, {}) equation - expLst = addAccStringChars({}, Util.listFill(" ",lineInd)); + true = (lineInd >= baseInd); + expLst = addAccStringChars({}, Util.listFill(" ",lineInd-baseInd)); expLst = finalizeLastStringToken(expLst); then expLst; + /* + //same as previous, but under the '<<' determined level + //AccStringChars = {} + // expLst = {} - special case, only space in the template + // template is empty + case (_, {}, {}, baseInd, lineInd, {}) + equation + true = (lineInd < baseInd); + Debug.fprint("failtrace", "Parse warning onTemplEnd() - indent level is under the level of the '<<' determined level.\n"); + then {}; + */ + //if drop-the-last-new-line is set //AccStringChars = {} // expLst = SNL :: _ -> dispose the SNL @@ -3528,19 +3570,20 @@ algorithm // pop all indent case (true, TplAbsyn.SOFT_NEW_LINE() :: expLst, indStack, actInd, _, {}) equation - (expLst, {}, 0) = popIndentStack(expLst, indStack, actInd, 0); + (expLst, {}, _) = popIndentStack(expLst, indStack, actInd, 0); then expLst; //if drop-the-last-new-line is set //AccStringChars = {} // expLst = ST opened with disposable new line :: _ -> dispose the \n on the line // ignore lineInd - // pop all indent + // pop all indent case (true, TplAbsyn.STR_TOKEN(value = Tpl.ST_STRING_LIST(strList = strLst as (""::_), lastHasNewLine = true)) :: expLst, indStack, actInd, _, {}) equation expLst = finalizeLastStringToken(TplAbsyn.STR_TOKEN(Tpl.ST_STRING_LIST(strLst, false)) :: expLst); - (expLst, {}, 0) = popIndentStack(expLst, indStack, actInd, 0); + (expLst, {},_) = popIndentStack(expLst, indStack, actInd, 0); + //TODO: warn when >> is under << determined indent then expLst; //if drop-the-last-new-line is set @@ -3551,10 +3594,10 @@ algorithm case (true, expLst, indStack, actInd, _, {}) equation expLst = finalizeLastStringToken(expLst); - (expLst, {}, 0) = popIndentStack(expLst, indStack, actInd, 0); + (expLst, {}, _) = popIndentStack(expLst, indStack, actInd, 0); then expLst; - //AccStringChars <> {} or drop-the-last-new-line is set + //AccStringChars = (_::_) or drop-the-last-new-line is set // lineInd >= actInd // align the string with prefixed space // pop all indent @@ -3564,12 +3607,23 @@ algorithm accChars = listAppend(accChars, Util.listFill(" ",lineInd - actInd)); expLst = addAccStringChars(expLst, accChars); expLst = finalizeLastStringToken(expLst); - (expLst, {}, 0) = popIndentStack(expLst, indStack, actInd, 0); + (expLst, {}, _) = popIndentStack(expLst, indStack, actInd, 0); + then expLst; + + // lineInd < baseInd + // the indent is under the base indent level, + // warn and make it 0 level + //pop indent level and try again (only the previous case will be the end of the recursion) + case (dropLastNL, expLst, {}, baseInd, lineInd, accChars) + equation + true = ( lineInd < baseInd ); + Debug.fprint("failtrace", "Parse warning onTemplEnd() - indent level is under the level of the '<<' determined level.\n"); + expLst = onTemplEnd(dropLastNL, expLst, {}, baseInd, baseInd, accChars); then expLst; // lineInd < actInd //pop indent level and try again (only the previous case will be the end of the recursion) - case (dropLastNL, expLst, indStack, actInd, lineInd, accChars) + case (dropLastNL, expLst, indStack as (_::_), actInd, lineInd, accChars) equation true = ( lineInd < actInd ); expLst = finalizeLastStringToken(expLst); @@ -3600,10 +3654,11 @@ algorithm (outExpressionList, outIndentStack, outActualIndent) := matchcontinue (inExpressionList, inIndentStack, inActualIndent, inLineIndent) local - Integer actInd, lineInd, d, prevInd; + Integer actInd, lineInd, baseInd, d, prevInd; list expLst, prevExpLst; list>> indStack; + case (expLst, (prevInd, prevExpLst) :: indStack, actInd, lineInd) equation true = (lineInd < actInd); //when actInd > 0 --> something has to be on the stack @@ -3618,6 +3673,11 @@ algorithm true = (lineInd >= actInd); then (expLst, indStack, actInd); + //base indent + case (expLst, {}, baseInd, _) + then (expLst, {}, baseInd); + + //should not happen case (_,_,_,_) equation diff --git a/Compiler/susan_codegen/SusanGrammar.txt b/Compiler/susan_codegen/SusanGrammar.txt index 7aa58d1ba45..c168987ce61 100644 --- a/Compiler/susan_codegen/SusanGrammar.txt +++ b/Compiler/susan_codegen/SusanGrammar.txt @@ -715,10 +715,6 @@ templateExp(lesc, resc): & templateBody(lesc, resc, isSingleQuote = false,{},{},0 ):exp => exp -templStripFirstNewLine: - takeSpaceAndNewLine - | - _ //just nothing // & ... no interleave takeSpaceAndNewLine: diff --git a/Compiler/susan_codegen/TplCodegen.mo b/Compiler/susan_codegen/TplCodegen.mo index d3e1f919036..5a3896e0f68 100644 --- a/Compiler/susan_codegen/TplCodegen.mo +++ b/Compiler/susan_codegen/TplCodegen.mo @@ -195,9 +195,9 @@ algorithm txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); txt = typedIdentsEx(txt, i_mf_outArgs, "output", "out_"); txt = Tpl.softNewLine(txt); + txt = Tpl.popBlock(txt); txt = fun_5(txt, i_mf_locals); txt = Tpl.softNewLine(txt); - txt = Tpl.popBlock(txt); txt = Tpl.writeTok(txt, Tpl.ST_LINE("algorithm\n")); txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); 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())); @@ -467,8 +467,8 @@ algorithm local TplAbsyn.TypedIdents i_locals; equation - txt = Tpl.writeTok(txt, Tpl.ST_LINE(" local\n")); - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(8)); + txt = Tpl.writeTok(txt, Tpl.ST_LINE(" local\n")); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(4)); txt = typedIdents(txt, i_locals); txt = Tpl.popBlock(txt); then txt; @@ -532,8 +532,8 @@ algorithm local list i_statements; equation - txt = Tpl.writeTok(txt, Tpl.ST_LINE(" equation\n")); - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(8)); + txt = Tpl.writeTok(txt, Tpl.ST_LINE(" equation\n")); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(4)); 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())); txt = lm_14(txt, i_statements); txt = Tpl.popIter(txt); @@ -639,7 +639,7 @@ algorithm list i_mexps; equation txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(4)); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); txt = Tpl.writeTok(txt, Tpl.ST_STRING("case ( ")); txt = Tpl.pushBlock(txt, Tpl.BT_ANCHOR(0)); txt = Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE, SOME(Tpl.ST_LINE(",\n")), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); @@ -647,16 +647,16 @@ algorithm txt = Tpl.popIter(txt); txt = Tpl.popBlock(txt); txt = Tpl.writeTok(txt, Tpl.ST_LINE(" )\n")); - txt = Tpl.popBlock(txt); txt = fun_13(txt, i_locals); txt = Tpl.softNewLine(txt); txt = fun_15(txt, i_statements); txt = Tpl.softNewLine(txt); - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(6)); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); txt = Tpl.writeTok(txt, Tpl.ST_STRING("then ")); txt = fun_17(txt, i_outArgs); txt = Tpl.writeTok(txt, Tpl.ST_STRING(";")); txt = Tpl.popBlock(txt); + txt = Tpl.popBlock(txt); txt = Tpl.nextIter(txt); txt = lm_18(txt, rest, i_outArgs); then txt; @@ -706,12 +706,12 @@ algorithm out_txt := typedIdents(out_txt, i_locals); out_txt := Tpl.softNewLine(out_txt); out_txt := Tpl.popBlock(out_txt); - out_txt := Tpl.popBlock(out_txt); out_txt := Tpl.pushIter(out_txt, Tpl.ITER_OPTIONS(0, NONE, SOME(Tpl.ST_NEW_LINE()), 0, 0, Tpl.ST_NEW_LINE(), 0, Tpl.ST_NEW_LINE())); out_txt := lm_18(out_txt, i_matchCases, i_outArgs); out_txt := Tpl.popIter(out_txt); out_txt := Tpl.softNewLine(out_txt); - out_txt := Tpl.writeTok(out_txt, Tpl.ST_STRING(" end matchcontinue;")); + out_txt := Tpl.writeTok(out_txt, Tpl.ST_STRING("end matchcontinue;")); + out_txt := Tpl.popBlock(out_txt); end mmMatchFunBody; public function pathIdent @@ -1271,8 +1271,8 @@ public function mmEscapeStringConst input Boolean i_escapeNewLine; output Tpl.Text out_txt; - protected - list ret_0; +protected + list ret_0; algorithm ret_0 := stringListStringChar(i_internalValue); out_txt := lm_32(txt, ret_0, i_escapeNewLine); @@ -1846,7 +1846,6 @@ algorithm TplAbsyn.PathIdent i_importPackage; Boolean i_isDefault; equation - txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); txt = fun_44(txt, i_isDefault); txt = Tpl.writeTok(txt, Tpl.ST_STRING("absyn ")); txt = pathIdent(txt, i_importPackage); @@ -1864,7 +1863,6 @@ algorithm txt = pathIdent(txt, i_importPackage); txt = Tpl.writeTok(txt, Tpl.ST_STRING(";")); txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); - txt = Tpl.popBlock(txt); txt = Tpl.nextIter(txt); txt = lm_46(txt, rest); then txt; @@ -1937,11 +1935,13 @@ algorithm txt = Tpl.writeTok(txt, Tpl.ST_STRING("spackage ")); txt = pathIdent(txt, i_name); txt = Tpl.softNewLine(txt); + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); 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())); txt = lm_46(txt, i_astDefs); txt = Tpl.popIter(txt); txt = Tpl.softNewLine(txt); txt = Tpl.writeTok(txt, Tpl.ST_NEW_LINE()); + txt = Tpl.popBlock(txt); txt = Tpl.pushIter(txt, Tpl.ITER_OPTIONS(0, NONE, SOME(Tpl.ST_STRING_LIST({ "\n", "\n" diff --git a/Compiler/susan_codegen/TplCodegen.tpl b/Compiler/susan_codegen/TplCodegen.tpl index 9c5f3009387..5d25d0b0273 100644 --- a/Compiler/susan_codegen/TplCodegen.tpl +++ b/Compiler/susan_codegen/TplCodegen.tpl @@ -6,60 +6,58 @@ typeview "TplCodegenTV.mo" mmPackage(MMPackage) ::= case MM_PACKAGE then - << -package + << + package -protected constant Tpl.Text emptyTxt = Tpl.MEM_TEXT({}, {}); + protected constant Tpl.Text emptyTxt = Tpl.MEM_TEXT({}, {}); -public import Tpl; + public import Tpl; - + -end ; - >> + end ; + >> mmDeclaration(MMDeclaration) ::= case MM_IMPORT(packageName = IDENT(ident = "Tpl")) then '' //ignore Tpl as it is always imported case MM_IMPORT(packageName = IDENT(ident = "builtin")) then '' //ignore Tpl as it is always imported case MM_IMPORT then - << - import ; - >> + << + import ; + >> case MM_STR_TOKEN_DECL then - << + << - constant Tpl.StringToken = ; - >> + constant Tpl.StringToken = ; + >> case MM_LITERAL_DECL then - << + << - constant = ; - >> + constant = ; + >> case mf as MM_FUN then - << + << - function -< match statements - case {c as MM_MATCH} then //match function - mmMatchFunBody(mf.inArgs, mf.outArgs, mf.locals, c.matchCases) - case sts then //simple assignment functions - << - + function + - - - >> - > -algorithm - + + >>> + algorithm + ) local - ) -< if locals /*<> {}*/ then - << + {}*/ then << local - >> -> -< if statements then - << + >>> + )' >; - >> - \n -> + >>\n> end matchcontinue; >> @@ -146,11 +138,11 @@ mmStringTokenConstant(StringToken) ::= case ST_STRING then 'Tpl.ST_STRING("")' case ST_LINE then 'Tpl.ST_LINE("")' case ST_STRING_LIST then - (<< -Tpl.ST_STRING_LIST({ - "' ",\n"> -}, ) - >>; anchor) // perhaps this should be automatic ? + (<< + Tpl.ST_STRING_LIST({ + "' ",\n"> + }, ) + >>; anchor) // perhaps this should be automatic ? mmEscapeStringConst(String internalValue, Boolean escapeNewLine) ::= stringListStringChar(internalValue) : @@ -169,12 +161,12 @@ mmEscapeStringConst(String internalValue, Boolean escapeNewLine) ::= mmExp(MMExp, String assignStr) ::= case MM_ASSIGN then - << -)' -> - >> + << + )' + > + >> case MM_FN_CALL then '()' case MM_IDENT then pathIdent(ident) case MM_STR_TOKEN then mmStringTokenConstant(value) @@ -187,12 +179,11 @@ mmMatchingExp(MatchingExp) ::= case BIND_AS_MATCH then '( as )' case BIND_MATCH then bindIdent case RECORD_MATCH then - << -( = ' - ", " - >) - >> + << + ( = ' + ", ">) + >> case SOME_MATCH then 'SOME()' case NONE_MATCH then "NONE" case TUPLE_MATCH then '()' @@ -210,46 +201,46 @@ mmStatements(list stmts) ::= sTemplPackage(TemplPackage) ::= - case TEMPL_PACKAGE then + case TEMPL_PACKAGE then << -spackage -absyn - - end ;<\n> ->> \n > - - -end ; + spackage + absyn + + end ;<\n> + >> \n > + + + end ; >> sASTDefType(Ident id, TypeInfo info) ::= - match info - case TI_UNION_TYPE then + match info + case TI_UNION_TYPE then << -uniontype - -end ; + uniontype + + end ; >> - case TI_RECORD_TYPE then sRecordTypeDef(id, fields) - case TI_ALIAS_TYPE then 'type = ;' - case TI_FUN_TYPE then - << -function - ;<\n>'> - ;<\n>'> -end ; + case TI_RECORD_TYPE then sRecordTypeDef(id, fields) + case TI_ALIAS_TYPE then 'type = ;' + case TI_FUN_TYPE then + << + function + ;<\n>'> + ;<\n>'> + end ; >> - case TI_CONST_TYPE then 'constant ;' + case TI_CONST_TYPE then 'constant ;' sRecordTypeDef(Ident id, TypedIdents fields) ::= << -record +record ;<\n>'> - >> +>> >end ; >> diff --git a/Compiler/susan_codegen/paper.mo b/Compiler/susan_codegen/paper.mo index ee14d3f661e..88f79e17d42 100644 --- a/Compiler/susan_codegen/paper.mo +++ b/Compiler/susan_codegen/paper.mo @@ -320,9 +320,9 @@ public function pok2 input String i_sep; output Tpl.Text out_txt; - protected - Tpl.StringToken ret_1; - Tpl.Text txt_0; +protected + Tpl.StringToken ret_1; + Tpl.Text txt_0; algorithm txt_0 := Tpl.writeTok(emptyTxt, Tpl.ST_STRING("o")); txt_0 := Tpl.writeStr(txt_0, i_sep); diff --git a/Compiler/susan_codegen/paper.tpl b/Compiler/susan_codegen/paper.tpl index f71a7740182..1747ae0b670 100644 --- a/Compiler/susan_codegen/paper.tpl +++ b/Compiler/susan_codegen/paper.tpl @@ -38,12 +38,12 @@ spackage paper statement(Statement) ::= case ASSIGN then << - = ; + = ; >> case WHILE then << -while() { - -} + while() { + + } >> exp(Exp) ::= diff --git a/Compiler/susan_codegen/test.mo b/Compiler/susan_codegen/test.mo index 1df38856113..473ed4b784d 100644 --- a/Compiler/susan_codegen/test.mo +++ b/Compiler/susan_codegen/test.mo @@ -135,13 +135,13 @@ public function test input Integer i_ind; output Tpl.Text out_txt; - protected - String ret_5; - Integer ret_4; - Tpl.StringToken ret_3; - Tpl.Text txt_2; - Integer ret_1; - String ret_0; +protected + String ret_5; + Integer ret_4; + Tpl.StringToken ret_3; + Tpl.Text txt_2; + Integer ret_1; + String ret_0; algorithm ret_0 := intString(i_ind); ret_1 := testfn(intString(i_ind)); @@ -830,11 +830,11 @@ public function test3 input Integer i_ii; output Tpl.Text out_txt; - protected - String str_3; - Tpl.Text txt_2; - Tpl.Text txt_1; - Tpl.Text txt_0; +protected + String str_3; + Tpl.Text txt_2; + Tpl.Text txt_1; + Tpl.Text txt_0; algorithm 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())); out_txt := lm_9(out_txt, i_items); @@ -1454,9 +1454,9 @@ public function ifTest input Integer i_i; output Tpl.Text out_txt; - protected - String str_1; - Tpl.Text txt_0; +protected + String str_1; + Tpl.Text txt_0; algorithm txt_0 := mapInt(emptyTxt, i_i); str_1 := Tpl.textString(txt_0); @@ -1479,8 +1479,10 @@ algorithm local Tpl.Text i_ii; equation + txt = Tpl.pushBlock(txt, Tpl.BT_INDENT(2)); txt = Tpl.writeTok(txt, Tpl.ST_STRING("some hej")); txt = Tpl.writeText(txt, i_ii); + txt = Tpl.popBlock(txt); then txt; end matchcontinue; end smf_59; @@ -1489,8 +1491,8 @@ public function bindTest input Tpl.Text txt; output Tpl.Text out_txt; - protected - Tpl.Text txt_0; +protected + Tpl.Text txt_0; algorithm txt_0 := ifTest(emptyTxt, 1); out_txt := smf_59(txt, txt_0); @@ -1500,8 +1502,8 @@ public function txtTest input Tpl.Text txt; output Tpl.Text out_txt; - protected - Tpl.Text i_txt; +protected + Tpl.Text i_txt; algorithm i_txt := Tpl.writeTok(emptyTxt, Tpl.ST_STRING("ahoj")); i_txt := Tpl.writeTok(i_txt, Tpl.ST_STRING("hej")); @@ -1512,8 +1514,8 @@ public function txtTest2 input Tpl.Text txt; output Tpl.Text out_txt; - protected - Tpl.Text i_txt; +protected + Tpl.Text i_txt; algorithm i_txt := Tpl.writeTok(emptyTxt, Tpl.ST_STRING("ahoj2")); i_txt := Tpl.writeTok(i_txt, Tpl.ST_STRING("hej2")); @@ -1530,8 +1532,8 @@ public function txtTest3 output Tpl.Text out_txt; output Tpl.Text out_i_buf; - protected - Tpl.Text i_txt; +protected + Tpl.Text i_txt; algorithm i_txt := Tpl.writeTok(emptyTxt, Tpl.ST_STRING("aahoj2")); i_txt := Tpl.writeTok(i_txt, Tpl.ST_STRING("ahej2")); @@ -1590,8 +1592,8 @@ public function txtTest5 output Tpl.Text out_txt; output Tpl.Text out_i_buf; output Tpl.Text out_i_nobuf; - protected - Tpl.Text i_txt; +protected + Tpl.Text i_txt; algorithm i_txt := Tpl.writeTok(emptyTxt, Tpl.ST_STRING("aahoj2")); i_txt := Tpl.writeTok(i_txt, Tpl.ST_STRING("ahej2")); @@ -1759,9 +1761,9 @@ public function txtTest6 output Tpl.Text out_txt; output Tpl.Text out_i_buf; - protected - Tpl.Text i_nomut; - Tpl.Text i_mytxt; +protected + Tpl.Text i_nomut; + Tpl.Text i_mytxt; algorithm i_mytxt := Tpl.writeTok(emptyTxt, Tpl.ST_STRING("bolo")); i_nomut := Tpl.writeTok(emptyTxt, Tpl.ST_STRING(",")); diff --git a/Compiler/susan_codegen/test.tpl b/Compiler/susan_codegen/test.tpl index b01f049ec3f..0eacba6692c 100644 --- a/Compiler/susan_codegen/test.tpl +++ b/Compiler/susan_codegen/test.tpl @@ -78,9 +78,9 @@ ifTest(Integer i) ::= if mapInt(i) then ' name;' else "/* weird I */" bindTest() ::= ifTest(1) of ii : - << -some hej - >> + << + some hej + >> txtTest() ::= # txt = "ahoj" @@ -114,9 +114,9 @@ if hej then # txt += hej # buf += txt << -bláá + bláá -jo + jo >> txtTest5(String hej, Text buf, Text nobuf) ::=