lbl-srg / modelica-json

Modelica to JSON Parser
Other
22 stars 17 forks source link

Expression parsing fails #241

Open AntoineGautier opened 3 months ago

AntoineGautier commented 3 months ago

When translating Modelica to JSON using commit 648b390, some expressions are not properly parsed and the original expressions are lost. For example, translating Buildings/Controls/OBC/ASHRAE/G36/AHUs/SingleZone/VAV/Controller.mo, we get:

                "component_clause": {
                  "type_specifier": "Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput",
                  "component_list": [
                    {
                      "declaration": {
                        "identifier": "y1RetFan"
                      },
                      "condition_attribute": {
                        "expression": {
                          "simple_expression": "([object Object])"
                        }
                      },

whereas the original declaration is:

  Buildings.Controls.OBC.CDL.Interfaces.BooleanOutput y1RetFan if (buiPreCon
     == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)

Another example: with Buildings/Controls/OBC/ASHRAE/G36/AHUs/SingleZone/VAV/Controller.mo, we get:

              {
                "component_clause": {
                  "type_specifier": "Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations.ReturnFan",
                  "component_list": [
                    {
                      "declaration": {
                        "identifier": "modRet",
                      },
                      "condition_attribute": {
                        "expression": {
                          "simple_expression": "([object Object])"
                        }
                      },

whereas the original declaration is:

  Buildings.Controls.OBC.ASHRAE.G36.AHUs.MultiZone.VAV.Economizers.Subsequences.Modulations.ReturnFan
    modRet if (buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanMeasuredAir
     or buiPreCon == Buildings.Controls.OBC.ASHRAE.G36.Types.PressureControl.ReturnFanDp)
AntoineGautier commented 3 months ago

@JayHuLBL Can you look into that?

AntoineGautier commented 2 months ago

This issue is probably related to the parentheses that are used around logical expressions (not, or, and, etc.). See the attached expression.json that results from parsing the following declarations.

  parameter Integer notexp = if not a < b then 1 else 2;
  parameter Integer andnotexp = if a < b and not a < b then 1 else 2;
  parameter Integer notexppar = if not (a < b) then 1 else 2;
  parameter Integer andnotexppar = if (a < b) and not (a < b) then 1 else 2;