Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/mbl misc updates #21

Merged
merged 3 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usage reports the command line arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, previously it would just say "error: ..." but having usage below the error will be helpful

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