Skip to content

Commit

Permalink
Merge pull request #21 from urbanopt/refactor/mbl-misc-updates
Browse files Browse the repository at this point in the history
Refactor/mbl misc updates
  • Loading branch information
macintoshpie authored Jan 28, 2021
2 parents c0e6007 + 1046dc0 commit a6d8e4b
Show file tree
Hide file tree
Showing 12 changed files with 1,689 additions and 1,326 deletions.
23 changes: 23 additions & 0 deletions examples/functions-out.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
within Somewhere;
class MyClass
"Class to demo function definitions"
extends Modelica.Icons.BasesPackage;
function constructor
"Construct to connect to a schedule in EnergyPlus"
extends Modelica.Icons.Function;
input Integer input1
"input 1 comment";
output MyClass adapter;
external "C" adapter=ExternalFunctionCall(
param1,
param2,
param3);
end constructor;
function destructor
"Some comment"
extends Modelica.Icons.Function;
input Integer input2;
external "C" EnergyPlusInputVariableFree(
input2);
end destructor;
end MyClass;
21 changes: 21 additions & 0 deletions examples/functions.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
within Somewhere;
class MyClass
"Class to demo function definitions"
extends Modelica.Icons.BasesPackage;

function constructor
"Construct to connect to a schedule in EnergyPlus"
extends Modelica.Icons.Function;

input Integer input1 "input 1 comment";
output MyClass adapter;
external "C" adapter = ExternalFunctionCall(param1, param2, param3);
end constructor;

function destructor "Some comment"
extends Modelica.Icons.Function;

input Integer input2;
external "C" EnergyPlusInputVariableFree(input2);
end destructor;
end MyClass;
31 changes: 30 additions & 1 deletion examples/gmt-building-out.mo
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,35 @@ February 21, 2020, by Antoine Gautier:<br/>
First implementation.
</li>
</ul>
</html>"));
</html>"),
Icon(
graphics={
Rectangle(
lineColor={200,200,200},
fillColor={248,248,248},
fillPattern=FillPattern.HorizontalCylinder,
extent={{-100,-100},{100,100}},
radius=25.0),
Polygon(
points={{0,76},{-80,-64},{80,-64},{0,76}},
fillColor={0,0,0},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None,
lineColor={0,0,0}),
Polygon(
points={{0,68},{-72,-60},{72,-60},{0,68}},
lineColor={0,0,0},
fillColor={255,255,170},
fillPattern=FillPattern.Solid),
Ellipse(
extent={{-6,-36},{4,-46}},
pattern=LinePattern.None,
fillColor={0,0,0},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{-4,34},{2,-28}},
fillColor={0,0,0},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None)}));
end building;
/* trailing comment */
3 changes: 2 additions & 1 deletion examples/gmt-building.mo
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ February 21, 2020, by Antoine Gautier:<br/>
First implementation.
</li>
</ul>
</html>"));
</html>"),Icon(
graphics={Rectangle(lineColor={200,200,200},fillColor={248,248,248},fillPattern=FillPattern.HorizontalCylinder,extent={{-100,-100},{100,100}},radius=25.0),Polygon(points={{0,76},{-80,-64},{80,-64},{0,76}},fillColor={0,0,0},fillPattern=FillPattern.Solid,pattern=LinePattern.None,lineColor={0,0,0}),Polygon(points={{0,68},{-72,-60},{72,-60},{0,68}},lineColor={0,0,0},fillColor={255,255,170},fillPattern=FillPattern.Solid),Ellipse(extent={{-6,-36},{4,-46}},pattern=LinePattern.None,fillColor={0,0,0},fillPattern=FillPattern.Solid),Rectangle(extent={{-4,34},{2,-28}},fillColor={0,0,0},fillPattern=FillPattern.Solid,pattern=LinePattern.None)}));
end building;
/* trailing comment */
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func main() {
}
if flag.NArg() == 0 {
fmt.Fprintln(os.Stderr, "error: must provide at least one file or directory")
usage()
os.Exit(2)
}

Expand Down
3 changes: 2 additions & 1 deletion modelicafmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func (l *modelicaListener) insertIndentBefore(rule antlr.ParserRuleContext) bool
parser.IExpression_listContext,
parser.IConstraining_clauseContext,
parser.IIf_expressionContext,
parser.IIf_expression_bodyContext:
parser.IIf_expression_bodyContext,
parser.IExternal_function_call_argumentContext:
return true
case parser.IString_commentContext:
return 0 == l.inAnnotation
Expand Down
1 change: 1 addition & 0 deletions modelicafmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var exampleFileTests = []struct {
}{
{"gmt-building.mo", "gmt-building-out.mo"},
{"gmt-coolingtower.mo", "gmt-coolingtower-out.mo"},
{"functions.mo", "functions-out.mo"},
}

func TestFormattingExamples(t *testing.T) {
Expand Down
11 changes: 10 additions & 1 deletion thirdparty/Modelica.g4
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,17 @@ language_specification
: STRING
;

// changed from original file
external_function_call
: (component_reference '=')? IDENT '(' (expression_list)? ')'
: (component_reference '=')? IDENT '(' (external_function_call_args)? ')'
;

external_function_call_args
: external_function_call_argument (',' external_function_call_argument)*
;

external_function_call_argument
: expression
;

element_list
Expand Down
4 changes: 3 additions & 1 deletion thirdparty/parser/Modelica.interp

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions thirdparty/parser/modelica_base_listener.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions thirdparty/parser/modelica_listener.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6d8e4b

Please sign in to comment.