Skip to content

Commit

Permalink
Parse annotations as elements
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Mar 25, 2021
1 parent 0054f58 commit 7746a39
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions OMCompiler/Compiler/Parsers/SimpleModelicaParser.mo
Original file line number Diff line number Diff line change
Expand Up @@ -604,25 +604,28 @@ function element_list
extends partialParser;
protected
TokenId id;
Boolean b;
Boolean b, isAnnotation;
algorithm
outTree := {};
while true loop
(tokens, tree, b) := LA1(tokens, tree, First.element);
if not b then
break;
end if;
(tokens, tree) := element(tokens, tree);
(tokens, tree, isAnnotation) := element(tokens, tree);
(tokens, tree) := scan(tokens, tree, TokenId.SEMICOLON);

outTree := makeNode(listReverse(tree), label=LEAF(makeToken(TokenId.IDENT, "$element")))::outTree;
tree := {};
if not isAnnotation then
outTree := makeNode(listReverse(tree), label=LEAF(makeToken(TokenId.IDENT, "$element")))::outTree;
tree := {};
end if;
end while;
outTree := listAppend(tree, listAppend(outTree, inTree));
end element_list;

function element
extends partialParser;
output Boolean isAnnotation = false;
protected
TokenId id;
Boolean b,b1;
Expand All @@ -637,6 +640,11 @@ algorithm
algorithm
(tokens, tree) := extends_clause(tokens, tree);
then ();
case TokenId.ANNOTATION
algorithm
(tokens, tree) := _annotation(tokens, tree);
isAnnotation := true;
then ();
else
algorithm
(tokens, tree) := scanOpt(tokens, tree, TokenId.REDECLARE);
Expand Down Expand Up @@ -3287,6 +3295,7 @@ package First "First token possible for a given non-terminal in the Modelica 3 g
};
constant list<TokenId> component_clause = listAppend(type_prefix,name);
constant list<TokenId> element = listAppend(component_clause, listAppend(class_definition, {
TokenId.ANNOTATION,
TokenId.IMPORT,
TokenId.EXTENDS,
TokenId.REDECLARE,
Expand Down

0 comments on commit 7746a39

Please sign in to comment.