Skip to content

Commit

Permalink
- TplParser.mo :
Browse files Browse the repository at this point in the history
  - hole is delimited by <% %> instead of < > 
  - %( )% syntax is removed
  - NO escape sequences inside of <<...>> and '...' are allowed, ... so, for example,  <<\\>> and '\\' is really double back-slash now
    ... to achieve "<%" inside a template, use ' ... <% "<%" %> ...' or << ... <% "<%" %> ...>>
    ... to achieve ">>"  inside <<.. >>, use  << ... <% ">>" %> ... >>, or use ' ... ' as template delimiter if possible, then ' ... << ... '
    ... to achieve "'" (single-quote) inside '...', use '...<%"'"%> ...', or (better) use << ... >> as template delimiter, then << ... ' ... >>

- all relevant .tpl are updated, so they produce the same resulting .mo files as before


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5477 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
pavolpr committed May 7, 2010
1 parent 18c24f5 commit 4e0e2ac
Show file tree
Hide file tree
Showing 7 changed files with 1,241 additions and 1,231 deletions.
6 changes: 4 additions & 2 deletions Compiler/TplMain.mo
Expand Up @@ -1110,6 +1110,7 @@ is\\n new lined!
"true*\nSusan\nis\n new lined!\n*~:)", true, true, "TplParser.expression \n>"+& str +&"<\n", notPassedCnt);

//*************
/*
str = "%(Susan)%~:)";
chars = stringListStringChar( str );
Expand All @@ -1127,8 +1128,9 @@ is\\n new lined!
strOut = Tpl.booleanString(tequal) +& "*" +& strOut +& "*" +& string_char_list_string(chars);
notPassedCnt = testStringEquality(strOut,
"true*Susan*~:)", true, true, "TplParser.expression \n\""+& str +&"\"\n", notPassedCnt);

*/
//*************
/*
str = "%/
Susan
is\\n verbatim!
Expand All @@ -1149,7 +1151,7 @@ is\\n verbatim!
strOut = Tpl.booleanString(tequal) +& "*" +& strOut +& "*" +& string_char_list_string(chars);
notPassedCnt = testStringEquality(strOut,
"true*Susan\nis\\n verbatim!*~:)", true, true, "TplParser.expression \n\""+& str +&"\"\n", notPassedCnt);

*/
//*************
str = "1234567~:)";
chars = stringListStringChar( str );
Expand Down
58 changes: 33 additions & 25 deletions Compiler/TplParser.mo
Expand Up @@ -2284,8 +2284,8 @@ end templDef_ConstOrTempl;
/*
templDef_AngleOrDolar:
'::=' expression(LEsc = '<',REsc = '>'):exp => (exp,'<','>')
|
'$$=' expression(LEsc = '$',REsc = '$'):exp => (exp,'$','$')
// |
// '$$=' expression(LEsc = '$',REsc = '$'):exp => (exp,'$','$')
*/
public function templDef_AngleOrDolar
input list<String> inChars;
Expand Down Expand Up @@ -2316,18 +2316,18 @@ algorithm
(chars, linfo, exp) = expression(chars, linfo, "<", ">", false);
then (chars, linfo, exp, "<", ">");

case ("$"::"$"::"=" :: chars, linfo)
equation
(chars, linfo) = interleave(chars, linfo);
(chars, linfo, exp) = expression(chars, linfo, "$", "$", false);
then (chars, linfo, exp, "$", "$");
//case ("$"::"$"::"=" :: chars, linfo)
// equation
// (chars, linfo) = interleave(chars, linfo);
// (chars, linfo, exp) = expression(chars, linfo, "$", "$", false);
// then (chars, linfo, exp, "$", "$");

//error expect ::= or $$=, try ::=
case (chars, linfo)
equation
failure(":"::":"::"=" :: _ = chars);
failure("$"::"$"::"=" :: _ = chars);
linfo = parseError(chars, linfo, "Expected '::=' symbol (or '$$=') before a template definition at the position.", false);
//failure("$"::"$"::"=" :: _ = chars);
linfo = parseError(chars, linfo, "Expected '::=' symbol before a template definition at the position.", false);
//try the ::= path
(chars, linfo, exp) = expression(chars, linfo, "<", ">", false);
then (chars, linfo, exp, "<", ">");
Expand Down Expand Up @@ -3013,9 +3013,9 @@ stringConstant:
'"' doubleQuoteConst({},{}):stRevLst
=> stRevLst
|
'%'(lquot) stripFirstNewLine verbatimConst(Rquote(lquot),{},{}):stRevLst
=> stRevLst
|
//'%'(lquot) stripFirstNewLine verbatimConst(Rquote(lquot),{},{}):stRevLst
// => stRevLst
//|
'\\n' escUnquotedChars({}, {"\n"}):stRevLst
=> stRevLst
|
Expand Down Expand Up @@ -3053,13 +3053,15 @@ algorithm
linfo = parseErrorPrevPositionOpt(startChars, startLinfo, linfo, optError, true);
then (chars, linfo, stRevLst);

