Absyn
OpenModelicaParser.Absyn is the abstract syntax of Modelica and MetaModelica: the tree that parseFile, parseString and Modelica"..." return. Each kind of node is an abstract type, and its forms are immutable records (structs) of that type: test them with isa or match on them. Lists are ImmutableList lists; optional fields are Option{T} (Some{T} or nothing). The fields are described by comments in src/Absyn/Absyn.jl.
import OpenModelicaParser
import OpenModelicaParser.Absyn
program = OpenModelicaParser.parseString("model M Real x; equation x = 1; end M;", "M.mo")
cls = first(program.classes) # an Absyn.CLASS
cls.name # "M"
cls.restriction isa Absyn.R_MODEL # true
cls.info.lineNumberStart # 1The tree
A PROGRAM holds the classes of a file and its within clause. A CLASS has a name, its prefixes, a Restriction, a body (ClassDef) and its position in the source (SourceInfo). A body of parts lists public and protected elements, equations and algorithms.
| Type | Records |
|---|---|
Program | PROGRAM |
Within | WITHIN, TOP |
Class | CLASS |
ClassDef | PARTS, DERIVED, ENUMERATION, OVERLOAD, CLASS_EXTENDS, PDER |
ClassPart | PUBLIC, PROTECTED, EQUATIONS, INITIALEQUATIONS, ALGORITHMS, INITIALALGORITHMS, CONSTRAINTS, EXTERNAL |
ElementItem | ELEMENTITEM, LEXER_COMMENT |
Element | ELEMENT, DEFINEUNIT, TEXT |
ElementSpec | CLASSDEF, EXTENDS, IMPORT, COMPONENTS |
Import | NAMED_IMPORT, QUAL_IMPORT, UNQUAL_IMPORT, GROUP_IMPORT |
ComponentItem, Component | COMPONENTITEM, COMPONENT |
Modification | CLASSMOD |
ElementArg | MODIFICATION, REDECLARATION, INHERITANCEBREAK |
EquationItem | EQUATIONITEM, EQUATIONITEMCOMMENT |
Equation | EQ_EQUALS, EQ_CONNECT, EQ_IF, EQ_FOR, EQ_WHEN_E, EQ_NORETCALL, EQ_FAILURE, EQ_PDE, EQ_RECONFIGURE |
AlgorithmItem | ALGORITHMITEM, ALGORITHMITEMCOMMENT |
Algorithm | ALG_ASSIGN, ALG_IF, ALG_FOR, ALG_PARFOR, ALG_WHILE, ALG_WHEN_A, ALG_NORETCALL, ALG_RETURN, ALG_BREAK, ALG_CONTINUE, ALG_FAILURE, ALG_TRY |
Exp | INTEGER, REAL, STRING, BOOL, CREF, BINARY, UNARY, LBINARY, LUNARY, RELATION, IFEXP, CALL, PARTEVALFUNCTION, ARRAY, MATRIX, RANGE, TUPLE, END, CODE, AS, CONS, MATCHEXP, LIST, DOT, SUBSCRIPTED_EXP, EXPRESSIONCOMMENT, BREAK |
ComponentRef | CREF_IDENT, CREF_QUAL, CREF_FULLYQUALIFIED, WILD, ALLWILD |
Path | IDENT, QUALIFIED, FULLYQUALIFIED |
Subscript | SUBSCRIPT, NOSUB |
TypeSpec | TPATH, TCOMPLEX |
Restriction | 22 records: R_MODEL, R_BLOCK, R_CONNECTOR, R_RECORD, R_FUNCTION, R_PACKAGE, R_TYPE, ... |
Comment, Annotation | COMMENT, ANNOTATION |
SourceInfo | SOURCEINFO |
Source positions, the optional type, printing
OpenModelicaParser.Absyn — Module
OpenModelicaParser.AbsynThe abstract syntax of Modelica and MetaModelica: the records that OpenModelicaParser.Parser builds and the frontend instantiates. Formerly the package Absyn.jl (1.4.2); import OpenModelicaParser.Absyn keeps the name Absyn in the code that uses it.
OpenModelicaParser.Absyn.DEFAULT_INFO — Constant
The source info of a value made without a source.
OpenModelicaParser.Absyn.SOURCEINFO — Type
SOURCEINFO(fileName, isReadOnly, lineNumberStart, columnNumberStart, lineNumberEnd, columnNumberEnd[,
lastModification])The file (isReadOnly: true for libraries), the start and end positions, and the file's modification time (stat(2) mtime as Float64; 0.0 when not given).
OpenModelicaParser.Absyn.SourceInfo — Type
SourceInfoWhere a syntax element or class is in the source (formerly MetaModelica's SourceInfo).
OpenModelicaParser.Absyn.dumpBinary — Method
A binary or logical operation: the right operand in parentheses also when it binds as tightly (a - (b - c)) or is a unary operation (a + (-b): Modelica allows a unary operator only at the start); ^ takes no operator expression unparenthesised on either side.
OpenModelicaParser.Absyn.dumpOperand — Method
An operand in parentheses when it binds looser than its operator, or as tightly with tight.
OpenModelicaParser.Absyn.dumpPrecedence — Method
How tightly an expression binds, higher is tighter: if-expressions and ranges, or, and, not, relations, + -, * /, unary + -, ^, then primaries. Unary minus binds tighter than * (-a*x) and looser than ^ ((-a)^2).
OpenModelicaParser.Absyn.sourceInfo — Method
MetaModelica's sourceInfo(): DEFAULT_INFO.
OpenModelicaParser.Absyn.Optional — Module
Option{T}: Union{Some{T}, Nothing}, MetaModelica's optional type. In a submodule, used without importing the name, so @exportAll does not export it: MetaModelica exports Option, and two exported bindings of one name clash in code that uses both.