Module Syntax

module Syntax: sig .. end
Modelica 3.x abstract syntax

This module contains an interpretation of a "usable" form of the abstract syntax of the modeling language Modelica Since Modelica only specifies the concrete syntax in the specification, there is a certain degree of freedom applied here.
Author(s): Christoph Höger


type str = string Location.loc 
type name = str list 
A type-name is a list of strings separated by dots, e.g. Modelica.Icons.Example
type 'a commented = {
   commented : 'a;
   comment : comment;
}
Something that can be commented can wrapped in this record
type 'a annotated = {
   annotated_elem : 'a;
   annotation : modification option;
}
Something that can be annotated can wrapped in this record
type comment = str option annotated 
Comments are optionally annotated optional strings
type unit_ = {
   within : name option;
   toplevel_defs : typedef list;
}
The stored definition unit is the representation of a single Modelica file
type typedef_options = {
   type_replaceable : bool;
   type_final : bool;
   partial : bool;
   encapsulated : bool;
}
The options of a type-definition: is the definition replaceable / final / partial / encapsulated ?
type 'a typedef_struct = {
   td_name : string;
   sort : sort;
   type_exp : 'a;
   cns : constraint_ option;
   type_options : typedef_options;
}
Typedefs share a lot of common code. This is reflected by the Syntax.typedef_struct:
'a
denotes the definition's distincitve payload.
type typedef_desc = 
| Short of texp typedef_struct
| Composition of composition typedef_struct
| Enumeration of enum_literal list typedef_struct
| OpenEnumeration of unit typedef_struct
| DerSpec of der_spec typedef_struct
| Extension of extension typedef_struct
The definition of a new type/class etc.
type extension = composition * modification option 
type typedef = typedef_desc commented 
type constraint_ = texp commented 
type algorithm = statement list 
type behavior = {
   algorithms : algorithm list;
   equations : equation list;
   initial_algorithms : algorithm list;
   initial_equations : equation list;
   external_ : external_def option;
}
type external_def_struct = {
   lang : string;
   ext_lhs : exp option;
   ext_ident : string;
   ext_args : exp list;
}
type external_def = external_def_struct annotated 
type elements = {
   typedefs : typedef list;
   redeclared_types : typedef list;
   extensions : extend list;
   defs : definition list;
   redeclared_defs : definition list;
}
type composition = {
   imports : import list;
   public : elements;
   protected : elements;
   cargo : behavior;
}
type enum_literal = string commented 
type der_spec = {
   der_name : name;
   idents : str list;
}
Partial derivative specification, see section 12.7.2
type sort = 
| Package
| Class
| Model
| Block
| Connector
| ExpandableConnector
| Record
| Function
| Type
| Operator
| OperatorRecord
| OperatorFunction
type connectivity = 
| Flow
| Stream
type variability = 
| Constant
| Parameter
| Discrete
type causality = 
| Input
| Output
type named_import = {
   global : name;
   local : string;
}
type import = import_desc commented 
type import_desc = 
| NamedImport of named_import
| Unnamed of name
| UnqualifiedImport of name
type extend = {
   ext_type : texp;
   ext_annotation : modification option;
}
type scope = 
| Inner
| Outer
| InnerOuter
| Local
type definition_options = {
   final : bool;
   scope : scope;
   replaceable : bool;
}
type definition_structure = {
   def_name : string;
   def_type : texp;
   def_constraint : constraint_ option;
   def_rhs : exp option;
   def_if : exp option;
   def_options : definition_options;
}
type definition = definition_structure commented 
type statement = statement_desc commented 
type statements = statement list 
type statement_desc = 
| Assignment of assignment
| Call of call_statement
| IfStmt of if_statement
| WhenStmt of when_statement
| Break
| Return
| ForStmt of for_statement
| WhileStmt of while_statement
type assignment = {
   target : exp;
   source : exp;
}
type named_arg = {
   argument_name : str;
   argument : exp;
}
type call_statement = {
   procedure : exp;
   pargs : exp list;
   pnamed_args : named_arg list;
}
type 'a else_condition = {
   guard : exp;
   elsethen : 'a;
}
type 'a condition_struct = {
   condition : exp;
   then_ : 'a;
   else_if : 'a else_condition list;
   else_ : 'a;
}
type if_statement = statements condition_struct 
type when_statement = statements condition_struct 
type 'a for_loop_struct = {
   idx : idx list;
   body : 'a;
}
type for_statement = statements for_loop_struct 
type while_statement = {
   while_ : exp;
   do_ : statements;
}
type equations = equation list 
type equation = equation_desc commented 
type equation_desc = 
| SimpleEquation of binary_exp
| ForEquation of for_equation
| IfEquation of if_equation
| WhenEquation of when_equation
| ExpEquation of exp
type for_equation = equations for_loop_struct 
type if_equation = equations condition_struct 
type when_equation = equations condition_struct 
type binary_exp = {
   left : exp;
   right : exp;
}
type if_expression = exp condition_struct 
type array_access = {
   lhs : exp;
   indices : exp list;
}
type range = {
   start : exp;
   end_ : exp;
   step : exp option;
}
type projection = {
   object_ : exp;
   field : string;
}
type application = {
   fun_ : exp;
   args : exp list;
   named_args : named_arg list;
}
type comprehension = {
   exp : exp;
   idxs : idx list;
}
type exp = 
| Pow of binary_exp
| DPow of binary_exp
| Mul of binary_exp
| DMul of binary_exp
| Div of binary_exp
| DDiv of binary_exp
| Plus of binary_exp
| DPlus of binary_exp
| Minus of binary_exp
| DMinus of binary_exp
| UMinus of exp
| UPlus of exp
| UDMinus of exp
| UDPlus of exp
| And of binary_exp
| Or of binary_exp
| Not of exp
| Gt of binary_exp
| Lt of binary_exp
| Leq of binary_exp
| Geq of binary_exp
| Neq of binary_exp
| Eq of binary_exp
| If of if_expression
| ArrayAccess of array_access
| Range of range
| RootIde of string
| Ide of string
| Proj of projection
| App of application
| Bool of bool
| Int of int
| Real of float
| String of string
| Compr of comprehension
| Array of exp list
| MArray of exp list list
| ExplicitClosure of exp
| End
| Colon
| Der
| Initial
| Assert
| OutputExpression of exp option list
type idx = {
   variable : str;
   range : exp option;
}
type tprojection = {
   class_type : texp;
   type_element : string;
}
type array_type = {
   base_type : texp;
   dims : exp list;
}
type mod_type = {
   mod_type : texp;
   modification : modification;
}
type texp = 
| TIde of string
| TRootide of string
| TProj of tprojection
| TArray of array_type
| TMod of mod_type
| TVar of variability flagged_type
| TCon of connectivity flagged_type
| TCau of causality flagged_type
type 'a flagged_type = {
   flag : 'a;
   flagged : texp;
}
type type_redeclaration = {
   redecl_each : bool;
   redecl_type : texp typedef_struct commented;
}
type component_redeclaration = {
   each : bool;
   def : definition;
}
type component_modification_struct = {
   mod_each : bool;
   mod_final : bool;
   mod_name : name;
   mod_value : modification_value option;
}
type modification_value = 
| Nested of modification
| Rebind of exp
| NestedRebind of nested_and_rebind_modification
type nested_and_rebind_modification = {
   nested : modification;
   new_value : exp;
}
type component_modification = component_modification_struct commented 
type modification = {
   types : type_redeclaration list;
   components : component_redeclaration list;
   modifications : component_modification list;
}