/*
case (startChars as ("%"::lquot:: chars), startLinfo)
equation
(chars, linfo) = stripFirstNewLine(chars, startLinfo);
rquot = rightVerbatimConstQuote(lquot);
(chars, linfo, stRevLst, optError) = verbatimConst(chars, linfo, rquot,{},{});
linfo = parseErrorPrevPositionOpt(startChars, startLinfo, linfo, optError, true);
then (chars, linfo, stRevLst);
*/

case ("\\"::"n":: chars, linfo)
equation
Expand Down Expand Up @@ -3779,12 +3781,12 @@ end lineIndent;
/*
// & ... no interleave
restOfTemplLine(lesc, resc, isSingleQuote, expList, indStack, actInd, lineInd, accStrChars):
(lesc)'#' nonTemplateExprWithOpts(lesc,resc):eexp '#'(resc)
{ (expList, indStack, actInd) = onEscapedExp(eexp, expList, indStack, actInd, lineInd, accStrChars) }
& restOfTemplLine(lesc,resc,isSingleQuote, expList, indStack, actInd, actInd, {}):exp
=> exp
|
//(lesc)'#' nonTemplateExprWithOpts(lesc,resc):eexp '#'(resc)
// { (expList, indStack, actInd) = onEscapedExp(eexp, expList, indStack, actInd, lineInd, accStrChars) }
// & restOfTemplLine(lesc,resc,isSingleQuote, expList, indStack, actInd, actInd, {}):exp
// => exp
//
//|
(lesc) (resc) // a comment | empty expression ... ignore completely
& restOfTemplLineAfterEmptyExp(lesc,resc,isSingleQuote, expList, indStack, actInd, lineInd, accStrChars):exp
=> exp
Expand Down Expand Up @@ -3855,6 +3857,7 @@ algorithm
list<tuple<Integer,list<TplAbsyn.Expression>>> indStack;

//<# #> or $# #$
/*
case (startChars as (c :: "#" :: chars), startLinfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, accChars)
equation
equality( c = lesc );
Expand All @@ -3870,25 +3873,27 @@ algorithm
linfo = parseErrorPrevPositionOpt(solChars, startLinfo, linfo, errOpt, false);
(chars, linfo, exp) = restOfTemplLine(chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd, actInd, {});
then (chars, linfo, exp);
*/

//< > or $ $ empty expression ... i.e. comment or a break in line that is not parsed
case (c :: chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, accChars)
//<% %> empty expression ... i.e. comment or a break in line that is not parsed
case (c :: "%":: chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, accChars)
equation
equality( c = lesc );
(chars, linfo) = interleave(chars, linfo);
(c :: chars) = chars;
("%" :: c :: chars) = chars;
equality( c = resc );
(chars, linfo, lineInd) = dropNewLineAfterEmptyExp(chars, linfo, lineInd, accChars);
(chars, linfo, exp) = restOfTemplLine(chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, accChars);
then (chars, linfo, exp);

//<expressionWithOpts> or $expressionWithOpts$
case (startChars as (c :: chars), startLinfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, accChars)
//<% expressionWithOpts %>
case (startChars as (c :: "%":: chars), startLinfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, accChars)
equation
equality( c = lesc );
(chars, linfo) = interleave(chars, startLinfo);
(chars, linfo, eexp) = expressionWithOpts(chars, linfo, lesc, resc);
(chars, linfo) = interleaveExpectChar(chars, linfo, resc);
(chars, linfo) = interleaveExpectChar(chars, linfo, "%");
(chars, linfo) = expectChar(chars, linfo, resc);
//(c :: chars) = chars;
//equality( c = resc );
(expLst, indStack, actInd, errOpt) = onEscapedExp(eexp, expLst, indStack, actInd, lineInd, accChars);
Expand Down Expand Up @@ -3920,12 +3925,15 @@ algorithm
exp = makeTemplateFromExpList(expLst, "<<",">>");
then (chars, linfo, exp);

//??? should we allow escaping at all ??
/* experimentally we will disallow it ... use "" constants in like 'hey son<%"'"%>s brother'
// \ will be taken literally, '\\' and <<\\>> are both double-backslash !
case ("\\":: c :: chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, accChars)
equation
true = (c ==& "\\" or c ==& "'" or c ==& lesc or c ==& resc);
(chars, linfo, exp) = restOfTemplLine(chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, c :: accChars);
then (chars, linfo, exp);

*/
case (c :: chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, accChars)
equation
(chars, linfo, exp) = restOfTemplLine(chars, linfo, lesc, resc, isSQ, expLst, indStack, actInd, lineInd, c :: accChars);
Expand Down

0 comments on commit 4e0e2ac

Please sign in to comment.