Skip to content

Commit

Permalink
- Fixed the parser (quoted identifiers are only allowed a restricted …
Browse files Browse the repository at this point in the history
…set of characters)

- Fixed XML escaping of variable- and classnames


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16470 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jun 24, 2013
1 parent d64f82f commit 4b721b4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3162,8 +3162,8 @@ case SIMCODE(modelInfo = MODELINFO(functions = functions, varInfo = vi as VARINF
<fmiModelDescription
fmiVersion = "1.0"

modelName = "<%dotPath(modelInfo.name)%>"
modelIdentifier = "<%underscorePath(modelInfo.name)%>"
modelName = "<%Util.escapeModelicaStringToXmlString(dotPath(modelInfo.name))%>"
modelIdentifier = "<%Util.escapeModelicaStringToXmlString(underscorePath(modelInfo.name))%>"

OPENMODELICAHOME = "<%makefileParams.omhome%>"

Expand Down Expand Up @@ -9261,7 +9261,7 @@ template ScalarVariableAttribute(SimVar simVar, Integer classIndex, String class
let alias = getAliasVar(aliasvar)
let caus = getCausality(causality)
<<
name = "<%crefStr(name)%>"
name = "<%Util.escapeModelicaStringToXmlString(crefStr(name))%>"
valueReference = "<%valueReference%>"
<%description%>
variability = "<%variability%>" isDiscrete = "<%isDiscrete%>"
Expand Down
12 changes: 6 additions & 6 deletions Compiler/Template/SimCodeDump.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ template dumpSimCode(SimCode code, Boolean withOperations)
::=
match code
case sc as SIMCODE(modelInfo=mi as MODELINFO(vars=vars as SIMVARS(__))) then
let name = dotPath(mi.name)
let name = Util.escapeModelicaStringToXmlString(dotPath(mi.name))
let res = <<
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="application/xml" href="simcodedump.xsl"?>
Expand Down Expand Up @@ -53,7 +53,7 @@ template dumpSimCode(SimCode code, Boolean withOperations)
case KERNEL_FUNCTION(__)
case PARALLEL_FUNCTION(__)
case RECORD_CONSTRUCTOR(__) then
'<function name="<%dotPath(name)%>"><%dumpInfo(info)%></function>' ; separator="\n"
'<function name="<%Util.escapeModelicaStringToXmlString(dotPath(name))%>"><%dumpInfo(info)%></function>' ; separator="\n"
%>
</functions>
</simcodedump><%\n%>
Expand All @@ -66,7 +66,7 @@ template dumpVarsShort(list<SimVar> vars)
::=
let varsString = (vars |> v as SIMVAR(__) hasindex index0 =>
<<
<%index0%>: <%crefStr(v.name)%>
<%index0%>: <%Util.escapeModelicaStringToXmlString(crefStr(v.name))%>
>>
;separator="\n";empty)
<<
Expand All @@ -80,7 +80,7 @@ template dumpVars(list<SimVar> vars, Boolean withOperations)
::=
vars |> v as SIMVAR(__) =>
<<
<variable name="<%crefStr(v.name)%>" comment="<%escapeModelicaStringToXmlString(v.comment)%>">
<variable name="<%Util.escapeModelicaStringToXmlString(crefStr(v.name))%>" comment="<%escapeModelicaStringToXmlString(v.comment)%>">
<%dumpAlias(v.aliasvar)%>
<%dumpElementSource(v.source,withOperations)%>
</variable><%\n%>
Expand All @@ -90,8 +90,8 @@ end dumpVars;
template dumpAlias(AliasVariable alias)
::=
match alias
case ALIAS(__) then '<alias><%crefStr(varName)%></alias>'
case NEGATEDALIAS(__) then ' <alias negated="true"><%crefStr(varName)%></alias>'
case ALIAS(__) then '<alias><%Util.escapeModelicaStringToXmlString(crefStr(varName))%></alias>'
case NEGATEDALIAS(__) then ' <alias negated="true"><%Util.escapeModelicaStringToXmlString(crefStr(varName))%></alias>'
end dumpAlias;

template eqIndex(SimEqSystem eq)
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Util/Util.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2271,7 +2271,7 @@ public function escapeModelicaStringToXmlString
algorithm
// C cannot handle newline in string constants
xmlString := System.stringReplace(modelicaString, "&", "&amp;");
xmlString := System.stringReplace(xmlString, "\\\"", "&quot;");
xmlString := System.stringReplace(xmlString, "\"", "&quot;");
xmlString := System.stringReplace(xmlString, "<", "&lt;");
xmlString := System.stringReplace(xmlString, ">", "&gt;");
// TODO! FIXME!, we have issues with accented chars in comments
Expand Down
3 changes: 2 additions & 1 deletion Parser/BaseModelica_Lexer.g
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ QIDENT :
'\'' (QCHAR | SESCAPE) (QCHAR | SESCAPE)* '\'' ;

fragment
QCHAR : NL | '\t' | ~('\n' | '\t' | '\r' | '\\' | '\'');
QCHAR : (DIGIT | NONDIGIT | '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | '>' | '=' | '?' | '@' | '[' | ']' | '^' |
'{' | '}' | '|' | '~' | ' ');

fragment
NONDIGIT : ('_' | 'a'..'z' | 'A'..'Z');
Expand Down

0 comments on commit 4b721b4

Please sign in to comment.