From f952d978c329ba1ea652308b7fa5b2c5d092ba40 Mon Sep 17 00:00:00 2001 From: Anand Krishnan Prakash Date: Fri, 9 Apr 2021 05:41:34 -0700 Subject: [PATCH 01/29] updating files according to grammar and new json data model --- .../lbl/parser/domain/Algorithm_section.java | 13 + .../gov/lbl/parser/domain/Annotation.java | 9 + .../java/gov/lbl/parser/domain/Argument.java | 11 + .../gov/lbl/parser/domain/Argument_list.java | 11 + .../parser/domain/Arithmetic_expression.java | 11 + .../lbl/parser/domain/Arithmetic_term.java | 11 + .../lbl/parser/domain/Array_subscripts.java | 11 + .../parser/domain/Assignment_equation.java | 11 + .../parser/domain/Assignment_statement.java | 13 + ...signment_with_function_call_statement.java | 13 + .../gov/lbl/parser/domain/Base_prefix.java | 9 + .../lbl/parser/domain/Class_definition.java | 20 +- .../lbl/parser/domain/Class_modification.java | 9 + .../lbl/parser/domain/Class_specifier.java | 12 +- .../java/gov/lbl/parser/domain/Comment.java | 741 +------------- .../lbl/parser/domain/Component_clause.java | 17 +- .../lbl/parser/domain/Component_clause1.java | 13 + .../parser/domain/Component_declaration.java | 16 +- .../parser/domain/Component_declaration1.java | 11 + .../gov/lbl/parser/domain/Component_list.java | 9 +- .../parser/domain/Component_reference.java | 11 + .../domain/Component_reference_part.java | 13 + .../gov/lbl/parser/domain/Composition.java | 912 +----------------- .../parser/domain/Condition_attribute.java | 9 + .../gov/lbl/parser/domain/Connect_clause.java | 29 +- .../parser/domain/Constraining_clause.java | 13 + .../gov/lbl/parser/domain/Declaration.java | 260 +---- .../parser/domain/Der_class_specifier.java | 18 +- .../domain/Der_class_specifier_value.java | 18 + .../java/gov/lbl/parser/domain/Element.java | 50 +- .../gov/lbl/parser/domain/Element_list.java | 4 +- .../parser/domain/Element_modification.java | 13 + .../Element_modification_or_replaceable.java | 15 + .../parser/domain/Element_redeclaration.java | 17 + .../parser/domain/Element_replaceable.java | 13 + .../java/gov/lbl/parser/domain/Enum_list.java | 7 +- .../parser/domain/Enumeration_literal.java | 9 +- .../java/gov/lbl/parser/domain/Equation.java | 49 +- .../lbl/parser/domain/Equation_section.java | 14 +- .../gov/lbl/parser/domain/Expression.java | 11 + .../lbl/parser/domain/Expression_list.java | 11 + .../gov/lbl/parser/domain/Extends_clause.java | 29 +- .../parser/domain/External_composition.java | 15 + .../parser/domain/External_function_call.java | 13 + .../java/gov/lbl/parser/domain/Factor.java | 14 + .../gov/lbl/parser/domain/For_equation.java | 13 + .../java/gov/lbl/parser/domain/For_index.java | 11 + .../gov/lbl/parser/domain/For_indices.java | 11 + .../gov/lbl/parser/domain/For_statement.java | 13 + .../lbl/parser/domain/Function_argument.java | 15 + .../lbl/parser/domain/Function_arguments.java | 17 + .../lbl/parser/domain/Function_call_args.java | 9 + .../parser/domain/Function_call_equation.java | 11 + .../parser/domain/Function_call_primary.java | 16 + .../domain/Function_call_statement.java | 11 + .../lbl/parser/domain/If_elseif_equation.java | 13 + .../parser/domain/If_elseif_expression.java | 13 + .../parser/domain/If_elseif_statement.java | 13 + .../gov/lbl/parser/domain/If_equation.java | 13 + .../gov/lbl/parser/domain/If_expression.java | 13 + .../gov/lbl/parser/domain/If_statement.java | 13 + .../gov/lbl/parser/domain/Import_clause.java | 31 +- .../gov/lbl/parser/domain/Import_list.java | 14 + .../lbl/parser/domain/Logical_expression.java | 11 + .../gov/lbl/parser/domain/Logical_factor.java | 11 + .../gov/lbl/parser/domain/Logical_term.java | 11 + .../parser/domain/Long_class_specifier.java | 27 +- .../gov/lbl/parser/domain/Modification.java | 15 + .../main/java/gov/lbl/parser/domain/Name.java | 11 + .../java/gov/lbl/parser/domain/Name_part.java | 11 + .../gov/lbl/parser/domain/Named_argument.java | 11 + .../parser/domain/Output_expression_list.java | 11 + .../java/gov/lbl/parser/domain/Primary.java | 28 + .../java/gov/lbl/parser/domain/Relation.java | 13 + .../lbl/parser/domain/Remaining_factor.java | 11 + .../parser/domain/Short_class_definition.java | 11 + .../parser/domain/Short_class_specifier.java | 44 +- .../domain/Short_class_specifier_value.java | 20 + .../lbl/parser/domain/Simple_expression.java | 15 + .../java/gov/lbl/parser/domain/Statement.java | 28 + .../lbl/parser/domain/Stored_definition.java | 10 +- .../java/gov/lbl/parser/domain/Subscript.java | 12 + .../main/java/gov/lbl/parser/domain/Term.java | 13 + .../gov/lbl/parser/domain/Type_specifier.java | 9 + .../parser/domain/When_elsewhen_equation.java | 14 + .../domain/When_elsewhen_statement.java | 14 + .../gov/lbl/parser/domain/When_equation.java | 11 + .../gov/lbl/parser/domain/When_statement.java | 11 + .../lbl/parser/domain/While_statement.java | 14 + .../java/gov/lbl/parser/domain/Within.java | 9 + 90 files changed, 1046 insertions(+), 2148 deletions(-) create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Algorithm_section.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Annotation.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Argument.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Argument_list.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Arithmetic_expression.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Arithmetic_term.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Array_subscripts.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Assignment_equation.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Assignment_statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Assignment_with_function_call_statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Base_prefix.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Class_modification.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Component_clause1.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Component_declaration1.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Component_reference.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Component_reference_part.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Condition_attribute.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Constraining_clause.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Der_class_specifier_value.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Element_modification.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Element_modification_or_replaceable.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Element_redeclaration.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Element_replaceable.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Expression.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Expression_list.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/External_composition.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/External_function_call.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Factor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/For_equation.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/For_index.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/For_indices.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/For_statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Function_argument.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Function_arguments.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Function_call_args.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Function_call_equation.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Function_call_primary.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Function_call_statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_equation.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_expression.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/If_equation.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/If_expression.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/If_statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Import_list.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Logical_expression.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Logical_factor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Logical_term.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Modification.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Name.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Name_part.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Named_argument.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Output_expression_list.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Primary.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Relation.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Remaining_factor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Short_class_definition.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Short_class_specifier_value.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Simple_expression.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Subscript.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Term.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Type_specifier.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/When_elsewhen_equation.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/When_elsewhen_statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/When_equation.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/When_statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/While_statement.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Within.java diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Algorithm_section.java b/java/parser/src/main/java/gov/lbl/parser/domain/Algorithm_section.java new file mode 100644 index 00000000..1aee3bce --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Algorithm_section.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Algorithm_section { + private Boolean initial; + private Collection statement; + + public Algorithm_section(Boolean initial, Collection statement) { + this.initial = initial; + this.statement = statement; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Annotation.java b/java/parser/src/main/java/gov/lbl/parser/domain/Annotation.java new file mode 100644 index 00000000..6d172e56 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Annotation.java @@ -0,0 +1,9 @@ +package gov.lbl.parser.domain; + +public class Annotation { + private Class_modification class_modification; + + public Annotation(Class_modification class_modification) { + this.class_modification = class_modification; + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Argument.java b/java/parser/src/main/java/gov/lbl/parser/domain/Argument.java new file mode 100644 index 00000000..6f019d17 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Argument.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Argument { + private Element_modification_or_replaceable element_modification_or_replaceable; + private Element_redeclaration element_redeclaration; + + public Argument(Element_modification_or_replaceable element_modification_or_replaceable, Element_redeclaration element_redeclaration) { + this.element_modification_or_replaceable = element_modification_or_replaceable; + this.element_redeclaration = element_redeclaration; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Argument_list.java b/java/parser/src/main/java/gov/lbl/parser/domain/Argument_list.java new file mode 100644 index 00000000..42ac4eb0 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Argument_list.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Argument_list { + private Collection arguments; + + public Argument_list(Collection arguments) { + this.arguments = arguments.size() > 0 ? arguments : null; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Arithmetic_expression.java b/java/parser/src/main/java/gov/lbl/parser/domain/Arithmetic_expression.java new file mode 100644 index 00000000..fcd4a6f8 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Arithmetic_expression.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Arithmetic_expression { + private Collection arithmetic_term_list; + + public Arithmetic_expression(Collection arithmetic_term_list) { + this.arithmetic_term_list = arithmetic_term_list; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Arithmetic_term.java b/java/parser/src/main/java/gov/lbl/parser/domain/Arithmetic_term.java new file mode 100644 index 00000000..1dfa3b16 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Arithmetic_term.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Arithmetic_term { + private String add_op; //'+' | '-' | '.+' | '.-' + private Term term; + + public Arithmetic_term(String add_op, Term term) { + this.add_op = add_op; + this.term = term; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Array_subscripts.java b/java/parser/src/main/java/gov/lbl/parser/domain/Array_subscripts.java new file mode 100644 index 00000000..fb2dc475 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Array_subscripts.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Array_subscripts { + private Collection subscripts; + + public Array_subscripts(Collection subscripts) { + this.subscripts = subscripts; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Assignment_equation.java b/java/parser/src/main/java/gov/lbl/parser/domain/Assignment_equation.java new file mode 100644 index 00000000..cd9b309f --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Assignment_equation.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Assignment_equation { + private Simple_expression lhs; + private Expression rhs; + + public Assignment_equation(Simple_expression lhs, Expression rhs) { + this.lhs = lhs; + this.rhs = rhs; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Assignment_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/Assignment_statement.java new file mode 100644 index 00000000..c07c4bee --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Assignment_statement.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import gov.lbl.antlr4.visitor.modelicaParser.Component_referenceContext; + +public class Assignment_statement { + private Component_reference identifier; + private Expression value; + + public Assignment_statement(Component_reference identifier, Expression value) { + this.identifier = identifier; + this.value = value; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Assignment_with_function_call_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/Assignment_with_function_call_statement.java new file mode 100644 index 00000000..b7bbfe8b --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Assignment_with_function_call_statement.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +public class Assignment_with_function_call_statement { + private Output_expression_list output_expression_list; + private Component_reference function_name; + private Function_call_args function_call_args; + + public Assignment_with_function_call_statement(Output_expression_list output_expression_list, Component_reference function_name, Function_call_args function_call_args) { + this.output_expression_list = output_expression_list; + this.function_name = function_name; + this.function_call_args = function_call_args; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Base_prefix.java b/java/parser/src/main/java/gov/lbl/parser/domain/Base_prefix.java new file mode 100644 index 00000000..190eaf41 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Base_prefix.java @@ -0,0 +1,9 @@ +package gov.lbl.parser.domain; + +public class Base_prefix { + String type_prefix; + + public Base_prefix(String type_prefix) { + this.type_prefix = type_prefix; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Class_definition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Class_definition.java index 87c032d5..33ada9da 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Class_definition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Class_definition.java @@ -1,15 +1,15 @@ package gov.lbl.parser.domain; public class Class_definition { - private String encapsulated; - private String class_prefixes; - private Class_specifier class_specifier; + private Boolean is_final; + private Boolean encapsulated; + private String class_prefixes; //class_prefixes: (PARTIAL)? (CLASS | MODEL | (OPERATOR)? RECORD | BLOCK | (EXPANDABLE)? CONNECTOR | TYPE | PACKAGE | ((PURE | IMPURE))? (OPERATOR)? FUNCTION | OPERATOR) + private Class_specifier class_specifier; - public Class_definition(String enca_dec, - String class_prefixes, - Class_specifier class_specifier) { - this.encapsulated = (enca_dec == null ? null : enca_dec); - this.class_prefixes = class_prefixes; - this.class_specifier = class_specifier; - } + public Class_definition(Boolean is_final, Boolean encapsulated, String class_prefixes, Class_specifier class_specifier) { + this.is_final = is_final; + this.encapsulated = encapsulated; + this.class_prefixes = class_prefixes; + this.class_specifier = class_specifier; + } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Class_modification.java b/java/parser/src/main/java/gov/lbl/parser/domain/Class_modification.java new file mode 100644 index 00000000..f8ec3eb9 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Class_modification.java @@ -0,0 +1,9 @@ +package gov.lbl.parser.domain; + +public class Class_modification { + private Argument_list argument_list; + + public Class_modification(Argument_list argument_list) { + this.argument_list = argument_list; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Class_specifier.java b/java/parser/src/main/java/gov/lbl/parser/domain/Class_specifier.java index 7ecd3ca8..e8ad69df 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Class_specifier.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Class_specifier.java @@ -5,11 +5,9 @@ public class Class_specifier { private Short_class_specifier short_class_specifier; private Der_class_specifier der_class_specifier; - public Class_specifier(Long_class_specifier long_class_specifier, - Short_class_specifier short_class_specifier, - Der_class_specifier der_class_specifier) { - this.long_class_specifier = long_class_specifier; - this.short_class_specifier = short_class_specifier; - this.der_class_specifier = der_class_specifier; - } + public Class_specifier(Long_class_specifier long_class_specifier, Short_class_specifier short_class_specifier, Der_class_specifier der_class_specifier) { + this.long_class_specifier = long_class_specifier; + this.short_class_specifier = short_class_specifier; + this.der_class_specifier = der_class_specifier; + } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Comment.java b/java/parser/src/main/java/gov/lbl/parser/domain/Comment.java index 8b1b3a60..067151ff 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Comment.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Comment.java @@ -1,742 +1,11 @@ package gov.lbl.parser.domain; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import gov.lbl.parser.domain.Composition.GraphicLayers; - -import java.util.ArrayList; -import gov.lbl.parser.domain.Composition; - public class Comment { - public String string_comment; - public AnnotationClass annotation; - - public Comment(String string_comment, - String annotation) { - this.string_comment = string_comment.isEmpty() ? null : string_comment; - String annTemp = ""; - if (annotation == null) { - this.annotation = null; - } else { - /** access text string in "annotation (annTemp)" **/ - annTemp = annotation.substring(1,annotation.length()-2); - AnnotationClass annCla = new AnnotationClass(); - annCla.annClass(annTemp); - this.annotation = annCla; - } - } - - /** - * AnnotationClass --- program to parse - * annotation(defaultComponentName = ..., - * Diagram (...), - * Icon (...), - * Dialog (..., ..., ...), - * Placement (..., ..., ...), - * Line (...), - * Text (...), - * Documentation (...), - * __Annotation (...)) - * - */ - public class AnnotationClass { - String defaultName; - Composition.GraphicLayers diagram; - Composition.GraphicLayers icon; - Collection dialog; - PlacementBlock placement; - LineBlock line; - String text; - Documentation documentation; - VendorAnnotation vendor_annotation; - Collection others; - - private TemCla annClass(String annStr) { - String nameStr; - String dialogStr = findSubStr(annStr, "Dialog "); - String placementStr = findSubStr(annStr, "Placement "); - String lineStr = findSubStr(annStr, "Line "); - String docStr = findSubStr(annStr, "Documentation "); - String diagramStr = findSubStr(annStr, "Diagram "); - String iconStr = findSubStr(annStr, "Icon "); - String textStr = findSubStr(annStr, "Text "); - String venAnnStr = findSubStr(annStr, "__"); - - if (placementStr != null) { - PlacementBlock placement = new PlacementBlock(); - placement.placementBlock(placementStr); - this.placement = placement; - } else { - this.placement = null; - } - - if (lineStr != null) { - LineBlock linBlo = new LineBlock(); - linBlo.lineBlock(lineStr); - this.line = linBlo; - } else { - this.line = null; - } - - Composition comp = new Composition(null, Collections.emptyList(), - Collections.emptyList(),null, - Collections.emptyList(), - Collections.emptyList(), - Collections.emptyList(), - null,null,null,null); - if (diagramStr != null) { - Composition.GraphicLayers temp = comp.new GraphicLayers(); - temp.graphicLayers(diagramStr); - this.diagram = temp; - } else { - this.diagram = null; - } - - if (iconStr != null) { - Composition.GraphicLayers temp = comp.new GraphicLayers(); - temp.graphicLayers(iconStr); - this.icon = temp; - } else { - this.icon = null; - } - - this.text = textStr; - - /** find vendor annotation **/ - String venAnnName = ""; - if (venAnnStr != null) { - venAnnName = annStr.substring(annStr.indexOf("__"), annStr.indexOf("(",annStr.indexOf("__"))); - VendorAnnotation venAnn = new VendorAnnotation(); - venAnn.vendorAnnotation(venAnnName,venAnnStr); - this.vendor_annotation = venAnn; - } else { - this.vendor_annotation = null; - } - - /** find "defaultComponentName" **/ - if (annStr.contains("defaultComponentName")) { - int beginInd = annStr.indexOf("\"", annStr.indexOf("defaultComponentName")+"defaultComponentName".length()-1); - int endInd = annStr.indexOf("\"", beginInd+1); - nameStr = annStr.substring(beginInd, endInd+1); - } else { - nameStr = null; - } - - /** created a list of String that will be removed from annotation string "annStr", - so to find out "others" **/ - List strListToBeRem = new ArrayList(); - if (dialogStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Dialog (") - .append(dialogStr) - .append(" )") - .toString()); - } - if (placementStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Placement (") - .append(placementStr) - .append(" )") - .toString()); - } - if (lineStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Line (") - .append(lineStr) - .append(" )") - .toString()); - } - if (docStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Documentation (") - .append(docStr) - .append(" )") - .toString()); - } - if (diagramStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Diagram (") - .append(diagramStr) - .append(" )") - .toString()); - } - if (iconStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Icon (") - .append(iconStr) - .append(" )") - .toString()); - } - if (textStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Text (") - .append(textStr) - .append(" )") - .toString()); - } - if (nameStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("defaultComponentName =") - .append(nameStr) - .toString()); - } - if (venAnnStr != null) { - StringBuilder temStr = new StringBuilder(); - int venAnnStrEndInd = annStr.indexOf(venAnnStr) + venAnnStr.length(); - String endBra = annStr.substring(venAnnStrEndInd, annStr.indexOf(")", venAnnStrEndInd)+1); - strListToBeRem.add(temStr.append(venAnnName).append("(") - .append(venAnnStr).append(endBra) - .toString()); - } + private String string_comment; + private Annotation annotation; - /** find out "others" **/ - String otherAnnStr = annStr; - String tempStrInList; - if (strListToBeRem.size()>0) { - for (int i=0; i diaEle = new ArrayList(); - if (dialogStr == null) { - this.dialog = null; - } else { - String name; - String value; - List strSets = new ArrayList(); - strSets.addAll(splitAtComma(dialogStr)); - for (int i=0; i othEle = new ArrayList(); - if (otherAnnStr == null || !otherAnnStr.contains("=")) { - this.others = null; - } else { - String name; - String value; - List othSetTemp = new ArrayList(); - othSetTemp.addAll(splitAtComma(otherAnnStr)); - List othSet = new ArrayList(); - for (int i=0; i", docStr.indexOf("info")) - 1; - int endIndTemp = docStr.indexOf("", docStr.indexOf("info")); - int endInd = endIndTemp + "".length() + 1; - infoStr = docStr.substring(beginInd, endInd); - } else { - infoStr = null; - } - if (docStr.contains("revisions =")) { - int beginInd = docStr.indexOf("", docStr.indexOf("revisions =")) - 1; - int endIndTemp = docStr.indexOf("", docStr.indexOf("revisions =")); - int endInd = endIndTemp + "".length() + 1; - revStr = docStr.substring(beginInd, endInd); - } else { - revStr = null; - } - this.documentation = new Documentation(infoStr, revStr); - } - return new TemCla(annStr); - } - } - - private class VendorAnnotation{ - private String name; - private Collection annotation; - private TemCla vendorAnnotation(String venAnnName, String venAnnStr) { - this.name = venAnnName.replaceAll("\\s+", ""); - List venAnnEle = new ArrayList(); - if (venAnnStr == null || !venAnnStr.contains("=")) { - this.annotation = null; - } else { - String name; - String value; - List venSetTemp = new ArrayList(); - venSetTemp.addAll(splitAtComma(venAnnStr)); - List venSet = new ArrayList(); - for (int i=0; i strSets = new ArrayList(); - strSets.addAll(splitAtComma(placementStr)); - Boolean visible = null; - Transformation transformation = null; - Transformation iconTransformation = null; - String name = null; - String lefStr = null; - for (String str : strSets) { - if (str.contains("visible")) { - visible = Boolean.valueOf(str.substring(str.indexOf('=')+1, str.length()).trim()); - } else { - name = str.substring(0, str.indexOf('(')).trim(); - lefStr = str.substring(str.indexOf('(')+1, str.lastIndexOf(')')).trim(); - Transformation temp = new Transformation(); - temp.transformation(lefStr); - if (name.contains("transformation")) { - transformation = temp; - } else if (name.contains("iconTransformation")) { - iconTransformation = temp; - } - } - } - - this.visible = visible; - this.transformation = transformation; - this.iconTransformation = iconTransformation; - return new TemCla(placementStr); - } - } - - public class Transformation{ - private Collection extent; - private Double rotation; - private Points origin; - public TemCla transformation(String traStr) { - List strSets = new ArrayList(); - strSets.addAll(splitAtComma(traStr)); - String extStr = null; - List extPoints = new ArrayList(); - Double rotStr = null; - String oriStr = null; - Points oriPoint = new Points(); - for (String str : strSets) { - if (str.contains("extent")) { - int temInd = str.indexOf('='); - extStr = str.substring(temInd+1,str.length()).trim(); - String temp = extStr.substring(extStr.indexOf('{') + 1, extStr.lastIndexOf('}')).trim(); - - List pointsSet = new ArrayList(); - pointsSet.addAll(splitAtComma(temp)); - for (String p : pointsSet) { - Points point = new Points(); - point.points(p); - extPoints.add(point); - } - } - if (str.contains("rotation")) { - rotStr = Double.valueOf(str.substring(str.indexOf('=')+1, str.length()).trim()); - } - if (str.contains("origin")) { - oriStr = str.substring(str.indexOf('=')+1, str.length()).trim(); - oriPoint.points(oriStr); - } - } - this.extent = extStr == null ? null : extPoints; - this.rotation = rotStr; - this.origin = oriStr == null ? null : oriPoint; - return new TemCla(traStr); - } - - } - - public class LineBlock{ - private Boolean visible; - private Points origin; - private Double rotation; - private Collection points; - private DynamicPoints dynPoints; - private Color color; - private DynamicColor dynColor; - private String pattern; - private Double thickness; - private String arrow; - private Double arrowSize; - private String smooth; - public TemCla lineBlock(String lineStr) { - List strSets = new ArrayList(); - strSets.addAll(splitAtComma(lineStr)); - for (String str : strSets) { - int indEq = str.indexOf('='); - String name = str.substring(0, indEq).trim(); - String value = str.substring(indEq+1, str.length()).trim(); - if (name.contains("points")) { - if (value.contains("DynamicSelect")) { - DynamicPoints dynPoi = new DynamicPoints(); - dynPoi.dynamicPoints(value); - this.dynPoints = dynPoi; - this.points = null; - } else { - int indRB= value.indexOf('{'); - String temp = value.substring(indRB+1, value.lastIndexOf('}')).trim(); - List linePoints = new ArrayList(); - List pointsSet = new ArrayList(); - pointsSet.addAll(splitAtComma(temp)); - for (String p : pointsSet) { - Points point = new Points(); - point.points(p); - linePoints.add(point); - } - this.points = linePoints; - this.dynPoints = null; - } - } else if (name.contains("color")) { - if (value.contains("DynamicSelect")) { - DynamicColor dynCol = new DynamicColor(); - dynCol.dynamicColor(value); - this.dynColor = dynCol; - this.color = null; - } else { - Color color = new Color(); - color.color(value); - this.color = color; - this.dynColor = null; - } - } else if (name.contains("pattern")) { - this.pattern = value; - } else if (name.contains("thickness")) { - this.thickness = Double.valueOf(value); - } else if (name.contains("arrow")) { - this.arrow = value; - } else if (name.contains("arrowSize")) { - this.arrowSize = Double.valueOf(value); - } else if (name.contains("smooth")) { - this.smooth = value; - } else if (name.contains("visible")) { - this.visible = Boolean.valueOf(value); - } else if (name.contains("origin")) { - Points origin = new Points(); - origin.points(value); - this.origin = origin; - } else if (name.contains("rotation")) { - this.rotation = Double.valueOf(value); - } - } - return new TemCla(lineStr); - } - } - - public class DynamicSelect{ - private String firstOpt; - private String secondOpt; - public TemCla dynamicSelect(String optStr) { - int lefBra = optStr.indexOf('('); - int rigBra = optStr.lastIndexOf(')'); - String temStr = optStr.substring(lefBra+1, rigBra).trim(); - List strSets = new ArrayList(); - strSets.addAll(splitAtComma(temStr)); - this.firstOpt = strSets.get(0); - this.secondOpt = strSets.get(1); - return new TemCla(optStr); - } - } - - public class Points{ - private Double x; - private Double y; - public TemCla points(String pointStr) { - int lefBra = pointStr.indexOf('{'); - int rigBra = pointStr.indexOf('}'); - String temStr = pointStr.substring(lefBra + 1, rigBra).trim(); - List strSets = new ArrayList(); - strSets.addAll(splitAtComma(temStr)); - this.x = Double.valueOf(strSets.get(0)); - this.y = Double.valueOf(strSets.get(1)); - return new TemCla(pointStr); - } - } - - public class DynamicPoints{ - private Collection points; - private String dynPoints; - public TemCla dynamicPoints(String poiStr) { - DynamicSelect poiOpts = new DynamicSelect(); - poiOpts.dynamicSelect(poiStr); - String firstOpt = poiOpts.firstOpt; - int lefBra = firstOpt.indexOf('{'); - int rigBra = firstOpt.lastIndexOf('}'); - String temStr = firstOpt.substring(lefBra + 1, rigBra).trim(); - List points = new ArrayList(); - List pointsSet = new ArrayList(); - pointsSet.addAll(splitAtComma(temStr)); - for (String p : pointsSet) { - Points point = new Points(); - point.points(p); - points.add(point); - } - this.points = points; - this.dynPoints = poiOpts.secondOpt; - return new TemCla(poiStr); - } - } - - public class Color{ - private Double r; - private Double g; - private Double b; - public TemCla color(String colorStr) { - int lefBra = colorStr.indexOf('{'); - int rigBra = colorStr.indexOf('}'); - String temStr = colorStr.substring(lefBra + 1, rigBra).trim(); - List strSets = new ArrayList(); - strSets.addAll(splitAtComma(temStr)); - this.r = Double.valueOf(strSets.get(0)); - this.g = Double.valueOf(strSets.get(1)); - this.b = Double.valueOf(strSets.get(2)); - return new TemCla(colorStr); - } - } - - public class DynamicColor{ - private Color color; - private String dynColor; - public TemCla dynamicColor(String colStr) { - DynamicSelect colOpts = new DynamicSelect(); - colOpts.dynamicSelect(colStr); - Color color = new Color(); - color.color(colOpts.firstOpt); - this.color = color; - this.dynColor = colOpts.secondOpt; - return new TemCla(colStr); - } - } - - /** access sub-string "subStr" in string "str" with syntax of "keyStr (subStr)" **/ - public static String findSubStr(String str, String keyStr) { - String subStr; - if (!ifEnclosed(str, "(", ")", str.indexOf(keyStr)) - || !ifEnclosed(str, "\"", "\"", str.indexOf(keyStr))) { - subStr = null; - } else { - if (str.contains(keyStr)) { - int leftRBcount = 0; - int beginInd = str.indexOf("(",str.indexOf(keyStr)+keyStr.length()-2); - int endInd = 0; - for (int i = beginInd; i < str.length(); i++) { - if (str.charAt(i) == '(') { - leftRBcount = leftRBcount+1; - } - if (str.charAt(i) == ')') { - leftRBcount = leftRBcount-1; - if (leftRBcount == 0) { - endInd = i; - break; - } - } - } - subStr = str.substring(beginInd+1, endInd).trim(); - } else { - subStr = null; - } - } - return subStr; - } - - - /** check if index "fromInd" is enclosed in a completed "symbol1" and "symbol2", - such as ( ), [ ], { }, " ". - If it is not enclosed and the symbols is completed, then return true, - otherwise, return false. **/ - public static Boolean ifEnclosed(String str, String symbol1, String symbol2, Integer fromInd) { - Boolean ifEnclosed = false; - if (symbol1 == "\"") { - if (str.contains(symbol1)) { - int index = 0; - for (int j = fromInd; j>=0; j--) { - if (str.charAt(j) == symbol1.charAt(0)) { - index = index + 1; - } - } - if (index % 2 == 0) { - ifEnclosed = true; - } - } else { - ifEnclosed = true; - } - } else { - if (str.contains(symbol1)) { - int index = 0; - for (int j=fromInd; j>=0 ; j--) { - if (str.charAt(j) == symbol2.charAt(0)) { - index = index+1; - } - if (str.charAt(j) == symbol1.charAt(0)) { - index = index-1; - } - } - if (index == 0) { - ifEnclosed = true; - } - } else { - ifEnclosed = true; - } - } - return ifEnclosed; - } - - /** Split string with commas. These commas are independent and not included in - brackets. **/ - public static Collection splitAtComma(String str) { - str.trim(); - List strSets = new ArrayList(); - if (!str.contains(",")) { - strSets.add(str); - } else { - List commaInd = new ArrayList(); - List fullCommaInd = new ArrayList (); - - for (int i=0; i cbCommaInd = new ArrayList (); - List sbCommaInd = new ArrayList (); - List rbCommaInd = new ArrayList (); - List quoCommaInd = new ArrayList (); - - for (int i=0; i searchComEle(Collection list1, - Collection list2, - Collection list3, - Collection list4) { - List comEle = new ArrayList (); - if (list1.size()>0 && list2.size()>0 && list3.size()>0 && list4.size()>0) { - list2.retainAll(list1); - list3.retainAll(list2); - list4.retainAll(list3); - comEle.addAll(list4); - } - return comEle; - } - - private class TemCla { - private TemCla(String str) { - } - } - - private class StrPair { - String name; - String value; - private StrPair(String name, String value) { - this.name = name; - this.value = value; - } - } - - private class Documentation { - String info; - String revisions; - private Documentation(String info, String revisions) { - this.info = info; - this.revisions = revisions; - } - } - } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Component_clause.java b/java/parser/src/main/java/gov/lbl/parser/domain/Component_clause.java index d40e3711..0abee3d5 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Component_clause.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Component_clause.java @@ -2,17 +2,14 @@ public class Component_clause { private String type_prefix; - private String type_specifier; - private String array_subscripts; + private Type_specifier type_specifier; + private Array_subscripts array_subscripts; private Component_list component_list; - public Component_clause(String type_prefix, - String type_specifier, - String array_subscripts, - Component_list component_list) { - this.type_prefix = type_prefix; - this.type_specifier = type_specifier; - this.array_subscripts = (array_subscripts==null ? null : array_subscripts); - this.component_list = component_list; + public Component_clause(String type_prefix, Type_specifier type_specifier, Array_subscripts array_subscripts, Component_list component_list) { + this.type_prefix = type_prefix; + this.type_specifier = type_specifier; + this.array_subscripts = array_subscripts; + this.component_list = component_list; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Component_clause1.java b/java/parser/src/main/java/gov/lbl/parser/domain/Component_clause1.java new file mode 100644 index 00000000..37f84a93 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Component_clause1.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +public class Component_clause1 { + private String type_prefix; + private Type_specifier type_specifier; + private Component_declaration1 component_declaration1; + + public Component_clause1 (String type_prefix, Type_specifier type_specifier, Component_declaration1 component_declaration1) { + this.type_prefix = type_prefix; + this.type_specifier = type_specifier; + this.component_declaration1 = component_declaration1; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Component_declaration.java b/java/parser/src/main/java/gov/lbl/parser/domain/Component_declaration.java index 93138e31..f454389c 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Component_declaration.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Component_declaration.java @@ -1,15 +1,13 @@ package gov.lbl.parser.domain; public class Component_declaration { - Declaration declaration; - String condition_attribute; - Comment comment; + private Declaration declaration; + private Condition_attribute condition_attribute; + private Comment comment; - public Component_declaration(Declaration declaration, - String condition_attribute, - Comment comment) { - this.declaration = declaration; - this.condition_attribute = (condition_attribute == null ? null : condition_attribute); - this.comment = (comment.string_comment==null && comment.annotation==null) ? null : comment; + public Component_declaration(Declaration declaration, Condition_attribute condition_attribute, Comment comment) { + this.declaration = declaration; + this.condition_attribute = condition_attribute; + this.comment = comment; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Component_declaration1.java b/java/parser/src/main/java/gov/lbl/parser/domain/Component_declaration1.java new file mode 100644 index 00000000..bc6bea3c --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Component_declaration1.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Component_declaration1 { + private Declaration declaration; + private Comment comment; + + public Component_declaration1(Declaration declaration, Comment comment) { + this.declaration = declaration; + this.comment = comment; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Component_list.java b/java/parser/src/main/java/gov/lbl/parser/domain/Component_list.java index e8f5374c..f5525b51 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Component_list.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Component_list.java @@ -3,9 +3,12 @@ import java.util.Collection; public class Component_list { - private Collection component_declaration; + Collection component_declaration_list; - public Component_list(Collection component_declaration) { - this.component_declaration = (component_declaration.size() > 0 ? component_declaration : null); + public Component_list(Collection component_declaration_list) throws Exception { + if (component_declaration_list.size() == 0) { + throw new Exception("component_list cannot be empty"); + } + this.component_declaration_list = component_declaration_list; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference.java b/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference.java new file mode 100644 index 00000000..0bc8a75f --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Component_reference { + private Collection component_reference_parts; + + public Component_reference(Collection component_reference_parts) { + this.component_reference_parts = component_reference_parts; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference_part.java b/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference_part.java new file mode 100644 index 00000000..fb0ab41c --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference_part.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +public class Component_reference_part { + private Boolean dot_op; + private String identifier; + private Array_subscripts array_subscripts; + + public Component_reference_part(Boolean dot_op, String identifier, Array_subscripts array_subscripts) { + this.dot_op = dot_op; + this.identifier = identifier; + this.array_subscripts = array_subscripts; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java index 1a2db2f5..2779718d 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java @@ -1,902 +1,24 @@ package gov.lbl.parser.domain; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; - -import gov.lbl.parser.domain.Comment; public class Composition { private Element_list element_list; - private Collection prefix_public; - private Collection prefix_protect; - private Collection prefixed_element; + private Collection public_element_list; + private Collection protected_element_list; private Collection equation_section; - private Collection algorithm_section; - private String external; - private String language_specification; - private String external_function_call; - private String ext_annotation; - private AnnotationClass comp_annotation; - - public Composition(String ext_dec, - Collection public_dec, - Collection protected_dec, - Element_list element_list1, - Collection element_list2, - Collection equation_section, - Collection algorithm_section, - String language_specification, - String external_function_call, - String annotation1, - String annotation2) { - this.element_list = element_list1; - this.prefix_public = (public_dec.size()==0 ? null : public_dec); - this.prefix_protect = (protected_dec.size()==0 ? null : protected_dec); - this.prefixed_element = (element_list2==null ? null : element_list2); - this.equation_section = (equation_section.size()==0 ? null : equation_section); - this.algorithm_section = (algorithm_section.size()==0 ? null : algorithm_section); - this.external = ext_dec; - this.language_specification = language_specification; - this.external_function_call = external_function_call; - this.ext_annotation = annotation1; - String annTemp = ""; - if (annotation2 == null) { - this.comp_annotation = null; - } else { - annTemp = annotation2.substring(1,annotation2.length()-2); - AnnotationClass annCla = new AnnotationClass(); - annCla.annClass(annTemp); - this.comp_annotation = annCla; - } - } - - private class AnnotationClass { - String defaultName; - GraphicLayers diagram; - GraphicLayers icon; - String text; - Documentation documentation; - VendorAnnotation vendor_annotation; - String othAnns; - - private TemCla annClass(String annStr) { - String nameStr; - String docStr = Comment.findSubStr(annStr, "Documentation "); - String diagramStr = Comment.findSubStr(annStr, "Diagram "); - String iconStr = Comment.findSubStr(annStr, "Icon "); - String textStr = Comment.findSubStr(annStr, "Text "); - String venAnnStr = Comment.findSubStr(annStr, "__"); - - this.text = textStr; - - if (diagramStr != null) { - GraphicLayers temp = new GraphicLayers(); - temp.graphicLayers(diagramStr); - this.diagram = temp; - } else { - this.diagram = null; - } - - if (iconStr != null) { - GraphicLayers temp = new GraphicLayers(); - temp.graphicLayers(iconStr); - this.icon = temp; - } else { - this.icon = null; - } - - if (annStr.contains("defaultComponentName")) { - int beginInd = annStr.indexOf("\"", annStr.indexOf("defaultComponentName")+"defaultComponentName".length()-1); - int endInd = annStr.indexOf("\"", beginInd+1); - nameStr = annStr.substring(beginInd, endInd+1); - this.defaultName = nameStr; - } else { - nameStr = null; - this.defaultName = null; - } - - /** find vendor annotation **/ - String venAnnName = ""; - if (venAnnStr != null) { - venAnnName = annStr.substring(annStr.indexOf("__"), annStr.indexOf("(",annStr.indexOf("__"))); - VendorAnnotation venAnn = new VendorAnnotation(); - venAnn.vendorAnnotation(venAnnName,venAnnStr); - this.vendor_annotation = venAnn; - } else { - this.vendor_annotation = null; - } - - List strListToBeRem = new ArrayList(); - if (docStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Documentation (") - .append(docStr).append(" )") - .toString()); - } - if (diagramStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Diagram (") - .append(diagramStr).append(" )") - .toString()); - } - if (iconStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Icon (") - .append(iconStr).append(" )") - .toString()); - } - if (textStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("Text (") - .append(textStr).append(" )") - .toString()); - } - if (nameStr != null) { - StringBuilder temStr = new StringBuilder(); - strListToBeRem.add(temStr.append("defaultComponentName =") - .append(nameStr) - .toString()); - } - if (venAnnStr != null) { - StringBuilder temStr = new StringBuilder(); - int venAnnStrEndInd = annStr.indexOf(venAnnStr) + venAnnStr.length(); - String endBra = annStr.substring(venAnnStrEndInd, annStr.indexOf(")", venAnnStrEndInd)+1); - strListToBeRem.add(temStr.append(venAnnName).append("(") - .append(venAnnStr).append(endBra) - .toString()); - } - - String otherAnnStr = annStr; - String tempStrInList; - if (strListToBeRem.size()>0) { - for (int i=0; i", docStr.indexOf("info =")) - 1; - int endIndTemp = docStr.indexOf("", beginInd); - int endInd = endIndTemp + "".length() + 1; - infoStr = docStr.substring(beginInd, endInd); - } else { - infoStr = null; - } - if (docStr.contains("revisions =")) { - docStr = docStr.toString(); - int beginInd = docStr.indexOf("", docStr.indexOf("revisions =")) - 1; - int endIndTemp = docStr.indexOf("", beginInd); - int endInd = endIndTemp + "".length() + 1; - revStr = docStr.substring(beginInd, endInd); - } else { - revStr = null; - } - this.documentation = new Documentation(infoStr, revStr); - } - return new TemCla(annStr); - } - } - - private class VendorAnnotation{ - private String name; - private Collection annotation; - private Collection innerAnnotation; - private TemCla vendorAnnotation(String venAnnName, String venAnnStr) { - this.name = venAnnName.replaceAll("\\s+", ""); - List venAnnEle = new ArrayList(); - List simAnnEle = new ArrayList(); - if (venAnnStr == null || !venAnnStr.contains("=")) { - this.annotation = null; - } else { - String name; - String value; - List venSetTemp = new ArrayList(); - venSetTemp.addAll(Comment.splitAtComma(venAnnStr)); - List venSet = new ArrayList(); - for (int i=0; i annotation; - private TemCla annStr(String annName, String str) { - this.name = annName; - List strSet = new ArrayList(); - strSet.addAll(Comment.splitAtComma(str)); - List strPair = new ArrayList(); - String name, value; - int equInd; - String temStr; - for (int i=0; i strSet = new ArrayList(); - strSet.addAll(Comment.splitAtComma(layStr)); - String coorSysStr = ""; - String grapStr = ""; - for (String str : strSet) { - if (str.contains("coordinateSystem (")) { - coorSysStr = str.substring(str.indexOf('(')+1,str.lastIndexOf(')')).trim(); - Coordinate temp = new Coordinate(); - temp.coordinate(coorSysStr); - this.coordinateSystem = temp; - } else if (str.contains("graphics =")) { - grapStr = str.substring(str.indexOf('{')+1, str.lastIndexOf('}')).trim(); - Graphics temp = new Graphics(); - temp.graphics(grapStr); - this.graphics = temp; - } - } - return new TemCla(layStr); - } - } - - /** parse coordinateSystem(extent={....}, preserveAspectRatio=..., initialScale=...) - */ - private class Coordinate { - private Collection extent; - private Boolean preserveAspectRatio; - private Double initialScale; - private TemCla coordinate(String coorSysStr) { - List strSet = new ArrayList(); - strSet.addAll(Comment.splitAtComma(coorSysStr)); - List extPoints = new ArrayList(); - Double iniScaStr = null; - Boolean preAspRatStr = null; - - for (String str : strSet) { - int indEq = str.indexOf('='); - String name = str.substring(0, indEq).trim(); - String value = str.substring(indEq+1, str.length()).trim(); - if (name.contains("extent")) { - String temp = value.substring(value.indexOf('{') + 1, value.lastIndexOf('}')).trim(); - List pointsSet = new ArrayList(); - pointsSet.addAll(Comment.splitAtComma(temp)); - for (String p : pointsSet) { - Comment test = new Comment("", null); - Comment.Points point = test.new Points(); - point.points(p); - extPoints.add(point); - } - } else if (name.contains("initialScale")) { - iniScaStr = Double.valueOf(value); - } else if (name.contains("preserveAspectRatio")) { - preAspRatStr = Boolean.valueOf(value); - } - } - this.extent = extPoints.isEmpty() ? null : extPoints; - this.initialScale = iniScaStr; - this.preserveAspectRatio = preAspRatStr; - return new TemCla(coorSysStr); - } - } - - - /** Parse graphical contents in Icon(), Diagram(): - * graphics={Rectangle(extent={....}),Text(extent={...}, textString="...")})); - **/ - private class Graphics { - private Collection line; - private Collection polygon; - private Collection rectangle; - private Collection ellipse; - private Collection text; - private Collection bitmap; - private TemCla graphics(String graStr) { - List strSet = new ArrayList(); - strSet.addAll(Comment.splitAtComma(graStr)); - Comment test = new Comment("", null); - - List lines = new ArrayList(); - List polygons = new ArrayList(); - List rectangles = new ArrayList(); - List ellipses = new ArrayList(); - List texts = new ArrayList(); - List bitmaps = new ArrayList(); - - for (String str : strSet) { - int indBr = str.indexOf('('); - String primitive = str.substring(0, indBr).trim(); - String specification = str.substring(indBr+1, str.lastIndexOf(')')).trim(); - if (primitive.contains("Line")) { - Comment.LineBlock line = test.new LineBlock(); - line.lineBlock(specification); - lines.add(line); - } else if (primitive.contains("Polygon")) { - Polygon polygon = new Polygon(); - polygon.polygon(specification); - polygons.add(polygon); - } else if (primitive.contains("Rectangle")) { - Rectangle rectangle = new Rectangle(); - rectangle.rectangle(specification); - rectangles.add(rectangle); - } else if (primitive.contains("Ellipse")) { - Ellipse ellipse = new Ellipse(); - ellipse.ellipse(specification); - ellipses.add(ellipse); - } else if (primitive.contains("Text")) { - Text text = new Text(); - text.text(specification); - texts.add(text); - } else if (primitive.contains("Bitmap")) { - Bitmap bitmap = new Bitmap(); - bitmap.bitmap(specification); - bitmaps.add(bitmap); - } - } - this.line = lines.isEmpty() ? null : lines; - this.polygon = polygons.isEmpty() ? null : polygons; - this.rectangle = rectangles.isEmpty() ? null : rectangles; - this.ellipse = ellipses.isEmpty() ? null : ellipses; - this.text = texts.isEmpty() ? null : texts; - this.bitmap = bitmaps.isEmpty() ? null : bitmaps; - return new TemCla(graStr); - } - } - - - private class Polygon { - private Boolean visible; - private Comment.Points origin; - private Double rotation; - private Comment.Color lineColor; - private Comment.DynamicColor dynLineColor; - private Comment.Color fillColor; - private Comment.DynamicColor dynFillColor; - private String pattern; - private String fillPattern; - private Comment.DynamicSelect dynFillPattern; - private Double lineThickness; - private Collection points; - private String smooth; - private TemCla polygon(String polStr) { - Comment test = new Comment("", null); - List strSet = new ArrayList(); - strSet.addAll(Comment.splitAtComma(polStr)); - for (String str : strSet) { - int indEq = str.indexOf('='); - String name = str.substring(0, indEq).trim(); - String value = str.substring(indEq+1, str.length()).trim(); - if (name.contains("visible")) { - this.visible = Boolean.valueOf(value); - } else if (name.contains("origin")) { - Comment.Points origin = test.new Points(); - origin.points(value); - this.origin = origin; - } else if (name.contains("rotation")) { - this.rotation = Double.valueOf(value); - } else if (name.contains("lineColor")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicColor dynLinCol = test.new DynamicColor(); - dynLinCol.dynamicColor(value); - this.dynLineColor = dynLinCol; - this.lineColor = null; - } else { - Comment.Color lineColor = test.new Color(); - lineColor.color(value); - this.lineColor = lineColor; - this.dynLineColor = null; - } - } else if (name.contains("fillColor")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicColor dynFilCol = test.new DynamicColor(); - dynFilCol.dynamicColor(value); - this.dynFillColor = dynFilCol; - this.fillColor = null; - } else { - Comment.Color fillColor = test.new Color(); - fillColor.color(value); - this.fillColor = fillColor; - this.dynFillColor = null; - } - } else if (name.contains("fillPattern")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicSelect dynFilPat = test.new DynamicSelect(); - dynFilPat.dynamicSelect(value); - this.fillPattern = null; - this.dynFillPattern = dynFilPat; - } else { - this.fillPattern = value; - this.dynFillPattern = null; - } - } else if (name.contains("pattern")) { - this.pattern = value; - } else if (name.contains("lineThickness")) { - this.lineThickness = Double.valueOf(value); - } else if (name.contains("smooth")) { - this.smooth = value; - } else if (name.contains("points")) { - int indRB= value.indexOf('{'); - String temp = value.substring(indRB+1, value.lastIndexOf('}')).trim(); - List pointsSet = new ArrayList(); - pointsSet.addAll(Comment.splitAtComma(temp)); - List points = new ArrayList(); - for (String p : pointsSet) { - Comment.Points point = test.new Points(); - point.points(p); - points.add(point); - } - this.points = points; - } - } - - return new TemCla(polStr); - } - } - - - private class Rectangle { - private Boolean visible; - private Comment.Points origin; - private Double rotation; - private Comment.Color lineColor; - private Comment.DynamicColor dynLineColor; - private Comment.Color fillColor; - private Comment.DynamicColor dynFillColor; - private String pattern; - private String fillPattern; - private Comment.DynamicSelect dynFillPattern; - private Double lineThickness; - private String borderPattern; - private Collection extent; - private Comment.DynamicPoints dynExtent; - private Double radius; - private TemCla rectangle(String recStr) { - Comment test = new Comment("", null); - List strSet = new ArrayList(); - strSet.addAll(Comment.splitAtComma(recStr)); - for (String str : strSet) { - int indEq = str.indexOf('='); - String name = str.substring(0, indEq).trim(); - String value = str.substring(indEq+1, str.length()).trim(); - if (name.contains("visible")) { - this.visible = Boolean.valueOf(value); - } else if (name.contains("origin")) { - Comment.Points origin = test.new Points(); - origin.points(value); - this.origin = origin; - } else if (name.contains("rotation")) { - this.rotation = Double.valueOf(value); - } else if (name.contains("lineColor")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicColor dynLinCol = test.new DynamicColor(); - dynLinCol.dynamicColor(value); - this.dynLineColor = dynLinCol; - this.lineColor = null; - } else { - Comment.Color lineColor = test.new Color(); - lineColor.color(value); - this.lineColor = lineColor; - this.dynLineColor = null; - } - } else if (name.contains("fillColor")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicColor dynFilCol = test.new DynamicColor(); - dynFilCol.dynamicColor(value); - this.dynFillColor = dynFilCol; - this.fillColor = null; - } else { - Comment.Color fillColor = test.new Color(); - fillColor.color(value); - this.fillColor = fillColor; - this.dynFillColor = null; - } - } else if (name.contains("fillPattern")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicSelect dynFilPat = test.new DynamicSelect(); - dynFilPat.dynamicSelect(value); - this.fillPattern = null; - this.dynFillPattern = dynFilPat; - } else { - this.fillPattern = value; - this.dynFillPattern = null; - } - } else if (name.contains("pattern")) { - this.pattern = value; - } else if (name.contains("lineThickness")) { - this.lineThickness = Double.valueOf(value); - } else if (name.contains("borderPattern")) { - this.borderPattern = value; - } else if (name.contains("radius")) { - this.radius = Double.valueOf(value); - } else if (name.contains("extent")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicPoints dynExtPoi = test.new DynamicPoints(); - dynExtPoi.dynamicPoints(value); - this.extent = null; - this.dynExtent = dynExtPoi; - } else { - int indRB= value.indexOf('{'); - String temp = value.substring(indRB+1, value.lastIndexOf('}')).trim(); - List pointsSet = new ArrayList(); - pointsSet.addAll(Comment.splitAtComma(temp)); - List extent = new ArrayList(); - for (String p : pointsSet) { - Comment.Points point = test.new Points(); - point.points(p); - extent.add(point); - } - this.extent = extent; - this.dynExtent = null; - } - } - } - return new TemCla(recStr); - } - } - - - private class Text { - private Boolean visible; - private Comment.Points origin; - private Double rotation; - private Comment.Color lineColor; - private Comment.DynamicColor dynLineColor; - private Comment.Color fillColor; - private Comment.DynamicColor dynFillColor; - private String pattern; - private String fillPattern; - private Comment.DynamicSelect dynFillPattern; - private Double lineThickness; - private Collection extent; - private Comment.DynamicPoints dynExtent; - private String textString; - private Comment.DynamicSelect dynTextString; - private Double fontSize; - private String fontName; - private String textStyle; - private Comment.Color textColor; - private String horizontalAlignment; - private TemCla text(String texStr) { - Comment test = new Comment("", null); - List strSet = new ArrayList(); - strSet.addAll(Comment.splitAtComma(texStr)); - for (String str : strSet) { - int indEq = str.indexOf('='); - String name = str.substring(0, indEq).trim(); - String value = str.substring(indEq+1, str.length()).trim(); - if (name.contains("visible")) { - this.visible = Boolean.valueOf(value); - } else if (name.contains("origin")) { - Comment.Points origin = test.new Points(); - origin.points(value); - this.origin = origin; - } else if (name.contains("rotation")) { - this.rotation = Double.valueOf(value); - } else if (name.contains("lineColor")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicColor dynLinCol = test.new DynamicColor(); - dynLinCol.dynamicColor(value); - this.dynLineColor = dynLinCol; - this.lineColor = null; - } else { - Comment.Color lineColor = test.new Color(); - lineColor.color(value); - this.lineColor = lineColor; - this.dynLineColor = null; - } - } else if (name.contains("fillColor")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicColor dynFilCol = test.new DynamicColor(); - dynFilCol.dynamicColor(value); - this.dynFillColor = dynFilCol; - this.fillColor = null; - } else { - Comment.Color fillColor = test.new Color(); - fillColor.color(value); - this.fillColor = fillColor; - this.dynFillColor = null; - } - } else if (name.contains("fillPattern")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicSelect dynFilPat = test.new DynamicSelect(); - dynFilPat.dynamicSelect(value); - this.fillPattern = null; - this.dynFillPattern = dynFilPat; - } else { - this.fillPattern = value; - this.dynFillPattern = null; - } - } else if (name.contains("pattern")) { - this.pattern = value; - } else if (name.contains("lineThickness")) { - this.lineThickness = Double.valueOf(value); - } else if (name.contains("extent")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicPoints dynExtPoi = test.new DynamicPoints(); - dynExtPoi.dynamicPoints(value); - this.extent = null; - this.dynExtent = dynExtPoi; - } else { - int indRB= value.indexOf('{'); - String temp = value.substring(indRB+1, value.lastIndexOf('}')).trim(); - List pointsSet = new ArrayList(); - pointsSet.addAll(Comment.splitAtComma(temp)); - List extent = new ArrayList(); - for (String p : pointsSet) { - Comment.Points point = test.new Points(); - point.points(p); - extent.add(point); - } - this.extent = extent; - this.dynExtent = null; - } - } else if (name.contains("textString")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicSelect dynTexStr = test.new DynamicSelect(); - dynTexStr.dynamicSelect(value); - this.textString = null; - this.dynTextString = dynTexStr; - } else { - this.textString = value; - this.dynTextString = null; - } - } else if (name.contains("fontSize")) { - this.fontSize = Double.valueOf(value); - } else if (name.contains("fontName")) { - this.fontName = value; - } else if (name.contains("textStyle")) { - this.textStyle = value; - } else if (name.contains("textColor")) { - Comment.Color textColor = test.new Color(); - textColor.color(value); - this.textColor = textColor; - } else if (name.contains("horizontalAlignment")) { - this.horizontalAlignment = value; - } - } - return new TemCla(texStr); - } - } - - - private class Bitmap { - private Boolean visible; - private Comment.Points origin; - private Double rotation; - private Collection extent; - private String fileName; - private String imageSource; - private TemCla bitmap(String bitStr) { - Comment test = new Comment("", null); - List strSet = new ArrayList(); - strSet.addAll(Comment.splitAtComma(bitStr)); - for (String str : strSet) { - int indEq = str.indexOf('='); - String name = str.substring(0, indEq).trim(); - String value = str.substring(indEq+1, str.length()).trim(); - if (name.contains("visible")) { - this.visible = Boolean.valueOf(value); - } else if (name.contains("origin")) { - Comment.Points origin = test.new Points(); - origin.points(value); - this.origin = origin; - } else if (name.contains("rotation")) { - this.rotation = Double.valueOf(value); - } else if (name.contains("extent")) { - int indRB= value.indexOf('{'); - String temp = value.substring(indRB+1, value.lastIndexOf('}')).trim(); - List pointsSet = new ArrayList(); - pointsSet.addAll(Comment.splitAtComma(temp)); - List extent = new ArrayList(); - for (String p : pointsSet) { - Comment.Points point = test.new Points(); - point.points(p); - extent.add(point); - } - this.extent = extent; - } else if (name.contains("fileName")) { - this.fileName = value; - } else if (name.contains("imageSource")) { - this.imageSource = value; - } - } - return new TemCla(bitStr); - } - } - - - private class Ellipse { - private Boolean visible; - private Comment.Points origin; - private Double rotation; - private Comment.Color lineColor; - private Comment.DynamicColor dynLineColor; - private Comment.Color fillColor; - private Comment.DynamicColor dynFillColor; - private String pattern; - private String fillPattern; - private Comment.DynamicSelect dynFillPattern; - private Double lineThickness; - private Collection extent; - private Comment.DynamicPoints dynExtent; - private Double startAngle; - private Double endAngle; - private String closure; - private TemCla ellipse(String ellStr) { - Comment test = new Comment("", null); - List strSet = new ArrayList(); - strSet.addAll(Comment.splitAtComma(ellStr)); - for (String str : strSet) { - int indEq = str.indexOf('='); - String name = str.substring(0, indEq).trim(); - String value = str.substring(indEq+1, str.length()).trim(); - if (name.contains("visible")) { - this.visible = Boolean.valueOf(value); - } else if (name.contains("origin")) { - Comment.Points origin = test.new Points(); - origin.points(value); - this.origin = origin; - } else if (name.contains("rotation")) { - this.rotation = Double.valueOf(value); - } else if (name.contains("lineColor")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicColor dynLinCol = test.new DynamicColor(); - dynLinCol.dynamicColor(value); - this.dynLineColor = dynLinCol; - this.lineColor = null; - } else { - Comment.Color lineColor = test.new Color(); - lineColor.color(value); - this.lineColor = lineColor; - this.dynLineColor = null; - } - } else if (name.contains("fillColor")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicColor dynFilCol = test.new DynamicColor(); - dynFilCol.dynamicColor(value); - this.dynFillColor = dynFilCol; - this.fillColor = null; - } else { - Comment.Color fillColor = test.new Color(); - fillColor.color(value); - this.fillColor = fillColor; - this.dynFillColor = null; - } - } else if (name.contains("fillPattern")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicSelect dynFilPat = test.new DynamicSelect(); - dynFilPat.dynamicSelect(value); - this.fillPattern = null; - this.dynFillPattern = dynFilPat; - } else { - this.fillPattern = value; - this.dynFillPattern = null; - } - } else if (name.contains("pattern")) { - this.pattern = value; - } else if (name.contains("lineThickness")) { - this.lineThickness = Double.valueOf(value); - } else if (name.contains("closure")) { - this.closure = value; - } else if (name.contains("startAngle")) { - this.startAngle = Double.valueOf(value); - } else if (name.contains("endAngle")) { - this.endAngle = Double.valueOf(value); - } else if (name.contains("extent")) { - if (value.contains("DynamicSelect")) { - Comment.DynamicPoints dynExtPoi = test.new DynamicPoints(); - dynExtPoi.dynamicPoints(value); - this.extent = null; - this.dynExtent = dynExtPoi; - } else { - int indRB= value.indexOf('{'); - String temp = value.substring(indRB+1, value.lastIndexOf('}')).trim(); - List pointsSet = new ArrayList(); - pointsSet.addAll(Comment.splitAtComma(temp)); - List extent = new ArrayList(); - for (String p : pointsSet) { - Comment.Points point = test.new Points(); - point.points(p); - extent.add(point); - } - this.extent = extent; - this.dynExtent = null; - } - } - } - return new TemCla(ellStr); - } - } - - - public class TemCla { - private TemCla(String str) { - } - } - - private class Documentation { - String info; - String revisions; - private Documentation(String info, String revisions) { - this.info = info; - this.revisions = revisions; - } - } - - private class StrPair { - String name; - String value; - private StrPair(String name, String value) { - this.name = name; - this.value = value; - } - } -} + private Collection algorithm_section; + private External_composition external_composition; + private Annotation annotation; + + public Composition(Element_list element_list, Collection public_element_list, Collection protected_element_list, Collection equation_section, + Collection algorithm_section, External_composition external_composition, Annotation annotation) { + this.element_list = element_list; + this.public_element_list = (public_element_list.size() > 0) ? public_element_list : null; + this.protected_element_list = (protected_element_list.size() > 0) ? protected_element_list : null; + this.equation_section = (equation_section.size() > 0) ? equation_section : null; + this.algorithm_section = (algorithm_section.size() > 0) ? algorithm_section : null; + this.external_composition = external_composition; + this.annotation = annotation; + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Condition_attribute.java b/java/parser/src/main/java/gov/lbl/parser/domain/Condition_attribute.java new file mode 100644 index 00000000..8643ecf6 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Condition_attribute.java @@ -0,0 +1,9 @@ +package gov.lbl.parser.domain; + +public class Condition_attribute { + private Expression expression; + + public Condition_attribute(Expression expression) { + this.expression = expression; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Connect_clause.java b/java/parser/src/main/java/gov/lbl/parser/domain/Connect_clause.java index e5b9a0ab..b3019350 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Connect_clause.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Connect_clause.java @@ -1,28 +1,11 @@ package gov.lbl.parser.domain; -import java.util.List; -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class Connect_clause { - private List component1; - private List component2; - - public Connect_clause(String component_reference1, String component_reference2) { - Pattern pattern = Pattern.compile("\\."); - Matcher matcher1 = pattern.matcher(component_reference1); - Matcher matcher2 = pattern.matcher(component_reference1); + private Component_reference from; + private Component_reference to; - if (!matcher1.matches()) { - this.component1 = Arrays.asList(component_reference1.split("\\.")); - } else { - this.component1 = Arrays.asList(component_reference1); - } - if (!matcher2.matches()) { - this.component2 = Arrays.asList(component_reference2.split("\\.")); - } else { - this.component2 = Arrays.asList(component_reference2); - } + public Connect_clause(Component_reference from, Component_reference to) { + this.from = from; + this.to = to; } -} +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Constraining_clause.java b/java/parser/src/main/java/gov/lbl/parser/domain/Constraining_clause.java new file mode 100644 index 00000000..86b3e796 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Constraining_clause.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import gov.lbl.antlr4.visitor.modelicaParser.Class_modificationContext; + +public class Constraining_clause { + private Name name; + private Class_modification class_modification; + + public Constraining_clause(Name name, Class_modification class_modification) { + this.name = name; + this.class_modification = class_modification; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Declaration.java b/java/parser/src/main/java/gov/lbl/parser/domain/Declaration.java index 14453113..5428982d 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Declaration.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Declaration.java @@ -1,259 +1,13 @@ package gov.lbl.parser.domain; -import java.util.Collection; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.List; -import java.util.ArrayList; -import java.util.Arrays; - -import gov.lbl.parser.domain.Comment; - public class Declaration { - private String name; - private String array_subscripts; - private ClassMod class_modification; - - private String operator; - private String value; - - public Declaration(String ident, - String array_subscripts, - String modification) { - this.name = ident; - this.array_subscripts = (array_subscripts == null ? null : array_subscripts); - if (modification != null) { - if (modification.charAt(0) == '(') { - List equSymbol = new ArrayList (); - equSymbol.addAll(isoEqu(modification)); - - String temStrL = ""; - String temStrR = ""; - if (!equSymbol.isEmpty()) { - temStrL = modification.substring(1, equSymbol.get(0)-1); - temStrR = modification.substring(equSymbol.get(0)+1,modification.length()); - } else { - temStrL = modification.substring(1,modification.length()-1); - } - - temStrL.trim(); - this.operator = null; - this.value = temStrR.isEmpty() ? null : temStrR.trim(); - ClassMod classMod = new ClassMod(); - classMod.classMod(temStrL); - this.class_modification = classMod; - } else { - this.class_modification = null; - if (modification.contains(":=")) { - this.operator = ":="; - int ind = modification.indexOf(":="); - this.value = modification.substring(ind+2,modification.length()).trim(); - } else { - this.operator = null; - int equInd = modification.indexOf("="); - this.value = modification.substring(equInd+1,modification.length()).trim(); - } - } - } - } - - public class ClassMod { - private Collection modifications; - public TemCla classMod(String classModStr) { - List strSets = new ArrayList(); - strSets.addAll(Comment.splitAtComma(classModStr)); - - List modListEle = new ArrayList(); - for (String str : strSets) { - String tempLeftStr = ""; - String tempRightStr = ""; - String prefix = ""; - String className = ""; - String packageName = ""; - String name = ""; - String value = ""; - ClassMod modification = null; - VariableMod variable_modification = null; - PerMod per_modification = null; - if (str.startsWith("redeclare")) { - if (str.contains("(")) { - int indBR = str.indexOf('('); - String modStr = str.substring(indBR+1, str.lastIndexOf(')')).trim(); - String lefStr = str.substring(0, indBR).trim(); - String[] lefStrSet = lefStr.split(" "); - if (lefStrSet.length > 3) { - String[] temStr = Arrays.copyOfRange(lefStrSet, 0, lefStrSet.length-3); - prefix = String.join(" ", temStr); - } else { - prefix = lefStrSet[0]; - } - className = lefStrSet[lefStrSet.length-2]; - name = lefStrSet[lefStrSet.length-1]; - - ClassMod classMod = new ClassMod(); - classMod.classMod(modStr); - modification = classMod; - modListEle.add(new ClassModList(prefix,name,null,null,null,className,null,modification)); - } else { - if (str.contains("package")) { - String[] strSet = str.split("="); - String[] temStr1 = strSet[0].split(" "); - String[] temStr2 = Arrays.copyOfRange(temStr1, 0, temStr1.length-1); - prefix = String.join(" ", temStr2); - packageName = temStr1[temStr1.length-1]; - name = strSet[strSet.length-1]; - modListEle.add(new ClassModList(prefix,name,null,null,null,null,packageName,null)); - } else { - String[] strSet = str.split(" "); - if (strSet.length > 3) { - String[] temStr = Arrays.copyOfRange(strSet, 0, strSet.length-3); - prefix = String.join(" ", temStr); - } else { - prefix = strSet[0]; - } - className = strSet[strSet.length-2]; - name = strSet[strSet.length-1]; - modListEle.add(new ClassModList(prefix,name,null,null,null,className,null,null)); - } - } - } else { - if (!str.contains("(") - || (str.contains("(") && (str.indexOf('(')> str.indexOf('=')))) { - if (str.contains("=")) { - int idx = str.indexOf('='); - tempLeftStr = str.substring(0, idx).trim(); - tempRightStr = str.substring(idx + 1, str.length()).trim(); - } else { - tempLeftStr = str; - tempRightStr = " "; - } - String[] tempLeftSets = tempLeftStr.split(" "); - if (tempLeftSets.length > 1) { - String[] temStr = Arrays.copyOfRange(tempLeftSets,0,tempLeftSets.length-1); - prefix = String.join(" ", temStr); - name = tempLeftSets[tempLeftSets.length-1]; - } else { - prefix = null; - name = tempLeftSets[0]; - } - tempRightStr.trim(); - value = tempRightStr.isEmpty() ? null : tempRightStr.trim(); - } else if ((str.contains("(") && (str.indexOf('(')< str.indexOf('=')))) { - String variable = str.substring(0,str.indexOf('(')-1).trim(); - String[] temStr = variable.split(" "); - if (temStr.length > 1) { - String[] temStr2 = Arrays.copyOfRange(temStr, 0, temStr.length-1); - prefix = String.join(" ", temStr2); - name = temStr[temStr.length-1]; - } else { - prefix = null; - name = (temStr[0] != "per") ? temStr[0] : null; - } - List isoEquInd = new ArrayList(); - isoEquInd.addAll(isoEqu(str)); - String temStr2 = ""; - if (!isoEquInd.isEmpty()) { - value = str.substring(isoEquInd.get(0)+1,str.length()).trim(); - int index = str.lastIndexOf(')',isoEquInd.get(0)); - temStr2 = str.substring(str.indexOf('(')+1, index).trim(); - } else { - value = null; - int index = str.lastIndexOf(')'); - temStr2 = str.substring(str.indexOf('(')+1, index).trim(); - } - if (!name.equals("per")) { - VariableMod varMod = new VariableMod(); - varMod.variableMod(temStr2); - variable_modification = varMod; - per_modification = null; - } else { - PerMod perMod = new PerMod(); - perMod.perMod(temStr2); - per_modification = perMod; - variable_modification = null; - } - } - modListEle.add(new ClassModList(prefix,name,value,variable_modification,per_modification, null,null,null)); - } - } - this.modifications = modListEle; - return new TemCla(classModStr); - } - } - - /** Check if the input string "str" contains isolated "=" that is not enclosed in bracket. - * If it has, then return their positions "equSymbol" in the string.*/ - private static Collection isoEqu(String str) { - List equSymbolTemp = new ArrayList(); - for (int i=1; i loop_equations; + + public For_equation(For_indices for_indices, Collection loop_equations) { + this.for_indices = for_indices; + this.loop_equations = loop_equations; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/For_index.java b/java/parser/src/main/java/gov/lbl/parser/domain/For_index.java new file mode 100644 index 00000000..fde58fc0 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/For_index.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class For_index { + private String identifier; + private Expression expression; + + public For_index(String identifier, Expression expression) { + this.identifier = identifier; + this.expression = expression; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/For_indices.java b/java/parser/src/main/java/gov/lbl/parser/domain/For_indices.java new file mode 100644 index 00000000..4ebef6ca --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/For_indices.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class For_indices { + Collection indices; + + public For_indices(Collection indices) { + this.indices = indices; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/For_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/For_statement.java new file mode 100644 index 00000000..93718f30 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/For_statement.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class For_statement { + private For_indices for_indices; + private Collection loop_statements; + + public For_statement(For_indices for_indices, Collection loop_statements) { + this.for_indices = for_indices; + this.loop_statements = loop_statements; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Function_argument.java b/java/parser/src/main/java/gov/lbl/parser/domain/Function_argument.java new file mode 100644 index 00000000..1b8a3737 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Function_argument.java @@ -0,0 +1,15 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Function_argument { + private Name function_name; + private Collection named_arguments; + private Expression expression; + + public Function_argument(Name function_name, Collection named_arguments, Expression expression) { + this.function_name = function_name; + this.named_arguments = named_arguments; + this.expression = expression; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Function_arguments.java b/java/parser/src/main/java/gov/lbl/parser/domain/Function_arguments.java new file mode 100644 index 00000000..99fb7a33 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Function_arguments.java @@ -0,0 +1,17 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Function_arguments { + private Collection named_arguments; + private Function_argument function_argument; + private For_indices for_indices; + private Function_arguments function_arguments; + + public Function_arguments(Collection named_arguments, Function_argument function_argument, For_indices for_indices, Function_arguments function_arguments) { + this.named_arguments = named_arguments; + this.function_argument = function_argument; + this.for_indices = for_indices; + this.function_arguments = function_arguments; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_args.java b/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_args.java new file mode 100644 index 00000000..983dc121 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_args.java @@ -0,0 +1,9 @@ +package gov.lbl.parser.domain; + +public class Function_call_args { + private Function_arguments function_arguments; + + public Function_call_args(Function_arguments function_arguments) { + this.function_arguments = function_arguments; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_equation.java b/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_equation.java new file mode 100644 index 00000000..a8565699 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_equation.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Function_call_equation { + private Name function_name; + private Function_call_args function_call_args; + + public Function_call_equation(Name function_name, Function_call_args function_call_args) { + this.function_name = function_name; + this.function_call_args = function_call_args; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_primary.java b/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_primary.java new file mode 100644 index 00000000..a4d8d655 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_primary.java @@ -0,0 +1,16 @@ +package gov.lbl.parser.domain; + +public class Function_call_primary { + private Name function_name; + private Boolean der; + private Boolean initial; + private Function_call_args function_call_args; + + public Function_call_primary(Name function_name, Boolean der, Boolean initial, Function_call_args function_call_args) { + this.function_name = function_name; + this.der = der; + this.initial = initial; + this.function_call_args = function_call_args; + } + +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_statement.java new file mode 100644 index 00000000..51ff3c6e --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Function_call_statement.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Function_call_statement { + private Component_reference function_name; + private Function_call_args function_call_args; + + public Function_call_statement(Component_reference function_name, Function_call_args function_call_args) { + this.function_name = function_name; + this.function_call_args = function_call_args; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_equation.java b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_equation.java new file mode 100644 index 00000000..2117ff1f --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_equation.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class If_elseif_equation { + private Expression condition; + private Collection then; + + public If_elseif_equation(Expression condition, Collection then) { + this.condition = condition; + this.then = then; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_expression.java b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_expression.java new file mode 100644 index 00000000..149178b0 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_expression.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class If_elseif_expression { + private Expression condition; + private Expression then; + + public If_elseif_expression(Expression condition, Expression then) { + this.condition = condition; + this.then = then; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_statement.java new file mode 100644 index 00000000..2f225f67 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_statement.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class If_elseif_statement { + private Expression condition; + private Collection then; + + public If_elseif_statement(Expression condition, Collection then) { + this.condition = condition; + this.then = then; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/If_equation.java b/java/parser/src/main/java/gov/lbl/parser/domain/If_equation.java new file mode 100644 index 00000000..432f0e3b --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/If_equation.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class If_equation { + private Collection if_elseif; + private Collection else_equation; + + public If_equation(Collection if_elseif, Collection else_equation) { + this.if_elseif = if_elseif; + this.else_equation = else_equation; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/If_expression.java b/java/parser/src/main/java/gov/lbl/parser/domain/If_expression.java new file mode 100644 index 00000000..5a5f7f6c --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/If_expression.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class If_expression { + private Collection if_elseif; + private Expression else_expression; + + public If_expression(Collection if_elseif, Expression else_expression) { + this.if_elseif = if_elseif; + this.else_expression = else_expression; + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/If_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/If_statement.java new file mode 100644 index 00000000..b057b0b5 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/If_statement.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class If_statement { + private Collection if_elseif; + private Collection else_statement; + + public If_statement(Collection if_elseif, Collection else_statement) { + this.if_elseif = if_elseif; + this.else_statement = else_statement; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Import_clause.java b/java/parser/src/main/java/gov/lbl/parser/domain/Import_clause.java index 2d41fda7..300744a6 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Import_clause.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Import_clause.java @@ -1,30 +1,17 @@ package gov.lbl.parser.domain; public class Import_clause { - private String prefix; - private String ident; - private String symbols; - private String name; - private String import_list; + private String identifier; + private Name name; + private Boolean dot_star; + private Import_list import_list; private Comment comment; - public Import_clause(String import_dec, - String ident, - String dotStar, - String name, - String import_list, - Comment comment) { - this.prefix = import_dec; - this.ident = ident; - this.name = name; - this.import_list = import_list; - if (ident != null) { - this.symbols = "="; - } else if (dotStar != null) { - this.symbols = dotStar; - } else { - this.symbols = null; - } + public Import_clause(String identifier, Name name, Boolean dot_star, Import_list import_list, Comment comment) { + this.identifier = identifier; + this.name = name; + this.dot_star = dot_star; + this.import_list = import_list; this.comment = comment; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Import_list.java b/java/parser/src/main/java/gov/lbl/parser/domain/Import_list.java new file mode 100644 index 00000000..556c9249 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Import_list.java @@ -0,0 +1,14 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Import_list { + Collection identifier_list; + + public Import_list (Collection identifier_list) throws Exception{ + if (identifier_list.size() == 0) { + throw new Exception("import_list cannot be empty"); + } + this.identifier_list = identifier_list; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Logical_expression.java b/java/parser/src/main/java/gov/lbl/parser/domain/Logical_expression.java new file mode 100644 index 00000000..8742ebb5 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Logical_expression.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Logical_expression { + private Collection logical_term_list; + + public Logical_expression(Collection logical_term_list) { + this.logical_term_list = logical_term_list; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Logical_factor.java b/java/parser/src/main/java/gov/lbl/parser/domain/Logical_factor.java new file mode 100644 index 00000000..bb888fab --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Logical_factor.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Logical_factor { + private Boolean not; + private Relation relation; + + public Logical_factor(Boolean not, Relation relation) { + this.not = not; + this.relation = relation; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Logical_term.java b/java/parser/src/main/java/gov/lbl/parser/domain/Logical_term.java new file mode 100644 index 00000000..0192fcb4 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Logical_term.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Logical_term { + private Collection logical_factor_list; + + public Logical_term(Collection logical_factor_list) { + this.logical_factor_list = logical_factor_list; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Long_class_specifier.java b/java/parser/src/main/java/gov/lbl/parser/domain/Long_class_specifier.java index 1b9e2d76..60c6842d 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Long_class_specifier.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Long_class_specifier.java @@ -1,22 +1,17 @@ package gov.lbl.parser.domain; public class Long_class_specifier { - private String prefix; - private String name; - private String class_modification; - private String comment; - private Composition composition; + private String identifier; + private String string_comment; + private Composition composition; + private Boolean is_extends; + private Class_modification class_modification; - - public Long_class_specifier(String extends_dec, - String ident, - String string_comment, - Composition composition, - String class_modification) { - this.prefix = extends_dec; - this.name = ident; - this.class_modification = (class_modification == null ? null : class_modification); - this.comment = string_comment; - this.composition = composition; + public Long_class_specifier(String identifier, String string_comment, Composition composition, Boolean is_extends, Class_modification class_modification) { + this.identifier = identifier; + this.string_comment = string_comment; + this.composition = composition; + this.is_extends = is_extends; + this.class_modification = class_modification; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Modification.java b/java/parser/src/main/java/gov/lbl/parser/domain/Modification.java new file mode 100644 index 00000000..cb67cb16 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Modification.java @@ -0,0 +1,15 @@ +package gov.lbl.parser.domain; + +public class Modification { + private Class_modification class_modification; + private Boolean equal; + private Boolean colon_equal; + private Expression expression; + + public Modification(Class_modification class_modification, Boolean equal, Boolean colon_equal, Expression expression) { + this.class_modification = class_modification; + this.equal = equal; + this.colon_equal = colon_equal; + this.expression = expression; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Name.java b/java/parser/src/main/java/gov/lbl/parser/domain/Name.java new file mode 100644 index 00000000..5b3ca06c --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Name.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Name { + Collection name_parts; + + public Name(Collection name_parts) { + this.name_parts = name_parts; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Name_part.java b/java/parser/src/main/java/gov/lbl/parser/domain/Name_part.java new file mode 100644 index 00000000..1929e624 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Name_part.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Name_part { + private Boolean dot_op; + private String identifier; + + public Name_part(Boolean dot_op, String identifier) { + this.dot_op = dot_op; + this.identifier = identifier; + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Named_argument.java b/java/parser/src/main/java/gov/lbl/parser/domain/Named_argument.java new file mode 100644 index 00000000..39d66722 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Named_argument.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Named_argument { + private String identifier; + private Function_argument value; + + public Named_argument(String identifier, Function_argument value) { + this.identifier = identifier; + this.value = value; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Output_expression_list.java b/java/parser/src/main/java/gov/lbl/parser/domain/Output_expression_list.java new file mode 100644 index 00000000..1c005c92 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Output_expression_list.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Output_expression_list { + Collection output_expressions; + + public Output_expression_list(Collection output_expressions) { + this.output_expressions = output_expressions; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Primary.java b/java/parser/src/main/java/gov/lbl/parser/domain/Primary.java new file mode 100644 index 00000000..a6a342fc --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Primary.java @@ -0,0 +1,28 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Primary { + private Double unsigned_number; + private String string; + private Boolean is_false; + private Boolean is_true; + private Function_call_primary function_call_primary; + private Component_reference component_reference; + private Output_expression_list output_expression_list; + private Collection expression_lists; + private Function_arguments function_arguments; + + public Primary(Double unsigned_number, String string, Boolean is_false, Boolean is_true, Function_call_primary function_call_primary, Component_reference component_reference, + Output_expression_list output_expression_list, Collection expression_lists, Function_arguments function_arguments){ + this.unsigned_number = unsigned_number; + this.string = string; + this.is_false = is_false; + this.is_true = is_true; + this.function_call_primary = function_call_primary; + this.component_reference = component_reference; + this.output_expression_list = output_expression_list; + this.expression_lists = expression_lists; + this.function_arguments = function_arguments; + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Relation.java b/java/parser/src/main/java/gov/lbl/parser/domain/Relation.java new file mode 100644 index 00000000..20a4ffe5 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Relation.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +public class Relation { + private Arithmetic_expression arithmetic_expression1; + private String rel_op; + private Arithmetic_expression arithmetic_expression2; + + public Relation(Arithmetic_expression arithmetic_expression1, String rel_op, Arithmetic_expression arithmetic_expression2) { + this.arithmetic_expression1 = arithmetic_expression1; + this.rel_op = rel_op; + this.arithmetic_expression2 = arithmetic_expression2; + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Remaining_factor.java b/java/parser/src/main/java/gov/lbl/parser/domain/Remaining_factor.java new file mode 100644 index 00000000..22f5aef6 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Remaining_factor.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Remaining_factor { + private String mul_op; // '*' | '/' | '.*' | './' + private Factor factor; + + public Remaining_factor(String mul_op, Factor factor) { + this.mul_op = mul_op; + this.factor = factor; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_definition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_definition.java new file mode 100644 index 00000000..50d53bd7 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_definition.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Short_class_definition { + private String class_prefixes; + private Short_class_specifier short_class_specifier; + + public Short_class_definition(String class_prefixes, Short_class_specifier short_class_specifier) { + this.class_prefixes = class_prefixes; + this.short_class_specifier = short_class_specifier; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_specifier.java b/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_specifier.java index 2b3aa376..5748bfcd 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_specifier.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_specifier.java @@ -1,43 +1,11 @@ package gov.lbl.parser.domain; -import gov.lbl.parser.domain.Declaration; - public class Short_class_specifier { - public String className; - public String base_prefix; - public String inputName; - public String array_subscripts; - public Declaration.ClassMod class_modification; - public String prefix; - public Enum_list enum_list; - public String list_colon; - public Comment comment; - - public Short_class_specifier(String enum_dec, - String ident, - String base_prefix, - String name, - String array_subscripts, - String class_modification, - Comment comment, - Enum_list enum_list) { + private String identifier; + private Short_class_specifier_value short_class_specifier_value; - this.className = ident; - this.base_prefix = base_prefix; - this.inputName = name; - this.array_subscripts = (array_subscripts == null ? null : array_subscripts); - if (class_modification != null) { - Declaration test = new Declaration(null, null, class_modification); - String tempStr = class_modification.substring(1,class_modification.length()-1); - Declaration.ClassMod classMod = test.new ClassMod(); - classMod.classMod(tempStr); - this.class_modification = classMod; - } else { - this.class_modification = null; - } - this.prefix = enum_dec; - this.enum_list = ((enum_dec != null) ? (enum_list!=null ? enum_list : null) : null); - this.list_colon = ((enum_dec != null && enum_list==null) ? ":" : null); - this.comment = comment; + public Short_class_specifier(String identifier, Short_class_specifier_value short_class_specifier_value) { + this.identifier = identifier; + this.short_class_specifier_value = short_class_specifier_value; } -} +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_specifier_value.java b/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_specifier_value.java new file mode 100644 index 00000000..b67db792 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Short_class_specifier_value.java @@ -0,0 +1,20 @@ +package gov.lbl.parser.domain; + +public class Short_class_specifier_value { + private Base_prefix base_prefix; + private Name name; + private Array_subscripts array_subscripts; + private Class_modification class_modification; + private Comment comment; + private Enum_list enum_list; + + public Short_class_specifier_value(Base_prefix base_prefix, Name name, Array_subscripts array_subscripts, + Class_modification class_modification, Comment comment, Enum_list enum_list) { + this.base_prefix = base_prefix; + this.name = name; + this.array_subscripts = array_subscripts; + this.class_modification = class_modification; + this.comment = comment; + this.enum_list = enum_list; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Simple_expression.java b/java/parser/src/main/java/gov/lbl/parser/domain/Simple_expression.java new file mode 100644 index 00000000..995552ba --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Simple_expression.java @@ -0,0 +1,15 @@ +package gov.lbl.parser.domain; + +public class Simple_expression { + //simple_expression: logical_expression (SYMBOL_COLON logical_expression (SYMBOL_COLON logical_expression)?)? + private Logical_expression logical_expression1; + private Logical_expression logical_expression2; + private Logical_expression logical_expression3; + + public Simple_expression(Logical_expression logical_expression1, Logical_expression logical_expression2, Logical_expression logical_expression3) { + this.logical_expression1 = logical_expression1; + this.logical_expression2 = logical_expression2; + this.logical_expression3 = logical_expression3; + } + +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/Statement.java new file mode 100644 index 00000000..4cfe5fc8 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Statement.java @@ -0,0 +1,28 @@ +package gov.lbl.parser.domain; + +public class Statement { + private Assignment_statement assignment_statement; + private Function_call_statement function_call_statement; + private Assignment_with_function_call_statement assignment_with_function_call_statement; + private Boolean is_break; + private Boolean is_return; + private If_statement if_statement; + private For_statement for_statement; + private While_statement while_statement; + private When_statement when_statement; + private Comment comment; + + public Statement(Assignment_statement assignment_statement, Function_call_statement function_call_statement, Assignment_with_function_call_statement assignment_with_function_call_statement, Boolean is_break, + Boolean is_return, If_statement if_statement, For_statement for_statement, While_statement while_statement, When_statement when_statement, Comment comment) { + this.assignment_statement = assignment_statement; + this.function_call_statement = function_call_statement; + this.assignment_with_function_call_statement = assignment_with_function_call_statement; + this.is_break = is_break; + this.is_return = is_return; + this.if_statement = if_statement; + this.for_statement = for_statement; + this.while_statement = while_statement; + this.when_statement = when_statement; + this.comment = comment; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Stored_definition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Stored_definition.java index 77320500..de09f4cd 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Stored_definition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Stored_definition.java @@ -3,16 +3,12 @@ import java.util.Collection; public class Stored_definition { - private Collection within; - private Collection prefix; + private Within within; private Collection class_definition; - public Stored_definition(Collection within_dec, - Collection final_dec, - Collection name, + public Stored_definition(Within within, Collection class_definition) { - this.within = (name.size()>0 ? name : null); - this.prefix = (final_dec.size() > 0 ? final_dec : null); + this.within = within; this.class_definition = (class_definition.size() > 0 ? class_definition : null); } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Subscript.java b/java/parser/src/main/java/gov/lbl/parser/domain/Subscript.java new file mode 100644 index 00000000..65fba6fa --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Subscript.java @@ -0,0 +1,12 @@ +package gov.lbl.parser.domain; + +public class Subscript { + private Expression expression; + private Boolean colon_op; + + public Subscript(Expression expression, Boolean colon_op) { + this.expression = expression; + this.colon_op = colon_op; + } + +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Term.java b/java/parser/src/main/java/gov/lbl/parser/domain/Term.java new file mode 100644 index 00000000..32ee3376 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Term.java @@ -0,0 +1,13 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Term { + private Factor initial_factor; + private Collection remaining_factors; + + public Term(Factor initial_factor, Collection remaining_factors) { + this.initial_factor = initial_factor; + this.remaining_factors = remaining_factors; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Type_specifier.java b/java/parser/src/main/java/gov/lbl/parser/domain/Type_specifier.java new file mode 100644 index 00000000..dcea3432 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Type_specifier.java @@ -0,0 +1,9 @@ +package gov.lbl.parser.domain; + +public class Type_specifier { + private Name name; + + public Type_specifier(Name name) { + this.name = name; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/When_elsewhen_equation.java b/java/parser/src/main/java/gov/lbl/parser/domain/When_elsewhen_equation.java new file mode 100644 index 00000000..79348a5c --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/When_elsewhen_equation.java @@ -0,0 +1,14 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class When_elsewhen_equation { + private Expression condition; + private Collection then; + + public When_elsewhen_equation(Expression condition, Collection then) { + this.condition = condition; + this.then = then; + } + +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/When_elsewhen_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/When_elsewhen_statement.java new file mode 100644 index 00000000..65b4de1e --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/When_elsewhen_statement.java @@ -0,0 +1,14 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class When_elsewhen_statement { + private Expression condition; + private Collection then; + + public When_elsewhen_statement(Expression condition, Collection then) { + this.condition = condition; + this.then = then; + } + +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/When_equation.java b/java/parser/src/main/java/gov/lbl/parser/domain/When_equation.java new file mode 100644 index 00000000..5206f694 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/When_equation.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class When_equation { + private Collection when_elsewhen; + + public When_equation(Collection when_elsewhen) { + this.when_elsewhen = when_elsewhen; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/When_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/When_statement.java new file mode 100644 index 00000000..c48f21a5 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/When_statement.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class When_statement { + private Collection when_elsewhen; + + public When_statement(Collection when_elsewhen) { + this.when_elsewhen = when_elsewhen; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/While_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/While_statement.java new file mode 100644 index 00000000..6cb0d0f4 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/While_statement.java @@ -0,0 +1,14 @@ +package gov.lbl.parser.domain; + +import java.beans.Expression; +import java.util.Collection; + +public class While_statement { + private Expression expression; + private Collection loop_statements; + + public While_statement(Expression expression, Collection loop_statements) { + this.expression = expression; + this.loop_statements = loop_statements; + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Within.java b/java/parser/src/main/java/gov/lbl/parser/domain/Within.java new file mode 100644 index 00000000..f7965f70 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Within.java @@ -0,0 +1,9 @@ +package gov.lbl.parser.domain; + +public class Within { + private Name name; + + public Within(Name name) { + this.name = name; + } +} From dcce1dcf223641ccc77259d870c6bff50156c433 Mon Sep 17 00:00:00 2001 From: Anand Krishnan Prakash Date: Sun, 30 May 2021 23:40:37 -0700 Subject: [PATCH 02/29] creating new visitor files --- .../src/main/java/gov/lbl/parser/Main.java | 2 + .../lbl/parser/domain/Algorithm_section.java | 6 +- .../lbl/parser/domain/Class_definition.java | 34 +- .../gov/lbl/parser/domain/Component_list.java | 5 +- .../gov/lbl/parser/domain/Composition.java | 20 +- .../domain/Der_class_specifier_value.java | 9 +- .../gov/lbl/parser/domain/Element_list.java | 6 +- .../lbl/parser/domain/Equation_section.java | 6 +- .../parser/domain/External_composition.java | 6 +- .../gov/lbl/parser/domain/Import_list.java | 5 +- .../main/java/gov/lbl/parser/domain/Name.java | 23 +- .../java/gov/lbl/parser/domain/Name_part.java | 8 + .../java/gov/lbl/parser/domain/Primary.java | 6 +- .../lbl/parser/domain/Remaining_factor.java | 11 - .../lbl/parser/domain/Stored_definition.java | 6 +- .../main/java/gov/lbl/parser/domain/Term.java | 10 +- .../lbl/parser/domain/While_statement.java | 2 +- .../java/gov/lbl/parser/domain/Within.java | 9 - .../parser/Algorithm_sectionVisitor.java | 24 + .../lbl/parser/parser/AnnotationVisitor.java | 15 + .../lbl/parser/parser/ArgumentVisitor.java | 21 + .../parser/parser/Argument_listVisitor.java | 23 + .../parser/Arithmetic_expressionVisitor.java | 38 + .../parser/Array_subscriptsVisitor.java | 24 + .../lbl/parser/parser/Base_prefixVisitor.java | 14 + .../parser/Class_definitionVisitor.java | 26 + .../parser/Class_modificationVisitor.java | 16 + .../parser/parser/Class_prefixesVisitor.java | 75 + .../parser/parser/Class_specifierVisitor.java | 24 + .../gov/lbl/parser/parser/CommentVisitor.java | 17 + .../parser/Component_clause1Visitor.java | 23 + .../parser/Component_clauseVisitor.java | 27 + .../parser/Component_declaration1Visitor.java | 21 + .../parser/Component_declarationVisitor.java | 21 + .../parser/parser/Component_listVisitor.java | 22 + .../parser/Component_referenceVisitor.java | 22 + .../lbl/parser/parser/CompositionVisitor.java | 85 + .../parser/Condition_attributeVisitor.java | 16 + .../parser/parser/Connect_clauseVisitor.java | 25 + .../parser/Constraining_clauseVisitor.java | 20 + .../lbl/parser/parser/DeclarationVisitor.java | 22 + .../parser/Der_class_specifierVisitor.java | 32 + .../gov/lbl/parser/parser/ElementVisitor.java | 42 + .../parser/parser/Element_listVisitor.java | 22 + .../parser/Element_modificationVisitor.java | 23 + ...nt_modification_or_replaceableVisitor.java | 24 + .../parser/Element_redeclarationVisitor.java | 27 + .../parser/Element_replaceableVisitor.java | 24 + .../lbl/parser/parser/Enum_listVisitor.java | 18 + .../parser/Enumeration_literalVisitor.java | 16 + .../lbl/parser/parser/EquationVisitor.java | 55 + .../parser/Equation_sectionVisitor.java | 24 + .../lbl/parser/parser/ExpressionVisitor.java | 39 + .../parser/parser/Extends_clauseVisitor.java | 23 + .../parser/External_function_callVisitor.java | 21 + .../gov/lbl/parser/parser/FactorVisitor.java | 29 + .../parser/parser/For_equationVisitor.java | 26 + .../lbl/parser/parser/For_indexVisitor.java | 16 + .../lbl/parser/parser/For_indicesVisitor.java | 22 + .../parser/parser/For_statementVisitor.java | 26 + .../lbl/parser/parser/If_equationVisitor.java | 46 + .../parser/parser/If_statementVisitor.java | 23 + .../parser/parser/Import_clauseVisitor.java | 29 + .../lbl/parser/parser/Import_listVisitor.java | 17 + .../parser/Logical_expressionVisitor.java | 24 + .../parser/parser/Logical_factorVisitor.java | 16 + .../parser/parser/Logical_termVisitor.java | 22 + .../parser/Long_class_specifierVisitor.java | 35 + .../parser/parser/ModificationVisitor.java | 23 + .../gov/lbl/parser/parser/NameVisitor.java | 63 + .../gov/lbl/parser/parser/PrimaryVisitor.java | 52 + .../gov/lbl/parser/parser/Rel_opVisitor.java | 12 + .../lbl/parser/parser/RelationVisitor.java | 31 + .../parser/Short_class_definitionVisitor.java | 19 + .../parser/Short_class_specifierVisitor.java | 36 + .../parser/Simple_expressionVisitor.java | 27 + .../lbl/parser/parser/StatementVisitor.java | 67 + .../parser/Stored_definitionVisitor.java | 40 + .../parser/parser/String_commentVisitor.java | 28 + .../lbl/parser/parser/SubscriptVisitor.java | 17 + .../gov/lbl/parser/parser/TermVisitor.java | 26 + .../lbl/parser/parser/Type_prefixVisitor.java | 25 + .../parser/parser/Type_specifierVisitor.java | 15 + .../parser/parser/VisitorOrientedParser.java | 3558 +++++++++-------- .../parser/parser/When_equationVisitor.java | 39 + .../parser/parser/When_statementVisitor.java | 39 + .../parser/parser/While_statementVisitor.java | 26 + 87 files changed, 3804 insertions(+), 1855 deletions(-) delete mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Remaining_factor.java delete mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Within.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Algorithm_sectionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/AnnotationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/ArgumentVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Argument_listVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Array_subscriptsVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Base_prefixVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Class_definitionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Class_modificationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Class_prefixesVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Class_specifierVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/CommentVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Component_clause1Visitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Component_clauseVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Component_declaration1Visitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Component_declarationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Component_listVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Component_referenceVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Condition_attributeVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Connect_clauseVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Constraining_clauseVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/DeclarationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Der_class_specifierVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/ElementVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Element_listVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Element_modificationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Element_modification_or_replaceableVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Element_redeclarationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Element_replaceableVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Enum_listVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Enumeration_literalVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/EquationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Equation_sectionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Extends_clauseVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/External_function_callVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/For_equationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/For_indexVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/For_indicesVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/For_statementVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/If_equationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/If_statementVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Import_clauseVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Import_listVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Logical_expressionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Logical_factorVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Logical_termVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Long_class_specifierVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/ModificationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/NameVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/PrimaryVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Rel_opVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/RelationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Short_class_definitionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Short_class_specifierVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Simple_expressionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/StatementVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/String_commentVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/SubscriptVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/TermVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Type_prefixVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Type_specifierVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/When_equationVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/When_statementVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/While_statementVisitor.java diff --git a/java/parser/src/main/java/gov/lbl/parser/Main.java b/java/parser/src/main/java/gov/lbl/parser/Main.java index b2cd05df..45ce4b03 100644 --- a/java/parser/src/main/java/gov/lbl/parser/Main.java +++ b/java/parser/src/main/java/gov/lbl/parser/Main.java @@ -1,3 +1,5 @@ +//java -Xmx2048m -Xms512m -jar java/moParser.jar --mo test/FromModelica/Modulation.mo + package gov.lbl.parser; import com.google.gson.Gson; diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Algorithm_section.java b/java/parser/src/main/java/gov/lbl/parser/domain/Algorithm_section.java index 1aee3bce..4c1dff23 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Algorithm_section.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Algorithm_section.java @@ -4,10 +4,10 @@ public class Algorithm_section { private Boolean initial; - private Collection statement; + private Collection statements; - public Algorithm_section(Boolean initial, Collection statement) { + public Algorithm_section(Boolean initial, Collection statements) { this.initial = initial; - this.statement = statement; + this.statements = statements; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Class_definition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Class_definition.java index 33ada9da..740da8cc 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Class_definition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Class_definition.java @@ -1,15 +1,37 @@ package gov.lbl.parser.domain; public class Class_definition { - private Boolean is_final; private Boolean encapsulated; private String class_prefixes; //class_prefixes: (PARTIAL)? (CLASS | MODEL | (OPERATOR)? RECORD | BLOCK | (EXPANDABLE)? CONNECTOR | TYPE | PACKAGE | ((PURE | IMPURE))? (OPERATOR)? FUNCTION | OPERATOR) private Class_specifier class_specifier; - public Class_definition(Boolean is_final, Boolean encapsulated, String class_prefixes, Class_specifier class_specifier) { - this.is_final = is_final; - this.encapsulated = encapsulated; - this.class_prefixes = class_prefixes; - this.class_specifier = class_specifier; + public Class_definition(Boolean encapsulated, String class_prefixes, Class_specifier class_specifier) { + this.setEncapsulated(encapsulated); + this.setClass_prefixes(class_prefixes); + this.setClass_specifier(class_specifier); + } + + public Class_specifier getClass_specifier() { + return class_specifier; + } + + public void setClass_specifier(Class_specifier class_specifier) { + this.class_specifier = class_specifier; + } + + public String getClass_prefixes() { + return class_prefixes; + } + + public void setClass_prefixes(String class_prefixes) { + this.class_prefixes = class_prefixes; + } + + public Boolean getEncapsulated() { + return encapsulated; + } + + public void setEncapsulated(Boolean encapsulated) { + this.encapsulated = encapsulated; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Component_list.java b/java/parser/src/main/java/gov/lbl/parser/domain/Component_list.java index f5525b51..a1c3f2bb 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Component_list.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Component_list.java @@ -5,10 +5,7 @@ public class Component_list { Collection component_declaration_list; - public Component_list(Collection component_declaration_list) throws Exception { - if (component_declaration_list.size() == 0) { - throw new Exception("component_list cannot be empty"); - } + public Component_list(Collection component_declaration_list) { this.component_declaration_list = component_declaration_list; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java index 2779718d..bf7e2318 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java @@ -4,20 +4,20 @@ public class Composition { private Element_list element_list; - private Collection public_element_list; - private Collection protected_element_list; - private Collection equation_section; - private Collection algorithm_section; + private Collection public_element_lists; + private Collection protected_element_lists; + private Collection equation_sections; + private Collection algorithm_sections; private External_composition external_composition; private Annotation annotation; - public Composition(Element_list element_list, Collection public_element_list, Collection protected_element_list, Collection equation_section, - Collection algorithm_section, External_composition external_composition, Annotation annotation) { + public Composition(Element_list element_list, Collection public_element_lists, Collection protected_element_lists, Collection equation_sections, + Collection algorithm_sections, External_composition external_composition, Annotation annotation) { this.element_list = element_list; - this.public_element_list = (public_element_list.size() > 0) ? public_element_list : null; - this.protected_element_list = (protected_element_list.size() > 0) ? protected_element_list : null; - this.equation_section = (equation_section.size() > 0) ? equation_section : null; - this.algorithm_section = (algorithm_section.size() > 0) ? algorithm_section : null; + this.public_element_lists = (public_element_lists.size() > 0) ? public_element_lists : null; + this.protected_element_lists = (protected_element_lists.size() > 0) ? protected_element_lists : null; + this.equation_sections = (equation_sections.size() > 0) ? equation_sections : null; + this.algorithm_sections = (algorithm_sections.size() > 0) ? algorithm_sections : null; this.external_composition = external_composition; this.annotation = annotation; } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Der_class_specifier_value.java b/java/parser/src/main/java/gov/lbl/parser/domain/Der_class_specifier_value.java index 3c5875c2..969a8415 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Der_class_specifier_value.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Der_class_specifier_value.java @@ -1,17 +1,14 @@ package gov.lbl.parser.domain; -import java.util.Collection; +import java.util.List; public class Der_class_specifier_value { private Name type_specifier; - private Collection identifiers; + private List identifiers; private Comment comment; - public Der_class_specifier_value(Name type_specifier, Collection identifiers, Comment comment) throws Exception { + public Der_class_specifier_value(Name type_specifier, List identifiers, Comment comment) { this.type_specifier = type_specifier; - if (identifiers.size() == 0) { - throw new Exception("Der_class_specifier_value identifiers cannot be empty"); - } this.identifiers = identifiers; this.comment = comment; } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Element_list.java b/java/parser/src/main/java/gov/lbl/parser/domain/Element_list.java index d88fb528..54fbffd0 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Element_list.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Element_list.java @@ -3,9 +3,9 @@ import java.util.Collection; public class Element_list { - private Collection element; + private Collection elements; - public Element_list(Collection element) { - this.element = element.size() > 0 ? element : null; + public Element_list(Collection elements) { + this.elements = elements.size() > 0 ? elements : null; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Equation_section.java b/java/parser/src/main/java/gov/lbl/parser/domain/Equation_section.java index 5879a9de..2cb98b0a 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Equation_section.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Equation_section.java @@ -4,10 +4,10 @@ public class Equation_section { private Boolean initial; - private Collection equation; + private Collection equations; - public Equation_section(Boolean initial, Collection equation) { + public Equation_section(Boolean initial, Collection equations) { this.initial = initial; - this.equation = equation; + this.equations = equations; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/External_composition.java b/java/parser/src/main/java/gov/lbl/parser/domain/External_composition.java index ee1ce650..2e63d872 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/External_composition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/External_composition.java @@ -5,11 +5,11 @@ public class External_composition { private String language_specification; private External_function_call external_function_call; - private Annotation annotation; + private Annotation external_annotation; - public External_composition(String language_specification, External_function_call external_function_call, Annotation annotation) { + public External_composition(String language_specification, External_function_call external_function_call, Annotation external_annotation) { this.language_specification = language_specification; this.external_function_call = external_function_call; - this.annotation = annotation; + this.external_annotation = external_annotation; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Import_list.java b/java/parser/src/main/java/gov/lbl/parser/domain/Import_list.java index 556c9249..afdddd91 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Import_list.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Import_list.java @@ -5,10 +5,7 @@ public class Import_list { Collection identifier_list; - public Import_list (Collection identifier_list) throws Exception{ - if (identifier_list.size() == 0) { - throw new Exception("import_list cannot be empty"); - } + public Import_list (Collection identifier_list) { this.identifier_list = identifier_list; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Name.java b/java/parser/src/main/java/gov/lbl/parser/domain/Name.java index 5b3ca06c..d53e6116 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Name.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Name.java @@ -1,11 +1,26 @@ package gov.lbl.parser.domain; -import java.util.Collection; +import java.util.List; public class Name { - Collection name_parts; + List name_parts; - public Name(Collection name_parts) { + public Name(List name_parts) { this.name_parts = name_parts; } -} + + public List get_Name_parts() { + return this.name_parts; + } + + public String getName() { + StringBuilder name = new StringBuilder(); + for (int j=0; j expression_lists; private Function_arguments function_arguments; - public Primary(Double unsigned_number, String string, Boolean is_false, Boolean is_true, Function_call_primary function_call_primary, Component_reference component_reference, + public Primary(Double unsigned_number, String primary_string, Boolean is_false, Boolean is_true, Function_call_primary function_call_primary, Component_reference component_reference, Output_expression_list output_expression_list, Collection expression_lists, Function_arguments function_arguments){ this.unsigned_number = unsigned_number; - this.string = string; + this.primary_string = primary_string; this.is_false = is_false; this.is_true = is_true; this.function_call_primary = function_call_primary; diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Remaining_factor.java b/java/parser/src/main/java/gov/lbl/parser/domain/Remaining_factor.java deleted file mode 100644 index 22f5aef6..00000000 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Remaining_factor.java +++ /dev/null @@ -1,11 +0,0 @@ -package gov.lbl.parser.domain; - -public class Remaining_factor { - private String mul_op; // '*' | '/' | '.*' | './' - private Factor factor; - - public Remaining_factor(String mul_op, Factor factor) { - this.mul_op = mul_op; - this.factor = factor; - } -} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Stored_definition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Stored_definition.java index de09f4cd..a111276b 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Stored_definition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Stored_definition.java @@ -3,12 +3,14 @@ import java.util.Collection; public class Stored_definition { - private Within within; + private String within; + private Boolean is_final; private Collection class_definition; - public Stored_definition(Within within, + public Stored_definition(String within, Boolean is_final, Collection class_definition) { this.within = within; + this.is_final = is_final; this.class_definition = (class_definition.size() > 0 ? class_definition : null); } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Term.java b/java/parser/src/main/java/gov/lbl/parser/domain/Term.java index 32ee3376..6a84d169 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Term.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Term.java @@ -3,11 +3,11 @@ import java.util.Collection; public class Term { - private Factor initial_factor; - private Collection remaining_factors; + private Collection factors; + private Collection mul_ops; - public Term(Factor initial_factor, Collection remaining_factors) { - this.initial_factor = initial_factor; - this.remaining_factors = remaining_factors; + public Term(Collection factors, Collection mul_ops) { + this.factors = factors; + this.mul_ops = mul_ops; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/While_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/While_statement.java index 6cb0d0f4..3612b08c 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/While_statement.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/While_statement.java @@ -1,7 +1,7 @@ package gov.lbl.parser.domain; -import java.beans.Expression; import java.util.Collection; +import java.util.List; public class While_statement { private Expression expression; diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Within.java b/java/parser/src/main/java/gov/lbl/parser/domain/Within.java deleted file mode 100644 index f7965f70..00000000 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Within.java +++ /dev/null @@ -1,9 +0,0 @@ -package gov.lbl.parser.domain; - -public class Within { - private Name name; - - public Within(Name name) { - this.name = name; - } -} diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Algorithm_sectionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Algorithm_sectionVisitor.java new file mode 100644 index 00000000..fe0e7de0 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Algorithm_sectionVisitor.java @@ -0,0 +1,24 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Statement; +import gov.lbl.parser.domain.Algorithm_section; + +import static java.util.stream.Collectors.toList; + +public class Algorithm_sectionVisitor extends modelicaBaseVisitor { + @Override + public Algorithm_section visitAlgorithm_section(modelicaParser.Algorithm_sectionContext ctx) { + Boolean initial = ctx.INITIAL() == null ? false : true; + + StatementVisitor statementVisitor = new StatementVisitor(); + List statements = ctx.statement() == null ? null : ctx.statement() + .stream() + .map(statement -> statement.accept(statementVisitor)) + .collect(toList()); + return new Algorithm_section(initial, statements); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/AnnotationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/AnnotationVisitor.java new file mode 100644 index 00000000..5f32a18a --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/AnnotationVisitor.java @@ -0,0 +1,15 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Annotation; +import gov.lbl.parser.domain.Class_modification; + +public class AnnotationVisitor extends modelicaBaseVisitor { + @Override + public Annotation visitAnnotation(modelicaParser.AnnotationContext ctx) { + Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + Class_modification class_modification = ctx.class_modification().accept(class_modificationVisitor); + return new Annotation(class_modification); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/ArgumentVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/ArgumentVisitor.java new file mode 100644 index 00000000..ef97ae6e --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/ArgumentVisitor.java @@ -0,0 +1,21 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Argument; +import gov.lbl.parser.domain.Element_modification_or_replaceable; +import gov.lbl.parser.domain.Element_redeclaration; + +public class ArgumentVisitor extends modelicaBaseVisitor { + @Override + public Argument visitArgument(modelicaParser.ArgumentContext ctx) { + Element_modification_or_replaceableVisitor element_modification_or_replaceableVisitor = new Element_modification_or_replaceableVisitor(); + Element_modification_or_replaceable element_modification_or_replaceable = + ctx.element_modification_or_replaceable() == null ? null : ctx.element_modification_or_replaceable().accept(element_modification_or_replaceableVisitor); + Element_redeclarationVisitor element_redeclarationVisitor = new Element_redeclarationVisitor(); + Element_redeclaration element_redeclaration = + ctx.element_redeclaration() == null ? null : ctx.element_redeclaration().accept(element_redeclarationVisitor); + + return new Argument(element_modification_or_replaceable, element_redeclaration); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Argument_listVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Argument_listVisitor.java new file mode 100644 index 00000000..c089d1f7 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Argument_listVisitor.java @@ -0,0 +1,23 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Argument; +import gov.lbl.parser.domain.Argument_list; + +import static java.util.stream.Collectors.toList; + +import java.util.List; + +public class Argument_listVisitor extends modelicaBaseVisitor { + @Override + public Argument_list visitArgument_list(modelicaParser.Argument_listContext ctx) { + + ArgumentVisitor argumentVisitor = new ArgumentVisitor(); + List arguments = ctx.argument() == null ? null : ctx.argument() + .stream() + .map(argument -> argument.accept(argumentVisitor)) + .collect(toList()); + return new Argument_list(arguments); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java new file mode 100644 index 00000000..9168624a --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java @@ -0,0 +1,38 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Arithmetic_expression; +import gov.lbl.parser.domain.Arithmetic_term; +import gov.lbl.parser.domain.Term; + +import static java.util.stream.Collectors.toList; + +import java.util.ArrayList; + +public class Arithmetic_expressionVisitor extends modelicaBaseVisitor { + @Override + public Arithmetic_expression visitArithmetic_expression(modelicaParser.Arithmetic_expressionContext ctx) { + TermVisitor termVisitor = new TermVisitor(); + List terms = ctx.term() == null ? null : ctx.term() + .stream() + .map(t -> t.accept(termVisitor)) + .collect(toList()); + + List add_ops = ctx.add_op() == null ? null : ctx.add_op() + .stream() + .map(add_op -> add_op.getText()) + .collect(toList()); + + List arithmetic_term_list = new ArrayList(); + if (add_ops.size() == (terms.size() - 1)) { + arithmetic_term_list.add(new Arithmetic_term(null, terms.get(0))); + } + for (int i=0; i { + @Override + public Array_subscripts visitArray_subscripts(modelicaParser.Array_subscriptsContext ctx) { + SubscriptVisitor subscriptVisitor = new SubscriptVisitor(); + List subscripts = ctx.subscript() + .stream() + .map(subscript -> subscript.accept(subscriptVisitor)) + .collect(toList()); + + return new Array_subscripts(subscripts); + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Base_prefixVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Base_prefixVisitor.java new file mode 100644 index 00000000..c9718f77 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Base_prefixVisitor.java @@ -0,0 +1,14 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Base_prefix; + +public class Base_prefixVisitor extends modelicaBaseVisitor { + @Override + public Base_prefix visitBase_prefix(modelicaParser.Base_prefixContext ctx) { + Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); + String type_prefix = ctx.type_prefix().accept(type_prefixVisitor); + return new Base_prefix(type_prefix); + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Class_definitionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Class_definitionVisitor.java new file mode 100644 index 00000000..5e3906aa --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Class_definitionVisitor.java @@ -0,0 +1,26 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Class_definition; +import gov.lbl.parser.domain.Class_specifier; + +public class Class_definitionVisitor extends modelicaBaseVisitor { + @Override + public Class_definition visitClass_definition(modelicaParser.Class_definitionContext ctx) { + String enca_dec = ctx.ENCAPSULATED() == null ? "" : ctx.ENCAPSULATED().getText(); + + Boolean encapsulated = false; + if (enca_dec.equals("encapsulated")) { + encapsulated = true; + } + + Class_prefixesVisitor class_prefixesVisitor = new Class_prefixesVisitor(); + String class_prefixes = ctx.class_prefixes().accept(class_prefixesVisitor); + + Class_specifierVisitor class_specifierVisitor = new Class_specifierVisitor(); + Class_specifier class_specifier = ctx.class_specifier().accept(class_specifierVisitor); + + return new Class_definition(encapsulated, class_prefixes, class_specifier); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Class_modificationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Class_modificationVisitor.java new file mode 100644 index 00000000..70032d39 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Class_modificationVisitor.java @@ -0,0 +1,16 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Argument_list; +import gov.lbl.parser.domain.Class_modification; + +public class Class_modificationVisitor extends modelicaBaseVisitor { + @Override + public Class_modification visitClass_modification(modelicaParser.Class_modificationContext ctx) { + Argument_listVisitor argument_listVisitor = new Argument_listVisitor(); + Argument_list argument_list = ctx.argument_list().accept(argument_listVisitor); + + return new Class_modification(argument_list); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Class_prefixesVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Class_prefixesVisitor.java new file mode 100644 index 00000000..819e8a59 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Class_prefixesVisitor.java @@ -0,0 +1,75 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; + +public class Class_prefixesVisitor extends modelicaBaseVisitor { + @Override + public String visitClass_prefixes(modelicaParser.Class_prefixesContext ctx) { + String partial_dec = + ctx.PARTIAL() == null ? "" : ctx.PARTIAL().getText(); + String class_dec = + ctx.CLASS() == null ? "" : ctx.CLASS().getText(); + String model_dec = + ctx.MODEL() == null ? "" : ctx.MODEL().getText(); + String block_dec = + ctx.BLOCK() == null ? "" : ctx.BLOCK().getText(); + String type_dec = + ctx.TYPE() == null ? "" : ctx.TYPE().getText(); + String package_dec = + ctx.PACKAGE() == null ? "" : ctx.PACKAGE().getText(); + String operator_dec = + ctx.OPERATOR() == null ? "" : ctx.OPERATOR().getText(); + String record_dec = + ctx.RECORD() == null ? "" : ctx.RECORD().getText(); + String expandable_dec = + ctx.EXPANDABLE() == null ? "" : ctx.EXPANDABLE().getText(); + String connector_dec = + ctx.CONNECTOR() == null ? "" : ctx.CONNECTOR().getText(); + String pure_dec = + ctx.PURE() == null ? "" : ctx.PURE().getText(); + String impure_dec = + ctx.IMPURE() == null ? "" : ctx.IMPURE().getText(); + String function_dec = + ctx.FUNCTION() == null ? "" : ctx.FUNCTION().getText(); + String other_dec; + if ((!function_dec.isEmpty()) && (connector_dec.isEmpty()) && (record_dec.isEmpty())) { + String tempStr; + if (operator_dec.isEmpty()) { + tempStr = function_dec; + } else { + StringBuilder temStr = new StringBuilder(); + tempStr = temStr.append(operator_dec).append(" ").append(function_dec).toString(); + } + if (pure_dec.isEmpty() && impure_dec.isEmpty()) { + other_dec = tempStr; + } else { + StringBuilder temStr = new StringBuilder(); + other_dec = temStr.append(pure_dec).append(impure_dec).append(" ").append(tempStr).toString(); + } + } else if ((!connector_dec.isEmpty()) && (function_dec.isEmpty()) && (record_dec.isEmpty())) { + StringBuilder temStr = new StringBuilder(); + other_dec = (expandable_dec.isEmpty()) ? connector_dec + : (temStr.append(expandable_dec).append(" ").append(connector_dec).toString()); + } else if ((!record_dec.isEmpty()) && (function_dec.isEmpty()) && (connector_dec.isEmpty())) { + StringBuilder temStr = new StringBuilder(); + other_dec = (operator_dec.isEmpty()) ? record_dec + : (temStr.append(operator_dec).append(" ").append(record_dec).toString()); + } else { + StringBuilder temStr = new StringBuilder(); + temStr.append(class_dec != null ? class_dec : "") + .append(model_dec != null ? model_dec : "") + .append(block_dec != null ? block_dec : "") + .append(type_dec != null ? type_dec : "") + .append(package_dec != null ? package_dec : "") + .append(operator_dec != null ? operator_dec : ""); + other_dec = temStr.toString(); + } + StringBuilder temStr = new StringBuilder(); + String claPreStr = + (!partial_dec.isEmpty()) ? (temStr.append(partial_dec).append(" ").append(other_dec).toString()) + : other_dec; + + return claPreStr; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Class_specifierVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Class_specifierVisitor.java new file mode 100644 index 00000000..959b5e68 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Class_specifierVisitor.java @@ -0,0 +1,24 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Class_specifier; +import gov.lbl.parser.domain.Der_class_specifier; +import gov.lbl.parser.domain.Long_class_specifier; +import gov.lbl.parser.domain.Short_class_specifier; + +public class Class_specifierVisitor extends modelicaBaseVisitor { + @Override + public Class_specifier visitClass_specifier(modelicaParser.Class_specifierContext ctx) { + Long_class_specifierVisitor long_class_specifierVisitor = new Long_class_specifierVisitor(); + Long_class_specifier long_class_specifier = + ctx.long_class_specifier() == null ? null : ctx.long_class_specifier().accept(long_class_specifierVisitor); + Short_class_specifierVisitor short_class_specifierVisitor = new Short_class_specifierVisitor(); + Short_class_specifier short_class_specifier = + ctx.short_class_specifier() == null ? null : ctx.short_class_specifier().accept(short_class_specifierVisitor); + Der_class_specifierVisitor der_class_specifierVisitor = new Der_class_specifierVisitor(); + Der_class_specifier der_class_specifier = + ctx.der_class_specifier() == null ? null : ctx.der_class_specifier().accept(der_class_specifierVisitor); + return new Class_specifier(long_class_specifier, short_class_specifier, der_class_specifier); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/CommentVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/CommentVisitor.java new file mode 100644 index 00000000..e3d0df4d --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/CommentVisitor.java @@ -0,0 +1,17 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Annotation; +import gov.lbl.parser.domain.Comment; + +public class CommentVisitor extends modelicaBaseVisitor { + @Override + public Comment visitComment(modelicaParser.CommentContext ctx) { + String_commentVisitor string_commentVisitor = new String_commentVisitor(); + String string_comment = ctx.string_comment() == null ? null : ctx.string_comment().accept(string_commentVisitor); + AnnotationVisitor annotationVisitor = new AnnotationVisitor(); + Annotation annotation = ctx.annotation() == null ? null : ctx.annotation().accept(annotationVisitor); + return new Comment(string_comment, annotation); + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Component_clause1Visitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Component_clause1Visitor.java new file mode 100644 index 00000000..1e87dbb5 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Component_clause1Visitor.java @@ -0,0 +1,23 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Component_clause1; +import gov.lbl.parser.domain.Component_declaration1; +import gov.lbl.parser.domain.Type_specifier; + +public class Component_clause1Visitor extends modelicaBaseVisitor { + @Override + public Component_clause1 visitComponent_clause1(modelicaParser.Component_clause1Context ctx) { + Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); + String type_prefix = ctx.type_prefix().accept(type_prefixVisitor); + + Type_specifierVisitor type_specifierVisitor = new Type_specifierVisitor(); + Type_specifier type_specifier = ctx.type_specifier().accept(type_specifierVisitor); + + Component_declaration1Visitor component_declaration1Visitor = new Component_declaration1Visitor(); + Component_declaration1 component_declaration1 = ctx.component_declaration1().accept(component_declaration1Visitor); + + return new Component_clause1(type_prefix, type_specifier, component_declaration1); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Component_clauseVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Component_clauseVisitor.java new file mode 100644 index 00000000..60bbc8ed --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Component_clauseVisitor.java @@ -0,0 +1,27 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Array_subscripts; +import gov.lbl.parser.domain.Component_clause; +import gov.lbl.parser.domain.Component_list; +import gov.lbl.parser.domain.Type_specifier; + +public class Component_clauseVisitor extends modelicaBaseVisitor { + @Override + public Component_clause visitComponent_clause(modelicaParser.Component_clauseContext ctx) { + Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); + String type_prefix = ctx.type_prefix() == null ? null : ctx.type_prefix().accept(type_prefixVisitor); + + Type_specifierVisitor type_specifierVisitor = new Type_specifierVisitor(); + Type_specifier type_specifier = ctx.type_specifier().accept(type_specifierVisitor); + + Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); + Array_subscripts array_subscripts = ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); + + Component_listVisitor component_listVisitor = new Component_listVisitor(); + Component_list component_list = ctx.component_list().accept(component_listVisitor); + + return new Component_clause(type_prefix, type_specifier, array_subscripts, component_list); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Component_declaration1Visitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Component_declaration1Visitor.java new file mode 100644 index 00000000..a1dd37be --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Component_declaration1Visitor.java @@ -0,0 +1,21 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Comment; +import gov.lbl.parser.domain.Component_declaration1; +import gov.lbl.parser.domain.Declaration; + +public class Component_declaration1Visitor extends modelicaBaseVisitor { + @Override + public Component_declaration1 visitComponent_declaration1(modelicaParser.Component_declaration1Context ctx) { + + DeclarationVisitor declarationVisitor = new DeclarationVisitor(); + Declaration declaration = ctx.declaration() == null ? null : ctx.declaration().accept(declarationVisitor); + + CommentVisitor commentVisitor = new CommentVisitor(); + Comment comment = ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + + return new Component_declaration1(declaration, comment); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Component_declarationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Component_declarationVisitor.java new file mode 100644 index 00000000..6e3c6144 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Component_declarationVisitor.java @@ -0,0 +1,21 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Comment; +import gov.lbl.parser.domain.Component_declaration; +import gov.lbl.parser.domain.Condition_attribute; +import gov.lbl.parser.domain.Declaration; + +public class Component_declarationVisitor extends modelicaBaseVisitor { + @Override + public Component_declaration visitComponent_declaration(modelicaParser.Component_declarationContext ctx) { + DeclarationVisitor declarationVisitor = new DeclarationVisitor(); + Declaration declaration = ctx.declaration().accept(declarationVisitor); + Condition_attributeVisitor condition_attributeVisitor = new Condition_attributeVisitor(); + Condition_attribute condition_attribute = ctx.condition_attribute() == null ? null : ctx.condition_attribute().accept(condition_attributeVisitor); + CommentVisitor commentVisitor = new CommentVisitor(); + Comment comment = ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + return new Component_declaration(declaration, condition_attribute, comment); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Component_listVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Component_listVisitor.java new file mode 100644 index 00000000..ff11ffad --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Component_listVisitor.java @@ -0,0 +1,22 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Component_declaration; +import gov.lbl.parser.domain.Component_list; + +import static java.util.stream.Collectors.toList; + +public class Component_listVisitor extends modelicaBaseVisitor { + @Override + public Component_list visitComponent_list(modelicaParser.Component_listContext ctx) { + Component_declarationVisitor component_declarationVisitor = new Component_declarationVisitor(); + List component_declaration_list = ctx.component_declaration() + .stream() + .map(component_declaration -> component_declaration.accept(component_declarationVisitor)) + .collect(toList()); + return new Component_list(component_declaration_list); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Component_referenceVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Component_referenceVisitor.java new file mode 100644 index 00000000..cdeda117 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Component_referenceVisitor.java @@ -0,0 +1,22 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; + +public class Component_referenceVisitor extends modelicaBaseVisitor { + @Override + public String visitComponent_reference(modelicaParser.Component_referenceContext ctx) { + String temStr = ""; + if (ctx.getText().isEmpty()) { + temStr = null; + } else { + int a = ctx.start.getStartIndex(); + int b = ctx.stop.getStopIndex(); + Interval interval = new Interval(a,b); + CharStream charStr = ctx.start.getInputStream(); + temStr = charStr.getText(interval).trim(); + } + return temStr; + // return new Component_reference(ident, dots, array_subscripts_1); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java new file mode 100644 index 00000000..88ae2244 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java @@ -0,0 +1,85 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Algorithm_section; +import gov.lbl.parser.domain.Annotation; +import gov.lbl.parser.domain.Composition; +import gov.lbl.parser.domain.Element_list; +import gov.lbl.parser.domain.Equation_section; +import gov.lbl.parser.domain.External_composition; +import gov.lbl.parser.domain.External_function_call; + +import static java.util.stream.Collectors.toList; + +public class CompositionVisitor extends modelicaBaseVisitor { + @Override + public Composition visitComposition(modelicaParser.CompositionContext ctx) { + + Element_listVisitor element_listVisitor = new Element_listVisitor(); + Equation_sectionVisitor equation_sectionVisitor = new Equation_sectionVisitor(); + Algorithm_sectionVisitor algorithm_sectionVisitor = new Algorithm_sectionVisitor(); + + List element_lists = ctx.element_list() + .stream() + .map(element_list -> element_list.accept(element_listVisitor)) + .collect(toList()); + + Element_list element_list = element_lists.get(0); + + List public_dec = ctx.PUBLIC() == null ? null : ctx.PUBLIC() + .stream() + .map(PUBLIC -> PUBLIC.getText()) + .collect(toList()); + + List protected_dec = ctx.PUBLIC() == null ? null : ctx.PROTECTED() + .stream() + .map(PROTECTED -> PROTECTED.getText()) + .collect(toList()); + + List public_element_lists = public_dec.size() == 0 ? null : element_lists.subList(1, public_dec.size()); + List protected_element_lists = protected_dec.size() == 0 ? null : element_lists.subList(1+public_dec.size(), + 1+public_dec.size()+protected_dec.size()); + List equation_sections = ctx.equation_section() == null ? null : ctx.equation_section() + .stream() + .map(equation_section -> equation_section.accept(equation_sectionVisitor)) + .collect(toList());; + List algorithm_sections = ctx.algorithm_section() == null ? null : ctx.algorithm_section() + .stream() + .map(algorithm_section -> algorithm_section.accept(algorithm_sectionVisitor)) + .collect(toList());; + + Boolean external = ctx.EXTERNAL() == null ? false : true; + String language_specification = ctx.language_specification() == null ? "" : ctx.language_specification().getText(); + + External_function_callVisitor external_function_callVisitor = new External_function_callVisitor(); + External_function_call external_function_call = ctx.external_function_call() == null ? null : ctx.external_function_call().accept(external_function_callVisitor); + + AnnotationVisitor annotationVisitor = new AnnotationVisitor(); + List annotations = ctx.annotation() == null ? null : ctx.annotation() + .stream() + .map(single_annotation -> single_annotation.accept(annotationVisitor)) + .collect(toList());; + Annotation external_annotation = null; + Annotation annotation = null; + if (annotations != null) { + if (annotations.size() == 2) { + external_annotation = annotations.get(0); + annotation = annotations.get(1); + } + else { + if (external) { + external_annotation = annotations.get(0); + } + else { + annotation = annotations.get(0); + } + } + } + External_composition external_composition = new External_composition(language_specification, external_function_call, external_annotation); + + return new Composition(element_list, public_element_lists, protected_element_lists, equation_sections, algorithm_sections, external_composition, annotation); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Condition_attributeVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Condition_attributeVisitor.java new file mode 100644 index 00000000..759ea97f --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Condition_attributeVisitor.java @@ -0,0 +1,16 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Condition_attribute; +import gov.lbl.parser.domain.Expression; + +public class Condition_attributeVisitor extends modelicaBaseVisitor { + @Override + public Condition_attribute visitCondition_attribute(modelicaParser.Condition_attributeContext ctx) { + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + Expression expression = ctx.expression() == null ? null :ctx.expression().accept(expressionVisitor); + + return new Condition_attribute(expression); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Connect_clauseVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Connect_clauseVisitor.java new file mode 100644 index 00000000..26821cb6 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Connect_clauseVisitor.java @@ -0,0 +1,25 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Component_reference; +import gov.lbl.parser.domain.Connect_clause; + +import static java.util.stream.Collectors.toList; + +public class Connect_clauseVisitor extends modelicaBaseVisitor { + @Override + public Connect_clause visitConnect_clause(modelicaParser.Connect_clauseContext ctx) { + Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); + List component_references = ctx.component_reference() + .stream() + .map(component_reference -> component_reference.accept(component_referenceVisitor)) + .collect(toList()); + + Component_reference from = component_references.get(0); + Component_reference to = component_references.get(1); + return new Connect_clause(from, to); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Constraining_clauseVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Constraining_clauseVisitor.java new file mode 100644 index 00000000..a325bd28 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Constraining_clauseVisitor.java @@ -0,0 +1,20 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Class_modification; +import gov.lbl.parser.domain.Constraining_clause; +import gov.lbl.parser.domain.Name; + +public class Constraining_clauseVisitor extends modelicaBaseVisitor { + @Override + public Constraining_clause visitConstraining_clause(modelicaParser.Constraining_clauseContext ctx) { + NameVisitor nameVisitor = new NameVisitor(); + Name name = ctx.name() == null ? null : ctx.name().accept(nameVisitor); + + Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + Class_modification class_modification = ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + + return new Constraining_clause(name, class_modification); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/DeclarationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/DeclarationVisitor.java new file mode 100644 index 00000000..b51557ef --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/DeclarationVisitor.java @@ -0,0 +1,22 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Array_subscripts; +import gov.lbl.parser.domain.Declaration; +import gov.lbl.parser.domain.Modification; + +public class DeclarationVisitor extends modelicaBaseVisitor { + @Override + public Declaration visitDeclaration(modelicaParser.DeclarationContext ctx) { + String identifier = ctx.IDENT().getText(); + + Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); + Array_subscripts array_subscripts = ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); + + ModificationVisitor modificationVisitor = new ModificationVisitor(); + Modification modification = ctx.modification() == null ? null : ctx.modification().accept(modificationVisitor); + + return new Declaration(identifier, array_subscripts, modification); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Der_class_specifierVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Der_class_specifierVisitor.java new file mode 100644 index 00000000..839abd29 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Der_class_specifierVisitor.java @@ -0,0 +1,32 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Comment; +import gov.lbl.parser.domain.Der_class_specifier; +import gov.lbl.parser.domain.Der_class_specifier_value; +import gov.lbl.parser.domain.Name; + +import static java.util.stream.Collectors.toList; + +public class Der_class_specifierVisitor extends modelicaBaseVisitor { + @Override + public Der_class_specifier visitDer_class_specifier(modelicaParser.Der_class_specifierContext ctx) { + List idents = ctx.IDENT() + .stream() + .map(IDENT -> IDENT.getText()) + .collect(toList()); + String identifier = idents.get(0); + + List identifiers = idents.subList(1, idents.size()); + NameVisitor nameVisitor = new NameVisitor(); + Name type_specifier = ctx.name().accept(nameVisitor); + CommentVisitor commentVisitor = new CommentVisitor(); + Comment comment = ctx.comment().accept(commentVisitor); + + Der_class_specifier_value der_class_specifier_value = new Der_class_specifier_value(type_specifier, identifiers, comment); + return new Der_class_specifier(identifier, der_class_specifier_value); + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/ElementVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/ElementVisitor.java new file mode 100644 index 00000000..1be0531b --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/ElementVisitor.java @@ -0,0 +1,42 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Class_definition; +import gov.lbl.parser.domain.Comment; +import gov.lbl.parser.domain.Component_clause; +import gov.lbl.parser.domain.Constraining_clause; +import gov.lbl.parser.domain.Element; +import gov.lbl.parser.domain.Extends_clause; +import gov.lbl.parser.domain.Import_clause; + +public class ElementVisitor extends modelicaBaseVisitor { + @Override + public Element visitElement(modelicaParser.ElementContext ctx) { + Import_clauseVisitor import_clauseVisitor = new Import_clauseVisitor(); + Import_clause import_clause = ctx.import_clause() == null ? null : ctx.import_clause().accept(import_clauseVisitor); + + Extends_clauseVisitor extends_clauseVisitor = new Extends_clauseVisitor(); + Extends_clause extends_clause = ctx.extends_clause() == null ? null : ctx.extends_clause().accept(extends_clauseVisitor); + + Boolean redeclare = ctx.REDECLARE() == null ? false : true; + Boolean is_final = ctx.FINAL() == null ? false : true; + Boolean inner = ctx.INNER() == null ? false : true; + Boolean outer = ctx.OUTER() == null ? false : true; + Boolean replaceable = ctx.REPLACEABLE() == null ? false : true; + + Constraining_clauseVisitor constraining_clauseVisitor = new Constraining_clauseVisitor(); + Constraining_clause constraining_clause = ctx.constraining_clause() == null ? null : ctx.constraining_clause().accept(constraining_clauseVisitor); + + Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); + Class_definition class_definition = ctx.class_definition() == null ? null : ctx.class_definition().accept(class_definitionVisitor); + + Component_clauseVisitor component_clauseVisitor = new Component_clauseVisitor(); + Component_clause component_clause = ctx.component_clause() == null ? null : ctx.component_clause().accept(component_clauseVisitor); + + CommentVisitor commentVisitor = new CommentVisitor(); + Comment comment = ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + + return new Element(import_clause, extends_clause, redeclare, is_final, inner, outer, replaceable, constraining_clause, class_definition, component_clause, comment); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Element_listVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Element_listVisitor.java new file mode 100644 index 00000000..cb6fdad6 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Element_listVisitor.java @@ -0,0 +1,22 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Element; +import gov.lbl.parser.domain.Element_list; + +import static java.util.stream.Collectors.toList; + +public class Element_listVisitor extends modelicaBaseVisitor { + @Override + public Element_list visitElement_list(modelicaParser.Element_listContext ctx) { + ElementVisitor elementVisitor = new ElementVisitor(); + List elements = ctx.element() == null ? null : ctx.element() + .stream() + .map(element -> element.accept(elementVisitor)) + .collect(toList()); + return new Element_list(elements); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Element_modificationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Element_modificationVisitor.java new file mode 100644 index 00000000..bd741f9b --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Element_modificationVisitor.java @@ -0,0 +1,23 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Element_modification; +import gov.lbl.parser.domain.Modification; +import gov.lbl.parser.domain.Name; + +public class Element_modificationVisitor extends modelicaBaseVisitor { + @Override + public Element_modification visitElement_modification(modelicaParser.Element_modificationContext ctx) { + NameVisitor nameVisitor = new NameVisitor(); + Name name = ctx.name() == null ? null : ctx.name().accept(nameVisitor); + + ModificationVisitor modificationVisitor = new ModificationVisitor(); + Modification modification = ctx.modification() == null ? null : ctx.modification().accept(modificationVisitor); + + String_commentVisitor string_commentVisitor = new String_commentVisitor(); + String string_comment = ctx.string_comment() == null ? null : ctx.string_comment().accept(string_commentVisitor); + + return new Element_modification(name, modification, string_comment); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Element_modification_or_replaceableVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Element_modification_or_replaceableVisitor.java new file mode 100644 index 00000000..27b01a92 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Element_modification_or_replaceableVisitor.java @@ -0,0 +1,24 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Element_modification; +import gov.lbl.parser.domain.Element_modification_or_replaceable; +import gov.lbl.parser.domain.Element_replaceable; + +public class Element_modification_or_replaceableVisitor extends modelicaBaseVisitor { + @Override + public Element_modification_or_replaceable visitElement_modification_or_replaceable(modelicaParser.Element_modification_or_replaceableContext ctx) { + + Boolean each = ctx.EACH() == null ? false : true; + Boolean is_final = ctx.FINAL() == null ? false : true; + + Element_modificationVisitor element_modificationVisitor = new Element_modificationVisitor(); + Element_modification element_modification = ctx.element_modification() == null ? null : ctx.element_modification().accept(element_modificationVisitor); + + Element_replaceableVisitor element_replaceableVisitor = new Element_replaceableVisitor(); + Element_replaceable element_replaceable = ctx.element_replaceable() == null ? null : ctx.element_replaceable().accept(element_replaceableVisitor); + + return new Element_modification_or_replaceable(each, is_final, element_modification, element_replaceable); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Element_redeclarationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Element_redeclarationVisitor.java new file mode 100644 index 00000000..0fabe960 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Element_redeclarationVisitor.java @@ -0,0 +1,27 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Component_clause1; +import gov.lbl.parser.domain.Element_redeclaration; +import gov.lbl.parser.domain.Element_replaceable; +import gov.lbl.parser.domain.Short_class_definition; + +public class Element_redeclarationVisitor extends modelicaBaseVisitor { + @Override + public Element_redeclaration visitElement_redeclaration(modelicaParser.Element_redeclarationContext ctx) { + Boolean each = ctx.EACH() == null ? false : true; + Boolean is_final = ctx.FINAL() == null ? false : true; + + Short_class_definitionVisitor short_class_definitionVisitor = new Short_class_definitionVisitor(); + Short_class_definition short_class_definition = ctx.short_class_definition() == null ? null : ctx.short_class_definition().accept(short_class_definitionVisitor); + + Component_clause1Visitor component_clause1Visitor = new Component_clause1Visitor(); + Component_clause1 component_clause1 = ctx.component_clause1() == null ? null : ctx.component_clause1().accept(component_clause1Visitor); + + Element_replaceableVisitor element_replaceableVisitor = new Element_replaceableVisitor(); + Element_replaceable element_replaceable = ctx.element_replaceable().accept(element_replaceableVisitor); + + return new Element_redeclaration(each, is_final, short_class_definition, component_clause1, element_replaceable); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Element_replaceableVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Element_replaceableVisitor.java new file mode 100644 index 00000000..353da92f --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Element_replaceableVisitor.java @@ -0,0 +1,24 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Component_clause1; +import gov.lbl.parser.domain.Constraining_clause; +import gov.lbl.parser.domain.Element_replaceable; +import gov.lbl.parser.domain.Short_class_definition; + +public class Element_replaceableVisitor extends modelicaBaseVisitor { + @Override + public Element_replaceable visitElement_replaceable(modelicaParser.Element_replaceableContext ctx) { + Short_class_definitionVisitor short_class_definitionVisitor = new Short_class_definitionVisitor(); + Short_class_definition short_class_definition = ctx.short_class_definition() == null ? null : ctx.short_class_definition().accept(short_class_definitionVisitor); + + Component_clause1Visitor component_clause1Visitor = new Component_clause1Visitor(); + Component_clause1 component_clause1 = ctx.component_clause1() == null ? null : ctx.component_clause1().accept(component_clause1Visitor); + + Constraining_clauseVisitor constraining_clauseVisitor = new Constraining_clauseVisitor(); + Constraining_clause constraining_clause = ctx.constraining_clause() == null ? null : ctx.constraining_clause().accept(constraining_clauseVisitor); + + return new Element_replaceable(short_class_definition, component_clause1, constraining_clause); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Enum_listVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Enum_listVisitor.java new file mode 100644 index 00000000..2c63f401 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Enum_listVisitor.java @@ -0,0 +1,18 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Enum_list; +import gov.lbl.parser.domain.Enumeration_literal; +import static java.util.stream.Collectors.toList; + +import java.util.List; + +public class Enum_listVisitor extends modelicaBaseVisitor { + @Override + public Enum_list visitEnum_list(modelicaParser.Enum_listContext ctx) { + Enumeration_literalVisitor enumeration_literalVisitor = new Enumeration_literalVisitor(); + List enumeration_literal_list = ctx.enumeration_literal().stream().map(enumeration_literal -> enumeration_literalVisitor.visitEnumeration_literal(enumeration_literal)).collect(toList()); + return new Enum_list(enumeration_literal_list); + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Enumeration_literalVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Enumeration_literalVisitor.java new file mode 100644 index 00000000..55dfacfe --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Enumeration_literalVisitor.java @@ -0,0 +1,16 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Comment; +import gov.lbl.parser.domain.Enumeration_literal; + +public class Enumeration_literalVisitor extends modelicaBaseVisitor { + @Override + public Enumeration_literal visitEnumeration_literal(modelicaParser.Enumeration_literalContext ctx) { + String identifier = ctx.IDENT().getText(); + CommentVisitor commentVisitor = new CommentVisitor(); + Comment comment = ctx.comment().accept(commentVisitor); + return new Enumeration_literal(identifier, comment); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/EquationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/EquationVisitor.java new file mode 100644 index 00000000..449ad8f5 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/EquationVisitor.java @@ -0,0 +1,55 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Assignment_equation; +import gov.lbl.parser.domain.Comment; +import gov.lbl.parser.domain.Connect_clause; +import gov.lbl.parser.domain.Equation; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.For_equation; +import gov.lbl.parser.domain.Function_call_args; +import gov.lbl.parser.domain.Function_call_equation; +import gov.lbl.parser.domain.If_equation; +import gov.lbl.parser.domain.Name; +import gov.lbl.parser.domain.Simple_expression; +import gov.lbl.parser.domain.When_equation; + +public class EquationVisitor extends modelicaBaseVisitor { + @Override + public Equation visitEquation(modelicaParser.EquationContext ctx) { + + Simple_expressionVisitor simple_expressionVisitor = new Simple_expressionVisitor(); + Simple_expression lhs = ctx.simple_expression() == null ? null : ctx.simple_expression().accept(simple_expressionVisitor); + + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + Expression rhs = ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + + Assignment_equation assignment_equation = new Assignment_equation(lhs, rhs); + + If_equationVisitor if_equationVisitor = new If_equationVisitor(); + If_equation if_equation = ctx.if_equation() == null ? null : ctx.if_equation().accept(if_equationVisitor); + + For_equationVisitor for_equationVisitor = new For_equationVisitor(); + For_equation for_equation = ctx.for_equation() == null ? null : ctx.for_equation().accept(for_equationVisitor); + + Connect_clauseVisitor connect_clauseVisitor = new Connect_clauseVisitor(); + Connect_clause connect_clause = ctx.connect_clause() == null ? null : ctx.connect_clause().accept(connect_clauseVisitor); + + When_equationVisitor when_equationVisitor = new When_equationVisitor(); + When_equation when_equation = ctx.when_equation() == null ? null : ctx.when_equation().accept(when_equationVisitor); + + NameVisitor nameVisitor = new NameVisitor(); + Name function_name = ctx.name() == null ? null : ctx.name().accept(nameVisitor); + + Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); + Function_call_args function_call_args = ctx.function_call_args() == null ? null : ctx.function_call_args().accept(function_call_argsVisitor); + + Function_call_equation function_call_equation = new Function_call_equation(function_name, function_call_args); + + CommentVisitor commentVisitor = new CommentVisitor(); + Comment comment = ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + + return new Equation(assignment_equation, if_equation, for_equation, connect_clause, when_equation, function_call_equation, comment); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Equation_sectionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Equation_sectionVisitor.java new file mode 100644 index 00000000..6509bd95 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Equation_sectionVisitor.java @@ -0,0 +1,24 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Equation; +import gov.lbl.parser.domain.Equation_section; + +import static java.util.stream.Collectors.toList; + +public class Equation_sectionVisitor extends modelicaBaseVisitor { + @Override + public Equation_section visitEquation_section(modelicaParser.Equation_sectionContext ctx) { + Boolean initial = ctx.INITIAL() == null ? false : true; + + EquationVisitor equationVisitor = new EquationVisitor(); + List equations = ctx.equation() == null ? null : ctx.equation() + .stream() + .map(equation -> equation.accept(equationVisitor)) + .collect(toList()); + return new Equation_section(initial, equations); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java new file mode 100644 index 00000000..0f8960a4 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java @@ -0,0 +1,39 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.If_elseif_expression; +import gov.lbl.parser.domain.If_expression; +import gov.lbl.parser.domain.Simple_expression; + +import static java.util.stream.Collectors.toList; + +import java.util.ArrayList; + +public class ExpressionVisitor extends modelicaBaseVisitor { + @Override + public Expression visitExpression(modelicaParser.ExpressionContext ctx) { + Simple_expressionVisitor simple_expressionVisitor = new Simple_expressionVisitor(); + Simple_expression simple_expression = ctx.simple_expression() == null ? null : ctx.simple_expression().accept(simple_expressionVisitor); + + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + List expressions = ctx.expression() == null ? null : ctx.expression() + .stream() + .map(expr -> expr.accept(expressionVisitor)) + .collect(toList()); + List if_elseif = new ArrayList(); + for (int i = 0; i { + @Override + public Extends_clause visitExtends_clause(modelicaParser.Extends_clauseContext ctx) { + NameVisitor nameVisitor = new NameVisitor(); + Name name = ctx.name() == null ? null : ctx.name().accept(nameVisitor); + + Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + Class_modification class_modification = ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + AnnotationVisitor annotationVisitor = new AnnotationVisitor(); + Annotation annotation = ctx.annotation() == null ? null : ctx.annotation().accept(annotationVisitor); + + return new Extends_clause(name, class_modification, annotation); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/External_function_callVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/External_function_callVisitor.java new file mode 100644 index 00000000..1e1ab1d1 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/External_function_callVisitor.java @@ -0,0 +1,21 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Component_reference; +import gov.lbl.parser.domain.Expression_list; +import gov.lbl.parser.domain.External_function_call; +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; + +public class External_function_callVisitor extends modelicaBaseVisitor { + @Override + public External_function_call visitExternal_function_call(modelicaParser.External_function_callContext ctx) { + String identifier = ctx.IDENT().getText(); + Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); + Component_reference component_reference = + ctx.component_reference() == null ? null : ctx.component_reference().accept(component_referenceVisitor); + Expression_listVisitor expression_listVisitor = new Expression_listVisitor(); + Expression_list expression_list = + ctx.expression_list() == null ? null : ctx.expression_list().accept(expression_listVisitor); + return new External_function_call(component_reference, identifier, expression_list); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java new file mode 100644 index 00000000..ab8bd34e --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java @@ -0,0 +1,29 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Factor; +import gov.lbl.parser.domain.Primary; + +import static java.util.stream.Collectors.toList; + +import java.util.List; + +public class FactorVisitor extends modelicaBaseVisitor { + @Override + public Factor visitFactor(modelicaParser.FactorContext ctx) { + PrimaryVisitor primaryVisitor = new PrimaryVisitor(); + List primarys = ctx.primary() == null ? null : ctx.primary() + .stream() + .map(primary -> primary.accept(primaryVisitor)) + .collect(toList()); + + String op = + ctx.SYMBOL_CARET()==null ? ctx.SYMBOL_DOTCARET().getText() : ctx.SYMBOL_CARET().getText(); + + Primary primary1 = primarys.get(0); + Primary primary2 = primarys.get(1); + + return new Factor(primary1, op, primary2); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/For_equationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/For_equationVisitor.java new file mode 100644 index 00000000..1157c3e9 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/For_equationVisitor.java @@ -0,0 +1,26 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Equation; +import gov.lbl.parser.domain.For_equation; +import gov.lbl.parser.domain.For_indices; + +import static java.util.stream.Collectors.toList; + +public class For_equationVisitor extends modelicaBaseVisitor { + @Override + public For_equation visitFor_equation(modelicaParser.For_equationContext ctx) { + For_indicesVisitor for_indicesVisitor = new For_indicesVisitor(); + For_indices for_indices = ctx.for_indices() == null? null : ctx.for_indices().accept(for_indicesVisitor); + + EquationVisitor equationVisitor = new EquationVisitor(); + List loop_equations = ctx.equation() == null ? null : ctx.equation() + .stream() + .map(eqn -> eqn.accept(equationVisitor)) + .collect(toList()); + return new For_equation(for_indices, loop_equations); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/For_indexVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/For_indexVisitor.java new file mode 100644 index 00000000..907befe8 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/For_indexVisitor.java @@ -0,0 +1,16 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.For_index; + +public class For_indexVisitor extends modelicaBaseVisitor { + @Override + public For_index visitFor_index(modelicaParser.For_indexContext ctx) { + String identifier = ctx.IDENT().getText(); + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + Expression expression = ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + return new For_index(identifier, expression); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/For_indicesVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/For_indicesVisitor.java new file mode 100644 index 00000000..a6649018 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/For_indicesVisitor.java @@ -0,0 +1,22 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.For_index; +import gov.lbl.parser.domain.For_indices; + +import static java.util.stream.Collectors.toList; + +public class For_indicesVisitor extends modelicaBaseVisitor { + @Override + public For_indices visitFor_indices(modelicaParser.For_indicesContext ctx) { + For_indexVisitor for_indexVisitor = new For_indexVisitor(); + List indices = ctx.for_index() + .stream() + .map(for_index -> for_index.accept(for_indexVisitor)) + .collect(toList()); + return new For_indices(indices); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/For_statementVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/For_statementVisitor.java new file mode 100644 index 00000000..2ba20ec5 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/For_statementVisitor.java @@ -0,0 +1,26 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Statement; +import gov.lbl.parser.domain.For_statement; +import gov.lbl.parser.domain.For_indices; + +import static java.util.stream.Collectors.toList; + +public class For_statementVisitor extends modelicaBaseVisitor { + @Override + public For_statement visitFor_statement(modelicaParser.For_statementContext ctx) { + For_indicesVisitor for_indicesVisitor = new For_indicesVisitor(); + For_indices for_indices = ctx.for_indices() == null? null : ctx.for_indices().accept(for_indicesVisitor); + + StatementVisitor statementVisitor = new StatementVisitor(); + List loop_statements = ctx.statement() == null ? null : ctx.statement() + .stream() + .map(stmt -> stmt.accept(statementVisitor)) + .collect(toList()); + return new For_statement(for_indices, loop_statements); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/If_equationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/If_equationVisitor.java new file mode 100644 index 00000000..1ad15865 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/If_equationVisitor.java @@ -0,0 +1,46 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Equation; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.If_equation; + +import static java.util.stream.Collectors.toList; + +public class If_equationVisitor extends modelicaBaseVisitor { + @Override + public If_equation visitIf_equation(modelicaParser.If_equationContext ctx) { + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + List expressions = ctx.expression() == null ? null : ctx.expression() + .stream() + .map(condition -> condition.accept(expressionVisitor)) + .collect(toList()); + EquationVisitor equationVisitor = new EquationVisitor(); + List equations = ctx.equation() == null ? null : ctx.equation() + .stream() + .map(equation -> equation.accept(equationVisitor)) + .collect(toList()); + Boolean else_condition = ctx.ELSE() == null ? false : true; + Equation else_equation = null; + if (else_condition) { + else_equation = equations.get(equations.size() - 1); + } + + // List { + @Override + public String visitIf_statement(modelicaParser.If_statementContext ctx) { + + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + return new If_statement(if_elseif, else_statement); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Import_clauseVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Import_clauseVisitor.java new file mode 100644 index 00000000..308fa809 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Import_clauseVisitor.java @@ -0,0 +1,29 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Comment; +import gov.lbl.parser.domain.Import_clause; +import gov.lbl.parser.domain.Import_list; +import gov.lbl.parser.domain.Name; + +public class Import_clauseVisitor extends modelicaBaseVisitor { + @Override + public Import_clause visitImport_clause(modelicaParser.Import_clauseContext ctx) { + + String identifier = ctx.IDENT() == null ? "" : ctx.IDENT().getText(); + + NameVisitor nameVisitor = new NameVisitor(); + Name name = ctx.name() == null ? null : ctx.name().accept(nameVisitor); + + Boolean dot_star = ctx.SYMBOL_DOTSTAR() == null ? false : true; + + Import_listVisitor import_listVisitor = new Import_listVisitor(); + Import_list import_list = ctx.import_list() == null ? null : ctx.import_list().accept(import_listVisitor); + + CommentVisitor commentVisitor = new CommentVisitor(); + Comment comment = ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + + return new Import_clause(identifier, name, dot_star, import_list, comment); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Import_listVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Import_listVisitor.java new file mode 100644 index 00000000..da287736 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Import_listVisitor.java @@ -0,0 +1,17 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Import_list; + +import static java.util.stream.Collectors.toList; + +import java.util.List; + +public class Import_listVisitor extends modelicaBaseVisitor { + @Override + public Import_list visitImport_list(modelicaParser.Import_listContext ctx) { + List identifier_list = ctx.IDENT() == null ? null : ctx.IDENT().stream().map(identifier -> identifier.getText()).collect(toList());; + return new Import_list(identifier_list); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Logical_expressionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Logical_expressionVisitor.java new file mode 100644 index 00000000..e19f926a --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Logical_expressionVisitor.java @@ -0,0 +1,24 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Logical_expression; +import gov.lbl.parser.domain.Logical_term; + +import static java.util.stream.Collectors.toList; + +public class Logical_expressionVisitor extends modelicaBaseVisitor { + @Override + public Logical_expression visitLogical_expression(modelicaParser.Logical_expressionContext ctx) { + + Logical_termVisitor logical_termVisitor = new Logical_termVisitor(); + List logical_term_list = ctx.logical_term() + .stream() + .map(l_term -> l_term.accept(logical_termVisitor)) + .collect(toList()); + + return new Logical_expression(logical_term_list); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Logical_factorVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Logical_factorVisitor.java new file mode 100644 index 00000000..6f8b5a0f --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Logical_factorVisitor.java @@ -0,0 +1,16 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Logical_factor; +import gov.lbl.parser.domain.Relation; + +public class Logical_factorVisitor extends modelicaBaseVisitor { + @Override + public Logical_factor visitLogical_factor(modelicaParser.Logical_factorContext ctx) { + Boolean not = ctx.NOT() == null ? false : true; + RelationVisitor relationVisitor = new RelationVisitor(); + Relation relation = ctx.relation() == null ? null : ctx.relation().accept(relationVisitor); + return new Logical_factor(not, relation); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Logical_termVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Logical_termVisitor.java new file mode 100644 index 00000000..c39c2432 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Logical_termVisitor.java @@ -0,0 +1,22 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Logical_factor; +import gov.lbl.parser.domain.Logical_term; + +import static java.util.stream.Collectors.toList; + +public class Logical_termVisitor extends modelicaBaseVisitor { + @Override + public Logical_term visitLogical_term(modelicaParser.Logical_termContext ctx) { + Logical_factorVisitor logical_factorVisitor = new Logical_factorVisitor(); + List logical_factor_list = ctx.logical_factor() + .stream() + .map(logical_factor -> logical_factor.accept(logical_factorVisitor)) + .collect(toList()); + return new Logical_term(logical_factor_list); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Long_class_specifierVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Long_class_specifierVisitor.java new file mode 100644 index 00000000..f441ec6c --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Long_class_specifierVisitor.java @@ -0,0 +1,35 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Class_modification; +import gov.lbl.parser.domain.Composition; +import gov.lbl.parser.domain.Long_class_specifier; + +import static java.util.stream.Collectors.toList; + +import java.util.List; + +public class Long_class_specifierVisitor extends modelicaBaseVisitor { + @Override + public Long_class_specifier visitLong_class_specifier(modelicaParser.Long_class_specifierContext ctx) { + List idents = ctx.IDENT() + .stream() + .map(IDENT -> IDENT.getText()) + .collect(toList()); + String identifier = idents.get(0); + String extends_dec = ctx.EXTENDS() == null ? "" : ctx.EXTENDS().getText(); + Boolean is_extends = false; + if (extends_dec.equals("extends")) { + is_extends = true; + } + + String_commentVisitor string_commentVisitor = new String_commentVisitor(); + String string_comment = ctx.string_comment().accept(string_commentVisitor); + CompositionVisitor compositionVisitor = new CompositionVisitor(); + Composition composition = ctx.composition().accept(compositionVisitor); + Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + Class_modification class_modification = ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + return new Long_class_specifier(identifier, string_comment, composition, is_extends, class_modification); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/ModificationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/ModificationVisitor.java new file mode 100644 index 00000000..6cf5e3f5 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/ModificationVisitor.java @@ -0,0 +1,23 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Class_modification; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.Modification; + +public class ModificationVisitor extends modelicaBaseVisitor { + @Override + public Modification visitModification(modelicaParser.ModificationContext ctx) { + Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + Class_modification class_modification = ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + Expression expression = ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + + Boolean equal = ctx.SYMBOL_EQUAL() == null ? false : true; + Boolean colon_equal = ctx.SYMBOL_COLONEQUAL() == null ? false : true; + + return new Modification(class_modification, equal, colon_equal, expression); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/NameVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/NameVisitor.java new file mode 100644 index 00000000..c0e6c3e0 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/NameVisitor.java @@ -0,0 +1,63 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Name; +import gov.lbl.parser.domain.Name_part; +import static java.util.stream.Collectors.toList; +import java.util.ArrayList; + +public class NameVisitor extends modelicaBaseVisitor { + @Override + public Name visitName(modelicaParser.NameContext ctx) { + List dots = ctx.SYMBOL_DOT()==null ? null : ctx.SYMBOL_DOT() + .stream() + .map(SYMBOL_DOT -> SYMBOL_DOT.getText()) + .collect(toList()); + List identifiers = ctx.IDENT() + .stream() + .map(IDENT -> IDENT.getText()) + .collect(toList()); + + List name_parts = new ArrayList(); + if (identifiers.size() == dots.size()+1) { + name_parts.add(new Name_part(false, identifiers.get(0))); + } + + for (int i=1; i name_parts = new ArrayList(); +// // for (int i=0; i { + @Override + public Primary visitPrimary(modelicaParser.PrimaryContext ctx) { + Double unsigned_number = ctx.UNSIGNED_NUMBER() == null ? null : Double.parseDouble(ctx.UNSIGNED_NUMBER().getText()); + String primary_string = ctx.STRING() == null ? null : ctx.STRING().getText(); + Boolean is_false = ctx.FALSE() == null ? false : true; + Boolean is_true = ctx.TRUE() == null ? false : true; + + NameVisitor nameVisitor = new NameVisitor(); + Name function_name = ctx.name() == null ? null : ctx.name().accept(nameVisitor); + Boolean der = ctx.DER() == null ? false : true; + Boolean initial = ctx.INITIAL() == null ? false : true; + + Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); + Function_call_args function_call_args = ctx.function_call_args() == null ? null :ctx.function_call_args().accept(function_call_argsVisitor); + Function_call_primary function_call_primary = new Function_call_primary(function_name, der, initial, function_call_args); + + Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); + Component_reference component_reference = ctx.component_reference() == null ? null : ctx.component_reference().accept(component_referenceVisitor); + + Output_expression_listVisitor output_expression_listVisitor = new Output_expression_listVisitor(); + Output_expression_list output_expression_list = ctx.output_expression_list() == null ? null : ctx.output_expression_list().accept(output_expression_listVisitor); + + Expression_listVisitor expression_listVisitor = new Expression_listVisitor(); + List expression_lists = ctx.expression_list() == null ? null : ctx.expression_list() + .stream() + .map(expression_list -> expression_list.accept(expression_listVisitor)) + .collect(toList()); + + Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); + Function_arguments function_arguments = ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); + + return new Primary(unsigned_number, primary_string, is_false, is_true, function_call_primary, component_reference, output_expression_list, expression_lists, function_arguments); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Rel_opVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Rel_opVisitor.java new file mode 100644 index 00000000..0134d360 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Rel_opVisitor.java @@ -0,0 +1,12 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; + +public class Rel_opVisitor extends modelicaBaseVisitor { + @Override + public String visitRel_op(modelicaParser.Rel_opContext ctx) { + String rel_op = ctx == null ? "" : ctx.getText(); + return rel_op; + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/RelationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/RelationVisitor.java new file mode 100644 index 00000000..4c88e1f7 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/RelationVisitor.java @@ -0,0 +1,31 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Relation; +import gov.lbl.parser.domain.Arithmetic_expression; + +import static java.util.stream.Collectors.toList; + +public class RelationVisitor extends modelicaBaseVisitor { + @Override + public Relation visitRelation(modelicaParser.RelationContext ctx) { + Arithmetic_expressionVisitor arithmetic_expressionVisitor = new Arithmetic_expressionVisitor(); + List arithmetic_expressions = ctx.arithmetic_expression() + .stream() + .map(arithmetic_expression -> arithmetic_expression.accept(arithmetic_expressionVisitor)) + .collect(toList()); + Rel_opVisitor rel_opVisitor = new Rel_opVisitor(); + String rel_op = ctx.rel_op() == null ? "" : ctx.rel_op().accept(rel_opVisitor); + + Arithmetic_expression arithmetic_expression1 = arithmetic_expressions.get(0); + Arithmetic_expression arithmetic_expression2 = null; + if (arithmetic_expressions.size() > 1) { + arithmetic_expression2 = arithmetic_expressions.get(1); + } + + return new Relation(arithmetic_expression1, rel_op, arithmetic_expression2); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_definitionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_definitionVisitor.java new file mode 100644 index 00000000..22f8335a --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_definitionVisitor.java @@ -0,0 +1,19 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Short_class_definition; +import gov.lbl.parser.domain.Short_class_specifier; + +public class Short_class_definitionVisitor extends modelicaBaseVisitor { + @Override + public Short_class_definition visitShort_class_definition(modelicaParser.Short_class_definitionContext ctx) { + Class_prefixesVisitor class_prefixesVisitor = new Class_prefixesVisitor(); + String class_prefixes = ctx.class_prefixes().accept(class_prefixesVisitor); + + Short_class_specifierVisitor short_class_specifierVisitor = new Short_class_specifierVisitor(); + Short_class_specifier short_class_specifier = ctx.short_class_specifier().accept(short_class_specifierVisitor); + + return new Short_class_definition(class_prefixes, short_class_specifier); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_specifierVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_specifierVisitor.java new file mode 100644 index 00000000..c0610642 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_specifierVisitor.java @@ -0,0 +1,36 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Array_subscripts; +import gov.lbl.parser.domain.Base_prefix; +import gov.lbl.parser.domain.Class_modification; +import gov.lbl.parser.domain.Comment; +import gov.lbl.parser.domain.Enum_list; +import gov.lbl.parser.domain.Name; +import gov.lbl.parser.domain.Short_class_specifier; +import gov.lbl.parser.domain.Short_class_specifier_value; + +public class Short_class_specifierVisitor extends modelicaBaseVisitor { + @Override + public Short_class_specifier visitShort_class_specifier(modelicaParser.Short_class_specifierContext ctx) { + String identifier = ctx.IDENT().getText(); + + Base_prefixVisitor base_prefixVisitor = new Base_prefixVisitor(); + Base_prefix base_prefix = ctx.base_prefix() == null ? null : ctx.base_prefix().accept(base_prefixVisitor); + Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); + Array_subscripts array_subscripts = ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); + NameVisitor nameVisitor = new NameVisitor(); + Name name = ctx.name().accept(nameVisitor); + Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + Class_modification class_modification = ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + CommentVisitor commentVisitor = new CommentVisitor(); + Comment comment = ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + Enum_listVisitor enum_listVisitor = new Enum_listVisitor(); + Enum_list enum_list = ctx.enum_list() == null ? null : ctx.enum_list().accept(enum_listVisitor); + + Short_class_specifier_value short_class_specifier_value = new Short_class_specifier_value(base_prefix, name, array_subscripts, class_modification, comment, enum_list); + + return new Short_class_specifier(identifier, short_class_specifier_value); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Simple_expressionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Simple_expressionVisitor.java new file mode 100644 index 00000000..9421733c --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Simple_expressionVisitor.java @@ -0,0 +1,27 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Logical_expression; +import gov.lbl.parser.domain.Simple_expression; + +import static java.util.stream.Collectors.toList; + +public class Simple_expressionVisitor extends modelicaBaseVisitor { + @Override + public Simple_expression visitSimple_expression(modelicaParser.Simple_expressionContext ctx) { + Logical_expressionVisitor logical_expressionVisitor = new Logical_expressionVisitor(); + List logical_expressions = ctx.logical_expression() == null ? null : ctx.logical_expression() + .stream() + .map(log_expr -> log_expr.accept(logical_expressionVisitor)) + .collect(toList()); + + Logical_expression logical_expression1 = logical_expressions.get(0); + Logical_expression logical_expression2 = logical_expressions.get(1); + Logical_expression logical_expression3 = logical_expressions.get(2); + + return new Simple_expression(logical_expression1, logical_expression2, logical_expression3); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/StatementVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/StatementVisitor.java new file mode 100644 index 00000000..f8b86b94 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/StatementVisitor.java @@ -0,0 +1,67 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Assignment_statement; +import gov.lbl.parser.domain.Assignment_with_function_call_statement; +import gov.lbl.parser.domain.Comment; +import gov.lbl.parser.domain.Component_reference; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.For_statement; +import gov.lbl.parser.domain.Function_call_args; +import gov.lbl.parser.domain.Function_call_statement; +import gov.lbl.parser.domain.If_statement; +import gov.lbl.parser.domain.Output_expression_list; +import gov.lbl.parser.domain.Statement; +import gov.lbl.parser.domain.When_statement; +import gov.lbl.parser.domain.While_statement; + +public class StatementVisitor extends modelicaBaseVisitor { + @Override + public Statement visitStatement(modelicaParser.StatementContext ctx) { + Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); + Component_reference component_reference = ctx.component_reference() == null ? null : ctx.component_reference().accept(component_referenceVisitor); + + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + Expression value = ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + + Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); + Function_call_args function_call_args = ctx.function_call_args() == null ? null : ctx.function_call_args().accept(function_call_argsVisitor); + + Output_expression_listVisitor output_expression_listVisitor = new Output_expression_listVisitor(); + Output_expression_list output_expression_list = ctx.output_expression_list() == null ? null : ctx.output_expression_list().accept(output_expression_listVisitor); + + Assignment_statement assignment_statement = null; + Function_call_statement function_call_statement = null; + Assignment_with_function_call_statement assignment_with_function_call_statement = null; + if (component_reference != null && value != null) { + assignment_statement = new Assignment_statement(component_reference, value); + } + else if (component_reference != null && function_call_args != null && output_expression_list != null) { + assignment_with_function_call_statement = new Assignment_with_function_call_statement(output_expression_list, component_reference, function_call_args); + } + else if (component_reference != null && function_call_args != null) { + function_call_statement = new Function_call_statement(component_reference, function_call_args); + } + + Boolean is_break = ctx.BREAK() == null ? false : true; + Boolean is_return = ctx.RETURN() == null ? false : true; + + If_statementVisitor if_statementVisitor = new If_statementVisitor(); + If_statement if_statement = ctx.if_statement() == null ? null : ctx.if_statement().accept(if_statementVisitor); + + For_statementVisitor for_statementVisitor = new For_statementVisitor(); + For_statement for_statement = ctx.for_statement() == null ? null : ctx.for_statement().accept(for_statementVisitor); + + While_statementVisitor while_statementVisitor = new While_statementVisitor(); + While_statement while_statement = ctx.while_statement() == null ? null : ctx.while_statement().accept(while_statementVisitor); + + When_statementVisitor when_statementVisitor = new When_statementVisitor(); + When_statement when_statement = ctx.when_statement() == null ? null : ctx.when_statement().accept(when_statementVisitor); + + CommentVisitor commentVisitor = new CommentVisitor(); + Comment comment = ctx.comment().accept(commentVisitor); + + return new Statement(assignment_statement, function_call_statement, assignment_with_function_call_statement, is_break, is_return, if_statement, for_statement, while_statement, when_statement, comment); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java new file mode 100644 index 00000000..0f27da40 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java @@ -0,0 +1,40 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Class_definition; +import gov.lbl.parser.domain.Name; +import static java.util.stream.Collectors.toList; + +import gov.lbl.parser.domain.Stored_definition; + +public class Stored_definitionVisitor extends modelicaBaseVisitor { + @Override + public Stored_definition visitStored_definition(modelicaParser.Stored_definitionContext ctx) { + NameVisitor nameVisitor = new NameVisitor(); + List names = ctx.name().stream().map(name -> nameVisitor.visitName(name)).collect(toList()); + System.out.println(names.get(0)); + + Name name = names.get(0); + String within = name.getName(); + + List final_dec = ctx.FINAL() == null ? null : ctx.FINAL() + .stream() + .map(FINAL -> FINAL.getText()) + .collect(toList()); + + Boolean is_final = false; + if (final_dec.size() > 0) { + is_final = true; + } + + Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); + List class_definitions = ctx.class_definition() + .stream() + .map(class_definition -> class_definitionVisitor.visitClass_definition(class_definition)) + .collect(toList()); + return new Stored_definition(within, is_final, class_definitions); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/String_commentVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/String_commentVisitor.java new file mode 100644 index 00000000..8b626875 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/String_commentVisitor.java @@ -0,0 +1,28 @@ +package gov.lbl.parser.parser; + +import java.util.List; +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import static java.util.stream.Collectors.toList; + +public class String_commentVisitor extends modelicaBaseVisitor { + @Override + public String visitString_comment(modelicaParser.String_commentContext ctx) { + List str_dec = ctx.STRING() == null ? null : ctx.STRING() + .stream() + .map(STRING -> STRING.getText()) + .collect(toList()); + String strCom = ""; + if (str_dec.size() == 1) { + strCom = str_dec.get(0); + } else if (str_dec.size() > 1) { + StringBuilder temStr = new StringBuilder(); + temStr.append(str_dec.get(0)); + for (int i=1; i { + @Override + public Subscript visitSubscript(modelicaParser.SubscriptContext ctx) { + Boolean colon = ctx.SYMBOL_COLON() == null ? false : true; + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + Expression expression = ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + + return new Subscript(expression, colon); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/TermVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/TermVisitor.java new file mode 100644 index 00000000..60b73f0e --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/TermVisitor.java @@ -0,0 +1,26 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Factor; +import gov.lbl.parser.domain.Term; + +import static java.util.stream.Collectors.toList; + +public class TermVisitor extends modelicaBaseVisitor { + @Override + public Term visitTerm(modelicaParser.TermContext ctx) { + List mul_ops = ctx.mul_op() == null ? null : ctx.mul_op() + .stream() + .map(mul_op -> mul_op.getText()) + .collect(toList()); + FactorVisitor factorVisitor = new FactorVisitor(); + List factors = ctx.factor() == null ? null : ctx.factor() + .stream() + .map(factor -> factor.accept(factorVisitor)) + .collect(toList()); + return new Term(factors, mul_ops); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Type_prefixVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Type_prefixVisitor.java new file mode 100644 index 00000000..07554a32 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Type_prefixVisitor.java @@ -0,0 +1,25 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; + +public class Type_prefixVisitor extends modelicaBaseVisitor { + @Override + public String visitType_prefix(modelicaParser.Type_prefixContext ctx) { + String flow_dec = ctx.FLOW() == null ? null : ctx.FLOW().getText(); + String stream_dec = ctx.STREAM() == null ? null : ctx.STREAM().getText(); + String disc_dec = ctx.DISCRETE() == null ? null : ctx.DISCRETE().getText(); + String par_dec = ctx.PARAMETER() == null ? null : ctx.PARAMETER().getText(); + String con_dec = ctx.CONSTANT() == null ? null : ctx.CONSTANT().getText(); + String in_dec = ctx.INPUT() == null ? null : ctx.INPUT().getText(); + String out_dec = ctx.OUTPUT() == null ? null : ctx.OUTPUT().getText(); + String prefix = (flow_dec != null) ? flow_dec + : (stream_dec != null ? stream_dec + : (disc_dec != null ? disc_dec + : (par_dec != null ? par_dec + : (con_dec != null ? con_dec + : (in_dec != null ? in_dec + : out_dec))))); + return prefix; + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Type_specifierVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Type_specifierVisitor.java new file mode 100644 index 00000000..c079c5ed --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Type_specifierVisitor.java @@ -0,0 +1,15 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Name; +import gov.lbl.parser.domain.Type_specifier; + +public class Type_specifierVisitor extends modelicaBaseVisitor { + @Override + public Type_specifier visitType_specifier(modelicaParser.Type_specifierContext ctx) { + NameVisitor nameVisitor = new NameVisitor(); + Name name = ctx.name() == null ? null : ctx.name().accept(nameVisitor); + return new Type_specifier(name); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/VisitorOrientedParser.java b/java/parser/src/main/java/gov/lbl/parser/parser/VisitorOrientedParser.java index c224f535..aa3c1e14 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/VisitorOrientedParser.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/VisitorOrientedParser.java @@ -21,1791 +21,1793 @@ public class VisitorOrientedParser implements Parser { public Stored_definition parse(String modelicaSourceCode) { - CharStream charStream = CharStreams.fromString(modelicaSourceCode); + CharStream charStream = CharStreams.fromString(modelicaSourceCode); modelicaLexer lexer = new modelicaLexer(charStream); TokenStream tokens = new CommonTokenStream(lexer); modelicaParser parser = new modelicaParser(tokens); Stored_definitionVisitor stored_definitionVisitor = new Stored_definitionVisitor(); - Stored_definition traverseResult = stored_definitionVisitor.visit(parser.stored_definition()); - return traverseResult; - } - - private static class Stored_definitionVisitor extends modelicaBaseVisitor { - @Override - public Stored_definition visitStored_definition(modelicaParser.Stored_definitionContext ctx) { - List within_dec = ctx.WITHIN() == null ? null : ctx.WITHIN() - .stream() - .map(WITHIN -> WITHIN.getText()) - .collect(toList()); - NameVisitor nameVisitor = new NameVisitor(); - List names = ctx.name() == null ? null : ctx.name() - .stream() - .map(name -> name.accept(nameVisitor)) - .collect(toList()); - List final_dec = ctx.FINAL() == null ? null : ctx.FINAL() - .stream() - .map(FINAL -> FINAL.getText()) - .collect(toList()); - Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); - List class_definitions = ctx.class_definition() - .stream() - .map(class_definition -> class_definition.accept(class_definitionVisitor)) - .collect(toList()); - return new Stored_definition(within_dec, final_dec, names, class_definitions); - } - } - - private static class Class_definitionVisitor extends modelicaBaseVisitor { - @Override - public Class_definition visitClass_definition(modelicaParser.Class_definitionContext ctx) { - String enca_dec = ctx.ENCAPSULATED() == null ? null : ctx.ENCAPSULATED().getText(); - Class_prefixesVisitor class_prefixesVisitor = new Class_prefixesVisitor(); - String class_prefixes_1 = ctx.class_prefixes().accept(class_prefixesVisitor); - Class_specifierVisitor class_specifierVisitor = new Class_specifierVisitor(); - Class_specifier class_specifier_1 = ctx.class_specifier().accept(class_specifierVisitor); - return new Class_definition(enca_dec, class_prefixes_1, class_specifier_1); - } - } - - private static class Class_specifierVisitor extends modelicaBaseVisitor { - @Override - public Class_specifier visitClass_specifier(modelicaParser.Class_specifierContext ctx) { - Long_class_specifierVisitor long_class_specifierVisitor = new Long_class_specifierVisitor(); - Long_class_specifier long_class_specifier_1 = - ctx.long_class_specifier() == null ? null : ctx.long_class_specifier().accept(long_class_specifierVisitor); - Short_class_specifierVisitor short_class_specifierVisitor = new Short_class_specifierVisitor(); - Short_class_specifier short_class_specifier_1 = - ctx.short_class_specifier() == null ? null : ctx.short_class_specifier().accept(short_class_specifierVisitor); - Der_class_specifierVisitor der_class_specifierVisitor = new Der_class_specifierVisitor(); - Der_class_specifier der_class_specifier_1 = - ctx.der_class_specifier() == null ? null : ctx.der_class_specifier().accept(der_class_specifierVisitor); - return new Class_specifier(long_class_specifier_1, short_class_specifier_1, der_class_specifier_1); - } - } - - private static class Class_prefixesVisitor extends modelicaBaseVisitor { - @Override - public String visitClass_prefixes(modelicaParser.Class_prefixesContext ctx) { - String partial_dec = - ctx.PARTIAL() == null ? "" : ctx.PARTIAL().getText(); - String class_dec = - ctx.CLASS() == null ? "" : ctx.CLASS().getText(); - String model_dec = - ctx.MODEL() == null ? "" : ctx.MODEL().getText(); - String block_dec = - ctx.BLOCK() == null ? "" : ctx.BLOCK().getText(); - String type_dec = - ctx.TYPE() == null ? "" : ctx.TYPE().getText(); - String package_dec = - ctx.PACKAGE() == null ? "" : ctx.PACKAGE().getText(); - String operator_dec = - ctx.OPERATOR() == null ? "" : ctx.OPERATOR().getText(); - String record_dec = - ctx.RECORD() == null ? "" : ctx.RECORD().getText(); - String expandable_dec = - ctx.EXPANDABLE() == null ? "" : ctx.EXPANDABLE().getText(); - String connector_dec = - ctx.CONNECTOR() == null ? "" : ctx.CONNECTOR().getText(); - String pure_dec = - ctx.PURE() == null ? "" : ctx.PURE().getText(); - String impure_dec = - ctx.IMPURE() == null ? "" : ctx.IMPURE().getText(); - String function_dec = - ctx.FUNCTION() == null ? "" : ctx.FUNCTION().getText(); - String other_dec; - if ((!function_dec.isEmpty()) && (connector_dec.isEmpty()) && (record_dec.isEmpty())) { - String tempStr; - if (operator_dec.isEmpty()) { - tempStr = function_dec; - } else { - StringBuilder temStr = new StringBuilder(); - tempStr = temStr.append(operator_dec).append(" ").append(function_dec).toString(); - } - if (pure_dec.isEmpty() && impure_dec.isEmpty()) { - other_dec = tempStr; - } else { - StringBuilder temStr = new StringBuilder(); - other_dec = temStr.append(pure_dec).append(impure_dec).append(" ").append(tempStr).toString(); - } - } else if ((!connector_dec.isEmpty()) && (function_dec.isEmpty()) && (record_dec.isEmpty())) { - StringBuilder temStr = new StringBuilder(); - other_dec = (expandable_dec.isEmpty()) ? connector_dec - : (temStr.append(expandable_dec).append(" ").append(connector_dec).toString()); - } else if ((!record_dec.isEmpty()) && (function_dec.isEmpty()) && (connector_dec.isEmpty())) { - StringBuilder temStr = new StringBuilder(); - other_dec = (operator_dec.isEmpty()) ? record_dec - : (temStr.append(operator_dec).append(" ").append(record_dec).toString()); - } else { - StringBuilder temStr = new StringBuilder(); - temStr.append(class_dec != null ? class_dec : "") - .append(model_dec != null ? model_dec : "") - .append(block_dec != null ? block_dec : "") - .append(type_dec != null ? type_dec : "") - .append(package_dec != null ? package_dec : "") - .append(operator_dec != null ? operator_dec : ""); - other_dec = temStr.toString(); - } - StringBuilder temStr = new StringBuilder(); - String claPreStr = - (!partial_dec.isEmpty()) ? (temStr.append(partial_dec).append(" ").append(other_dec).toString()) - : other_dec; + Stored_definition traverseResult = stored_definitionVisitor.visitStored_definition(parser.stored_definition()); + System.out.println("output = "); + System.out.println(traverseResult); + return null; + } + + // private static class Stored_definitionVisitor extends modelicaBaseVisitor { + // @Override + // public Stored_definition visitStored_definition(modelicaParser.Stored_definitionContext ctx) { + // List within_dec = ctx.WITHIN() == null ? null : ctx.WITHIN() + // .stream() + // .map(WITHIN -> WITHIN.getText()) + // .collect(toList()); + // NameVisitor nameVisitor = new NameVisitor(); + // List names = ctx.name() == null ? null : ctx.name() + // .stream() + // .map(name -> name.accept(nameVisitor)) + // .collect(toList()); + // List final_dec = ctx.FINAL() == null ? null : ctx.FINAL() + // .stream() + // .map(FINAL -> FINAL.getText()) + // .collect(toList()); + // Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); + // List class_definitions = ctx.class_definition() + // .stream() + // .map(class_definition -> class_definition.accept(class_definitionVisitor)) + // .collect(toList()); + // return new Stored_definition(within_dec, final_dec, names, class_definitions); + // } + // } + + // private static class Class_definitionVisitor extends modelicaBaseVisitor { + // @Override + // public Class_definition visitClass_definition(modelicaParser.Class_definitionContext ctx) { + // String enca_dec = ctx.ENCAPSULATED() == null ? null : ctx.ENCAPSULATED().getText(); + // Class_prefixesVisitor class_prefixesVisitor = new Class_prefixesVisitor(); + // String class_prefixes_1 = ctx.class_prefixes().accept(class_prefixesVisitor); + // Class_specifierVisitor class_specifierVisitor = new Class_specifierVisitor(); + // Class_specifier class_specifier_1 = ctx.class_specifier().accept(class_specifierVisitor); + // return new Class_definition(enca_dec, class_prefixes_1, class_specifier_1); + // } + // } + + // private static class Class_specifierVisitor extends modelicaBaseVisitor { + // @Override + // public Class_specifier visitClass_specifier(modelicaParser.Class_specifierContext ctx) { + // Long_class_specifierVisitor long_class_specifierVisitor = new Long_class_specifierVisitor(); + // Long_class_specifier long_class_specifier_1 = + // ctx.long_class_specifier() == null ? null : ctx.long_class_specifier().accept(long_class_specifierVisitor); + // Short_class_specifierVisitor short_class_specifierVisitor = new Short_class_specifierVisitor(); + // Short_class_specifier short_class_specifier_1 = + // ctx.short_class_specifier() == null ? null : ctx.short_class_specifier().accept(short_class_specifierVisitor); + // Der_class_specifierVisitor der_class_specifierVisitor = new Der_class_specifierVisitor(); + // Der_class_specifier der_class_specifier_1 = + // ctx.der_class_specifier() == null ? null : ctx.der_class_specifier().accept(der_class_specifierVisitor); + // return new Class_specifier(long_class_specifier_1, short_class_specifier_1, der_class_specifier_1); + // } + // } + + // private static class Class_prefixesVisitor extends modelicaBaseVisitor { + // @Override + // public String visitClass_prefixes(modelicaParser.Class_prefixesContext ctx) { + // String partial_dec = + // ctx.PARTIAL() == null ? "" : ctx.PARTIAL().getText(); + // String class_dec = + // ctx.CLASS() == null ? "" : ctx.CLASS().getText(); + // String model_dec = + // ctx.MODEL() == null ? "" : ctx.MODEL().getText(); + // String block_dec = + // ctx.BLOCK() == null ? "" : ctx.BLOCK().getText(); + // String type_dec = + // ctx.TYPE() == null ? "" : ctx.TYPE().getText(); + // String package_dec = + // ctx.PACKAGE() == null ? "" : ctx.PACKAGE().getText(); + // String operator_dec = + // ctx.OPERATOR() == null ? "" : ctx.OPERATOR().getText(); + // String record_dec = + // ctx.RECORD() == null ? "" : ctx.RECORD().getText(); + // String expandable_dec = + // ctx.EXPANDABLE() == null ? "" : ctx.EXPANDABLE().getText(); + // String connector_dec = + // ctx.CONNECTOR() == null ? "" : ctx.CONNECTOR().getText(); + // String pure_dec = + // ctx.PURE() == null ? "" : ctx.PURE().getText(); + // String impure_dec = + // ctx.IMPURE() == null ? "" : ctx.IMPURE().getText(); + // String function_dec = + // ctx.FUNCTION() == null ? "" : ctx.FUNCTION().getText(); + // String other_dec; + // if ((!function_dec.isEmpty()) && (connector_dec.isEmpty()) && (record_dec.isEmpty())) { + // String tempStr; + // if (operator_dec.isEmpty()) { + // tempStr = function_dec; + // } else { + // StringBuilder temStr = new StringBuilder(); + // tempStr = temStr.append(operator_dec).append(" ").append(function_dec).toString(); + // } + // if (pure_dec.isEmpty() && impure_dec.isEmpty()) { + // other_dec = tempStr; + // } else { + // StringBuilder temStr = new StringBuilder(); + // other_dec = temStr.append(pure_dec).append(impure_dec).append(" ").append(tempStr).toString(); + // } + // } else if ((!connector_dec.isEmpty()) && (function_dec.isEmpty()) && (record_dec.isEmpty())) { + // StringBuilder temStr = new StringBuilder(); + // other_dec = (expandable_dec.isEmpty()) ? connector_dec + // : (temStr.append(expandable_dec).append(" ").append(connector_dec).toString()); + // } else if ((!record_dec.isEmpty()) && (function_dec.isEmpty()) && (connector_dec.isEmpty())) { + // StringBuilder temStr = new StringBuilder(); + // other_dec = (operator_dec.isEmpty()) ? record_dec + // : (temStr.append(operator_dec).append(" ").append(record_dec).toString()); + // } else { + // StringBuilder temStr = new StringBuilder(); + // temStr.append(class_dec != null ? class_dec : "") + // .append(model_dec != null ? model_dec : "") + // .append(block_dec != null ? block_dec : "") + // .append(type_dec != null ? type_dec : "") + // .append(package_dec != null ? package_dec : "") + // .append(operator_dec != null ? operator_dec : ""); + // other_dec = temStr.toString(); + // } + // StringBuilder temStr = new StringBuilder(); + // String claPreStr = + // (!partial_dec.isEmpty()) ? (temStr.append(partial_dec).append(" ").append(other_dec).toString()) + // : other_dec; - return claPreStr; - } - } - - private static class Long_class_specifierVisitor extends modelicaBaseVisitor { - @Override - public Long_class_specifier visitLong_class_specifier(modelicaParser.Long_class_specifierContext ctx) { - List ident = ctx.IDENT() - .stream() - .map(IDENT -> IDENT.getText()) - .collect(toList()); - String extends_dec = - ctx.EXTENDS() == null ? null : ctx.EXTENDS().getText(); - String_commentVisitor string_commentVisitor = new String_commentVisitor(); - String string_comment_1 = ctx.string_comment().accept(string_commentVisitor); - CompositionVisitor compositionVisitor = new CompositionVisitor(); - Composition composition_1 = ctx.composition().accept(compositionVisitor); - Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - String class_modification_1 = - ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - return new Long_class_specifier(extends_dec, ident.get(0), string_comment_1, composition_1, class_modification_1); - } - } - - private static class Short_class_specifierVisitor extends modelicaBaseVisitor { - @Override - public Short_class_specifier visitShort_class_specifier(modelicaParser.Short_class_specifierContext ctx) { - String enum_dec = - ctx.ENUMERATION() == null ? null : ctx.ENUMERATION().getText(); - String ident = ctx.IDENT().getText(); - Base_prefixVisitor base_prefixVisitor = new Base_prefixVisitor(); - String base_prefix_1 = - ctx.base_prefix() == null ? null : ctx.base_prefix().accept(base_prefixVisitor); - Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); - String array_subscripts_1 = - ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); - Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - String class_modification_1 = - ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + // return claPreStr; + // } + // } + + // private static class Long_class_specifierVisitor extends modelicaBaseVisitor { + // @Override + // public Long_class_specifier visitLong_class_specifier(modelicaParser.Long_class_specifierContext ctx) { + // List ident = ctx.IDENT() + // .stream() + // .map(IDENT -> IDENT.getText()) + // .collect(toList()); + // String extends_dec = + // ctx.EXTENDS() == null ? null : ctx.EXTENDS().getText(); + // String_commentVisitor string_commentVisitor = new String_commentVisitor(); + // String string_comment_1 = ctx.string_comment().accept(string_commentVisitor); + // CompositionVisitor compositionVisitor = new CompositionVisitor(); + // Composition composition_1 = ctx.composition().accept(compositionVisitor); + // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + // String class_modification_1 = + // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + // return new Long_class_specifier(extends_dec, ident.get(0), string_comment_1, composition_1, class_modification_1); + // } + // } + + // private static class Short_class_specifierVisitor extends modelicaBaseVisitor { + // @Override + // public Short_class_specifier visitShort_class_specifier(modelicaParser.Short_class_specifierContext ctx) { + // String enum_dec = + // ctx.ENUMERATION() == null ? null : ctx.ENUMERATION().getText(); + // String ident = ctx.IDENT().getText(); + // Base_prefixVisitor base_prefixVisitor = new Base_prefixVisitor(); + // String base_prefix_1 = + // ctx.base_prefix() == null ? null : ctx.base_prefix().accept(base_prefixVisitor); + // Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); + // String array_subscripts_1 = + // ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); + // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + // String class_modification_1 = + // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - CommentVisitor commentVisitor = new CommentVisitor(); - Comment comment = - ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); - Enum_listVisitor enum_listVisitor = new Enum_listVisitor(); - Enum_list enum_list_1 = - ctx.enum_list() == null ? null : ctx.enum_list().accept(enum_listVisitor); - NameVisitor nameVisitor = new NameVisitor(); - String name_1 = - ctx.name() == null ? null : ctx.name().accept(nameVisitor); - String symCol = - ctx.SYMBOL_COLON() == null ? null : ctx.SYMBOL_COLON().getText(); - return new Short_class_specifier(enum_dec, ident, base_prefix_1, name_1, array_subscripts_1, - class_modification_1, comment, enum_list_1); - } - } - - private static class Der_class_specifierVisitor extends modelicaBaseVisitor { - @Override - public Der_class_specifier visitDer_class_specifier(modelicaParser.Der_class_specifierContext ctx) { - List idents = ctx.IDENT() - .stream() - .map(IDENT -> IDENT.getText()) - .collect(toList()); - String ident1 = idents.get(0); - List ident2 = idents.subList(1, idents.size()); - List comma = ctx.SYMBOL_COMMA() == null ? null : ctx.SYMBOL_COMMA() - .stream() - .map(SYMBOL_COMMA -> SYMBOL_COMMA.getText()) - .collect(toList()); - NameVisitor nameVisitor = new NameVisitor(); - String name_1 = ctx.name().accept(nameVisitor); - CommentVisitor commentVisitor = new CommentVisitor(); - Comment comment_1 = ctx.comment().accept(commentVisitor); - return new Der_class_specifier(ident1, comma, ident2, name_1, comment_1); - } - } - - private static class Base_prefixVisitor extends modelicaBaseVisitor { - @Override - public String visitBase_prefix(modelicaParser.Base_prefixContext ctx) { - Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); - String basPreStr = ctx.type_prefix().accept(type_prefixVisitor); - return basPreStr; - //return new Base_prefix(type_prefix_1); - } - } - - private static class Enum_listVisitor extends modelicaBaseVisitor { - @Override - public Enum_list visitEnum_list(modelicaParser.Enum_listContext ctx) { - Enumeration_literalVisitor enumeration_literalVisitor = new Enumeration_literalVisitor(); - List enumeration_literal_1 = ctx.enumeration_literal() - .stream() - .map(enumeration_literal -> enumeration_literal.accept(enumeration_literalVisitor)) - .collect(toList()); - return new Enum_list(enumeration_literal_1); - } - } - - private static class Enumeration_literalVisitor extends modelicaBaseVisitor { - @Override - public Enumeration_literal visitEnumeration_literal(modelicaParser.Enumeration_literalContext ctx) { - String ident = ctx.IDENT().getText(); - CommentVisitor commentVisitor = new CommentVisitor(); - Comment comment_1 = ctx.comment().accept(commentVisitor); - return new Enumeration_literal(ident, comment_1); - } - } - - private static class CompositionVisitor extends modelicaBaseVisitor { - @Override - public Composition visitComposition(modelicaParser.CompositionContext ctx) { - List public_dec = ctx.PUBLIC() == null ? null : ctx.PUBLIC() - .stream() - .map(PUBLIC -> PUBLIC.getText()) - .collect(toList()); - List protected_dec = ctx.PROTECTED() == null ? null : ctx.PROTECTED() - .stream() - .map(PROTECTED -> PROTECTED.getText()) - .collect(toList()); - String external_dec = - ctx.EXTERNAL() == null ? null : ctx.EXTERNAL().getText(); - Element_listVisitor element_listVisitor = new Element_listVisitor(); - List element_lists = ctx.element_list() - .stream() - .map(element_list -> element_list.accept(element_listVisitor)) - .collect(toList()); - Element_list element_list1 = element_lists.get(0); - List element_list2 = - element_lists.size() < 2 ? null : element_lists.subList(1,element_lists.size()); - Equation_sectionVisitor equation_sectionVisitor = new Equation_sectionVisitor(); - List equation_section_1 = ctx.equation_section() == null ? null : ctx.equation_section() - .stream() - .map(equation_section -> equation_section.accept(equation_sectionVisitor)) - .collect(toList()); - Algorithm_sectionVisitor algorithm_sectionVisitor = new Algorithm_sectionVisitor(); - List algorithm_section_1 = ctx.algorithm_section() == null ? null : ctx.algorithm_section() - .stream() - .map(algorithm_section -> algorithm_section.accept(algorithm_sectionVisitor)) - .collect(toList()); - Language_specificationVisitor language_specificationVisitor = new Language_specificationVisitor(); - String language_specification_1 = - ctx.language_specification() == null ? null : ctx.language_specification().accept(language_specificationVisitor); - External_function_callVisitor external_function_callVisitor = new External_function_callVisitor(); - String external_function_call_1 = - ctx.external_function_call() == null ? null : ctx.external_function_call().accept(external_function_callVisitor); - AnnotationVisitor annotationVisitor = new AnnotationVisitor(); - List annotations = ctx.annotation() == null ? null : ctx.annotation() - .stream() - .map(annotation -> annotation.accept(annotationVisitor)) - .collect(toList()); - String annotation1 = null; - String annotation2 = null; - if (annotations.size() == 2) { - annotation1 = annotations.get(0); - annotation2 = annotations.get(1); - } else if (annotations.size() == 1 && external_dec != null) { - annotation1 = annotations.get(0); - } else if (annotations.size() == 1 && external_dec == null) { - annotation2 = annotations.get(0); - } else { - annotation1 = null; - annotation2 = null; - } - return new Composition(external_dec, public_dec, protected_dec, element_list1, element_list2, - equation_section_1, algorithm_section_1, language_specification_1, external_function_call_1, - annotation1, annotation2); - } - } - - private static class Language_specificationVisitor extends modelicaBaseVisitor { - @Override - public String visitLanguage_specification(modelicaParser.Language_specificationContext ctx) { - String string = ctx.STRING().getText(); - return string; - //return new Language_specification(ident); - } - } - - private static class External_function_callVisitor extends modelicaBaseVisitor { - @Override - public String visitExternal_function_call(modelicaParser.External_function_callContext ctx) { - String ident = ctx.IDENT().getText(); - Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); - String component_reference_1 = - ctx.component_reference() == null ? null : ctx.component_reference().accept(component_referenceVisitor); - Expression_listVisitor expression_listVisitor = new Expression_listVisitor(); - String expression_list_1 = - ctx.expression_list() == null ? "" : ctx.expression_list().accept(expression_listVisitor); - StringBuilder temStr1 = new StringBuilder(); - StringBuilder temStr2 = new StringBuilder(); - String extFunCalStr = (component_reference_1 != null) - ? (temStr1.append(component_reference_1).append("=").append(ident).append("(").append(expression_list_1).append(")").toString()) - : (temStr2.append(ident).append("(").append(expression_list_1).append(")").toString()); - return extFunCalStr; - //return new External_function_call(ident, component_reference_1, expression_list_1); - } - } - - private static class Element_listVisitor extends modelicaBaseVisitor { - @Override - public Element_list visitElement_list(modelicaParser.Element_listContext ctx) { - ElementVisitor elementVisitor = new ElementVisitor(); - List element_1 = ctx.element() == null ? null : ctx.element() - .stream() - .map(element -> element.accept(elementVisitor)) - .collect(toList()); - return new Element_list(element_1); - } - } - - private static class ElementVisitor extends modelicaBaseVisitor { - @Override - public Element visitElement(modelicaParser.ElementContext ctx) { - String red_dec = - ctx.REDECLARE() == null ? null : ctx.REDECLARE().getText(); - String final_dec = - ctx.FINAL() == null ? null : ctx.FINAL().getText(); - String inner_dec = - ctx.INNER() == null ? null : ctx.INNER().getText(); - String outer_der = - ctx.OUTER() == null ? null : ctx.OUTER().getText(); - String rep_dec = - ctx.REPLACEABLE() == null ? null : ctx.REPLACEABLE().getText(); - Class_definition class_definition1; - Class_definition class_definition2; - Component_clause component_clause1; - Component_clause component_clause2; - if (rep_dec != null) { - Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); - class_definition2 = - ctx.class_definition() == null ? null : ctx.class_definition().accept(class_definitionVisitor); - Component_clauseVisitor component_clauseVisitor = new Component_clauseVisitor(); - component_clause2 = - ctx.component_clause() == null ? null : ctx.component_clause().accept(component_clauseVisitor); - class_definition1 = null; - component_clause1 = null; - } else { - Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); - class_definition1 = - ctx.class_definition() == null ? null : ctx.class_definition().accept(class_definitionVisitor); - Component_clauseVisitor component_clauseVisitor = new Component_clauseVisitor(); - component_clause1 = - ctx.component_clause() == null ? null : ctx.component_clause().accept(component_clauseVisitor); - class_definition2 = null; - component_clause2 = null; - } - Import_clauseVisitor import_clauseVisitor = new Import_clauseVisitor(); - Import_clause import_clause_1 = - ctx.import_clause() == null ? null : ctx.import_clause().accept(import_clauseVisitor); - Extends_clauseVisitor extends_clauseVisitor = new Extends_clauseVisitor(); - Extends_clause extends_clause_1 = - ctx.extends_clause() == null ? null : ctx.extends_clause().accept(extends_clauseVisitor); - Constraining_clauseVisitor constraining_clauseVisitor = new Constraining_clauseVisitor(); - String constraining_clause_1 = - ctx.constraining_clause() == null ? null : ctx.constraining_clause().accept(constraining_clauseVisitor); - CommentVisitor commentVisitor = new CommentVisitor(); - Comment comment_1 = - ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); - return new Element(red_dec, final_dec, inner_dec, outer_der, rep_dec, import_clause_1, - extends_clause_1, class_definition1, class_definition2, - component_clause1, component_clause2, constraining_clause_1, comment_1); - } - } - - private static class Import_clauseVisitor extends modelicaBaseVisitor { - @Override - public Import_clause visitImport_clause(modelicaParser.Import_clauseContext ctx) { - String import_dec = ctx.IMPORT().getText(); - String ident = - ctx.IDENT() == null ? null : ctx.IDENT().getText(); - String dotStar = - ctx.SYMBOL_DOTSTAR() == null ? null : ctx.SYMBOL_DOTSTAR().getText(); - Import_listVisitor import_listVisitor = new Import_listVisitor(); - String import_list_1 = - ctx.import_list() == null ? null : ctx.import_list().accept(import_listVisitor); - CommentVisitor commentVisitor = new CommentVisitor(); - Comment comment_1 = - ctx.comment().getText().length() == 0 ? null : ctx.comment().accept(commentVisitor); - NameVisitor nameVisitor = new NameVisitor(); - String name_1 = ctx.name().accept(nameVisitor); - return new Import_clause(import_dec, ident, dotStar, name_1, import_list_1, comment_1); - } - } - - private static class Import_listVisitor extends modelicaBaseVisitor { - @Override - public String visitImport_list(modelicaParser.Import_listContext ctx) { - List ident = ctx.IDENT() - .stream() - .map(IDENT -> IDENT.getText()) - .collect(toList()); - String impLisStr = ident.get(0); - StringBuilder temStr = new StringBuilder(); - temStr.append(impLisStr); - if (ident.size()>1) { - for (int i=1; i { - @Override - public Extends_clause visitExtends_clause(modelicaParser.Extends_clauseContext ctx) { - String ext_dec = ctx.EXTENDS().getText(); - NameVisitor nameVisitor = new NameVisitor(); - String name_1 = ctx.name().accept(nameVisitor); - Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - String class_modification_1 = - ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - AnnotationVisitor annotationVisitor = new AnnotationVisitor(); - String annotation_1 = - ctx.annotation() == null ? null : ctx.annotation().accept(annotationVisitor); - return new Extends_clause(ext_dec, name_1, class_modification_1, annotation_1); - } - } - - private static class Constraining_clauseVisitor extends modelicaBaseVisitor { - @Override - public String visitConstraining_clause(modelicaParser.Constraining_clauseContext ctx) { - String constrain_dec = ctx.CONSTRAINEDBY().getText(); - NameVisitor nameVisitor = new NameVisitor(); - String name_1 = ctx.name().accept(nameVisitor); - Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - String class_modification_1 = - ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - StringBuilder temStr = new StringBuilder(); - String conClaStr = temStr.append(constrain_dec).append(" ").append(name_1).toString(); - if (class_modification_1 != null) { - conClaStr = temStr.append(" ").append(class_modification_1).toString(); } - return conClaStr; - //return new Constraining_clause(constrain_dec, name_1, class_modification_1); - } - } - - private static class Component_clauseVisitor extends modelicaBaseVisitor { - @Override - public Component_clause visitComponent_clause(modelicaParser.Component_clauseContext ctx) { - Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); - String type_prefix_1 = - ctx.type_prefix() == null ? null : ctx.type_prefix().accept(type_prefixVisitor); - Type_specifierVisitor type_specifierVisitor = new Type_specifierVisitor(); - String type_specifier_1 = ctx.type_specifier().accept(type_specifierVisitor); - Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); - String array_subscripts_1 = - ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); - Component_listVisitor component_listVisitor = new Component_listVisitor(); - Component_list component_list_1 = ctx.component_list().accept(component_listVisitor); - return new Component_clause(type_prefix_1, type_specifier_1, array_subscripts_1, component_list_1); - } - } - - private static class Type_prefixVisitor extends modelicaBaseVisitor { - @Override - public String visitType_prefix(modelicaParser.Type_prefixContext ctx) { - String flow_dec = - ctx.FLOW() == null ? null : ctx.FLOW().getText(); - String stream_dec = - ctx.STREAM() == null ? null : ctx.STREAM().getText(); - String disc_dec = - ctx.DISCRETE() == null ? null : ctx.DISCRETE().getText(); - String par_dec = - ctx.PARAMETER() == null ? null : ctx.PARAMETER().getText(); - String con_dec = - ctx.CONSTANT() == null ? null : ctx.CONSTANT().getText(); - String in_dec = - ctx.INPUT() == null ? null : ctx.INPUT().getText(); - String out_dec = - ctx.OUTPUT() == null ? null : ctx.OUTPUT().getText(); - String prefix = (flow_dec != null) ? flow_dec - : (stream_dec != null ? stream_dec - : (disc_dec != null ? disc_dec - : (par_dec != null ? par_dec - : (con_dec != null ? con_dec - : (in_dec != null ? in_dec - : out_dec))))); - return prefix; - //return new Type_prefix(flow_dec, stream_dec, disc_dec, par_dec, - // con_dec, in_dec, out_dec); - } - } - - private static class Type_specifierVisitor extends modelicaBaseVisitor { - @Override - public String visitType_specifier(modelicaParser.Type_specifierContext ctx) { - NameVisitor nameVisitor = new NameVisitor(); - String specifier = ctx.name().accept(nameVisitor); - return specifier; - //return new Type_specifier(name_1); - } - } - - private static class Component_listVisitor extends modelicaBaseVisitor { - @Override - public Component_list visitComponent_list(modelicaParser.Component_listContext ctx) { - Component_declarationVisitor component_declarationVisitor = new Component_declarationVisitor(); - List component_declaration_1 = ctx.component_declaration() - .stream() - .map(component_declaration -> component_declaration.accept(component_declarationVisitor)) - .collect(toList()); - return new Component_list(component_declaration_1); - } - } - - private static class Component_declarationVisitor extends modelicaBaseVisitor { - @Override - public Component_declaration visitComponent_declaration(modelicaParser.Component_declarationContext ctx) { - DeclarationVisitor declarationVisitor = new DeclarationVisitor(); - Declaration declaration_1 = ctx.declaration().accept(declarationVisitor); - Condition_attributeVisitor condition_attributeVisitor = new Condition_attributeVisitor(); - String condition_attribute_1 = - ctx.condition_attribute() == null ? null : ctx.condition_attribute().accept(condition_attributeVisitor); - CommentVisitor commentVisitor = new CommentVisitor(); - Comment comment_1 = - ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); - return new Component_declaration(declaration_1, condition_attribute_1, comment_1); - } - } - - private static class Condition_attributeVisitor extends modelicaBaseVisitor { - @Override - public String visitCondition_attribute(modelicaParser.Condition_attributeContext ctx) { - String if_dec = ctx.IF().getText(); - ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - String expression_1 = ctx.expression().accept(expressionVisitor); - StringBuilder temStr = new StringBuilder(); - String conAttStr = temStr.append(if_dec).append(" ").append(expression_1).toString(); - return conAttStr; - // return new Condition_attribute(if_dec, expression_1); - } - } - - private static class DeclarationVisitor extends modelicaBaseVisitor { - @Override - public Declaration visitDeclaration(modelicaParser.DeclarationContext ctx) { - String ident = ctx.IDENT().getText(); - Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); - String array_subscripts_1 = - ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); - ModificationVisitor modificationVisitor = new ModificationVisitor(); - String modification_1 = - ctx.modification() == null ? null : ctx.modification().accept(modificationVisitor); - return new Declaration(ident, array_subscripts_1, modification_1); - } - } - - private static class ModificationVisitor extends modelicaBaseVisitor { - @Override - public String visitModification(modelicaParser.ModificationContext ctx) { - Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - String class_modification_1 = - ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - String expression_1 = - ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - String eqSymb = ctx.SYMBOL_EQUAL() == null ? null : ctx.SYMBOL_EQUAL().getText(); - String colEqSymb = ctx.SYMBOL_COLONEQUAL() == null ? null : ctx.SYMBOL_COLONEQUAL().getText(); - String modStr = ""; - StringBuilder temStr = new StringBuilder(); - if (class_modification_1 != null) { - if (expression_1 != null) { - modStr = temStr.append(class_modification_1).append("=").append(expression_1).toString(); - } else { - modStr = class_modification_1; - } - } else if (eqSymb != null && expression_1 != null) { - modStr = temStr.append(eqSymb).append(expression_1).toString(); - } else if (colEqSymb != null && expression_1 != null) { - modStr = temStr.append(colEqSymb).append(expression_1).toString(); - } - return modStr; - // return new Modification(class_modification_1, eqSymb, colEqSymb, expression_1); - } - } - - private static class Class_modificationVisitor extends modelicaBaseVisitor { - @Override - public String visitClass_modification(modelicaParser.Class_modificationContext ctx) { - Argument_listVisitor argument_listVisitor = new Argument_listVisitor(); - String argument_list_1 = - ctx.argument_list() == null ? null : ctx.argument_list().accept(argument_listVisitor); - StringBuilder temStr = new StringBuilder(); - String claModStr = temStr.append("(").append(argument_list_1).append(")").toString(); - return claModStr; - //return new Class_modification(argument_list_1); - } - } - - private static class Argument_listVisitor extends modelicaBaseVisitor { - @Override - public String visitArgument_list(modelicaParser.Argument_listContext ctx) { - ArgumentVisitor argumentVisitor = new ArgumentVisitor(); - List argument_1 = ctx.argument() - .stream() - .map(argument -> argument.accept(argumentVisitor)) - .collect(toList()); - String argLisStr = argument_1.get(0); - StringBuilder temStr = new StringBuilder(); - temStr.append(argLisStr); - if (argument_1.size()>1) { - for (int i=1; i { - @Override - public String visitArgument(modelicaParser.ArgumentContext ctx) { - Element_modification_or_replaceableVisitor element_modification_or_replaceableVisitor = new Element_modification_or_replaceableVisitor(); - String element_modification_or_replaceable_1 = - ctx.element_modification_or_replaceable() == null ? null : ctx.element_modification_or_replaceable().accept(element_modification_or_replaceableVisitor); - Element_redeclarationVisitor element_redeclarationVisitor = new Element_redeclarationVisitor(); - String element_redeclaration_1 = - ctx.element_redeclaration() == null ? null : ctx.element_redeclaration().accept(element_redeclarationVisitor); - String argStr = (element_redeclaration_1 != null) ? element_redeclaration_1 : element_modification_or_replaceable_1; - return argStr; - //return new Argument(element_modification_or_replaceable_1, element_redeclaration_1); - } - } - - private static class Element_modification_or_replaceableVisitor extends modelicaBaseVisitor { - @Override - public String visitElement_modification_or_replaceable(modelicaParser.Element_modification_or_replaceableContext ctx) { - String each_dec = - ctx.EACH() == null ? null : ctx.EACH().getText(); - String final_dec = - ctx.FINAL() == null ? null : ctx.FINAL().getText(); - Element_modificationVisitor element_modificationVisitor = new Element_modificationVisitor(); - String element_modification_1 = - ctx.element_modification() == null ? null : ctx.element_modification().accept(element_modificationVisitor); - Element_replaceableVisitor element_replaceableVisitor = new Element_replaceableVisitor(); - String element_replaceable_1 = - ctx.element_replaceable() == null ? null : ctx.element_replaceable().accept(element_replaceableVisitor); - String eleModRep = ""; - StringBuilder temStr = new StringBuilder(); - temStr.append(eleModRep); - if (each_dec != null) {temStr.append(each_dec).append(" ");} - if (final_dec != null) {temStr.append(final_dec).append(" ");} - if (element_modification_1 != null) { - temStr.append(element_modification_1); - } else { - temStr.append(element_replaceable_1); - } - eleModRep = temStr.toString(); - return eleModRep; - //return new Element_modification_or_replaceable(each_dec, final_dec, element_modification_1, element_replaceable_1); - } - } - - private static class Element_modificationVisitor extends modelicaBaseVisitor { - @Override - public String visitElement_modification(modelicaParser.Element_modificationContext ctx) { - NameVisitor nameVisitor = new NameVisitor(); - String name_1 = ctx.name().accept(nameVisitor); - ModificationVisitor modificationVisitor = new ModificationVisitor(); - String modification_1 = - ctx.modification() == null ? null : ctx.modification().accept(modificationVisitor); - //String modStr = String.valueOf(modification_1); - String_commentVisitor string_commentVisitor = new String_commentVisitor(); - String string_comment_1 = ctx.string_comment().accept(string_commentVisitor); - StringBuilder temStr1 = new StringBuilder(); - StringBuilder temStr2 = new StringBuilder(); - String eleModStr = (modification_1 == null) - ? (temStr1.append(name_1).append(" ").append(string_comment_1).toString()) - : (temStr2.append(name_1).append(" ").append(modification_1).append(" ").append(string_comment_1).toString()); - return eleModStr; - //return new Element_modification(name_1, modification_1, string_comment_1); - } - } - - private static class Element_redeclarationVisitor extends modelicaBaseVisitor { - @Override - public String visitElement_redeclaration(modelicaParser.Element_redeclarationContext ctx) { - String red_dec = ctx.REDECLARE().getText(); - String each_dec = - ctx.EACH() == null ? null : ctx.EACH().getText(); - String final_dec = - ctx.FINAL() == null ? null : ctx.FINAL().getText(); - Short_class_definitionVisitor short_class_definitionVisitor = new Short_class_definitionVisitor(); - String shoClaDefStr = - ctx.short_class_definition() == null ? null : ctx.short_class_definition().accept(short_class_definitionVisitor); - Component_clause1Visitor component_clause1Visitor = new Component_clause1Visitor(); - String component_clause1_1 = - ctx.component_clause1() == null ? null : ctx.component_clause1().accept(component_clause1Visitor); - Element_replaceableVisitor element_replaceableVisitor = new Element_replaceableVisitor(); - String element_replaceable_1 = - ctx.element_replaceable() == null ? null : ctx.element_replaceable().accept(element_replaceableVisitor); - StringBuilder temStr = new StringBuilder(); - String eleRedStr = temStr.append(red_dec).append(" ").toString(); - if (each_dec != null) {temStr.append(each_dec).append(" ");} - if (final_dec != null) {temStr.append(final_dec).append(" ");} - if (element_replaceable_1 != null) { - temStr.append(element_replaceable_1); - } else { - if (shoClaDefStr != null) { - temStr.append(shoClaDefStr); - } else { - temStr.append(component_clause1_1); - } - } - eleRedStr = temStr.toString(); - return eleRedStr; - //return new Element_redeclaration(red_dec, each_dec, final_dec, short_class_definition_1, component_clause1_1, element_replaceable_1); - } - } - - private static class Element_replaceableVisitor extends modelicaBaseVisitor { - @Override - public String visitElement_replaceable(modelicaParser.Element_replaceableContext ctx) { - String rep_dec = ctx.REPLACEABLE().getText(); - Short_class_definitionVisitor short_class_definitionVisitor = new Short_class_definitionVisitor(); - String shoClaDefStr = - ctx.short_class_definition() == null ? null : ctx.short_class_definition().accept(short_class_definitionVisitor); - Component_clause1Visitor component_clause1Visitor = new Component_clause1Visitor(); - String component_clause1_1 = - ctx.component_clause1() == null ? null : ctx.component_clause1().accept(component_clause1Visitor); - Constraining_clauseVisitor constraining_clauseVisitor = new Constraining_clauseVisitor(); - String constraining_clause_1 = - ctx.constraining_clause() == null ? null : ctx.constraining_clause().accept(constraining_clauseVisitor); - StringBuilder temStr = new StringBuilder(); - String eleRepStr = temStr.append(rep_dec).append(" ").toString(); - if (component_clause1_1 == null) { - temStr.append(shoClaDefStr); - } else { - temStr.append(component_clause1_1); - } - if (constraining_clause_1 != null) { - temStr.append(constraining_clause_1); - } - eleRepStr = temStr.toString(); - return eleRepStr; - //return new Element_replaceable(rep_dec, short_class_definition_1, component_clause1_1, constraining_clause_1); - } - } - - private static class Component_clause1Visitor extends modelicaBaseVisitor { - @Override - public String visitComponent_clause1(modelicaParser.Component_clause1Context ctx) { - Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); - String type_prefix_1 = ctx.type_prefix().accept(type_prefixVisitor); - Type_specifierVisitor type_specifierVisitor = new Type_specifierVisitor(); - String type_specifier_1 = ctx.type_specifier().accept(type_specifierVisitor); - Component_declaration1Visitor component_declaration1Visitor = new Component_declaration1Visitor(); - String component_declaration1_1 = ctx.component_declaration1().accept(component_declaration1Visitor); - StringBuilder temStr = new StringBuilder(); - if (type_prefix_1 != null) { - temStr.append(type_prefix_1).append(" "); - } - String comCla1Str = temStr.append(type_specifier_1).append(" ") - .append(component_declaration1_1) - .toString(); - return comCla1Str; - //return new Component_clause1(type_prefix_1, type_specifier_1, component_declaration1_1); - } - } - - private static class Component_declaration1Visitor extends modelicaBaseVisitor { - @Override - public String visitComponent_declaration1(modelicaParser.Component_declaration1Context ctx) { - String declaration_1 = ""; - if (ctx.declaration().getText().isEmpty()) { - declaration_1 = null; - } else { - int a = ctx.declaration().start.getStartIndex(); - int b = ctx.declaration().stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream decStr = ctx.declaration().start.getInputStream(); - declaration_1 = decStr.getText(interval).trim(); - } + // CommentVisitor commentVisitor = new CommentVisitor(); + // Comment comment = + // ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + // Enum_listVisitor enum_listVisitor = new Enum_listVisitor(); + // Enum_list enum_list_1 = + // ctx.enum_list() == null ? null : ctx.enum_list().accept(enum_listVisitor); + // NameVisitor nameVisitor = new NameVisitor(); + // String name_1 = + // ctx.name() == null ? null : ctx.name().accept(nameVisitor); + // String symCol = + // ctx.SYMBOL_COLON() == null ? null : ctx.SYMBOL_COLON().getText(); + // return new Short_class_specifier(enum_dec, ident, base_prefix_1, name_1, array_subscripts_1, + // class_modification_1, comment, enum_list_1); + // } + // } + + // private static class Der_class_specifierVisitor extends modelicaBaseVisitor { + // @Override + // public Der_class_specifier visitDer_class_specifier(modelicaParser.Der_class_specifierContext ctx) { + // List idents = ctx.IDENT() + // .stream() + // .map(IDENT -> IDENT.getText()) + // .collect(toList()); + // String ident1 = idents.get(0); + // List ident2 = idents.subList(1, idents.size()); + // List comma = ctx.SYMBOL_COMMA() == null ? null : ctx.SYMBOL_COMMA() + // .stream() + // .map(SYMBOL_COMMA -> SYMBOL_COMMA.getText()) + // .collect(toList()); + // NameVisitor nameVisitor = new NameVisitor(); + // String name_1 = ctx.name().accept(nameVisitor); + // CommentVisitor commentVisitor = new CommentVisitor(); + // Comment comment_1 = ctx.comment().accept(commentVisitor); + // return new Der_class_specifier(ident1, comma, ident2, name_1, comment_1); + // } + // } + + // private static class Base_prefixVisitor extends modelicaBaseVisitor { + // @Override + // public String visitBase_prefix(modelicaParser.Base_prefixContext ctx) { + // Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); + // String basPreStr = ctx.type_prefix().accept(type_prefixVisitor); + // return basPreStr; + // //return new Base_prefix(type_prefix_1); + // } + // } + + // private static class Enum_listVisitor extends modelicaBaseVisitor { + // @Override + // public Enum_list visitEnum_list(modelicaParser.Enum_listContext ctx) { + // Enumeration_literalVisitor enumeration_literalVisitor = new Enumeration_literalVisitor(); + // List enumeration_literal_1 = ctx.enumeration_literal() + // .stream() + // .map(enumeration_literal -> enumeration_literal.accept(enumeration_literalVisitor)) + // .collect(toList()); + // return new Enum_list(enumeration_literal_1); + // } + // } + + // private static class Enumeration_literalVisitor extends modelicaBaseVisitor { + // @Override + // public Enumeration_literal visitEnumeration_literal(modelicaParser.Enumeration_literalContext ctx) { + // String ident = ctx.IDENT().getText(); + // CommentVisitor commentVisitor = new CommentVisitor(); + // Comment comment_1 = ctx.comment().accept(commentVisitor); + // return new Enumeration_literal(ident, comment_1); + // } + // } + + // private static class CompositionVisitor extends modelicaBaseVisitor { + // @Override + // public Composition visitComposition(modelicaParser.CompositionContext ctx) { + // List public_dec = ctx.PUBLIC() == null ? null : ctx.PUBLIC() + // .stream() + // .map(PUBLIC -> PUBLIC.getText()) + // .collect(toList()); + // List protected_dec = ctx.PROTECTED() == null ? null : ctx.PROTECTED() + // .stream() + // .map(PROTECTED -> PROTECTED.getText()) + // .collect(toList()); + // String external_dec = + // ctx.EXTERNAL() == null ? null : ctx.EXTERNAL().getText(); + // Element_listVisitor element_listVisitor = new Element_listVisitor(); + // List element_lists = ctx.element_list() + // .stream() + // .map(element_list -> element_list.accept(element_listVisitor)) + // .collect(toList()); + // Element_list element_list1 = element_lists.get(0); + // List element_list2 = + // element_lists.size() < 2 ? null : element_lists.subList(1,element_lists.size()); + // Equation_sectionVisitor equation_sectionVisitor = new Equation_sectionVisitor(); + // List equation_section_1 = ctx.equation_section() == null ? null : ctx.equation_section() + // .stream() + // .map(equation_section -> equation_section.accept(equation_sectionVisitor)) + // .collect(toList()); + // Algorithm_sectionVisitor algorithm_sectionVisitor = new Algorithm_sectionVisitor(); + // List algorithm_section_1 = ctx.algorithm_section() == null ? null : ctx.algorithm_section() + // .stream() + // .map(algorithm_section -> algorithm_section.accept(algorithm_sectionVisitor)) + // .collect(toList()); + // Language_specificationVisitor language_specificationVisitor = new Language_specificationVisitor(); + // String language_specification_1 = + // ctx.language_specification() == null ? null : ctx.language_specification().accept(language_specificationVisitor); + // External_function_callVisitor external_function_callVisitor = new External_function_callVisitor(); + // String external_function_call_1 = + // ctx.external_function_call() == null ? null : ctx.external_function_call().accept(external_function_callVisitor); + // AnnotationVisitor annotationVisitor = new AnnotationVisitor(); + // List annotations = ctx.annotation() == null ? null : ctx.annotation() + // .stream() + // .map(annotation -> annotation.accept(annotationVisitor)) + // .collect(toList()); + // String annotation1 = null; + // String annotation2 = null; + // if (annotations.size() == 2) { + // annotation1 = annotations.get(0); + // annotation2 = annotations.get(1); + // } else if (annotations.size() == 1 && external_dec != null) { + // annotation1 = annotations.get(0); + // } else if (annotations.size() == 1 && external_dec == null) { + // annotation2 = annotations.get(0); + // } else { + // annotation1 = null; + // annotation2 = null; + // } + // return new Composition(external_dec, public_dec, protected_dec, element_list1, element_list2, + // equation_section_1, algorithm_section_1, language_specification_1, external_function_call_1, + // annotation1, annotation2); + // } + // } + + // private static class Language_specificationVisitor extends modelicaBaseVisitor { + // @Override + // public String visitLanguage_specification(modelicaParser.Language_specificationContext ctx) { + // String string = ctx.STRING().getText(); + // return string; + // //return new Language_specification(ident); + // } + // } + + // private static class External_function_callVisitor extends modelicaBaseVisitor { + // @Override + // public String visitExternal_function_call(modelicaParser.External_function_callContext ctx) { + // String ident = ctx.IDENT().getText(); + // Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); + // String component_reference_1 = + // ctx.component_reference() == null ? null : ctx.component_reference().accept(component_referenceVisitor); + // Expression_listVisitor expression_listVisitor = new Expression_listVisitor(); + // String expression_list_1 = + // ctx.expression_list() == null ? "" : ctx.expression_list().accept(expression_listVisitor); + // StringBuilder temStr1 = new StringBuilder(); + // StringBuilder temStr2 = new StringBuilder(); + // String extFunCalStr = (component_reference_1 != null) + // ? (temStr1.append(component_reference_1).append("=").append(ident).append("(").append(expression_list_1).append(")").toString()) + // : (temStr2.append(ident).append("(").append(expression_list_1).append(")").toString()); + // return extFunCalStr; + // //return new External_function_call(ident, component_reference_1, expression_list_1); + // } + // } + + // private static class Element_listVisitor extends modelicaBaseVisitor { + // @Override + // public Element_list visitElement_list(modelicaParser.Element_listContext ctx) { + // ElementVisitor elementVisitor = new ElementVisitor(); + // List element_1 = ctx.element() == null ? null : ctx.element() + // .stream() + // .map(element -> element.accept(elementVisitor)) + // .collect(toList()); + // return new Element_list(element_1); + // } + // } + + // private static class ElementVisitor extends modelicaBaseVisitor { + // @Override + // public Element visitElement(modelicaParser.ElementContext ctx) { + // String red_dec = + // ctx.REDECLARE() == null ? null : ctx.REDECLARE().getText(); + // String final_dec = + // ctx.FINAL() == null ? null : ctx.FINAL().getText(); + // String inner_dec = + // ctx.INNER() == null ? null : ctx.INNER().getText(); + // String outer_der = + // ctx.OUTER() == null ? null : ctx.OUTER().getText(); + // String rep_dec = + // ctx.REPLACEABLE() == null ? null : ctx.REPLACEABLE().getText(); + // Class_definition class_definition1; + // Class_definition class_definition2; + // Component_clause component_clause1; + // Component_clause component_clause2; + // if (rep_dec != null) { + // Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); + // class_definition2 = + // ctx.class_definition() == null ? null : ctx.class_definition().accept(class_definitionVisitor); + // Component_clauseVisitor component_clauseVisitor = new Component_clauseVisitor(); + // component_clause2 = + // ctx.component_clause() == null ? null : ctx.component_clause().accept(component_clauseVisitor); + // class_definition1 = null; + // component_clause1 = null; + // } else { + // Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); + // class_definition1 = + // ctx.class_definition() == null ? null : ctx.class_definition().accept(class_definitionVisitor); + // Component_clauseVisitor component_clauseVisitor = new Component_clauseVisitor(); + // component_clause1 = + // ctx.component_clause() == null ? null : ctx.component_clause().accept(component_clauseVisitor); + // class_definition2 = null; + // component_clause2 = null; + // } + // Import_clauseVisitor import_clauseVisitor = new Import_clauseVisitor(); + // Import_clause import_clause_1 = + // ctx.import_clause() == null ? null : ctx.import_clause().accept(import_clauseVisitor); + // Extends_clauseVisitor extends_clauseVisitor = new Extends_clauseVisitor(); + // Extends_clause extends_clause_1 = + // ctx.extends_clause() == null ? null : ctx.extends_clause().accept(extends_clauseVisitor); + // Constraining_clauseVisitor constraining_clauseVisitor = new Constraining_clauseVisitor(); + // String constraining_clause_1 = + // ctx.constraining_clause() == null ? null : ctx.constraining_clause().accept(constraining_clauseVisitor); + // CommentVisitor commentVisitor = new CommentVisitor(); + // Comment comment_1 = + // ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + // return new Element(red_dec, final_dec, inner_dec, outer_der, rep_dec, import_clause_1, + // extends_clause_1, class_definition1, class_definition2, + // component_clause1, component_clause2, constraining_clause_1, comment_1); + // } + // } + + // private static class Import_clauseVisitor extends modelicaBaseVisitor { + // @Override + // public Import_clause visitImport_clause(modelicaParser.Import_clauseContext ctx) { + // String import_dec = ctx.IMPORT().getText(); + // String ident = + // ctx.IDENT() == null ? null : ctx.IDENT().getText(); + // String dotStar = + // ctx.SYMBOL_DOTSTAR() == null ? null : ctx.SYMBOL_DOTSTAR().getText(); + // Import_listVisitor import_listVisitor = new Import_listVisitor(); + // String import_list_1 = + // ctx.import_list() == null ? null : ctx.import_list().accept(import_listVisitor); + // CommentVisitor commentVisitor = new CommentVisitor(); + // Comment comment_1 = + // ctx.comment().getText().length() == 0 ? null : ctx.comment().accept(commentVisitor); + // NameVisitor nameVisitor = new NameVisitor(); + // String name_1 = ctx.name().accept(nameVisitor); + // return new Import_clause(import_dec, ident, dotStar, name_1, import_list_1, comment_1); + // } + // } + + // private static class Import_listVisitor extends modelicaBaseVisitor { + // @Override + // public String visitImport_list(modelicaParser.Import_listContext ctx) { + // List ident = ctx.IDENT() + // .stream() + // .map(IDENT -> IDENT.getText()) + // .collect(toList()); + // String impLisStr = ident.get(0); + // StringBuilder temStr = new StringBuilder(); + // temStr.append(impLisStr); + // if (ident.size()>1) { + // for (int i=1; i { + // @Override + // public Extends_clause visitExtends_clause(modelicaParser.Extends_clauseContext ctx) { + // String ext_dec = ctx.EXTENDS().getText(); + // NameVisitor nameVisitor = new NameVisitor(); + // String name_1 = ctx.name().accept(nameVisitor); + // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + // String class_modification_1 = + // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + // AnnotationVisitor annotationVisitor = new AnnotationVisitor(); + // String annotation_1 = + // ctx.annotation() == null ? null : ctx.annotation().accept(annotationVisitor); + // return new Extends_clause(ext_dec, name_1, class_modification_1, annotation_1); + // } + // } + + // private static class Constraining_clauseVisitor extends modelicaBaseVisitor { + // @Override + // public String visitConstraining_clause(modelicaParser.Constraining_clauseContext ctx) { + // String constrain_dec = ctx.CONSTRAINEDBY().getText(); + // NameVisitor nameVisitor = new NameVisitor(); + // String name_1 = ctx.name().accept(nameVisitor); + // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + // String class_modification_1 = + // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + // StringBuilder temStr = new StringBuilder(); + // String conClaStr = temStr.append(constrain_dec).append(" ").append(name_1).toString(); + // if (class_modification_1 != null) { + // conClaStr = temStr.append(" ").append(class_modification_1).toString(); } + // return conClaStr; + // //return new Constraining_clause(constrain_dec, name_1, class_modification_1); + // } + // } + + // private static class Component_clauseVisitor extends modelicaBaseVisitor { + // @Override + // public Component_clause visitComponent_clause(modelicaParser.Component_clauseContext ctx) { + // Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); + // String type_prefix_1 = + // ctx.type_prefix() == null ? null : ctx.type_prefix().accept(type_prefixVisitor); + // Type_specifierVisitor type_specifierVisitor = new Type_specifierVisitor(); + // String type_specifier_1 = ctx.type_specifier().accept(type_specifierVisitor); + // Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); + // String array_subscripts_1 = + // ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); + // Component_listVisitor component_listVisitor = new Component_listVisitor(); + // Component_list component_list_1 = ctx.component_list().accept(component_listVisitor); + // return new Component_clause(type_prefix_1, type_specifier_1, array_subscripts_1, component_list_1); + // } + // } + + // private static class Type_prefixVisitor extends modelicaBaseVisitor { + // @Override + // public String visitType_prefix(modelicaParser.Type_prefixContext ctx) { + // String flow_dec = + // ctx.FLOW() == null ? null : ctx.FLOW().getText(); + // String stream_dec = + // ctx.STREAM() == null ? null : ctx.STREAM().getText(); + // String disc_dec = + // ctx.DISCRETE() == null ? null : ctx.DISCRETE().getText(); + // String par_dec = + // ctx.PARAMETER() == null ? null : ctx.PARAMETER().getText(); + // String con_dec = + // ctx.CONSTANT() == null ? null : ctx.CONSTANT().getText(); + // String in_dec = + // ctx.INPUT() == null ? null : ctx.INPUT().getText(); + // String out_dec = + // ctx.OUTPUT() == null ? null : ctx.OUTPUT().getText(); + // String prefix = (flow_dec != null) ? flow_dec + // : (stream_dec != null ? stream_dec + // : (disc_dec != null ? disc_dec + // : (par_dec != null ? par_dec + // : (con_dec != null ? con_dec + // : (in_dec != null ? in_dec + // : out_dec))))); + // return prefix; + // //return new Type_prefix(flow_dec, stream_dec, disc_dec, par_dec, + // // con_dec, in_dec, out_dec); + // } + // } + + // private static class Type_specifierVisitor extends modelicaBaseVisitor { + // @Override + // public String visitType_specifier(modelicaParser.Type_specifierContext ctx) { + // NameVisitor nameVisitor = new NameVisitor(); + // String specifier = ctx.name().accept(nameVisitor); + // return specifier; + // //return new Type_specifier(name_1); + // } + // } + + // private static class Component_listVisitor extends modelicaBaseVisitor { + // @Override + // public Component_list visitComponent_list(modelicaParser.Component_listContext ctx) { + // Component_declarationVisitor component_declarationVisitor = new Component_declarationVisitor(); + // List component_declaration_1 = ctx.component_declaration() + // .stream() + // .map(component_declaration -> component_declaration.accept(component_declarationVisitor)) + // .collect(toList()); + // return new Component_list(component_declaration_1); + // } + // } + + // private static class Component_declarationVisitor extends modelicaBaseVisitor { + // @Override + // public Component_declaration visitComponent_declaration(modelicaParser.Component_declarationContext ctx) { + // DeclarationVisitor declarationVisitor = new DeclarationVisitor(); + // Declaration declaration_1 = ctx.declaration().accept(declarationVisitor); + // Condition_attributeVisitor condition_attributeVisitor = new Condition_attributeVisitor(); + // String condition_attribute_1 = + // ctx.condition_attribute() == null ? null : ctx.condition_attribute().accept(condition_attributeVisitor); + // CommentVisitor commentVisitor = new CommentVisitor(); + // Comment comment_1 = + // ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + // return new Component_declaration(declaration_1, condition_attribute_1, comment_1); + // } + // } + + // private static class Condition_attributeVisitor extends modelicaBaseVisitor { + // @Override + // public String visitCondition_attribute(modelicaParser.Condition_attributeContext ctx) { + // String if_dec = ctx.IF().getText(); + // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + // String expression_1 = ctx.expression().accept(expressionVisitor); + // StringBuilder temStr = new StringBuilder(); + // String conAttStr = temStr.append(if_dec).append(" ").append(expression_1).toString(); + // return conAttStr; + // // return new Condition_attribute(if_dec, expression_1); + // } + // } + + // private static class DeclarationVisitor extends modelicaBaseVisitor { + // @Override + // public Declaration visitDeclaration(modelicaParser.DeclarationContext ctx) { + // String ident = ctx.IDENT().getText(); + // Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); + // String array_subscripts_1 = + // ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); + // ModificationVisitor modificationVisitor = new ModificationVisitor(); + // String modification_1 = + // ctx.modification() == null ? null : ctx.modification().accept(modificationVisitor); + // return new Declaration(ident, array_subscripts_1, modification_1); + // } + // } + + // private static class ModificationVisitor extends modelicaBaseVisitor { + // @Override + // public String visitModification(modelicaParser.ModificationContext ctx) { + // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + // String class_modification_1 = + // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); + // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + // String expression_1 = + // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + // String eqSymb = ctx.SYMBOL_EQUAL() == null ? null : ctx.SYMBOL_EQUAL().getText(); + // String colEqSymb = ctx.SYMBOL_COLONEQUAL() == null ? null : ctx.SYMBOL_COLONEQUAL().getText(); + // String modStr = ""; + // StringBuilder temStr = new StringBuilder(); + // if (class_modification_1 != null) { + // if (expression_1 != null) { + // modStr = temStr.append(class_modification_1).append("=").append(expression_1).toString(); + // } else { + // modStr = class_modification_1; + // } + // } else if (eqSymb != null && expression_1 != null) { + // modStr = temStr.append(eqSymb).append(expression_1).toString(); + // } else if (colEqSymb != null && expression_1 != null) { + // modStr = temStr.append(colEqSymb).append(expression_1).toString(); + // } + // return modStr; + // // return new Modification(class_modification_1, eqSymb, colEqSymb, expression_1); + // } + // } + + // private static class Class_modificationVisitor extends modelicaBaseVisitor { + // @Override + // public String visitClass_modification(modelicaParser.Class_modificationContext ctx) { + // Argument_listVisitor argument_listVisitor = new Argument_listVisitor(); + // String argument_list_1 = + // ctx.argument_list() == null ? null : ctx.argument_list().accept(argument_listVisitor); + // StringBuilder temStr = new StringBuilder(); + // String claModStr = temStr.append("(").append(argument_list_1).append(")").toString(); + // return claModStr; + // //return new Class_modification(argument_list_1); + // } + // } + + // private static class Argument_listVisitor extends modelicaBaseVisitor { + // @Override + // public String visitArgument_list(modelicaParser.Argument_listContext ctx) { + // ArgumentVisitor argumentVisitor = new ArgumentVisitor(); + // List argument_1 = ctx.argument() + // .stream() + // .map(argument -> argument.accept(argumentVisitor)) + // .collect(toList()); + // String argLisStr = argument_1.get(0); + // StringBuilder temStr = new StringBuilder(); + // temStr.append(argLisStr); + // if (argument_1.size()>1) { + // for (int i=1; i { + // @Override + // public String visitArgument(modelicaParser.ArgumentContext ctx) { + // Element_modification_or_replaceableVisitor element_modification_or_replaceableVisitor = new Element_modification_or_replaceableVisitor(); + // String element_modification_or_replaceable_1 = + // ctx.element_modification_or_replaceable() == null ? null : ctx.element_modification_or_replaceable().accept(element_modification_or_replaceableVisitor); + // Element_redeclarationVisitor element_redeclarationVisitor = new Element_redeclarationVisitor(); + // String element_redeclaration_1 = + // ctx.element_redeclaration() == null ? null : ctx.element_redeclaration().accept(element_redeclarationVisitor); + // String argStr = (element_redeclaration_1 != null) ? element_redeclaration_1 : element_modification_or_replaceable_1; + // return argStr; + // //return new Argument(element_modification_or_replaceable_1, element_redeclaration_1); + // } + // } + + // private static class Element_modification_or_replaceableVisitor extends modelicaBaseVisitor { + // @Override + // public String visitElement_modification_or_replaceable(modelicaParser.Element_modification_or_replaceableContext ctx) { + // String each_dec = + // ctx.EACH() == null ? null : ctx.EACH().getText(); + // String final_dec = + // ctx.FINAL() == null ? null : ctx.FINAL().getText(); + // Element_modificationVisitor element_modificationVisitor = new Element_modificationVisitor(); + // String element_modification_1 = + // ctx.element_modification() == null ? null : ctx.element_modification().accept(element_modificationVisitor); + // Element_replaceableVisitor element_replaceableVisitor = new Element_replaceableVisitor(); + // String element_replaceable_1 = + // ctx.element_replaceable() == null ? null : ctx.element_replaceable().accept(element_replaceableVisitor); + // String eleModRep = ""; + // StringBuilder temStr = new StringBuilder(); + // temStr.append(eleModRep); + // if (each_dec != null) {temStr.append(each_dec).append(" ");} + // if (final_dec != null) {temStr.append(final_dec).append(" ");} + // if (element_modification_1 != null) { + // temStr.append(element_modification_1); + // } else { + // temStr.append(element_replaceable_1); + // } + // eleModRep = temStr.toString(); + // return eleModRep; + // //return new Element_modification_or_replaceable(each_dec, final_dec, element_modification_1, element_replaceable_1); + // } + // } + + // private static class Element_modificationVisitor extends modelicaBaseVisitor { + // @Override + // public String visitElement_modification(modelicaParser.Element_modificationContext ctx) { + // NameVisitor nameVisitor = new NameVisitor(); + // String name_1 = ctx.name().accept(nameVisitor); + // ModificationVisitor modificationVisitor = new ModificationVisitor(); + // String modification_1 = + // ctx.modification() == null ? null : ctx.modification().accept(modificationVisitor); + // //String modStr = String.valueOf(modification_1); + // String_commentVisitor string_commentVisitor = new String_commentVisitor(); + // String string_comment_1 = ctx.string_comment().accept(string_commentVisitor); + // StringBuilder temStr1 = new StringBuilder(); + // StringBuilder temStr2 = new StringBuilder(); + // String eleModStr = (modification_1 == null) + // ? (temStr1.append(name_1).append(" ").append(string_comment_1).toString()) + // : (temStr2.append(name_1).append(" ").append(modification_1).append(" ").append(string_comment_1).toString()); + // return eleModStr; + // //return new Element_modification(name_1, modification_1, string_comment_1); + // } + // } + + // private static class Element_redeclarationVisitor extends modelicaBaseVisitor { + // @Override + // public String visitElement_redeclaration(modelicaParser.Element_redeclarationContext ctx) { + // String red_dec = ctx.REDECLARE().getText(); + // String each_dec = + // ctx.EACH() == null ? null : ctx.EACH().getText(); + // String final_dec = + // ctx.FINAL() == null ? null : ctx.FINAL().getText(); + // Short_class_definitionVisitor short_class_definitionVisitor = new Short_class_definitionVisitor(); + // String shoClaDefStr = + // ctx.short_class_definition() == null ? null : ctx.short_class_definition().accept(short_class_definitionVisitor); + // Component_clause1Visitor component_clause1Visitor = new Component_clause1Visitor(); + // String component_clause1_1 = + // ctx.component_clause1() == null ? null : ctx.component_clause1().accept(component_clause1Visitor); + // Element_replaceableVisitor element_replaceableVisitor = new Element_replaceableVisitor(); + // String element_replaceable_1 = + // ctx.element_replaceable() == null ? null : ctx.element_replaceable().accept(element_replaceableVisitor); + // StringBuilder temStr = new StringBuilder(); + // String eleRedStr = temStr.append(red_dec).append(" ").toString(); + // if (each_dec != null) {temStr.append(each_dec).append(" ");} + // if (final_dec != null) {temStr.append(final_dec).append(" ");} + // if (element_replaceable_1 != null) { + // temStr.append(element_replaceable_1); + // } else { + // if (shoClaDefStr != null) { + // temStr.append(shoClaDefStr); + // } else { + // temStr.append(component_clause1_1); + // } + // } + // eleRedStr = temStr.toString(); + // return eleRedStr; + // //return new Element_redeclaration(red_dec, each_dec, final_dec, short_class_definition_1, component_clause1_1, element_replaceable_1); + // } + // } + + // private static class Element_replaceableVisitor extends modelicaBaseVisitor { + // @Override + // public String visitElement_replaceable(modelicaParser.Element_replaceableContext ctx) { + // String rep_dec = ctx.REPLACEABLE().getText(); + // Short_class_definitionVisitor short_class_definitionVisitor = new Short_class_definitionVisitor(); + // String shoClaDefStr = + // ctx.short_class_definition() == null ? null : ctx.short_class_definition().accept(short_class_definitionVisitor); + // Component_clause1Visitor component_clause1Visitor = new Component_clause1Visitor(); + // String component_clause1_1 = + // ctx.component_clause1() == null ? null : ctx.component_clause1().accept(component_clause1Visitor); + // Constraining_clauseVisitor constraining_clauseVisitor = new Constraining_clauseVisitor(); + // String constraining_clause_1 = + // ctx.constraining_clause() == null ? null : ctx.constraining_clause().accept(constraining_clauseVisitor); + // StringBuilder temStr = new StringBuilder(); + // String eleRepStr = temStr.append(rep_dec).append(" ").toString(); + // if (component_clause1_1 == null) { + // temStr.append(shoClaDefStr); + // } else { + // temStr.append(component_clause1_1); + // } + // if (constraining_clause_1 != null) { + // temStr.append(constraining_clause_1); + // } + // eleRepStr = temStr.toString(); + // return eleRepStr; + // //return new Element_replaceable(rep_dec, short_class_definition_1, component_clause1_1, constraining_clause_1); + // } + // } + + // private static class Component_clause1Visitor extends modelicaBaseVisitor { + // @Override + // public String visitComponent_clause1(modelicaParser.Component_clause1Context ctx) { + // Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); + // String type_prefix_1 = ctx.type_prefix().accept(type_prefixVisitor); + // Type_specifierVisitor type_specifierVisitor = new Type_specifierVisitor(); + // String type_specifier_1 = ctx.type_specifier().accept(type_specifierVisitor); + // Component_declaration1Visitor component_declaration1Visitor = new Component_declaration1Visitor(); + // String component_declaration1_1 = ctx.component_declaration1().accept(component_declaration1Visitor); + // StringBuilder temStr = new StringBuilder(); + // if (type_prefix_1 != null) { + // temStr.append(type_prefix_1).append(" "); + // } + // String comCla1Str = temStr.append(type_specifier_1).append(" ") + // .append(component_declaration1_1) + // .toString(); + // return comCla1Str; + // //return new Component_clause1(type_prefix_1, type_specifier_1, component_declaration1_1); + // } + // } + + // private static class Component_declaration1Visitor extends modelicaBaseVisitor { + // @Override + // public String visitComponent_declaration1(modelicaParser.Component_declaration1Context ctx) { + // String declaration_1 = ""; + // if (ctx.declaration().getText().isEmpty()) { + // declaration_1 = null; + // } else { + // int a = ctx.declaration().start.getStartIndex(); + // int b = ctx.declaration().stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream decStr = ctx.declaration().start.getInputStream(); + // declaration_1 = decStr.getText(interval).trim(); + // } - String comStr = ctx.comment().getText(); - StringBuilder temStr = new StringBuilder(); - String comDec1Str = temStr.append(declaration_1).append(" ").append(comStr).toString(); + // String comStr = ctx.comment().getText(); + // StringBuilder temStr = new StringBuilder(); + // String comDec1Str = temStr.append(declaration_1).append(" ").append(comStr).toString(); - return comDec1Str; - //return new Component_declaration1(declaration_1, comment_1); - } - } - - private static class Short_class_definitionVisitor extends modelicaBaseVisitor { - @Override - public String visitShort_class_definition(modelicaParser.Short_class_definitionContext ctx) { - Class_prefixesVisitor class_prefixesVisitor = new Class_prefixesVisitor(); - String class_prefixes_1 - = ctx.class_prefixes().accept(class_prefixesVisitor); - Short_class_specifierVisitor short_class_specifierVisitor = new Short_class_specifierVisitor(); - Short_class_specifier shortClaSpe = ctx.short_class_specifier().accept(short_class_specifierVisitor); - String shortClaSpeStr; - String comeStr; - if (shortClaSpe.comment != null) { - if (shortClaSpe.comment.string_comment == null && shortClaSpe.comment.annotation == null) { - comeStr = ""; - } else if (shortClaSpe.comment.string_comment == null && shortClaSpe.comment.annotation != null) { - StringBuilder temStr = new StringBuilder(); - comeStr = temStr.append("annotation (") - .append(shortClaSpe.comment.annotation.toString()) - .append(")").toString(); - } else if (shortClaSpe.comment.string_comment != null && shortClaSpe.comment.annotation == null) { - comeStr = shortClaSpe.comment.string_comment; - } else { - StringBuilder temStr = new StringBuilder(); - comeStr = temStr.append(shortClaSpe.comment.string_comment).append(" ") - .append("annotation (") - .append(shortClaSpe.comment.annotation.toString()).append(")") - .toString(); - } - } else { - comeStr = ""; - } - if (shortClaSpe.base_prefix != null || shortClaSpe.inputName != null) { - StringBuilder temStr = new StringBuilder(); - shortClaSpeStr = temStr.append(shortClaSpe.className).append(" =") - .append((shortClaSpe.base_prefix == null ? "" : (shortClaSpe.base_prefix+ " "))) - .append((shortClaSpe.inputName == null ? "" : (shortClaSpe.inputName+" "))) - .append((shortClaSpe.array_subscripts == null ? "" : (shortClaSpe.array_subscripts+" "))) - .append((shortClaSpe.class_modification == null ? "" : (shortClaSpe.class_modification+" "))) - .append(comeStr) - .toString(); - } else { - String listStr; - if (shortClaSpe.list_colon == null) { - listStr = shortClaSpe.enum_list == null ? "" : shortClaSpe.enum_list.toString(); - } else { - listStr = shortClaSpe.list_colon; - } - StringBuilder temStr = new StringBuilder(); - shortClaSpeStr = temStr.append(shortClaSpe.className).append(" =") - .append(shortClaSpe.prefix).append("(").append(listStr).append(")") - .append(comeStr).toString(); - } - StringBuilder temStr = new StringBuilder(); - String shoClaDef = temStr.append(class_prefixes_1).append(" ").append(shortClaSpeStr).toString(); - return shoClaDef; - //return new Short_class_definition(class_prefixes_1, short_class_specifier_1); - } - } - - private static class Equation_sectionVisitor extends modelicaBaseVisitor { - @Override - public Equation_section visitEquation_section(modelicaParser.Equation_sectionContext ctx) { - String init_dec = - ctx.INITIAL() == null ? null : ctx.INITIAL().getText(); - String equ_dec = ctx.EQUATION().getText(); - EquationVisitor equationVisitor = new EquationVisitor(); - List equation_1 = ctx.equation() == null ? null : ctx.equation() - .stream() - .map(equation -> equation.accept(equationVisitor)) - .collect(toList()); - return new Equation_section(init_dec, equ_dec, equation_1); - } - } - - private static class Algorithm_sectionVisitor extends modelicaBaseVisitor { - @Override - public String visitAlgorithm_section(modelicaParser.Algorithm_sectionContext ctx) { - String init_dec = - ctx.INITIAL() == null ? null : ctx.INITIAL().getText(); - String alg_dec = ctx.ALGORITHM().getText(); - StatementVisitor statementVisitor = new StatementVisitor(); - List statement_1 = ctx.statement() == null ? null : ctx.statement() - .stream() - .map(statement -> statement.accept(statementVisitor)) - .collect(toList()); - StringBuilder temStr = new StringBuilder(); - String algSecStr = (init_dec != null) ? (temStr.append(init_dec).append(" ").append(alg_dec).toString()) - : alg_dec; - if (statement_1.size()>0) { - StringBuilder temStr2 = new StringBuilder(); - temStr2.append(algSecStr).append("\n"); - for (int i=0; i { - @Override - public Equation visitEquation(modelicaParser.EquationContext ctx) { - Simple_expressionVisitor simple_expressionVisitor = new Simple_expressionVisitor(); - String simple_expression_1 = - ctx.simple_expression() == null ? null : ctx.simple_expression().accept(simple_expressionVisitor); - ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - String expression_1 = - ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - If_equationVisitor if_equationVisitor = new If_equationVisitor(); - String if_equation_1 = - ctx.if_equation() == null ? null : ctx.if_equation().accept(if_equationVisitor); - For_equationVisitor for_equationVisitor = new For_equationVisitor(); - String for_equation_1 = - ctx.for_equation() == null ? null : ctx.for_equation().accept(for_equationVisitor); - Connect_clauseVisitor connect_clauseVisitor = new Connect_clauseVisitor(); - Connect_clause connect_clause_1 = - ctx.connect_clause() == null ? null : ctx.connect_clause().accept(connect_clauseVisitor); - When_equationVisitor when_equationVisitor = new When_equationVisitor(); - String when_equation_1 = - ctx.when_equation() == null ? null : ctx.when_equation().accept(when_equationVisitor); - NameVisitor nameVisitor = new NameVisitor(); - String name_1 = - ctx.name() == null ? null : ctx.name().accept(nameVisitor); - Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); - String function_call_args_1 = - ctx.function_call_args() == null ? null : ctx.function_call_args().accept(function_call_argsVisitor); - CommentVisitor commentVisitor = new CommentVisitor(); - Comment comment_1 = - ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); - return new Equation(simple_expression_1, expression_1, if_equation_1, for_equation_1, connect_clause_1, - when_equation_1, name_1, function_call_args_1, comment_1); - } - } - - private static class StatementVisitor extends modelicaBaseVisitor { - @Override - public String visitStatement(modelicaParser.StatementContext ctx) { - String bre_dec = - ctx.BREAK() == null ? "" : ctx.BREAK().getText(); - String ret_dec = - ctx.RETURN() == null ? "" : ctx.RETURN().getText(); - Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); - String component_reference_1 = - ctx.component_reference() == null ? "" : ctx.component_reference().accept(component_referenceVisitor); - ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - String expression_1 = - ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); - String function_call_args_1 = - ctx.function_call_args() == null ? "" : ctx.function_call_args().accept(function_call_argsVisitor); - Output_expression_listVisitor output_expression_listVisitor = new Output_expression_listVisitor(); - String output_expression_list_1 = - ctx.output_expression_list() == null ? null : ctx.output_expression_list().accept(output_expression_listVisitor); - If_statementVisitor if_statementVisitor = new If_statementVisitor(); - String if_statement_1 = - ctx.if_statement() == null ? "" : ctx.if_statement().accept(if_statementVisitor); - For_statementVisitor for_statementVisitor = new For_statementVisitor(); - String for_statement_1 = - ctx.for_statement() == null ? "" : ctx.for_statement().accept(for_statementVisitor); - While_statementVisitor while_statementVisitor = new While_statementVisitor(); - String while_statement_1 = - ctx.while_statement() == null ? "" : ctx.while_statement().accept(while_statementVisitor); - When_statementVisitor when_statementVisitor = new When_statementVisitor(); - String when_statement_1 = - ctx.when_statement() == null ? "" : ctx.when_statement().accept(when_statementVisitor); - CommentVisitor commentVisitor = new CommentVisitor(); - Comment comment_1 = ctx.comment().accept(commentVisitor); - String comStr = String.valueOf(comment_1); - StringBuilder temStr1 = new StringBuilder(); - StringBuilder temStr2 = new StringBuilder(); - StringBuilder temStr3 = new StringBuilder(); - String temp1 = (expression_1 == null) ? "" : (temStr1.append("=").append(expression_1).toString()); - String temp2 = (output_expression_list_1 == null) ? "" - : (temStr2.append("(").append(output_expression_list_1).append(")").append(":=") - .append(component_reference_1).append(" ").append(function_call_args_1) - .toString()); - String staStr = temStr3.append(component_reference_1).append(temp1).append(function_call_args_1) - .append(temp2).append(bre_dec).append(ret_dec).append(if_statement_1) - .append(for_statement_1).append(while_statement_1) - .append(when_statement_1).append(comStr) - .toString(); - return staStr; - //return new Statement(bre_dec, ret_dec, component_reference_1, expression_1, function_call_args_1, - // output_expression_list_1, if_statement_1, for_statement_1, while_statement_1, when_statement_1, comment_1); - } - } - - private static class If_equationVisitor extends modelicaBaseVisitor { - @Override - public String visitIf_equation(modelicaParser.If_equationContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new If_equation(expression1, equation1, expression2, equation2, equation3); - } - } - - private static class If_statementVisitor extends modelicaBaseVisitor { - @Override - public String visitIf_statement(modelicaParser.If_statementContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new If_statement(expression1, statement1, expression2, statement2, statement3); - } - } - - private static class For_equationVisitor extends modelicaBaseVisitor { - @Override - public String visitFor_equation(modelicaParser.For_equationContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new For_equation(for_indices_1, equation_1); - } - } - - private static class For_statementVisitor extends modelicaBaseVisitor { - @Override - public String visitFor_statement(modelicaParser.For_statementContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new For_statement(for_indices_1, statement_1); - } - } - - private static class For_indicesVisitor extends modelicaBaseVisitor { - @Override - public String visitFor_indices(modelicaParser.For_indicesContext ctx) { - For_indexVisitor for_indexVisitor = new For_indexVisitor(); - List for_index_1 = ctx.for_index() - .stream() - .map(for_index -> for_index.accept(for_indexVisitor)) - .collect(toList()); - StringBuilder temStr = new StringBuilder(); - temStr.append(for_index_1.get(0)); - if (for_index_1.size() > 1) { - for (int i=1; i { - @Override - public String visitFor_index(modelicaParser.For_indexContext ctx) { - String ident = ctx.IDENT().getText(); - ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - String expression_1 = - ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - StringBuilder temStr = new StringBuilder(); - temStr.append(ident); - if (expression_1 != null) { - temStr.append(" in ").append(expression_1); - } - return temStr.toString(); - //return new For_index(ident, expression_1); - } - } - - private static class While_statementVisitor extends modelicaBaseVisitor { - @Override - public String visitWhile_statement(modelicaParser.While_statementContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new While_statement(expression_1, statement_1); - } - } - - private static class When_equationVisitor extends modelicaBaseVisitor { - @Override - public String visitWhen_equation(modelicaParser.When_equationContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new When_equation(expression1, equation1, expression2, equation2); - } - } - - private static class When_statementVisitor extends modelicaBaseVisitor { - @Override - public String visitWhen_statement(modelicaParser.When_statementContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new When_statement(expression1, statement1, expression2, statement2); - } - } - - private static class Connect_clauseVisitor extends modelicaBaseVisitor { - @Override - public Connect_clause visitConnect_clause(modelicaParser.Connect_clauseContext ctx) { - Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); - List component_reference_1 = ctx.component_reference() - .stream() - .map(component_reference -> component_reference.accept(component_referenceVisitor)) - .collect(toList()); - return new Connect_clause(component_reference_1.get(0), component_reference_1.get(1)); - } - } - - private static class ExpressionVisitor extends modelicaBaseVisitor { - @Override - public String visitExpression(modelicaParser.ExpressionContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new Expression(simple_expression_1, expression1, expression2, - // expression3, expression4, expression5); - } - } - - private static class Simple_expressionVisitor extends modelicaBaseVisitor { - @Override - public String visitSimple_expression(modelicaParser.Simple_expressionContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new Simple_expression(logical_expression1, logical_expression2, logical_expression3); - } - } - - private static class Logical_expressionVisitor extends modelicaBaseVisitor { - @Override - public String visitLogical_expression(modelicaParser.Logical_expressionContext ctx) { - List or_decs = ctx.OR() == null ? null : ctx.OR() - .stream() - .map(OR -> OR.getText()) - .collect(toList()); - Logical_termVisitor logical_termVisitor = new Logical_termVisitor(); - List logical_terms = ctx.logical_term() - .stream() - .map(logical_term -> logical_term.accept(logical_termVisitor)) - .collect(toList()); - StringBuilder temStr = new StringBuilder(); - temStr.append(logical_terms.get(0)); - if (or_decs != null) { - for (int i=0; i { - @Override - public String visitLogical_term(modelicaParser.Logical_termContext ctx) { - List and_decs = ctx.AND() == null ? null : ctx.AND() - .stream() - .map(AND -> AND.getText()) - .collect(toList()); - Logical_factorVisitor logical_factorVisitor = new Logical_factorVisitor(); - List logical_factors = ctx.logical_factor() - .stream() - .map(logical_factor -> logical_factor.accept(logical_factorVisitor)) - .collect(toList()); - StringBuilder temStr = new StringBuilder(); - temStr.append(logical_factors.get(0)); - if (and_decs != null) { - for (int i=0; i { - @Override - public String visitLogical_factor(modelicaParser.Logical_factorContext ctx) { - String not_dec = - ctx.NOT() == null ? null : ctx.NOT().getText(); - RelationVisitor relationVisitor = new RelationVisitor(); - String relation = ctx.relation().accept(relationVisitor); - StringBuilder temStr = new StringBuilder(); - String logFacStr = (not_dec != null) ? (temStr.append(not_dec).append(" ").append(relation).toString()) - : (relation); - return logFacStr; - //return new Logical_factor(not_dec, relation); - } - } - - private static class RelationVisitor extends modelicaBaseVisitor { - @Override - public String visitRelation(modelicaParser.RelationContext ctx) { - Arithmetic_expressionVisitor arithmetic_expressionVisitor = new Arithmetic_expressionVisitor(); - List arithmetic_expressions = ctx.arithmetic_expression() - .stream() - .map(arithmetic_expression -> arithmetic_expression.accept(arithmetic_expressionVisitor)) - .collect(toList()); - Rel_opVisitor rel_opVisitor = new Rel_opVisitor(); - String rel_op1 = - ctx.rel_op() == null ? null : ctx.rel_op().accept(rel_opVisitor); - StringBuilder temStr = new StringBuilder(); - temStr.append(arithmetic_expressions.get(0)); - if (rel_op1 != null) { - temStr.append(rel_op1).append(arithmetic_expressions.get(1)); - } - return temStr.toString(); - // return new Relation(arithmetic_expression1, rel_op1, arithmetic_expression2); - } - } - - private static class Rel_opVisitor extends modelicaBaseVisitor { - @Override - public String visitRel_op(modelicaParser.Rel_opContext ctx) { - String relOpe = ctx.getText(); - return relOpe; - //return new Rel_op(ope_dec); - } - } - - private static class Arithmetic_expressionVisitor extends modelicaBaseVisitor { - @Override - public String visitArithmetic_expression(modelicaParser.Arithmetic_expressionContext ctx) { - Add_opVisitor add_opVisitor = new Add_opVisitor(); - List add_ops = ctx.add_op() == null ? null : ctx.add_op() - .stream() - .map(add_op -> add_op.accept(add_opVisitor)) - .collect(toList()); - TermVisitor termVisitor = new TermVisitor(); - List terms = ctx.term() - .stream() - .map(term -> term.accept(termVisitor)) - .collect(toList()); - StringBuilder temStr = new StringBuilder(); - if (add_ops.size() == terms.size()) { - for (int i=0; i { - @Override - public String visitAdd_op(modelicaParser.Add_opContext ctx) { - String addOpe = ctx.getText(); - return addOpe; - //return new Add_op(add_dec); - } - } - - private static class TermVisitor extends modelicaBaseVisitor { - @Override - public String visitTerm(modelicaParser.TermContext ctx) { - Mul_opVisitor mul_opVisitor = new Mul_opVisitor(); - List mul_op_1 = ctx.mul_op() == null ? null : ctx.mul_op() - .stream() - .map(mul_op -> mul_op.accept(mul_opVisitor)) - .collect(toList()); - FactorVisitor factorVisitor = new FactorVisitor(); - List factors = ctx.factor() - .stream() - .map(factor -> factor.accept(factorVisitor)) - .collect(toList()); - StringBuilder temStr = new StringBuilder(); - temStr.append(factors.get(0)); - if (mul_op_1 != null) { - for (int i=0; i { - @Override - public String visitMul_op(modelicaParser.Mul_opContext ctx) { - String mulOpe = ctx.getText(); - return mulOpe; - //return new Mul_op(mul_dec); - } - } - - private static class FactorVisitor extends modelicaBaseVisitor { - @Override - public String visitFactor(modelicaParser.FactorContext ctx) { - PrimaryVisitor primaryVisitor = new PrimaryVisitor(); - List primarys = ctx.primary() - .stream() - .map(primary -> primary.accept(primaryVisitor)) - .collect(toList()); - String caret = - ctx.SYMBOL_CARET()==null ? null : ctx.SYMBOL_CARET().getText(); - String dotCaret = - ctx.SYMBOL_DOTCARET()==null ? null : ctx.SYMBOL_DOTCARET().getText(); - String facStr = primarys.get(0); - if (primarys.size()>1) { - StringBuilder temStr = new StringBuilder(); - if (caret != null) { - facStr = temStr.append(primarys.get(0)).append(caret) - .append(primarys.get(1)) - .toString(); - } else { - facStr = temStr.append(primarys.get(0)).append(dotCaret) - .append(primarys.get(1)) - .toString(); - } - } - return facStr; - // return new Factor(primarys, caret, dotCaret); - } - } - - private static class PrimaryVisitor extends modelicaBaseVisitor { - @Override - public String visitPrimary(modelicaParser.PrimaryContext ctx) { - String num_dec = - ctx.UNSIGNED_NUMBER() == null ? null : ctx.UNSIGNED_NUMBER().getText(); - String str_dec = - ctx.STRING() == null ? null : ctx.STRING().getText(); - String false_dec = - ctx.FALSE() == null ? null : ctx.FALSE().getText(); - String true_dec = - ctx.TRUE() == null ? null : ctx.TRUE().getText(); - String der_der = - ctx.DER() == null ? null : ctx.DER().getText(); - String init_dec = - ctx.INITIAL() == null ? null : ctx.INITIAL().getText(); - String end_dec = - ctx.END() == null ? null : ctx.END().getText(); - NameVisitor nameVisitor = new NameVisitor(); - String name1 = - ctx.name() == null ? null : ctx.name().accept(nameVisitor); - Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); - String function_call_args1 = - ctx.function_call_args() == null ? null : ctx.function_call_args().accept(function_call_argsVisitor); - Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); - String component_reference1 = - ctx.component_reference() == null ? null : ctx.component_reference().accept(component_referenceVisitor); - Output_expression_listVisitor output_expression_listVisitor = new Output_expression_listVisitor(); - String output_expression_list1 = - ctx.output_expression_list() == null ? null : ctx.output_expression_list().accept(output_expression_listVisitor); - Expression_listVisitor expression_listVisitor = new Expression_listVisitor(); - List expression_list_1 = ctx.expression_list() == null ? null : ctx.expression_list() - .stream() - .map(expression_list -> expression_list.accept(expression_listVisitor)) - .collect(toList()); - List semiColon = ctx.SYMBOL_SEMICOLON() == null ? null : ctx.SYMBOL_SEMICOLON() - .stream() - .map(SYMBOL_SEMICOLON -> SYMBOL_SEMICOLON.getText()) - .collect(toList()); - Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); - String function_arguments1 = - ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); - StringBuilder temStr = new StringBuilder(); - String priStr = num_dec; - if (str_dec != null) {priStr = str_dec;} - else if (false_dec != null) {priStr = false_dec;} - else if (true_dec != null) {priStr = true_dec;} - else if (function_call_args1 != null) { - if (name1 != null) { - priStr = temStr.append(name1).append(" ").append(function_call_args1).toString();} - else if (der_der != null) { - priStr = temStr.append(der_der).append(" ").append(function_call_args1).toString();} - else { - priStr = temStr.append(init_dec).append(" ").append(function_call_args1).toString();} - } - else if (component_reference1 != null) { - priStr = component_reference1;} - else if (output_expression_list1 != null) { - priStr = temStr.append("(").append(output_expression_list1).append(")").toString();} - else if (expression_list_1.size() > 0 ) { - temStr.append(expression_list_1.get(0)); - if (semiColon != null) { - for (int i=0; i { - @Override - public String visitName(modelicaParser.NameContext ctx) { - List dots = ctx.SYMBOL_DOT()==null ? null : ctx.SYMBOL_DOT() - .stream() - .map(SYMBOL_DOT -> SYMBOL_DOT.getText()) - .collect(toList()); - List ident = ctx.IDENT() - .stream() - .map(IDENT -> IDENT.getText()) - .collect(toList()); - StringBuilder temStr = new StringBuilder(); - if (dots == null) { - temStr.append(ident.get(0)); - } else { - if (dots.size() == ident.size()) { - for (int i=0; i { - @Override - public String visitComponent_reference(modelicaParser.Component_referenceContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - // return new Component_reference(ident, dots, array_subscripts_1); - } - } - - private static class Function_call_argsVisitor extends modelicaBaseVisitor { - @Override - public String visitFunction_call_args(modelicaParser.Function_call_argsContext ctx) { - Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); - String function_arguments = - ctx.function_arguments() == null ? "" : ctx.function_arguments().accept(function_argumentsVisitor); - StringBuilder temStr = new StringBuilder(); - String funCalArgs = temStr.append("(").append(function_arguments).append(")") - .toString(); - return funCalArgs; - //return new Function_call_args(function_arguments); - } - } - - private static class Function_argumentsVisitor extends modelicaBaseVisitor { - @Override - public String visitFunction_arguments(modelicaParser.Function_argumentsContext ctx) { - Function_argumentVisitor function_argumentVisitor = new Function_argumentVisitor(); - String function_argument = - ctx.function_argument() == null ? null : ctx.function_argument().accept(function_argumentVisitor); - Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); - String function_arguments = - ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); - String for_dec = - ctx.FOR() == null ? null : ctx.FOR().getText(); - For_indicesVisitor for_indicesVisitor = new For_indicesVisitor(); - String for_indices = - ctx.for_indices() == null ? null : ctx.for_indices().accept(for_indicesVisitor); - Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); - String named_arguments = - ctx.named_arguments() == null ? null : ctx.named_arguments().accept(named_argumentsVisitor); - String funArgsStr = named_arguments; - if (function_argument != null) { - StringBuilder temStr1 = new StringBuilder(); - if (function_arguments != null) { - temStr1.append(",").append(function_arguments); - } else if (for_indices != null) { - temStr1.append("for ").append(for_indices); - } - StringBuilder temStr2 = new StringBuilder(); - funArgsStr = temStr2.append(function_argument) - .append(temStr1.toString()) - .toString(); - } - return funArgsStr; - //return new Function_arguments(function_argument, function_arguments, for_dec, for_indices, named_arguments); - } - } - - private static class Named_argumentsVisitor extends modelicaBaseVisitor { - @Override - public String visitNamed_arguments(modelicaParser.Named_argumentsContext ctx) { - Named_argumentVisitor named_argumentVisitor = new Named_argumentVisitor(); - String named_argument = - ctx.named_argument().accept(named_argumentVisitor); - Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); - String named_arguments = - ctx.named_arguments() == null ? null : ctx.named_arguments().accept(named_argumentsVisitor); - String comma = - ctx.SYMBOL_COMMA()==null ? null : ctx.SYMBOL_COMMA().getText(); - String namedArgsStr = named_argument; - if (comma != null) { - StringBuilder temStr = new StringBuilder(); - namedArgsStr = temStr.append(namedArgsStr).append(",") - .append(named_arguments) - .toString(); - } - return namedArgsStr; - //return new Named_arguments(named_argument,named_arguments); - } - } - - private static class Named_argumentVisitor extends modelicaBaseVisitor { - @Override - public String visitNamed_argument(modelicaParser.Named_argumentContext ctx) { - String ident = ctx.IDENT().getText(); - Function_argumentVisitor function_argumentVisitor = new Function_argumentVisitor(); - String function_argument = - ctx.function_argument().accept(function_argumentVisitor); - StringBuilder temStr = new StringBuilder(); - String namedArgStr = temStr.append(ident).append("=") - .append(function_argument) - .toString(); - return namedArgStr; - //return new Named_argument(ident, function_argument); - } - } - - private static class Function_argumentVisitor extends modelicaBaseVisitor { - @Override - public String visitFunction_argument(modelicaParser.Function_argumentContext ctx) { - String fun_dec = - ctx.FUNCTION() == null ? null : ctx.FUNCTION().getText(); - NameVisitor nameVisitor = new NameVisitor(); - String name = - ctx.name() == null ? null : ctx.name().accept(nameVisitor); - Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); - String named_arguments = - ctx.named_arguments() == null ? "" : ctx.named_arguments().accept(named_argumentsVisitor); - ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - String expression = - ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - String funArgStr = expression; - if (fun_dec != null) { - StringBuilder temStr = new StringBuilder(); - funArgStr = temStr.append(fun_dec).append(" ").append(name) - .append("(").append(named_arguments).append(")") - .toString(); - } - return funArgStr; - //return new Function_argument(fun_dec, name, named_arguments, expression); - } - } - - private static class Output_expression_listVisitor extends modelicaBaseVisitor { - @Override - public String visitOutput_expression_list(modelicaParser.Output_expression_listContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - //return new Output_expression_list(expression_1); - } - } - - private static class Expression_listVisitor extends modelicaBaseVisitor { - @Override - public String visitExpression_list(modelicaParser.Expression_listContext ctx) { - ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - List expression_1 = ctx.expression() - .stream() - .map(expression -> expression.accept(expressionVisitor)) - .collect(toList()); - StringBuilder temStr = new StringBuilder(); - temStr.append(expression_1.get(0)); - if (expression_1.size()>1) { - for (int i=1; i { - @Override - public String visitArray_subscripts(modelicaParser.Array_subscriptsContext ctx) { - SubscriptVisitor subscriptVisitor = new SubscriptVisitor(); - List subscript_1 = ctx.subscript() - .stream() - .map(subscript -> subscript.accept(subscriptVisitor)) - .collect(toList()); - StringBuilder temStr1 = new StringBuilder(); - String arraySubStr = temStr1.append("[") - .append(subscript_1.get(0)) - .append("]") - .toString(); - if (subscript_1.size() > 1) { - StringBuilder temStr2 = new StringBuilder(); - temStr2.append(subscript_1.get(0)); - for (int i=1; i { - @Override - public String visitSubscript(modelicaParser.SubscriptContext ctx) { - String colon = - ctx.SYMBOL_COLON() == null ? null : ctx.SYMBOL_COLON().getText(); - ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - String expression = - ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - String subStr = - colon != null ? colon : expression; - return subStr; - //return new Subscript(expression); - } - } - - public static class CommentVisitor extends modelicaBaseVisitor { - String string_comment1; - String annotation1; - @Override - public Comment visitComment(modelicaParser.CommentContext ctx) { - String_commentVisitor string_commentVisitor = new String_commentVisitor(); - String string_comment1 = - ctx.string_comment() == null ? null : ctx.string_comment().accept(string_commentVisitor); - AnnotationVisitor annotationVisitor = new AnnotationVisitor(); - String annotation1 = - ctx.annotation() == null ? null : ctx.annotation().accept(annotationVisitor); - this.string_comment1 = string_comment1; - this.annotation1 = annotation1; - return new Comment(string_comment1, annotation1); - } - } - - public static class String_commentVisitor extends modelicaBaseVisitor { - @Override - public String visitString_comment(modelicaParser.String_commentContext ctx) { - List str_dec = ctx.STRING() == null ? null : ctx.STRING() - .stream() - .map(STRING -> STRING.getText()) - .collect(toList()); - String strCom = ""; - if (str_dec.size() == 1) { - strCom = str_dec.get(0); - } else if (str_dec.size() > 1) { - StringBuilder temStr = new StringBuilder(); - temStr.append(str_dec.get(0)); - for (int i=1; i { - @Override - public String visitAnnotation(modelicaParser.AnnotationContext ctx) { - String ann_dec = ctx.ANNOTATION().getText(); - Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - String class_modification = ctx.class_modification().accept(class_modificationVisitor); - return class_modification; - //return new Annotation(ann_dec, class_modification); - } - } + // return comDec1Str; + // //return new Component_declaration1(declaration_1, comment_1); + // } + // } + + // private static class Short_class_definitionVisitor extends modelicaBaseVisitor { + // @Override + // public String visitShort_class_definition(modelicaParser.Short_class_definitionContext ctx) { + // Class_prefixesVisitor class_prefixesVisitor = new Class_prefixesVisitor(); + // String class_prefixes_1 + // = ctx.class_prefixes().accept(class_prefixesVisitor); + // Short_class_specifierVisitor short_class_specifierVisitor = new Short_class_specifierVisitor(); + // Short_class_specifier shortClaSpe = ctx.short_class_specifier().accept(short_class_specifierVisitor); + // String shortClaSpeStr; + // String comeStr; + // if (shortClaSpe.comment != null) { + // if (shortClaSpe.comment.string_comment == null && shortClaSpe.comment.annotation == null) { + // comeStr = ""; + // } else if (shortClaSpe.comment.string_comment == null && shortClaSpe.comment.annotation != null) { + // StringBuilder temStr = new StringBuilder(); + // comeStr = temStr.append("annotation (") + // .append(shortClaSpe.comment.annotation.toString()) + // .append(")").toString(); + // } else if (shortClaSpe.comment.string_comment != null && shortClaSpe.comment.annotation == null) { + // comeStr = shortClaSpe.comment.string_comment; + // } else { + // StringBuilder temStr = new StringBuilder(); + // comeStr = temStr.append(shortClaSpe.comment.string_comment).append(" ") + // .append("annotation (") + // .append(shortClaSpe.comment.annotation.toString()).append(")") + // .toString(); + // } + // } else { + // comeStr = ""; + // } + // if (shortClaSpe.base_prefix != null || shortClaSpe.inputName != null) { + // StringBuilder temStr = new StringBuilder(); + // shortClaSpeStr = temStr.append(shortClaSpe.className).append(" =") + // .append((shortClaSpe.base_prefix == null ? "" : (shortClaSpe.base_prefix+ " "))) + // .append((shortClaSpe.inputName == null ? "" : (shortClaSpe.inputName+" "))) + // .append((shortClaSpe.array_subscripts == null ? "" : (shortClaSpe.array_subscripts+" "))) + // .append((shortClaSpe.class_modification == null ? "" : (shortClaSpe.class_modification+" "))) + // .append(comeStr) + // .toString(); + // } else { + // String listStr; + // if (shortClaSpe.list_colon == null) { + // listStr = shortClaSpe.enum_list == null ? "" : shortClaSpe.enum_list.toString(); + // } else { + // listStr = shortClaSpe.list_colon; + // } + // StringBuilder temStr = new StringBuilder(); + // shortClaSpeStr = temStr.append(shortClaSpe.className).append(" =") + // .append(shortClaSpe.prefix).append("(").append(listStr).append(")") + // .append(comeStr).toString(); + // } + // StringBuilder temStr = new StringBuilder(); + // String shoClaDef = temStr.append(class_prefixes_1).append(" ").append(shortClaSpeStr).toString(); + // return shoClaDef; + // //return new Short_class_definition(class_prefixes_1, short_class_specifier_1); + // } + // } + + // private static class Equation_sectionVisitor extends modelicaBaseVisitor { + // @Override + // public Equation_section visitEquation_section(modelicaParser.Equation_sectionContext ctx) { + // String init_dec = + // ctx.INITIAL() == null ? null : ctx.INITIAL().getText(); + // String equ_dec = ctx.EQUATION().getText(); + // EquationVisitor equationVisitor = new EquationVisitor(); + // List equation_1 = ctx.equation() == null ? null : ctx.equation() + // .stream() + // .map(equation -> equation.accept(equationVisitor)) + // .collect(toList()); + // return new Equation_section(init_dec, equ_dec, equation_1); + // } + // } + + // private static class Algorithm_sectionVisitor extends modelicaBaseVisitor { + // @Override + // public String visitAlgorithm_section(modelicaParser.Algorithm_sectionContext ctx) { + // String init_dec = + // ctx.INITIAL() == null ? null : ctx.INITIAL().getText(); + // String alg_dec = ctx.ALGORITHM().getText(); + // StatementVisitor statementVisitor = new StatementVisitor(); + // List statement_1 = ctx.statement() == null ? null : ctx.statement() + // .stream() + // .map(statement -> statement.accept(statementVisitor)) + // .collect(toList()); + // StringBuilder temStr = new StringBuilder(); + // String algSecStr = (init_dec != null) ? (temStr.append(init_dec).append(" ").append(alg_dec).toString()) + // : alg_dec; + // if (statement_1.size()>0) { + // StringBuilder temStr2 = new StringBuilder(); + // temStr2.append(algSecStr).append("\n"); + // for (int i=0; i { + // @Override + // public Equation visitEquation(modelicaParser.EquationContext ctx) { + // Simple_expressionVisitor simple_expressionVisitor = new Simple_expressionVisitor(); + // String simple_expression_1 = + // ctx.simple_expression() == null ? null : ctx.simple_expression().accept(simple_expressionVisitor); + // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + // String expression_1 = + // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + // If_equationVisitor if_equationVisitor = new If_equationVisitor(); + // String if_equation_1 = + // ctx.if_equation() == null ? null : ctx.if_equation().accept(if_equationVisitor); + // For_equationVisitor for_equationVisitor = new For_equationVisitor(); + // String for_equation_1 = + // ctx.for_equation() == null ? null : ctx.for_equation().accept(for_equationVisitor); + // Connect_clauseVisitor connect_clauseVisitor = new Connect_clauseVisitor(); + // Connect_clause connect_clause_1 = + // ctx.connect_clause() == null ? null : ctx.connect_clause().accept(connect_clauseVisitor); + // When_equationVisitor when_equationVisitor = new When_equationVisitor(); + // String when_equation_1 = + // ctx.when_equation() == null ? null : ctx.when_equation().accept(when_equationVisitor); + // NameVisitor nameVisitor = new NameVisitor(); + // String name_1 = + // ctx.name() == null ? null : ctx.name().accept(nameVisitor); + // Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); + // String function_call_args_1 = + // ctx.function_call_args() == null ? null : ctx.function_call_args().accept(function_call_argsVisitor); + // CommentVisitor commentVisitor = new CommentVisitor(); + // Comment comment_1 = + // ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); + // return new Equation(simple_expression_1, expression_1, if_equation_1, for_equation_1, connect_clause_1, + // when_equation_1, name_1, function_call_args_1, comment_1); + // } + // } + + // private static class StatementVisitor extends modelicaBaseVisitor { + // @Override + // public String visitStatement(modelicaParser.StatementContext ctx) { + // String bre_dec = + // ctx.BREAK() == null ? "" : ctx.BREAK().getText(); + // String ret_dec = + // ctx.RETURN() == null ? "" : ctx.RETURN().getText(); + // Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); + // String component_reference_1 = + // ctx.component_reference() == null ? "" : ctx.component_reference().accept(component_referenceVisitor); + // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + // String expression_1 = + // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + // Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); + // String function_call_args_1 = + // ctx.function_call_args() == null ? "" : ctx.function_call_args().accept(function_call_argsVisitor); + // Output_expression_listVisitor output_expression_listVisitor = new Output_expression_listVisitor(); + // String output_expression_list_1 = + // ctx.output_expression_list() == null ? null : ctx.output_expression_list().accept(output_expression_listVisitor); + // If_statementVisitor if_statementVisitor = new If_statementVisitor(); + // String if_statement_1 = + // ctx.if_statement() == null ? "" : ctx.if_statement().accept(if_statementVisitor); + // For_statementVisitor for_statementVisitor = new For_statementVisitor(); + // String for_statement_1 = + // ctx.for_statement() == null ? "" : ctx.for_statement().accept(for_statementVisitor); + // While_statementVisitor while_statementVisitor = new While_statementVisitor(); + // String while_statement_1 = + // ctx.while_statement() == null ? "" : ctx.while_statement().accept(while_statementVisitor); + // When_statementVisitor when_statementVisitor = new When_statementVisitor(); + // String when_statement_1 = + // ctx.when_statement() == null ? "" : ctx.when_statement().accept(when_statementVisitor); + // CommentVisitor commentVisitor = new CommentVisitor(); + // Comment comment_1 = ctx.comment().accept(commentVisitor); + // String comStr = String.valueOf(comment_1); + // StringBuilder temStr1 = new StringBuilder(); + // StringBuilder temStr2 = new StringBuilder(); + // StringBuilder temStr3 = new StringBuilder(); + // String temp1 = (expression_1 == null) ? "" : (temStr1.append("=").append(expression_1).toString()); + // String temp2 = (output_expression_list_1 == null) ? "" + // : (temStr2.append("(").append(output_expression_list_1).append(")").append(":=") + // .append(component_reference_1).append(" ").append(function_call_args_1) + // .toString()); + // String staStr = temStr3.append(component_reference_1).append(temp1).append(function_call_args_1) + // .append(temp2).append(bre_dec).append(ret_dec).append(if_statement_1) + // .append(for_statement_1).append(while_statement_1) + // .append(when_statement_1).append(comStr) + // .toString(); + // return staStr; + // //return new Statement(bre_dec, ret_dec, component_reference_1, expression_1, function_call_args_1, + // // output_expression_list_1, if_statement_1, for_statement_1, while_statement_1, when_statement_1, comment_1); + // } + // } + + // private static class If_equationVisitor extends modelicaBaseVisitor { + // @Override + // public String visitIf_equation(modelicaParser.If_equationContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new If_equation(expression1, equation1, expression2, equation2, equation3); + // } + // } + + // private static class If_statementVisitor extends modelicaBaseVisitor { + // @Override + // public String visitIf_statement(modelicaParser.If_statementContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new If_statement(expression1, statement1, expression2, statement2, statement3); + // } + // } + + // private static class For_equationVisitor extends modelicaBaseVisitor { + // @Override + // public String visitFor_equation(modelicaParser.For_equationContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new For_equation(for_indices_1, equation_1); + // } + // } + + // private static class For_statementVisitor extends modelicaBaseVisitor { + // @Override + // public String visitFor_statement(modelicaParser.For_statementContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new For_statement(for_indices_1, statement_1); + // } + // } + + // private static class For_indicesVisitor extends modelicaBaseVisitor { + // @Override + // public String visitFor_indices(modelicaParser.For_indicesContext ctx) { + // For_indexVisitor for_indexVisitor = new For_indexVisitor(); + // List for_index_1 = ctx.for_index() + // .stream() + // .map(for_index -> for_index.accept(for_indexVisitor)) + // .collect(toList()); + // StringBuilder temStr = new StringBuilder(); + // temStr.append(for_index_1.get(0)); + // if (for_index_1.size() > 1) { + // for (int i=1; i { + // @Override + // public String visitFor_index(modelicaParser.For_indexContext ctx) { + // String ident = ctx.IDENT().getText(); + // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + // String expression_1 = + // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + // StringBuilder temStr = new StringBuilder(); + // temStr.append(ident); + // if (expression_1 != null) { + // temStr.append(" in ").append(expression_1); + // } + // return temStr.toString(); + // //return new For_index(ident, expression_1); + // } + // } + + // private static class While_statementVisitor extends modelicaBaseVisitor { + // @Override + // public String visitWhile_statement(modelicaParser.While_statementContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new While_statement(expression_1, statement_1); + // } + // } + + // private static class When_equationVisitor extends modelicaBaseVisitor { + // @Override + // public String visitWhen_equation(modelicaParser.When_equationContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new When_equation(expression1, equation1, expression2, equation2); + // } + // } + + // private static class When_statementVisitor extends modelicaBaseVisitor { + // @Override + // public String visitWhen_statement(modelicaParser.When_statementContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new When_statement(expression1, statement1, expression2, statement2); + // } + // } + + // private static class Connect_clauseVisitor extends modelicaBaseVisitor { + // @Override + // public Connect_clause visitConnect_clause(modelicaParser.Connect_clauseContext ctx) { + // Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); + // List component_reference_1 = ctx.component_reference() + // .stream() + // .map(component_reference -> component_reference.accept(component_referenceVisitor)) + // .collect(toList()); + // return new Connect_clause(component_reference_1.get(0), component_reference_1.get(1)); + // } + // } + + // private static class ExpressionVisitor extends modelicaBaseVisitor { + // @Override + // public String visitExpression(modelicaParser.ExpressionContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new Expression(simple_expression_1, expression1, expression2, + // // expression3, expression4, expression5); + // } + // } + + // private static class Simple_expressionVisitor extends modelicaBaseVisitor { + // @Override + // public String visitSimple_expression(modelicaParser.Simple_expressionContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new Simple_expression(logical_expression1, logical_expression2, logical_expression3); + // } + // } + + // private static class Logical_expressionVisitor extends modelicaBaseVisitor { + // @Override + // public String visitLogical_expression(modelicaParser.Logical_expressionContext ctx) { + // List or_decs = ctx.OR() == null ? null : ctx.OR() + // .stream() + // .map(OR -> OR.getText()) + // .collect(toList()); + // Logical_termVisitor logical_termVisitor = new Logical_termVisitor(); + // List logical_terms = ctx.logical_term() + // .stream() + // .map(logical_term -> logical_term.accept(logical_termVisitor)) + // .collect(toList()); + // StringBuilder temStr = new StringBuilder(); + // temStr.append(logical_terms.get(0)); + // if (or_decs != null) { + // for (int i=0; i { + // @Override + // public String visitLogical_term(modelicaParser.Logical_termContext ctx) { + // List and_decs = ctx.AND() == null ? null : ctx.AND() + // .stream() + // .map(AND -> AND.getText()) + // .collect(toList()); + // Logical_factorVisitor logical_factorVisitor = new Logical_factorVisitor(); + // List logical_factors = ctx.logical_factor() + // .stream() + // .map(logical_factor -> logical_factor.accept(logical_factorVisitor)) + // .collect(toList()); + // StringBuilder temStr = new StringBuilder(); + // temStr.append(logical_factors.get(0)); + // if (and_decs != null) { + // for (int i=0; i { + // @Override + // public String visitLogical_factor(modelicaParser.Logical_factorContext ctx) { + // String not_dec = + // ctx.NOT() == null ? null : ctx.NOT().getText(); + // RelationVisitor relationVisitor = new RelationVisitor(); + // String relation = ctx.relation().accept(relationVisitor); + // StringBuilder temStr = new StringBuilder(); + // String logFacStr = (not_dec != null) ? (temStr.append(not_dec).append(" ").append(relation).toString()) + // : (relation); + // return logFacStr; + // //return new Logical_factor(not_dec, relation); + // } + // } + + // private static class RelationVisitor extends modelicaBaseVisitor { + // @Override + // public String visitRelation(modelicaParser.RelationContext ctx) { + // Arithmetic_expressionVisitor arithmetic_expressionVisitor = new Arithmetic_expressionVisitor(); + // List arithmetic_expressions = ctx.arithmetic_expression() + // .stream() + // .map(arithmetic_expression -> arithmetic_expression.accept(arithmetic_expressionVisitor)) + // .collect(toList()); + // Rel_opVisitor rel_opVisitor = new Rel_opVisitor(); + // String rel_op1 = + // ctx.rel_op() == null ? null : ctx.rel_op().accept(rel_opVisitor); + // StringBuilder temStr = new StringBuilder(); + // temStr.append(arithmetic_expressions.get(0)); + // if (rel_op1 != null) { + // temStr.append(rel_op1).append(arithmetic_expressions.get(1)); + // } + // return temStr.toString(); + // // return new Relation(arithmetic_expression1, rel_op1, arithmetic_expression2); + // } + // } + + // private static class Rel_opVisitor extends modelicaBaseVisitor { + // @Override + // public String visitRel_op(modelicaParser.Rel_opContext ctx) { + // String relOpe = ctx.getText(); + // return relOpe; + // //return new Rel_op(ope_dec); + // } + // } + + // private static class Arithmetic_expressionVisitor extends modelicaBaseVisitor { + // @Override + // public String visitArithmetic_expression(modelicaParser.Arithmetic_expressionContext ctx) { + // Add_opVisitor add_opVisitor = new Add_opVisitor(); + // List add_ops = ctx.add_op() == null ? null : ctx.add_op() + // .stream() + // .map(add_op -> add_op.accept(add_opVisitor)) + // .collect(toList()); + // TermVisitor termVisitor = new TermVisitor(); + // List terms = ctx.term() + // .stream() + // .map(term -> term.accept(termVisitor)) + // .collect(toList()); + // StringBuilder temStr = new StringBuilder(); + // if (add_ops.size() == terms.size()) { + // for (int i=0; i { + // @Override + // public String visitAdd_op(modelicaParser.Add_opContext ctx) { + // String addOpe = ctx.getText(); + // return addOpe; + // //return new Add_op(add_dec); + // } + // } + + // private static class TermVisitor extends modelicaBaseVisitor { + // @Override + // public String visitTerm(modelicaParser.TermContext ctx) { + // Mul_opVisitor mul_opVisitor = new Mul_opVisitor(); + // List mul_op_1 = ctx.mul_op() == null ? null : ctx.mul_op() + // .stream() + // .map(mul_op -> mul_op.accept(mul_opVisitor)) + // .collect(toList()); + // FactorVisitor factorVisitor = new FactorVisitor(); + // List factors = ctx.factor() + // .stream() + // .map(factor -> factor.accept(factorVisitor)) + // .collect(toList()); + // StringBuilder temStr = new StringBuilder(); + // temStr.append(factors.get(0)); + // if (mul_op_1 != null) { + // for (int i=0; i { + // @Override + // public String visitMul_op(modelicaParser.Mul_opContext ctx) { + // String mulOpe = ctx.getText(); + // return mulOpe; + // //return new Mul_op(mul_dec); + // } + // } + + // private static class FactorVisitor extends modelicaBaseVisitor { + // @Override + // public String visitFactor(modelicaParser.FactorContext ctx) { + // PrimaryVisitor primaryVisitor = new PrimaryVisitor(); + // List primarys = ctx.primary() + // .stream() + // .map(primary -> primary.accept(primaryVisitor)) + // .collect(toList()); + // String caret = + // ctx.SYMBOL_CARET()==null ? null : ctx.SYMBOL_CARET().getText(); + // String dotCaret = + // ctx.SYMBOL_DOTCARET()==null ? null : ctx.SYMBOL_DOTCARET().getText(); + // String facStr = primarys.get(0); + // if (primarys.size()>1) { + // StringBuilder temStr = new StringBuilder(); + // if (caret != null) { + // facStr = temStr.append(primarys.get(0)).append(caret) + // .append(primarys.get(1)) + // .toString(); + // } else { + // facStr = temStr.append(primarys.get(0)).append(dotCaret) + // .append(primarys.get(1)) + // .toString(); + // } + // } + // return facStr; + // // return new Factor(primarys, caret, dotCaret); + // } + // } + + // private static class PrimaryVisitor extends modelicaBaseVisitor { + // @Override + // public String visitPrimary(modelicaParser.PrimaryContext ctx) { + // String num_dec = + // ctx.UNSIGNED_NUMBER() == null ? null : ctx.UNSIGNED_NUMBER().getText(); + // String str_dec = + // ctx.STRING() == null ? null : ctx.STRING().getText(); + // String false_dec = + // ctx.FALSE() == null ? null : ctx.FALSE().getText(); + // String true_dec = + // ctx.TRUE() == null ? null : ctx.TRUE().getText(); + // String der_der = + // ctx.DER() == null ? null : ctx.DER().getText(); + // String init_dec = + // ctx.INITIAL() == null ? null : ctx.INITIAL().getText(); + // String end_dec = + // ctx.END() == null ? null : ctx.END().getText(); + // NameVisitor nameVisitor = new NameVisitor(); + // String name1 = + // ctx.name() == null ? null : ctx.name().accept(nameVisitor); + // Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); + // String function_call_args1 = + // ctx.function_call_args() == null ? null : ctx.function_call_args().accept(function_call_argsVisitor); + // Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); + // String component_reference1 = + // ctx.component_reference() == null ? null : ctx.component_reference().accept(component_referenceVisitor); + // Output_expression_listVisitor output_expression_listVisitor = new Output_expression_listVisitor(); + // String output_expression_list1 = + // ctx.output_expression_list() == null ? null : ctx.output_expression_list().accept(output_expression_listVisitor); + // Expression_listVisitor expression_listVisitor = new Expression_listVisitor(); + // List expression_list_1 = ctx.expression_list() == null ? null : ctx.expression_list() + // .stream() + // .map(expression_list -> expression_list.accept(expression_listVisitor)) + // .collect(toList()); + // List semiColon = ctx.SYMBOL_SEMICOLON() == null ? null : ctx.SYMBOL_SEMICOLON() + // .stream() + // .map(SYMBOL_SEMICOLON -> SYMBOL_SEMICOLON.getText()) + // .collect(toList()); + // Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); + // String function_arguments1 = + // ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); + // StringBuilder temStr = new StringBuilder(); + // String priStr = num_dec; + // if (str_dec != null) {priStr = str_dec;} + // else if (false_dec != null) {priStr = false_dec;} + // else if (true_dec != null) {priStr = true_dec;} + // else if (function_call_args1 != null) { + // if (name1 != null) { + // priStr = temStr.append(name1).append(" ").append(function_call_args1).toString();} + // else if (der_der != null) { + // priStr = temStr.append(der_der).append(" ").append(function_call_args1).toString();} + // else { + // priStr = temStr.append(init_dec).append(" ").append(function_call_args1).toString();} + // } + // else if (component_reference1 != null) { + // priStr = component_reference1;} + // else if (output_expression_list1 != null) { + // priStr = temStr.append("(").append(output_expression_list1).append(")").toString();} + // else if (expression_list_1.size() > 0 ) { + // temStr.append(expression_list_1.get(0)); + // if (semiColon != null) { + // for (int i=0; i { + // @Override + // public String visitName(modelicaParser.NameContext ctx) { + // List dots = ctx.SYMBOL_DOT()==null ? null : ctx.SYMBOL_DOT() + // .stream() + // .map(SYMBOL_DOT -> SYMBOL_DOT.getText()) + // .collect(toList()); + // List ident = ctx.IDENT() + // .stream() + // .map(IDENT -> IDENT.getText()) + // .collect(toList()); + // StringBuilder temStr = new StringBuilder(); + // if (dots == null) { + // temStr.append(ident.get(0)); + // } else { + // if (dots.size() == ident.size()) { + // for (int i=0; i { + // @Override + // public String visitComponent_reference(modelicaParser.Component_referenceContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // // return new Component_reference(ident, dots, array_subscripts_1); + // } + // } + + // private static class Function_call_argsVisitor extends modelicaBaseVisitor { + // @Override + // public String visitFunction_call_args(modelicaParser.Function_call_argsContext ctx) { + // Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); + // String function_arguments = + // ctx.function_arguments() == null ? "" : ctx.function_arguments().accept(function_argumentsVisitor); + // StringBuilder temStr = new StringBuilder(); + // String funCalArgs = temStr.append("(").append(function_arguments).append(")") + // .toString(); + // return funCalArgs; + // //return new Function_call_args(function_arguments); + // } + // } + + // private static class Function_argumentsVisitor extends modelicaBaseVisitor { + // @Override + // public String visitFunction_arguments(modelicaParser.Function_argumentsContext ctx) { + // Function_argumentVisitor function_argumentVisitor = new Function_argumentVisitor(); + // String function_argument = + // ctx.function_argument() == null ? null : ctx.function_argument().accept(function_argumentVisitor); + // Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); + // String function_arguments = + // ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); + // String for_dec = + // ctx.FOR() == null ? null : ctx.FOR().getText(); + // For_indicesVisitor for_indicesVisitor = new For_indicesVisitor(); + // String for_indices = + // ctx.for_indices() == null ? null : ctx.for_indices().accept(for_indicesVisitor); + // Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); + // String named_arguments = + // ctx.named_arguments() == null ? null : ctx.named_arguments().accept(named_argumentsVisitor); + // String funArgsStr = named_arguments; + // if (function_argument != null) { + // StringBuilder temStr1 = new StringBuilder(); + // if (function_arguments != null) { + // temStr1.append(",").append(function_arguments); + // } else if (for_indices != null) { + // temStr1.append("for ").append(for_indices); + // } + // StringBuilder temStr2 = new StringBuilder(); + // funArgsStr = temStr2.append(function_argument) + // .append(temStr1.toString()) + // .toString(); + // } + // return funArgsStr; + // //return new Function_arguments(function_argument, function_arguments, for_dec, for_indices, named_arguments); + // } + // } + + // private static class Named_argumentsVisitor extends modelicaBaseVisitor { + // @Override + // public String visitNamed_arguments(modelicaParser.Named_argumentsContext ctx) { + // Named_argumentVisitor named_argumentVisitor = new Named_argumentVisitor(); + // String named_argument = + // ctx.named_argument().accept(named_argumentVisitor); + // Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); + // String named_arguments = + // ctx.named_arguments() == null ? null : ctx.named_arguments().accept(named_argumentsVisitor); + // String comma = + // ctx.SYMBOL_COMMA()==null ? null : ctx.SYMBOL_COMMA().getText(); + // String namedArgsStr = named_argument; + // if (comma != null) { + // StringBuilder temStr = new StringBuilder(); + // namedArgsStr = temStr.append(namedArgsStr).append(",") + // .append(named_arguments) + // .toString(); + // } + // return namedArgsStr; + // //return new Named_arguments(named_argument,named_arguments); + // } + // } + + // private static class Named_argumentVisitor extends modelicaBaseVisitor { + // @Override + // public String visitNamed_argument(modelicaParser.Named_argumentContext ctx) { + // String ident = ctx.IDENT().getText(); + // Function_argumentVisitor function_argumentVisitor = new Function_argumentVisitor(); + // String function_argument = + // ctx.function_argument().accept(function_argumentVisitor); + // StringBuilder temStr = new StringBuilder(); + // String namedArgStr = temStr.append(ident).append("=") + // .append(function_argument) + // .toString(); + // return namedArgStr; + // //return new Named_argument(ident, function_argument); + // } + // } + + // private static class Function_argumentVisitor extends modelicaBaseVisitor { + // @Override + // public String visitFunction_argument(modelicaParser.Function_argumentContext ctx) { + // String fun_dec = + // ctx.FUNCTION() == null ? null : ctx.FUNCTION().getText(); + // NameVisitor nameVisitor = new NameVisitor(); + // String name = + // ctx.name() == null ? null : ctx.name().accept(nameVisitor); + // Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); + // String named_arguments = + // ctx.named_arguments() == null ? "" : ctx.named_arguments().accept(named_argumentsVisitor); + // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + // String expression = + // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + // String funArgStr = expression; + // if (fun_dec != null) { + // StringBuilder temStr = new StringBuilder(); + // funArgStr = temStr.append(fun_dec).append(" ").append(name) + // .append("(").append(named_arguments).append(")") + // .toString(); + // } + // return funArgStr; + // //return new Function_argument(fun_dec, name, named_arguments, expression); + // } + // } + + // private static class Output_expression_listVisitor extends modelicaBaseVisitor { + // @Override + // public String visitOutput_expression_list(modelicaParser.Output_expression_listContext ctx) { + // String temStr = ""; + // if (ctx.getText().isEmpty()) { + // temStr = null; + // } else { + // int a = ctx.start.getStartIndex(); + // int b = ctx.stop.getStopIndex(); + // Interval interval = new Interval(a,b); + // CharStream charStr = ctx.start.getInputStream(); + // temStr = charStr.getText(interval).trim(); + // } + // return temStr; + // //return new Output_expression_list(expression_1); + // } + // } + + // private static class Expression_listVisitor extends modelicaBaseVisitor { + // @Override + // public String visitExpression_list(modelicaParser.Expression_listContext ctx) { + // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + // List expression_1 = ctx.expression() + // .stream() + // .map(expression -> expression.accept(expressionVisitor)) + // .collect(toList()); + // StringBuilder temStr = new StringBuilder(); + // temStr.append(expression_1.get(0)); + // if (expression_1.size()>1) { + // for (int i=1; i { + // @Override + // public String visitArray_subscripts(modelicaParser.Array_subscriptsContext ctx) { + // SubscriptVisitor subscriptVisitor = new SubscriptVisitor(); + // List subscript_1 = ctx.subscript() + // .stream() + // .map(subscript -> subscript.accept(subscriptVisitor)) + // .collect(toList()); + // StringBuilder temStr1 = new StringBuilder(); + // String arraySubStr = temStr1.append("[") + // .append(subscript_1.get(0)) + // .append("]") + // .toString(); + // if (subscript_1.size() > 1) { + // StringBuilder temStr2 = new StringBuilder(); + // temStr2.append(subscript_1.get(0)); + // for (int i=1; i { + // @Override + // public String visitSubscript(modelicaParser.SubscriptContext ctx) { + // String colon = + // ctx.SYMBOL_COLON() == null ? null : ctx.SYMBOL_COLON().getText(); + // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + // String expression = + // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + // String subStr = + // colon != null ? colon : expression; + // return subStr; + // //return new Subscript(expression); + // } + // } + + // public static class CommentVisitor extends modelicaBaseVisitor { + // String string_comment1; + // String annotation1; + // @Override + // public Comment visitComment(modelicaParser.CommentContext ctx) { + // String_commentVisitor string_commentVisitor = new String_commentVisitor(); + // String string_comment1 = + // ctx.string_comment() == null ? null : ctx.string_comment().accept(string_commentVisitor); + // AnnotationVisitor annotationVisitor = new AnnotationVisitor(); + // String annotation1 = + // ctx.annotation() == null ? null : ctx.annotation().accept(annotationVisitor); + // this.string_comment1 = string_comment1; + // this.annotation1 = annotation1; + // return new Comment(string_comment1, annotation1); + // } + // } + + // public static class String_commentVisitor extends modelicaBaseVisitor { + // @Override + // public String visitString_comment(modelicaParser.String_commentContext ctx) { + // List str_dec = ctx.STRING() == null ? null : ctx.STRING() + // .stream() + // .map(STRING -> STRING.getText()) + // .collect(toList()); + // String strCom = ""; + // if (str_dec.size() == 1) { + // strCom = str_dec.get(0); + // } else if (str_dec.size() > 1) { + // StringBuilder temStr = new StringBuilder(); + // temStr.append(str_dec.get(0)); + // for (int i=1; i { + // @Override + // public String visitAnnotation(modelicaParser.AnnotationContext ctx) { + // String ann_dec = ctx.ANNOTATION().getText(); + // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); + // String class_modification = ctx.class_modification().accept(class_modificationVisitor); + // return class_modification; + // //return new Annotation(ann_dec, class_modification); + // } + // } } diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/When_equationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/When_equationVisitor.java new file mode 100644 index 00000000..0fe3c96a --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/When_equationVisitor.java @@ -0,0 +1,39 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Equation; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.When_elsewhen_equation; +import gov.lbl.parser.domain.When_equation; + +import static java.util.stream.Collectors.toList; + +import java.util.ArrayList; + +public class When_equationVisitor extends modelicaBaseVisitor { + @Override + public When_equation visitWhen_equation(modelicaParser.When_equationContext ctx) { + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + List expressions = ctx.expression() == null ? null : ctx.expression() + .stream() + .map(expr -> expr.accept(expressionVisitor)) + .collect(toList()); + EquationVisitor equationVisitor = new EquationVisitor(); + List equations = ctx.equation() == null ? null : ctx.equation() + .stream() + .map(eqn -> eqn.accept(equationVisitor)) + .collect(toList()); + + List when_elsewhen = new ArrayList(); + for (int i = 0; i< expressions.size(); i++) { + + //check? + when_elsewhen.add(new When_elsewhen_equation(expressions.get(i), equations.subList(i, i+1))); + } + + return new When_equation(when_elsewhen); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/When_statementVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/When_statementVisitor.java new file mode 100644 index 00000000..0db6f5c4 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/When_statementVisitor.java @@ -0,0 +1,39 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Statement; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.When_elsewhen_statement; +import gov.lbl.parser.domain.When_statement; + +import static java.util.stream.Collectors.toList; + +import java.util.ArrayList; + +public class When_statementVisitor extends modelicaBaseVisitor { + @Override + public When_statement visitWhen_statement(modelicaParser.When_statementContext ctx) { + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + List expressions = ctx.expression() == null ? null : ctx.expression() + .stream() + .map(expr -> expr.accept(expressionVisitor)) + .collect(toList()); + StatementVisitor statementVisitor = new StatementVisitor(); + List statements = ctx.statement() == null ? null : ctx.statement() + .stream() + .map(stmt -> stmt.accept(statementVisitor)) + .collect(toList()); + + List when_elsewhen = new ArrayList(); + for (int i = 0; i< expressions.size(); i++) { + + //check? + when_elsewhen.add(new When_elsewhen_statement(expressions.get(i), statements.subList(i, i+1))); + } + + return new When_statement(when_elsewhen); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/While_statementVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/While_statementVisitor.java new file mode 100644 index 00000000..e05f620c --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/While_statementVisitor.java @@ -0,0 +1,26 @@ +package gov.lbl.parser.parser; + +import java.util.List; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.Statement; +import gov.lbl.parser.domain.While_statement; + +import static java.util.stream.Collectors.toList; + +public class While_statementVisitor extends modelicaBaseVisitor { + @Override + public While_statement visitWhile_statement(modelicaParser.While_statementContext ctx) { + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + Expression expression = ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + + StatementVisitor statementVisitor = new StatementVisitor(); + List loop_statements = ctx.statement() == null ? null : ctx.statement() + .stream() + .map(stmt -> stmt.accept(statementVisitor)) + .collect(toList()); + return new While_statement(expression, loop_statements); + } +} \ No newline at end of file From 25ab1d7c29bc79c20f25fb3f067f679e5f30722a Mon Sep 17 00:00:00 2001 From: Anand Krishnan Prakash Date: Fri, 11 Jun 2021 16:36:00 -0700 Subject: [PATCH 03/29] completed updated raw-json parser --- .../src/main/java/gov/lbl/parser/Main.java | 2 - .../lbl/parser/domain/Function_argument.java | 4 +- .../lbl/parser/domain/Function_arguments.java | 4 +- .../lbl/parser/domain/If_elseif_equation.java | 8 + .../parser/domain/If_elseif_statement.java | 8 + .../lbl/parser/domain/Named_arguments.java | 15 + .../parser/Arithmetic_expressionVisitor.java | 2 +- .../parser/Component_referenceVisitor.java | 75 +- .../lbl/parser/parser/CompositionVisitor.java | 32 +- .../lbl/parser/parser/ExpressionVisitor.java | 11 +- .../parser/parser/Expression_listVisitor.java | 22 + .../gov/lbl/parser/parser/FactorVisitor.java | 6 +- .../parser/Function_argumentVisitor.java | 24 + .../parser/Function_argumentsVisitor.java | 27 + .../parser/Function_call_argsVisitor.java | 15 + .../lbl/parser/parser/If_equationVisitor.java | 62 +- .../parser/parser/If_statementVisitor.java | 76 +- .../parser/parser/Named_argumentVisitor.java | 16 + .../parser/parser/Named_argumentsVisitor.java | 19 + .../parser/Output_expression_listVisitor.java | 22 + .../parser/Simple_expressionVisitor.java | 11 +- .../parser/Stored_definitionVisitor.java | 1 - .../parser/parser/VisitorOrientedParser.java | 1790 +---------------- 23 files changed, 398 insertions(+), 1854 deletions(-) create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Named_arguments.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Expression_listVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Function_argumentVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Function_argumentsVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Function_call_argsVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Named_argumentVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Named_argumentsVisitor.java create mode 100644 java/parser/src/main/java/gov/lbl/parser/parser/Output_expression_listVisitor.java diff --git a/java/parser/src/main/java/gov/lbl/parser/Main.java b/java/parser/src/main/java/gov/lbl/parser/Main.java index 45ce4b03..07423143 100644 --- a/java/parser/src/main/java/gov/lbl/parser/Main.java +++ b/java/parser/src/main/java/gov/lbl/parser/Main.java @@ -14,8 +14,6 @@ import java.nio.file.Path; import java.util.List; import java.util.ArrayList; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class Main { List sumResults; diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Function_argument.java b/java/parser/src/main/java/gov/lbl/parser/domain/Function_argument.java index 1b8a3737..cfbbc8f3 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Function_argument.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Function_argument.java @@ -4,10 +4,10 @@ public class Function_argument { private Name function_name; - private Collection named_arguments; + private Named_arguments named_arguments; private Expression expression; - public Function_argument(Name function_name, Collection named_arguments, Expression expression) { + public Function_argument(Name function_name, Named_arguments named_arguments, Expression expression) { this.function_name = function_name; this.named_arguments = named_arguments; this.expression = expression; diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Function_arguments.java b/java/parser/src/main/java/gov/lbl/parser/domain/Function_arguments.java index 99fb7a33..d6754a70 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Function_arguments.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Function_arguments.java @@ -3,12 +3,12 @@ import java.util.Collection; public class Function_arguments { - private Collection named_arguments; + private Named_arguments named_arguments; private Function_argument function_argument; private For_indices for_indices; private Function_arguments function_arguments; - public Function_arguments(Collection named_arguments, Function_argument function_argument, For_indices for_indices, Function_arguments function_arguments) { + public Function_arguments(Named_arguments named_arguments, Function_argument function_argument, For_indices for_indices, Function_arguments function_arguments) { this.named_arguments = named_arguments; this.function_argument = function_argument; this.for_indices = for_indices; diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_equation.java b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_equation.java index 2117ff1f..471344cf 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_equation.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_equation.java @@ -10,4 +10,12 @@ public If_elseif_equation(Expression condition, Collection then) { this.condition = condition; this.then = then; } + + public Collection getThen() { + return this.then; + } + + public Expression getCondition() { + return this.condition; + } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_statement.java b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_statement.java index 2f225f67..dd680a5c 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_statement.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/If_elseif_statement.java @@ -10,4 +10,12 @@ public If_elseif_statement(Expression condition, Collection then) { this.condition = condition; this.then = then; } + + public Expression getCondition() { + return this.condition; + } + + public Collection getThen() { + return this.then; + } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Named_arguments.java b/java/parser/src/main/java/gov/lbl/parser/domain/Named_arguments.java new file mode 100644 index 00000000..e41918a8 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Named_arguments.java @@ -0,0 +1,15 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Named_arguments { + + private Named_argument named_argument; + private Named_arguments named_arguments; + + public Named_arguments(Named_argument named_argument, Named_arguments named_arguments) { + this.named_argument = named_argument; + this.named_arguments = named_arguments; + } + +} diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java index 9168624a..a279f475 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java @@ -31,7 +31,7 @@ public Arithmetic_expression visitArithmetic_expression(modelicaParser.Arithmeti arithmetic_term_list.add(new Arithmetic_term(null, terms.get(0))); } for (int i=0; i { +import static java.util.stream.Collectors.toList; + +import java.util.ArrayList; +import java.util.List; + +public class Component_referenceVisitor extends modelicaBaseVisitor { @Override - public String visitComponent_reference(modelicaParser.Component_referenceContext ctx) { - String temStr = ""; - if (ctx.getText().isEmpty()) { - temStr = null; - } else { - int a = ctx.start.getStartIndex(); - int b = ctx.stop.getStopIndex(); - Interval interval = new Interval(a,b); - CharStream charStr = ctx.start.getInputStream(); - temStr = charStr.getText(interval).trim(); - } - return temStr; - // return new Component_reference(ident, dots, array_subscripts_1); + public Component_reference visitComponent_reference(modelicaParser.Component_referenceContext ctx) { + List identifiers = ctx.IDENT() == null ? null : ctx.IDENT() + .stream() + .map(identifier -> identifier.getText()) + .collect(toList()); + + Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); + List array_subscripts_list = ctx.array_subscripts() == null ? null : ctx.array_subscripts() + .stream() + .map(array_subscripts -> array_subscripts.accept(array_subscriptsVisitor)) + .collect(toList()); + + List array_subscripts_exists = new ArrayList<>(); + + Boolean first_dot = false; + String context_str = ctx.getText(); + if (ctx.getText().charAt(0) == '.') { + first_dot = true; + context_str = context_str.substring(1); + } + + String[] comp_refs = context_str.split("\\."); + for (int i=0; i component_reference_parts = new ArrayList(); + int array_sbuscript_index = 0; + for(int i=0;i0 && comp_refs.length > 1) { + dot_op = true; + } + + Array_subscripts array_subscripts = null; + if (array_subscripts_exists.get(i)) { + array_subscripts = array_subscripts_list.get(array_sbuscript_index); + array_sbuscript_index+=1; + } + component_reference_parts.add(new Component_reference_part(dot_op, identifier, array_subscripts)); + } + return new Component_reference(component_reference_parts); } } \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java index 88ae2244..37014dc2 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java @@ -14,9 +14,25 @@ import static java.util.stream.Collectors.toList; +import java.util.ArrayList; + public class CompositionVisitor extends modelicaBaseVisitor { @Override public Composition visitComposition(modelicaParser.CompositionContext ctx) { + List element_lists_types = new ArrayList(); + element_lists_types.add("None"); + + for (int i=1; i PROTECTED.getText()) .collect(toList()); + + List public_element_lists = public_dec.size() == 0 ? null : new ArrayList(); + List protected_element_lists = protected_dec.size() == 0 ? null : new ArrayList(); + + for(int i=1; i public_element_lists = public_dec.size() == 0 ? null : element_lists.subList(1, public_dec.size()); - List protected_element_lists = protected_dec.size() == 0 ? null : element_lists.subList(1+public_dec.size(), - 1+public_dec.size()+protected_dec.size()); List equation_sections = ctx.equation_section() == null ? null : ctx.equation_section() .stream() .map(equation_section -> equation_section.accept(equation_sectionVisitor)) diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java index 0f8960a4..da45a9e2 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java @@ -24,16 +24,21 @@ public Expression visitExpression(modelicaParser.ExpressionContext ctx) { .stream() .map(expr -> expr.accept(expressionVisitor)) .collect(toList()); + If_expression if_expression = null; + List if_elseif = new ArrayList(); for (int i = 0; i 2) { + // expressions always have else? + Expression else_expression = expressions.get(expressions.size()-1); - If_expression if_expression = new If_expression(if_elseif, else_expression); + if_expression = new If_expression(if_elseif, else_expression); + } + return new Expression(simple_expression, if_expression); } } diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Expression_listVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Expression_listVisitor.java new file mode 100644 index 00000000..9ba59288 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Expression_listVisitor.java @@ -0,0 +1,22 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.Expression_list; + +import static java.util.stream.Collectors.toList; + +import java.util.List; + +public class Expression_listVisitor extends modelicaBaseVisitor { + @Override + public Expression_list visitExpression_list(modelicaParser.Expression_listContext ctx) { + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + List expressions = ctx.expression() == null ? null : ctx.expression() + .stream() + .map(expression -> expression.accept(expressionVisitor)) + .collect(toList()); + return new Expression_list(expressions); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java index ab8bd34e..e962c0ee 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java @@ -19,10 +19,10 @@ public Factor visitFactor(modelicaParser.FactorContext ctx) { .collect(toList()); String op = - ctx.SYMBOL_CARET()==null ? ctx.SYMBOL_DOTCARET().getText() : ctx.SYMBOL_CARET().getText(); - + ctx.SYMBOL_CARET()==null ? ( ctx.SYMBOL_DOTCARET() == null ? "" : ctx.SYMBOL_DOTCARET().getText()) + : ctx.SYMBOL_CARET().getText(); Primary primary1 = primarys.get(0); - Primary primary2 = primarys.get(1); + Primary primary2 = primarys.size() == 2 ? primarys.get(1) : null; return new Factor(primary1, op, primary2); } diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Function_argumentVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Function_argumentVisitor.java new file mode 100644 index 00000000..ffb11cdd --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Function_argumentVisitor.java @@ -0,0 +1,24 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.Function_argument; +import gov.lbl.parser.domain.Name; +import gov.lbl.parser.domain.Named_arguments; + +public class Function_argumentVisitor extends modelicaBaseVisitor { + @Override + public Function_argument visitFunction_argument(modelicaParser.Function_argumentContext ctx) { + NameVisitor nameVisitor = new NameVisitor(); + Name function_name = ctx.name() == null? null : ctx.name().accept(nameVisitor); + + Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); + Named_arguments named_arguments = ctx.named_arguments() == null ? null : ctx.named_arguments().accept(named_argumentsVisitor); + + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + Expression expression = ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); + + return new Function_argument(function_name, named_arguments, expression); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Function_argumentsVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Function_argumentsVisitor.java new file mode 100644 index 00000000..1128653b --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Function_argumentsVisitor.java @@ -0,0 +1,27 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.For_indices; +import gov.lbl.parser.domain.Function_argument; +import gov.lbl.parser.domain.Function_arguments; +import gov.lbl.parser.domain.Named_arguments; + +public class Function_argumentsVisitor extends modelicaBaseVisitor { + @Override + public Function_arguments visitFunction_arguments(modelicaParser.Function_argumentsContext ctx) { + Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); + Named_arguments named_arguments = ctx.named_arguments() == null ? null : ctx.named_arguments().accept(named_argumentsVisitor); + + Function_argumentVisitor function_argumentVisitor = new Function_argumentVisitor(); + Function_argument function_argument = ctx.function_argument() == null ? null : ctx.function_argument().accept(function_argumentVisitor); + + Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); + Function_arguments function_arguments = ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); + + For_indicesVisitor for_indicesVisitor = new For_indicesVisitor(); + For_indices for_indices = ctx.for_indices() == null ? null : ctx.for_indices().accept(for_indicesVisitor); + + return new Function_arguments(named_arguments, function_argument, for_indices, function_arguments); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Function_call_argsVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Function_call_argsVisitor.java new file mode 100644 index 00000000..4cf4e9f1 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Function_call_argsVisitor.java @@ -0,0 +1,15 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Function_arguments; +import gov.lbl.parser.domain.Function_call_args; + +public class Function_call_argsVisitor extends modelicaBaseVisitor { + @Override + public Function_call_args visitFunction_call_args(modelicaParser.Function_call_argsContext ctx) { + Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); + Function_arguments function_arguments = ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); + return new Function_call_args(function_arguments); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/If_equationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/If_equationVisitor.java index 1ad15865..80315a0b 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/If_equationVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/If_equationVisitor.java @@ -6,10 +6,13 @@ import gov.lbl.antlr4.visitor.modelicaParser; import gov.lbl.parser.domain.Equation; import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.If_elseif_equation; import gov.lbl.parser.domain.If_equation; import static java.util.stream.Collectors.toList; +import java.util.ArrayList; + public class If_equationVisitor extends modelicaBaseVisitor { @Override public If_equation visitIf_equation(modelicaParser.If_equationContext ctx) { @@ -23,24 +26,47 @@ public If_equation visitIf_equation(modelicaParser.If_equationContext ctx) { .stream() .map(equation -> equation.accept(equationVisitor)) .collect(toList()); - Boolean else_condition = ctx.ELSE() == null ? false : true; - Equation else_equation = null; - if (else_condition) { - else_equation = equations.get(equations.size() - 1); - } - - // List if_elseif = new ArrayList<>(); + List else_equation = null; + while (i then = equations.subList(equation_idx, equation_idx + (end_idx-start_idx)/2); + if_elseif.add(new If_elseif_equation(condition, then)); + equation_idx = equation_idx + (end_idx-start_idx)/2; + i=end_idx; + } + else if (ctx.getChild(i).getText().equals("else")) { + int start_idx = i+1; + int end_idx = start_idx; + for (int j=start_idx; j { +import java.util.ArrayList; + +public class If_statementVisitor extends modelicaBaseVisitor { @Override - public String visitIf_statement(modelicaParser.If_statementContext ctx) { - - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } + public If_statement visitIf_statement(modelicaParser.If_statementContext ctx) { + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + List expressions = ctx.expression() == null ? null : ctx.expression() + .stream() + .map(condition -> condition.accept(expressionVisitor)) + .collect(toList()); + StatementVisitor statementVisitor = new StatementVisitor(); + List statements = ctx.statement() == null ? null : ctx.statement() + .stream() + .map(statement -> statement.accept(statementVisitor)) + .collect(toList()); + + int i=0; + int expression_idx = 0; + int statement_idx = 0; + List if_elseif = new ArrayList<>(); + List else_statement = null; + while (i then = statements.subList(statement_idx, statement_idx + (end_idx-start_idx)/2); + if_elseif.add(new If_elseif_statement(condition, then)); + statement_idx = statement_idx + (end_idx-start_idx)/2; + i=end_idx; + } + else if (ctx.getChild(i).getText().equals("else")) { + int start_idx = i+1; + int end_idx = start_idx; + for (int j=start_idx; j { + @Override + public Named_argument visitNamed_argument(modelicaParser.Named_argumentContext ctx) { + String identifier = ctx.IDENT() == null? "" : ctx.IDENT().getText(); + Function_argumentVisitor function_argumentVisitor = new Function_argumentVisitor(); + Function_argument value = ctx.function_argument().accept(function_argumentVisitor); + return new Named_argument(identifier, value); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Named_argumentsVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Named_argumentsVisitor.java new file mode 100644 index 00000000..1af86ed1 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Named_argumentsVisitor.java @@ -0,0 +1,19 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Named_argument; +import gov.lbl.parser.domain.Named_arguments; + +public class Named_argumentsVisitor extends modelicaBaseVisitor { + @Override + public Named_arguments visitNamed_arguments(modelicaParser.Named_argumentsContext ctx) { + Named_argumentVisitor named_argumentVisitor = new Named_argumentVisitor(); + Named_argument named_argument = ctx.named_argument() == null ? null : ctx.named_argument().accept(named_argumentVisitor); + + Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); + Named_arguments named_arguments = ctx.named_arguments() == null ? null : ctx.named_arguments().accept(named_argumentsVisitor); + + return new Named_arguments(named_argument, named_arguments); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Output_expression_listVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Output_expression_listVisitor.java new file mode 100644 index 00000000..eba17fc9 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Output_expression_listVisitor.java @@ -0,0 +1,22 @@ +package gov.lbl.parser.parser; + +import gov.lbl.antlr4.visitor.modelicaBaseVisitor; +import gov.lbl.antlr4.visitor.modelicaParser; +import gov.lbl.parser.domain.Expression; +import gov.lbl.parser.domain.Output_expression_list; + +import static java.util.stream.Collectors.toList; + +import java.util.List; + +public class Output_expression_listVisitor extends modelicaBaseVisitor { + @Override + public Output_expression_list visitOutput_expression_list(modelicaParser.Output_expression_listContext ctx) { + ExpressionVisitor expressionVisitor = new ExpressionVisitor(); + List output_expressions = ctx.expression() == null ? null : ctx.expression() + .stream() + .map(expression -> expression.accept(expressionVisitor)) + .collect(toList()); + return new Output_expression_list(output_expressions); + } +} \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Simple_expressionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Simple_expressionVisitor.java index 9421733c..30ec3cd3 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Simple_expressionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Simple_expressionVisitor.java @@ -19,9 +19,14 @@ public Simple_expression visitSimple_expression(modelicaParser.Simple_expression .collect(toList()); Logical_expression logical_expression1 = logical_expressions.get(0); - Logical_expression logical_expression2 = logical_expressions.get(1); - Logical_expression logical_expression3 = logical_expressions.get(2); - + Logical_expression logical_expression2 = null; + Logical_expression logical_expression3 = null; + if (logical_expressions.size() > 1) { + logical_expression2 = logical_expressions.get(1); + } + if (logical_expressions.size() > 2) { + logical_expression3 = logical_expressions.get(2); + } return new Simple_expression(logical_expression1, logical_expression2, logical_expression3); } } \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java index 0f27da40..8b429639 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java @@ -15,7 +15,6 @@ public class Stored_definitionVisitor extends modelicaBaseVisitor names = ctx.name().stream().map(name -> nameVisitor.visitName(name)).collect(toList()); - System.out.println(names.get(0)); Name name = names.get(0); String within = name.getName(); diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/VisitorOrientedParser.java b/java/parser/src/main/java/gov/lbl/parser/parser/VisitorOrientedParser.java index aa3c1e14..9d5cd560 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/VisitorOrientedParser.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/VisitorOrientedParser.java @@ -1,6 +1,5 @@ package gov.lbl.parser.parser; -import gov.lbl.antlr4.visitor.modelicaBaseVisitor; import gov.lbl.antlr4.visitor.modelicaLexer; import gov.lbl.antlr4.visitor.modelicaParser; @@ -10,13 +9,6 @@ import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.misc.Interval; - -import java.util.List; -import java.util.stream.Collectors; - -import static java.util.stream.Collectors.toList; -import java.util.ArrayList; public class VisitorOrientedParser implements Parser { @@ -28,1786 +20,6 @@ public Stored_definition parse(String modelicaSourceCode) { Stored_definitionVisitor stored_definitionVisitor = new Stored_definitionVisitor(); Stored_definition traverseResult = stored_definitionVisitor.visitStored_definition(parser.stored_definition()); - System.out.println("output = "); - System.out.println(traverseResult); - return null; + return traverseResult; } - - // private static class Stored_definitionVisitor extends modelicaBaseVisitor { - // @Override - // public Stored_definition visitStored_definition(modelicaParser.Stored_definitionContext ctx) { - // List within_dec = ctx.WITHIN() == null ? null : ctx.WITHIN() - // .stream() - // .map(WITHIN -> WITHIN.getText()) - // .collect(toList()); - // NameVisitor nameVisitor = new NameVisitor(); - // List names = ctx.name() == null ? null : ctx.name() - // .stream() - // .map(name -> name.accept(nameVisitor)) - // .collect(toList()); - // List final_dec = ctx.FINAL() == null ? null : ctx.FINAL() - // .stream() - // .map(FINAL -> FINAL.getText()) - // .collect(toList()); - // Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); - // List class_definitions = ctx.class_definition() - // .stream() - // .map(class_definition -> class_definition.accept(class_definitionVisitor)) - // .collect(toList()); - // return new Stored_definition(within_dec, final_dec, names, class_definitions); - // } - // } - - // private static class Class_definitionVisitor extends modelicaBaseVisitor { - // @Override - // public Class_definition visitClass_definition(modelicaParser.Class_definitionContext ctx) { - // String enca_dec = ctx.ENCAPSULATED() == null ? null : ctx.ENCAPSULATED().getText(); - // Class_prefixesVisitor class_prefixesVisitor = new Class_prefixesVisitor(); - // String class_prefixes_1 = ctx.class_prefixes().accept(class_prefixesVisitor); - // Class_specifierVisitor class_specifierVisitor = new Class_specifierVisitor(); - // Class_specifier class_specifier_1 = ctx.class_specifier().accept(class_specifierVisitor); - // return new Class_definition(enca_dec, class_prefixes_1, class_specifier_1); - // } - // } - - // private static class Class_specifierVisitor extends modelicaBaseVisitor { - // @Override - // public Class_specifier visitClass_specifier(modelicaParser.Class_specifierContext ctx) { - // Long_class_specifierVisitor long_class_specifierVisitor = new Long_class_specifierVisitor(); - // Long_class_specifier long_class_specifier_1 = - // ctx.long_class_specifier() == null ? null : ctx.long_class_specifier().accept(long_class_specifierVisitor); - // Short_class_specifierVisitor short_class_specifierVisitor = new Short_class_specifierVisitor(); - // Short_class_specifier short_class_specifier_1 = - // ctx.short_class_specifier() == null ? null : ctx.short_class_specifier().accept(short_class_specifierVisitor); - // Der_class_specifierVisitor der_class_specifierVisitor = new Der_class_specifierVisitor(); - // Der_class_specifier der_class_specifier_1 = - // ctx.der_class_specifier() == null ? null : ctx.der_class_specifier().accept(der_class_specifierVisitor); - // return new Class_specifier(long_class_specifier_1, short_class_specifier_1, der_class_specifier_1); - // } - // } - - // private static class Class_prefixesVisitor extends modelicaBaseVisitor { - // @Override - // public String visitClass_prefixes(modelicaParser.Class_prefixesContext ctx) { - // String partial_dec = - // ctx.PARTIAL() == null ? "" : ctx.PARTIAL().getText(); - // String class_dec = - // ctx.CLASS() == null ? "" : ctx.CLASS().getText(); - // String model_dec = - // ctx.MODEL() == null ? "" : ctx.MODEL().getText(); - // String block_dec = - // ctx.BLOCK() == null ? "" : ctx.BLOCK().getText(); - // String type_dec = - // ctx.TYPE() == null ? "" : ctx.TYPE().getText(); - // String package_dec = - // ctx.PACKAGE() == null ? "" : ctx.PACKAGE().getText(); - // String operator_dec = - // ctx.OPERATOR() == null ? "" : ctx.OPERATOR().getText(); - // String record_dec = - // ctx.RECORD() == null ? "" : ctx.RECORD().getText(); - // String expandable_dec = - // ctx.EXPANDABLE() == null ? "" : ctx.EXPANDABLE().getText(); - // String connector_dec = - // ctx.CONNECTOR() == null ? "" : ctx.CONNECTOR().getText(); - // String pure_dec = - // ctx.PURE() == null ? "" : ctx.PURE().getText(); - // String impure_dec = - // ctx.IMPURE() == null ? "" : ctx.IMPURE().getText(); - // String function_dec = - // ctx.FUNCTION() == null ? "" : ctx.FUNCTION().getText(); - // String other_dec; - // if ((!function_dec.isEmpty()) && (connector_dec.isEmpty()) && (record_dec.isEmpty())) { - // String tempStr; - // if (operator_dec.isEmpty()) { - // tempStr = function_dec; - // } else { - // StringBuilder temStr = new StringBuilder(); - // tempStr = temStr.append(operator_dec).append(" ").append(function_dec).toString(); - // } - // if (pure_dec.isEmpty() && impure_dec.isEmpty()) { - // other_dec = tempStr; - // } else { - // StringBuilder temStr = new StringBuilder(); - // other_dec = temStr.append(pure_dec).append(impure_dec).append(" ").append(tempStr).toString(); - // } - // } else if ((!connector_dec.isEmpty()) && (function_dec.isEmpty()) && (record_dec.isEmpty())) { - // StringBuilder temStr = new StringBuilder(); - // other_dec = (expandable_dec.isEmpty()) ? connector_dec - // : (temStr.append(expandable_dec).append(" ").append(connector_dec).toString()); - // } else if ((!record_dec.isEmpty()) && (function_dec.isEmpty()) && (connector_dec.isEmpty())) { - // StringBuilder temStr = new StringBuilder(); - // other_dec = (operator_dec.isEmpty()) ? record_dec - // : (temStr.append(operator_dec).append(" ").append(record_dec).toString()); - // } else { - // StringBuilder temStr = new StringBuilder(); - // temStr.append(class_dec != null ? class_dec : "") - // .append(model_dec != null ? model_dec : "") - // .append(block_dec != null ? block_dec : "") - // .append(type_dec != null ? type_dec : "") - // .append(package_dec != null ? package_dec : "") - // .append(operator_dec != null ? operator_dec : ""); - // other_dec = temStr.toString(); - // } - // StringBuilder temStr = new StringBuilder(); - // String claPreStr = - // (!partial_dec.isEmpty()) ? (temStr.append(partial_dec).append(" ").append(other_dec).toString()) - // : other_dec; - - // return claPreStr; - // } - // } - - // private static class Long_class_specifierVisitor extends modelicaBaseVisitor { - // @Override - // public Long_class_specifier visitLong_class_specifier(modelicaParser.Long_class_specifierContext ctx) { - // List ident = ctx.IDENT() - // .stream() - // .map(IDENT -> IDENT.getText()) - // .collect(toList()); - // String extends_dec = - // ctx.EXTENDS() == null ? null : ctx.EXTENDS().getText(); - // String_commentVisitor string_commentVisitor = new String_commentVisitor(); - // String string_comment_1 = ctx.string_comment().accept(string_commentVisitor); - // CompositionVisitor compositionVisitor = new CompositionVisitor(); - // Composition composition_1 = ctx.composition().accept(compositionVisitor); - // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - // String class_modification_1 = - // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - // return new Long_class_specifier(extends_dec, ident.get(0), string_comment_1, composition_1, class_modification_1); - // } - // } - - // private static class Short_class_specifierVisitor extends modelicaBaseVisitor { - // @Override - // public Short_class_specifier visitShort_class_specifier(modelicaParser.Short_class_specifierContext ctx) { - // String enum_dec = - // ctx.ENUMERATION() == null ? null : ctx.ENUMERATION().getText(); - // String ident = ctx.IDENT().getText(); - // Base_prefixVisitor base_prefixVisitor = new Base_prefixVisitor(); - // String base_prefix_1 = - // ctx.base_prefix() == null ? null : ctx.base_prefix().accept(base_prefixVisitor); - // Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); - // String array_subscripts_1 = - // ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); - // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - // String class_modification_1 = - // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - - // CommentVisitor commentVisitor = new CommentVisitor(); - // Comment comment = - // ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); - // Enum_listVisitor enum_listVisitor = new Enum_listVisitor(); - // Enum_list enum_list_1 = - // ctx.enum_list() == null ? null : ctx.enum_list().accept(enum_listVisitor); - // NameVisitor nameVisitor = new NameVisitor(); - // String name_1 = - // ctx.name() == null ? null : ctx.name().accept(nameVisitor); - // String symCol = - // ctx.SYMBOL_COLON() == null ? null : ctx.SYMBOL_COLON().getText(); - // return new Short_class_specifier(enum_dec, ident, base_prefix_1, name_1, array_subscripts_1, - // class_modification_1, comment, enum_list_1); - // } - // } - - // private static class Der_class_specifierVisitor extends modelicaBaseVisitor { - // @Override - // public Der_class_specifier visitDer_class_specifier(modelicaParser.Der_class_specifierContext ctx) { - // List idents = ctx.IDENT() - // .stream() - // .map(IDENT -> IDENT.getText()) - // .collect(toList()); - // String ident1 = idents.get(0); - // List ident2 = idents.subList(1, idents.size()); - // List comma = ctx.SYMBOL_COMMA() == null ? null : ctx.SYMBOL_COMMA() - // .stream() - // .map(SYMBOL_COMMA -> SYMBOL_COMMA.getText()) - // .collect(toList()); - // NameVisitor nameVisitor = new NameVisitor(); - // String name_1 = ctx.name().accept(nameVisitor); - // CommentVisitor commentVisitor = new CommentVisitor(); - // Comment comment_1 = ctx.comment().accept(commentVisitor); - // return new Der_class_specifier(ident1, comma, ident2, name_1, comment_1); - // } - // } - - // private static class Base_prefixVisitor extends modelicaBaseVisitor { - // @Override - // public String visitBase_prefix(modelicaParser.Base_prefixContext ctx) { - // Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); - // String basPreStr = ctx.type_prefix().accept(type_prefixVisitor); - // return basPreStr; - // //return new Base_prefix(type_prefix_1); - // } - // } - - // private static class Enum_listVisitor extends modelicaBaseVisitor { - // @Override - // public Enum_list visitEnum_list(modelicaParser.Enum_listContext ctx) { - // Enumeration_literalVisitor enumeration_literalVisitor = new Enumeration_literalVisitor(); - // List enumeration_literal_1 = ctx.enumeration_literal() - // .stream() - // .map(enumeration_literal -> enumeration_literal.accept(enumeration_literalVisitor)) - // .collect(toList()); - // return new Enum_list(enumeration_literal_1); - // } - // } - - // private static class Enumeration_literalVisitor extends modelicaBaseVisitor { - // @Override - // public Enumeration_literal visitEnumeration_literal(modelicaParser.Enumeration_literalContext ctx) { - // String ident = ctx.IDENT().getText(); - // CommentVisitor commentVisitor = new CommentVisitor(); - // Comment comment_1 = ctx.comment().accept(commentVisitor); - // return new Enumeration_literal(ident, comment_1); - // } - // } - - // private static class CompositionVisitor extends modelicaBaseVisitor { - // @Override - // public Composition visitComposition(modelicaParser.CompositionContext ctx) { - // List public_dec = ctx.PUBLIC() == null ? null : ctx.PUBLIC() - // .stream() - // .map(PUBLIC -> PUBLIC.getText()) - // .collect(toList()); - // List protected_dec = ctx.PROTECTED() == null ? null : ctx.PROTECTED() - // .stream() - // .map(PROTECTED -> PROTECTED.getText()) - // .collect(toList()); - // String external_dec = - // ctx.EXTERNAL() == null ? null : ctx.EXTERNAL().getText(); - // Element_listVisitor element_listVisitor = new Element_listVisitor(); - // List element_lists = ctx.element_list() - // .stream() - // .map(element_list -> element_list.accept(element_listVisitor)) - // .collect(toList()); - // Element_list element_list1 = element_lists.get(0); - // List element_list2 = - // element_lists.size() < 2 ? null : element_lists.subList(1,element_lists.size()); - // Equation_sectionVisitor equation_sectionVisitor = new Equation_sectionVisitor(); - // List equation_section_1 = ctx.equation_section() == null ? null : ctx.equation_section() - // .stream() - // .map(equation_section -> equation_section.accept(equation_sectionVisitor)) - // .collect(toList()); - // Algorithm_sectionVisitor algorithm_sectionVisitor = new Algorithm_sectionVisitor(); - // List algorithm_section_1 = ctx.algorithm_section() == null ? null : ctx.algorithm_section() - // .stream() - // .map(algorithm_section -> algorithm_section.accept(algorithm_sectionVisitor)) - // .collect(toList()); - // Language_specificationVisitor language_specificationVisitor = new Language_specificationVisitor(); - // String language_specification_1 = - // ctx.language_specification() == null ? null : ctx.language_specification().accept(language_specificationVisitor); - // External_function_callVisitor external_function_callVisitor = new External_function_callVisitor(); - // String external_function_call_1 = - // ctx.external_function_call() == null ? null : ctx.external_function_call().accept(external_function_callVisitor); - // AnnotationVisitor annotationVisitor = new AnnotationVisitor(); - // List annotations = ctx.annotation() == null ? null : ctx.annotation() - // .stream() - // .map(annotation -> annotation.accept(annotationVisitor)) - // .collect(toList()); - // String annotation1 = null; - // String annotation2 = null; - // if (annotations.size() == 2) { - // annotation1 = annotations.get(0); - // annotation2 = annotations.get(1); - // } else if (annotations.size() == 1 && external_dec != null) { - // annotation1 = annotations.get(0); - // } else if (annotations.size() == 1 && external_dec == null) { - // annotation2 = annotations.get(0); - // } else { - // annotation1 = null; - // annotation2 = null; - // } - // return new Composition(external_dec, public_dec, protected_dec, element_list1, element_list2, - // equation_section_1, algorithm_section_1, language_specification_1, external_function_call_1, - // annotation1, annotation2); - // } - // } - - // private static class Language_specificationVisitor extends modelicaBaseVisitor { - // @Override - // public String visitLanguage_specification(modelicaParser.Language_specificationContext ctx) { - // String string = ctx.STRING().getText(); - // return string; - // //return new Language_specification(ident); - // } - // } - - // private static class External_function_callVisitor extends modelicaBaseVisitor { - // @Override - // public String visitExternal_function_call(modelicaParser.External_function_callContext ctx) { - // String ident = ctx.IDENT().getText(); - // Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); - // String component_reference_1 = - // ctx.component_reference() == null ? null : ctx.component_reference().accept(component_referenceVisitor); - // Expression_listVisitor expression_listVisitor = new Expression_listVisitor(); - // String expression_list_1 = - // ctx.expression_list() == null ? "" : ctx.expression_list().accept(expression_listVisitor); - // StringBuilder temStr1 = new StringBuilder(); - // StringBuilder temStr2 = new StringBuilder(); - // String extFunCalStr = (component_reference_1 != null) - // ? (temStr1.append(component_reference_1).append("=").append(ident).append("(").append(expression_list_1).append(")").toString()) - // : (temStr2.append(ident).append("(").append(expression_list_1).append(")").toString()); - // return extFunCalStr; - // //return new External_function_call(ident, component_reference_1, expression_list_1); - // } - // } - - // private static class Element_listVisitor extends modelicaBaseVisitor { - // @Override - // public Element_list visitElement_list(modelicaParser.Element_listContext ctx) { - // ElementVisitor elementVisitor = new ElementVisitor(); - // List element_1 = ctx.element() == null ? null : ctx.element() - // .stream() - // .map(element -> element.accept(elementVisitor)) - // .collect(toList()); - // return new Element_list(element_1); - // } - // } - - // private static class ElementVisitor extends modelicaBaseVisitor { - // @Override - // public Element visitElement(modelicaParser.ElementContext ctx) { - // String red_dec = - // ctx.REDECLARE() == null ? null : ctx.REDECLARE().getText(); - // String final_dec = - // ctx.FINAL() == null ? null : ctx.FINAL().getText(); - // String inner_dec = - // ctx.INNER() == null ? null : ctx.INNER().getText(); - // String outer_der = - // ctx.OUTER() == null ? null : ctx.OUTER().getText(); - // String rep_dec = - // ctx.REPLACEABLE() == null ? null : ctx.REPLACEABLE().getText(); - // Class_definition class_definition1; - // Class_definition class_definition2; - // Component_clause component_clause1; - // Component_clause component_clause2; - // if (rep_dec != null) { - // Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); - // class_definition2 = - // ctx.class_definition() == null ? null : ctx.class_definition().accept(class_definitionVisitor); - // Component_clauseVisitor component_clauseVisitor = new Component_clauseVisitor(); - // component_clause2 = - // ctx.component_clause() == null ? null : ctx.component_clause().accept(component_clauseVisitor); - // class_definition1 = null; - // component_clause1 = null; - // } else { - // Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); - // class_definition1 = - // ctx.class_definition() == null ? null : ctx.class_definition().accept(class_definitionVisitor); - // Component_clauseVisitor component_clauseVisitor = new Component_clauseVisitor(); - // component_clause1 = - // ctx.component_clause() == null ? null : ctx.component_clause().accept(component_clauseVisitor); - // class_definition2 = null; - // component_clause2 = null; - // } - // Import_clauseVisitor import_clauseVisitor = new Import_clauseVisitor(); - // Import_clause import_clause_1 = - // ctx.import_clause() == null ? null : ctx.import_clause().accept(import_clauseVisitor); - // Extends_clauseVisitor extends_clauseVisitor = new Extends_clauseVisitor(); - // Extends_clause extends_clause_1 = - // ctx.extends_clause() == null ? null : ctx.extends_clause().accept(extends_clauseVisitor); - // Constraining_clauseVisitor constraining_clauseVisitor = new Constraining_clauseVisitor(); - // String constraining_clause_1 = - // ctx.constraining_clause() == null ? null : ctx.constraining_clause().accept(constraining_clauseVisitor); - // CommentVisitor commentVisitor = new CommentVisitor(); - // Comment comment_1 = - // ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); - // return new Element(red_dec, final_dec, inner_dec, outer_der, rep_dec, import_clause_1, - // extends_clause_1, class_definition1, class_definition2, - // component_clause1, component_clause2, constraining_clause_1, comment_1); - // } - // } - - // private static class Import_clauseVisitor extends modelicaBaseVisitor { - // @Override - // public Import_clause visitImport_clause(modelicaParser.Import_clauseContext ctx) { - // String import_dec = ctx.IMPORT().getText(); - // String ident = - // ctx.IDENT() == null ? null : ctx.IDENT().getText(); - // String dotStar = - // ctx.SYMBOL_DOTSTAR() == null ? null : ctx.SYMBOL_DOTSTAR().getText(); - // Import_listVisitor import_listVisitor = new Import_listVisitor(); - // String import_list_1 = - // ctx.import_list() == null ? null : ctx.import_list().accept(import_listVisitor); - // CommentVisitor commentVisitor = new CommentVisitor(); - // Comment comment_1 = - // ctx.comment().getText().length() == 0 ? null : ctx.comment().accept(commentVisitor); - // NameVisitor nameVisitor = new NameVisitor(); - // String name_1 = ctx.name().accept(nameVisitor); - // return new Import_clause(import_dec, ident, dotStar, name_1, import_list_1, comment_1); - // } - // } - - // private static class Import_listVisitor extends modelicaBaseVisitor { - // @Override - // public String visitImport_list(modelicaParser.Import_listContext ctx) { - // List ident = ctx.IDENT() - // .stream() - // .map(IDENT -> IDENT.getText()) - // .collect(toList()); - // String impLisStr = ident.get(0); - // StringBuilder temStr = new StringBuilder(); - // temStr.append(impLisStr); - // if (ident.size()>1) { - // for (int i=1; i { - // @Override - // public Extends_clause visitExtends_clause(modelicaParser.Extends_clauseContext ctx) { - // String ext_dec = ctx.EXTENDS().getText(); - // NameVisitor nameVisitor = new NameVisitor(); - // String name_1 = ctx.name().accept(nameVisitor); - // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - // String class_modification_1 = - // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - // AnnotationVisitor annotationVisitor = new AnnotationVisitor(); - // String annotation_1 = - // ctx.annotation() == null ? null : ctx.annotation().accept(annotationVisitor); - // return new Extends_clause(ext_dec, name_1, class_modification_1, annotation_1); - // } - // } - - // private static class Constraining_clauseVisitor extends modelicaBaseVisitor { - // @Override - // public String visitConstraining_clause(modelicaParser.Constraining_clauseContext ctx) { - // String constrain_dec = ctx.CONSTRAINEDBY().getText(); - // NameVisitor nameVisitor = new NameVisitor(); - // String name_1 = ctx.name().accept(nameVisitor); - // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - // String class_modification_1 = - // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - // StringBuilder temStr = new StringBuilder(); - // String conClaStr = temStr.append(constrain_dec).append(" ").append(name_1).toString(); - // if (class_modification_1 != null) { - // conClaStr = temStr.append(" ").append(class_modification_1).toString(); } - // return conClaStr; - // //return new Constraining_clause(constrain_dec, name_1, class_modification_1); - // } - // } - - // private static class Component_clauseVisitor extends modelicaBaseVisitor { - // @Override - // public Component_clause visitComponent_clause(modelicaParser.Component_clauseContext ctx) { - // Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); - // String type_prefix_1 = - // ctx.type_prefix() == null ? null : ctx.type_prefix().accept(type_prefixVisitor); - // Type_specifierVisitor type_specifierVisitor = new Type_specifierVisitor(); - // String type_specifier_1 = ctx.type_specifier().accept(type_specifierVisitor); - // Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); - // String array_subscripts_1 = - // ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); - // Component_listVisitor component_listVisitor = new Component_listVisitor(); - // Component_list component_list_1 = ctx.component_list().accept(component_listVisitor); - // return new Component_clause(type_prefix_1, type_specifier_1, array_subscripts_1, component_list_1); - // } - // } - - // private static class Type_prefixVisitor extends modelicaBaseVisitor { - // @Override - // public String visitType_prefix(modelicaParser.Type_prefixContext ctx) { - // String flow_dec = - // ctx.FLOW() == null ? null : ctx.FLOW().getText(); - // String stream_dec = - // ctx.STREAM() == null ? null : ctx.STREAM().getText(); - // String disc_dec = - // ctx.DISCRETE() == null ? null : ctx.DISCRETE().getText(); - // String par_dec = - // ctx.PARAMETER() == null ? null : ctx.PARAMETER().getText(); - // String con_dec = - // ctx.CONSTANT() == null ? null : ctx.CONSTANT().getText(); - // String in_dec = - // ctx.INPUT() == null ? null : ctx.INPUT().getText(); - // String out_dec = - // ctx.OUTPUT() == null ? null : ctx.OUTPUT().getText(); - // String prefix = (flow_dec != null) ? flow_dec - // : (stream_dec != null ? stream_dec - // : (disc_dec != null ? disc_dec - // : (par_dec != null ? par_dec - // : (con_dec != null ? con_dec - // : (in_dec != null ? in_dec - // : out_dec))))); - // return prefix; - // //return new Type_prefix(flow_dec, stream_dec, disc_dec, par_dec, - // // con_dec, in_dec, out_dec); - // } - // } - - // private static class Type_specifierVisitor extends modelicaBaseVisitor { - // @Override - // public String visitType_specifier(modelicaParser.Type_specifierContext ctx) { - // NameVisitor nameVisitor = new NameVisitor(); - // String specifier = ctx.name().accept(nameVisitor); - // return specifier; - // //return new Type_specifier(name_1); - // } - // } - - // private static class Component_listVisitor extends modelicaBaseVisitor { - // @Override - // public Component_list visitComponent_list(modelicaParser.Component_listContext ctx) { - // Component_declarationVisitor component_declarationVisitor = new Component_declarationVisitor(); - // List component_declaration_1 = ctx.component_declaration() - // .stream() - // .map(component_declaration -> component_declaration.accept(component_declarationVisitor)) - // .collect(toList()); - // return new Component_list(component_declaration_1); - // } - // } - - // private static class Component_declarationVisitor extends modelicaBaseVisitor { - // @Override - // public Component_declaration visitComponent_declaration(modelicaParser.Component_declarationContext ctx) { - // DeclarationVisitor declarationVisitor = new DeclarationVisitor(); - // Declaration declaration_1 = ctx.declaration().accept(declarationVisitor); - // Condition_attributeVisitor condition_attributeVisitor = new Condition_attributeVisitor(); - // String condition_attribute_1 = - // ctx.condition_attribute() == null ? null : ctx.condition_attribute().accept(condition_attributeVisitor); - // CommentVisitor commentVisitor = new CommentVisitor(); - // Comment comment_1 = - // ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); - // return new Component_declaration(declaration_1, condition_attribute_1, comment_1); - // } - // } - - // private static class Condition_attributeVisitor extends modelicaBaseVisitor { - // @Override - // public String visitCondition_attribute(modelicaParser.Condition_attributeContext ctx) { - // String if_dec = ctx.IF().getText(); - // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - // String expression_1 = ctx.expression().accept(expressionVisitor); - // StringBuilder temStr = new StringBuilder(); - // String conAttStr = temStr.append(if_dec).append(" ").append(expression_1).toString(); - // return conAttStr; - // // return new Condition_attribute(if_dec, expression_1); - // } - // } - - // private static class DeclarationVisitor extends modelicaBaseVisitor { - // @Override - // public Declaration visitDeclaration(modelicaParser.DeclarationContext ctx) { - // String ident = ctx.IDENT().getText(); - // Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); - // String array_subscripts_1 = - // ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); - // ModificationVisitor modificationVisitor = new ModificationVisitor(); - // String modification_1 = - // ctx.modification() == null ? null : ctx.modification().accept(modificationVisitor); - // return new Declaration(ident, array_subscripts_1, modification_1); - // } - // } - - // private static class ModificationVisitor extends modelicaBaseVisitor { - // @Override - // public String visitModification(modelicaParser.ModificationContext ctx) { - // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - // String class_modification_1 = - // ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); - // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - // String expression_1 = - // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - // String eqSymb = ctx.SYMBOL_EQUAL() == null ? null : ctx.SYMBOL_EQUAL().getText(); - // String colEqSymb = ctx.SYMBOL_COLONEQUAL() == null ? null : ctx.SYMBOL_COLONEQUAL().getText(); - // String modStr = ""; - // StringBuilder temStr = new StringBuilder(); - // if (class_modification_1 != null) { - // if (expression_1 != null) { - // modStr = temStr.append(class_modification_1).append("=").append(expression_1).toString(); - // } else { - // modStr = class_modification_1; - // } - // } else if (eqSymb != null && expression_1 != null) { - // modStr = temStr.append(eqSymb).append(expression_1).toString(); - // } else if (colEqSymb != null && expression_1 != null) { - // modStr = temStr.append(colEqSymb).append(expression_1).toString(); - // } - // return modStr; - // // return new Modification(class_modification_1, eqSymb, colEqSymb, expression_1); - // } - // } - - // private static class Class_modificationVisitor extends modelicaBaseVisitor { - // @Override - // public String visitClass_modification(modelicaParser.Class_modificationContext ctx) { - // Argument_listVisitor argument_listVisitor = new Argument_listVisitor(); - // String argument_list_1 = - // ctx.argument_list() == null ? null : ctx.argument_list().accept(argument_listVisitor); - // StringBuilder temStr = new StringBuilder(); - // String claModStr = temStr.append("(").append(argument_list_1).append(")").toString(); - // return claModStr; - // //return new Class_modification(argument_list_1); - // } - // } - - // private static class Argument_listVisitor extends modelicaBaseVisitor { - // @Override - // public String visitArgument_list(modelicaParser.Argument_listContext ctx) { - // ArgumentVisitor argumentVisitor = new ArgumentVisitor(); - // List argument_1 = ctx.argument() - // .stream() - // .map(argument -> argument.accept(argumentVisitor)) - // .collect(toList()); - // String argLisStr = argument_1.get(0); - // StringBuilder temStr = new StringBuilder(); - // temStr.append(argLisStr); - // if (argument_1.size()>1) { - // for (int i=1; i { - // @Override - // public String visitArgument(modelicaParser.ArgumentContext ctx) { - // Element_modification_or_replaceableVisitor element_modification_or_replaceableVisitor = new Element_modification_or_replaceableVisitor(); - // String element_modification_or_replaceable_1 = - // ctx.element_modification_or_replaceable() == null ? null : ctx.element_modification_or_replaceable().accept(element_modification_or_replaceableVisitor); - // Element_redeclarationVisitor element_redeclarationVisitor = new Element_redeclarationVisitor(); - // String element_redeclaration_1 = - // ctx.element_redeclaration() == null ? null : ctx.element_redeclaration().accept(element_redeclarationVisitor); - // String argStr = (element_redeclaration_1 != null) ? element_redeclaration_1 : element_modification_or_replaceable_1; - // return argStr; - // //return new Argument(element_modification_or_replaceable_1, element_redeclaration_1); - // } - // } - - // private static class Element_modification_or_replaceableVisitor extends modelicaBaseVisitor { - // @Override - // public String visitElement_modification_or_replaceable(modelicaParser.Element_modification_or_replaceableContext ctx) { - // String each_dec = - // ctx.EACH() == null ? null : ctx.EACH().getText(); - // String final_dec = - // ctx.FINAL() == null ? null : ctx.FINAL().getText(); - // Element_modificationVisitor element_modificationVisitor = new Element_modificationVisitor(); - // String element_modification_1 = - // ctx.element_modification() == null ? null : ctx.element_modification().accept(element_modificationVisitor); - // Element_replaceableVisitor element_replaceableVisitor = new Element_replaceableVisitor(); - // String element_replaceable_1 = - // ctx.element_replaceable() == null ? null : ctx.element_replaceable().accept(element_replaceableVisitor); - // String eleModRep = ""; - // StringBuilder temStr = new StringBuilder(); - // temStr.append(eleModRep); - // if (each_dec != null) {temStr.append(each_dec).append(" ");} - // if (final_dec != null) {temStr.append(final_dec).append(" ");} - // if (element_modification_1 != null) { - // temStr.append(element_modification_1); - // } else { - // temStr.append(element_replaceable_1); - // } - // eleModRep = temStr.toString(); - // return eleModRep; - // //return new Element_modification_or_replaceable(each_dec, final_dec, element_modification_1, element_replaceable_1); - // } - // } - - // private static class Element_modificationVisitor extends modelicaBaseVisitor { - // @Override - // public String visitElement_modification(modelicaParser.Element_modificationContext ctx) { - // NameVisitor nameVisitor = new NameVisitor(); - // String name_1 = ctx.name().accept(nameVisitor); - // ModificationVisitor modificationVisitor = new ModificationVisitor(); - // String modification_1 = - // ctx.modification() == null ? null : ctx.modification().accept(modificationVisitor); - // //String modStr = String.valueOf(modification_1); - // String_commentVisitor string_commentVisitor = new String_commentVisitor(); - // String string_comment_1 = ctx.string_comment().accept(string_commentVisitor); - // StringBuilder temStr1 = new StringBuilder(); - // StringBuilder temStr2 = new StringBuilder(); - // String eleModStr = (modification_1 == null) - // ? (temStr1.append(name_1).append(" ").append(string_comment_1).toString()) - // : (temStr2.append(name_1).append(" ").append(modification_1).append(" ").append(string_comment_1).toString()); - // return eleModStr; - // //return new Element_modification(name_1, modification_1, string_comment_1); - // } - // } - - // private static class Element_redeclarationVisitor extends modelicaBaseVisitor { - // @Override - // public String visitElement_redeclaration(modelicaParser.Element_redeclarationContext ctx) { - // String red_dec = ctx.REDECLARE().getText(); - // String each_dec = - // ctx.EACH() == null ? null : ctx.EACH().getText(); - // String final_dec = - // ctx.FINAL() == null ? null : ctx.FINAL().getText(); - // Short_class_definitionVisitor short_class_definitionVisitor = new Short_class_definitionVisitor(); - // String shoClaDefStr = - // ctx.short_class_definition() == null ? null : ctx.short_class_definition().accept(short_class_definitionVisitor); - // Component_clause1Visitor component_clause1Visitor = new Component_clause1Visitor(); - // String component_clause1_1 = - // ctx.component_clause1() == null ? null : ctx.component_clause1().accept(component_clause1Visitor); - // Element_replaceableVisitor element_replaceableVisitor = new Element_replaceableVisitor(); - // String element_replaceable_1 = - // ctx.element_replaceable() == null ? null : ctx.element_replaceable().accept(element_replaceableVisitor); - // StringBuilder temStr = new StringBuilder(); - // String eleRedStr = temStr.append(red_dec).append(" ").toString(); - // if (each_dec != null) {temStr.append(each_dec).append(" ");} - // if (final_dec != null) {temStr.append(final_dec).append(" ");} - // if (element_replaceable_1 != null) { - // temStr.append(element_replaceable_1); - // } else { - // if (shoClaDefStr != null) { - // temStr.append(shoClaDefStr); - // } else { - // temStr.append(component_clause1_1); - // } - // } - // eleRedStr = temStr.toString(); - // return eleRedStr; - // //return new Element_redeclaration(red_dec, each_dec, final_dec, short_class_definition_1, component_clause1_1, element_replaceable_1); - // } - // } - - // private static class Element_replaceableVisitor extends modelicaBaseVisitor { - // @Override - // public String visitElement_replaceable(modelicaParser.Element_replaceableContext ctx) { - // String rep_dec = ctx.REPLACEABLE().getText(); - // Short_class_definitionVisitor short_class_definitionVisitor = new Short_class_definitionVisitor(); - // String shoClaDefStr = - // ctx.short_class_definition() == null ? null : ctx.short_class_definition().accept(short_class_definitionVisitor); - // Component_clause1Visitor component_clause1Visitor = new Component_clause1Visitor(); - // String component_clause1_1 = - // ctx.component_clause1() == null ? null : ctx.component_clause1().accept(component_clause1Visitor); - // Constraining_clauseVisitor constraining_clauseVisitor = new Constraining_clauseVisitor(); - // String constraining_clause_1 = - // ctx.constraining_clause() == null ? null : ctx.constraining_clause().accept(constraining_clauseVisitor); - // StringBuilder temStr = new StringBuilder(); - // String eleRepStr = temStr.append(rep_dec).append(" ").toString(); - // if (component_clause1_1 == null) { - // temStr.append(shoClaDefStr); - // } else { - // temStr.append(component_clause1_1); - // } - // if (constraining_clause_1 != null) { - // temStr.append(constraining_clause_1); - // } - // eleRepStr = temStr.toString(); - // return eleRepStr; - // //return new Element_replaceable(rep_dec, short_class_definition_1, component_clause1_1, constraining_clause_1); - // } - // } - - // private static class Component_clause1Visitor extends modelicaBaseVisitor { - // @Override - // public String visitComponent_clause1(modelicaParser.Component_clause1Context ctx) { - // Type_prefixVisitor type_prefixVisitor = new Type_prefixVisitor(); - // String type_prefix_1 = ctx.type_prefix().accept(type_prefixVisitor); - // Type_specifierVisitor type_specifierVisitor = new Type_specifierVisitor(); - // String type_specifier_1 = ctx.type_specifier().accept(type_specifierVisitor); - // Component_declaration1Visitor component_declaration1Visitor = new Component_declaration1Visitor(); - // String component_declaration1_1 = ctx.component_declaration1().accept(component_declaration1Visitor); - // StringBuilder temStr = new StringBuilder(); - // if (type_prefix_1 != null) { - // temStr.append(type_prefix_1).append(" "); - // } - // String comCla1Str = temStr.append(type_specifier_1).append(" ") - // .append(component_declaration1_1) - // .toString(); - // return comCla1Str; - // //return new Component_clause1(type_prefix_1, type_specifier_1, component_declaration1_1); - // } - // } - - // private static class Component_declaration1Visitor extends modelicaBaseVisitor { - // @Override - // public String visitComponent_declaration1(modelicaParser.Component_declaration1Context ctx) { - // String declaration_1 = ""; - // if (ctx.declaration().getText().isEmpty()) { - // declaration_1 = null; - // } else { - // int a = ctx.declaration().start.getStartIndex(); - // int b = ctx.declaration().stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream decStr = ctx.declaration().start.getInputStream(); - // declaration_1 = decStr.getText(interval).trim(); - // } - - // String comStr = ctx.comment().getText(); - // StringBuilder temStr = new StringBuilder(); - // String comDec1Str = temStr.append(declaration_1).append(" ").append(comStr).toString(); - - // return comDec1Str; - // //return new Component_declaration1(declaration_1, comment_1); - // } - // } - - // private static class Short_class_definitionVisitor extends modelicaBaseVisitor { - // @Override - // public String visitShort_class_definition(modelicaParser.Short_class_definitionContext ctx) { - // Class_prefixesVisitor class_prefixesVisitor = new Class_prefixesVisitor(); - // String class_prefixes_1 - // = ctx.class_prefixes().accept(class_prefixesVisitor); - // Short_class_specifierVisitor short_class_specifierVisitor = new Short_class_specifierVisitor(); - // Short_class_specifier shortClaSpe = ctx.short_class_specifier().accept(short_class_specifierVisitor); - // String shortClaSpeStr; - // String comeStr; - // if (shortClaSpe.comment != null) { - // if (shortClaSpe.comment.string_comment == null && shortClaSpe.comment.annotation == null) { - // comeStr = ""; - // } else if (shortClaSpe.comment.string_comment == null && shortClaSpe.comment.annotation != null) { - // StringBuilder temStr = new StringBuilder(); - // comeStr = temStr.append("annotation (") - // .append(shortClaSpe.comment.annotation.toString()) - // .append(")").toString(); - // } else if (shortClaSpe.comment.string_comment != null && shortClaSpe.comment.annotation == null) { - // comeStr = shortClaSpe.comment.string_comment; - // } else { - // StringBuilder temStr = new StringBuilder(); - // comeStr = temStr.append(shortClaSpe.comment.string_comment).append(" ") - // .append("annotation (") - // .append(shortClaSpe.comment.annotation.toString()).append(")") - // .toString(); - // } - // } else { - // comeStr = ""; - // } - // if (shortClaSpe.base_prefix != null || shortClaSpe.inputName != null) { - // StringBuilder temStr = new StringBuilder(); - // shortClaSpeStr = temStr.append(shortClaSpe.className).append(" =") - // .append((shortClaSpe.base_prefix == null ? "" : (shortClaSpe.base_prefix+ " "))) - // .append((shortClaSpe.inputName == null ? "" : (shortClaSpe.inputName+" "))) - // .append((shortClaSpe.array_subscripts == null ? "" : (shortClaSpe.array_subscripts+" "))) - // .append((shortClaSpe.class_modification == null ? "" : (shortClaSpe.class_modification+" "))) - // .append(comeStr) - // .toString(); - // } else { - // String listStr; - // if (shortClaSpe.list_colon == null) { - // listStr = shortClaSpe.enum_list == null ? "" : shortClaSpe.enum_list.toString(); - // } else { - // listStr = shortClaSpe.list_colon; - // } - // StringBuilder temStr = new StringBuilder(); - // shortClaSpeStr = temStr.append(shortClaSpe.className).append(" =") - // .append(shortClaSpe.prefix).append("(").append(listStr).append(")") - // .append(comeStr).toString(); - // } - // StringBuilder temStr = new StringBuilder(); - // String shoClaDef = temStr.append(class_prefixes_1).append(" ").append(shortClaSpeStr).toString(); - // return shoClaDef; - // //return new Short_class_definition(class_prefixes_1, short_class_specifier_1); - // } - // } - - // private static class Equation_sectionVisitor extends modelicaBaseVisitor { - // @Override - // public Equation_section visitEquation_section(modelicaParser.Equation_sectionContext ctx) { - // String init_dec = - // ctx.INITIAL() == null ? null : ctx.INITIAL().getText(); - // String equ_dec = ctx.EQUATION().getText(); - // EquationVisitor equationVisitor = new EquationVisitor(); - // List equation_1 = ctx.equation() == null ? null : ctx.equation() - // .stream() - // .map(equation -> equation.accept(equationVisitor)) - // .collect(toList()); - // return new Equation_section(init_dec, equ_dec, equation_1); - // } - // } - - // private static class Algorithm_sectionVisitor extends modelicaBaseVisitor { - // @Override - // public String visitAlgorithm_section(modelicaParser.Algorithm_sectionContext ctx) { - // String init_dec = - // ctx.INITIAL() == null ? null : ctx.INITIAL().getText(); - // String alg_dec = ctx.ALGORITHM().getText(); - // StatementVisitor statementVisitor = new StatementVisitor(); - // List statement_1 = ctx.statement() == null ? null : ctx.statement() - // .stream() - // .map(statement -> statement.accept(statementVisitor)) - // .collect(toList()); - // StringBuilder temStr = new StringBuilder(); - // String algSecStr = (init_dec != null) ? (temStr.append(init_dec).append(" ").append(alg_dec).toString()) - // : alg_dec; - // if (statement_1.size()>0) { - // StringBuilder temStr2 = new StringBuilder(); - // temStr2.append(algSecStr).append("\n"); - // for (int i=0; i { - // @Override - // public Equation visitEquation(modelicaParser.EquationContext ctx) { - // Simple_expressionVisitor simple_expressionVisitor = new Simple_expressionVisitor(); - // String simple_expression_1 = - // ctx.simple_expression() == null ? null : ctx.simple_expression().accept(simple_expressionVisitor); - // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - // String expression_1 = - // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - // If_equationVisitor if_equationVisitor = new If_equationVisitor(); - // String if_equation_1 = - // ctx.if_equation() == null ? null : ctx.if_equation().accept(if_equationVisitor); - // For_equationVisitor for_equationVisitor = new For_equationVisitor(); - // String for_equation_1 = - // ctx.for_equation() == null ? null : ctx.for_equation().accept(for_equationVisitor); - // Connect_clauseVisitor connect_clauseVisitor = new Connect_clauseVisitor(); - // Connect_clause connect_clause_1 = - // ctx.connect_clause() == null ? null : ctx.connect_clause().accept(connect_clauseVisitor); - // When_equationVisitor when_equationVisitor = new When_equationVisitor(); - // String when_equation_1 = - // ctx.when_equation() == null ? null : ctx.when_equation().accept(when_equationVisitor); - // NameVisitor nameVisitor = new NameVisitor(); - // String name_1 = - // ctx.name() == null ? null : ctx.name().accept(nameVisitor); - // Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); - // String function_call_args_1 = - // ctx.function_call_args() == null ? null : ctx.function_call_args().accept(function_call_argsVisitor); - // CommentVisitor commentVisitor = new CommentVisitor(); - // Comment comment_1 = - // ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); - // return new Equation(simple_expression_1, expression_1, if_equation_1, for_equation_1, connect_clause_1, - // when_equation_1, name_1, function_call_args_1, comment_1); - // } - // } - - // private static class StatementVisitor extends modelicaBaseVisitor { - // @Override - // public String visitStatement(modelicaParser.StatementContext ctx) { - // String bre_dec = - // ctx.BREAK() == null ? "" : ctx.BREAK().getText(); - // String ret_dec = - // ctx.RETURN() == null ? "" : ctx.RETURN().getText(); - // Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); - // String component_reference_1 = - // ctx.component_reference() == null ? "" : ctx.component_reference().accept(component_referenceVisitor); - // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - // String expression_1 = - // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - // Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); - // String function_call_args_1 = - // ctx.function_call_args() == null ? "" : ctx.function_call_args().accept(function_call_argsVisitor); - // Output_expression_listVisitor output_expression_listVisitor = new Output_expression_listVisitor(); - // String output_expression_list_1 = - // ctx.output_expression_list() == null ? null : ctx.output_expression_list().accept(output_expression_listVisitor); - // If_statementVisitor if_statementVisitor = new If_statementVisitor(); - // String if_statement_1 = - // ctx.if_statement() == null ? "" : ctx.if_statement().accept(if_statementVisitor); - // For_statementVisitor for_statementVisitor = new For_statementVisitor(); - // String for_statement_1 = - // ctx.for_statement() == null ? "" : ctx.for_statement().accept(for_statementVisitor); - // While_statementVisitor while_statementVisitor = new While_statementVisitor(); - // String while_statement_1 = - // ctx.while_statement() == null ? "" : ctx.while_statement().accept(while_statementVisitor); - // When_statementVisitor when_statementVisitor = new When_statementVisitor(); - // String when_statement_1 = - // ctx.when_statement() == null ? "" : ctx.when_statement().accept(when_statementVisitor); - // CommentVisitor commentVisitor = new CommentVisitor(); - // Comment comment_1 = ctx.comment().accept(commentVisitor); - // String comStr = String.valueOf(comment_1); - // StringBuilder temStr1 = new StringBuilder(); - // StringBuilder temStr2 = new StringBuilder(); - // StringBuilder temStr3 = new StringBuilder(); - // String temp1 = (expression_1 == null) ? "" : (temStr1.append("=").append(expression_1).toString()); - // String temp2 = (output_expression_list_1 == null) ? "" - // : (temStr2.append("(").append(output_expression_list_1).append(")").append(":=") - // .append(component_reference_1).append(" ").append(function_call_args_1) - // .toString()); - // String staStr = temStr3.append(component_reference_1).append(temp1).append(function_call_args_1) - // .append(temp2).append(bre_dec).append(ret_dec).append(if_statement_1) - // .append(for_statement_1).append(while_statement_1) - // .append(when_statement_1).append(comStr) - // .toString(); - // return staStr; - // //return new Statement(bre_dec, ret_dec, component_reference_1, expression_1, function_call_args_1, - // // output_expression_list_1, if_statement_1, for_statement_1, while_statement_1, when_statement_1, comment_1); - // } - // } - - // private static class If_equationVisitor extends modelicaBaseVisitor { - // @Override - // public String visitIf_equation(modelicaParser.If_equationContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new If_equation(expression1, equation1, expression2, equation2, equation3); - // } - // } - - // private static class If_statementVisitor extends modelicaBaseVisitor { - // @Override - // public String visitIf_statement(modelicaParser.If_statementContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new If_statement(expression1, statement1, expression2, statement2, statement3); - // } - // } - - // private static class For_equationVisitor extends modelicaBaseVisitor { - // @Override - // public String visitFor_equation(modelicaParser.For_equationContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new For_equation(for_indices_1, equation_1); - // } - // } - - // private static class For_statementVisitor extends modelicaBaseVisitor { - // @Override - // public String visitFor_statement(modelicaParser.For_statementContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new For_statement(for_indices_1, statement_1); - // } - // } - - // private static class For_indicesVisitor extends modelicaBaseVisitor { - // @Override - // public String visitFor_indices(modelicaParser.For_indicesContext ctx) { - // For_indexVisitor for_indexVisitor = new For_indexVisitor(); - // List for_index_1 = ctx.for_index() - // .stream() - // .map(for_index -> for_index.accept(for_indexVisitor)) - // .collect(toList()); - // StringBuilder temStr = new StringBuilder(); - // temStr.append(for_index_1.get(0)); - // if (for_index_1.size() > 1) { - // for (int i=1; i { - // @Override - // public String visitFor_index(modelicaParser.For_indexContext ctx) { - // String ident = ctx.IDENT().getText(); - // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - // String expression_1 = - // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - // StringBuilder temStr = new StringBuilder(); - // temStr.append(ident); - // if (expression_1 != null) { - // temStr.append(" in ").append(expression_1); - // } - // return temStr.toString(); - // //return new For_index(ident, expression_1); - // } - // } - - // private static class While_statementVisitor extends modelicaBaseVisitor { - // @Override - // public String visitWhile_statement(modelicaParser.While_statementContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new While_statement(expression_1, statement_1); - // } - // } - - // private static class When_equationVisitor extends modelicaBaseVisitor { - // @Override - // public String visitWhen_equation(modelicaParser.When_equationContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new When_equation(expression1, equation1, expression2, equation2); - // } - // } - - // private static class When_statementVisitor extends modelicaBaseVisitor { - // @Override - // public String visitWhen_statement(modelicaParser.When_statementContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new When_statement(expression1, statement1, expression2, statement2); - // } - // } - - // private static class Connect_clauseVisitor extends modelicaBaseVisitor { - // @Override - // public Connect_clause visitConnect_clause(modelicaParser.Connect_clauseContext ctx) { - // Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); - // List component_reference_1 = ctx.component_reference() - // .stream() - // .map(component_reference -> component_reference.accept(component_referenceVisitor)) - // .collect(toList()); - // return new Connect_clause(component_reference_1.get(0), component_reference_1.get(1)); - // } - // } - - // private static class ExpressionVisitor extends modelicaBaseVisitor { - // @Override - // public String visitExpression(modelicaParser.ExpressionContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new Expression(simple_expression_1, expression1, expression2, - // // expression3, expression4, expression5); - // } - // } - - // private static class Simple_expressionVisitor extends modelicaBaseVisitor { - // @Override - // public String visitSimple_expression(modelicaParser.Simple_expressionContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new Simple_expression(logical_expression1, logical_expression2, logical_expression3); - // } - // } - - // private static class Logical_expressionVisitor extends modelicaBaseVisitor { - // @Override - // public String visitLogical_expression(modelicaParser.Logical_expressionContext ctx) { - // List or_decs = ctx.OR() == null ? null : ctx.OR() - // .stream() - // .map(OR -> OR.getText()) - // .collect(toList()); - // Logical_termVisitor logical_termVisitor = new Logical_termVisitor(); - // List logical_terms = ctx.logical_term() - // .stream() - // .map(logical_term -> logical_term.accept(logical_termVisitor)) - // .collect(toList()); - // StringBuilder temStr = new StringBuilder(); - // temStr.append(logical_terms.get(0)); - // if (or_decs != null) { - // for (int i=0; i { - // @Override - // public String visitLogical_term(modelicaParser.Logical_termContext ctx) { - // List and_decs = ctx.AND() == null ? null : ctx.AND() - // .stream() - // .map(AND -> AND.getText()) - // .collect(toList()); - // Logical_factorVisitor logical_factorVisitor = new Logical_factorVisitor(); - // List logical_factors = ctx.logical_factor() - // .stream() - // .map(logical_factor -> logical_factor.accept(logical_factorVisitor)) - // .collect(toList()); - // StringBuilder temStr = new StringBuilder(); - // temStr.append(logical_factors.get(0)); - // if (and_decs != null) { - // for (int i=0; i { - // @Override - // public String visitLogical_factor(modelicaParser.Logical_factorContext ctx) { - // String not_dec = - // ctx.NOT() == null ? null : ctx.NOT().getText(); - // RelationVisitor relationVisitor = new RelationVisitor(); - // String relation = ctx.relation().accept(relationVisitor); - // StringBuilder temStr = new StringBuilder(); - // String logFacStr = (not_dec != null) ? (temStr.append(not_dec).append(" ").append(relation).toString()) - // : (relation); - // return logFacStr; - // //return new Logical_factor(not_dec, relation); - // } - // } - - // private static class RelationVisitor extends modelicaBaseVisitor { - // @Override - // public String visitRelation(modelicaParser.RelationContext ctx) { - // Arithmetic_expressionVisitor arithmetic_expressionVisitor = new Arithmetic_expressionVisitor(); - // List arithmetic_expressions = ctx.arithmetic_expression() - // .stream() - // .map(arithmetic_expression -> arithmetic_expression.accept(arithmetic_expressionVisitor)) - // .collect(toList()); - // Rel_opVisitor rel_opVisitor = new Rel_opVisitor(); - // String rel_op1 = - // ctx.rel_op() == null ? null : ctx.rel_op().accept(rel_opVisitor); - // StringBuilder temStr = new StringBuilder(); - // temStr.append(arithmetic_expressions.get(0)); - // if (rel_op1 != null) { - // temStr.append(rel_op1).append(arithmetic_expressions.get(1)); - // } - // return temStr.toString(); - // // return new Relation(arithmetic_expression1, rel_op1, arithmetic_expression2); - // } - // } - - // private static class Rel_opVisitor extends modelicaBaseVisitor { - // @Override - // public String visitRel_op(modelicaParser.Rel_opContext ctx) { - // String relOpe = ctx.getText(); - // return relOpe; - // //return new Rel_op(ope_dec); - // } - // } - - // private static class Arithmetic_expressionVisitor extends modelicaBaseVisitor { - // @Override - // public String visitArithmetic_expression(modelicaParser.Arithmetic_expressionContext ctx) { - // Add_opVisitor add_opVisitor = new Add_opVisitor(); - // List add_ops = ctx.add_op() == null ? null : ctx.add_op() - // .stream() - // .map(add_op -> add_op.accept(add_opVisitor)) - // .collect(toList()); - // TermVisitor termVisitor = new TermVisitor(); - // List terms = ctx.term() - // .stream() - // .map(term -> term.accept(termVisitor)) - // .collect(toList()); - // StringBuilder temStr = new StringBuilder(); - // if (add_ops.size() == terms.size()) { - // for (int i=0; i { - // @Override - // public String visitAdd_op(modelicaParser.Add_opContext ctx) { - // String addOpe = ctx.getText(); - // return addOpe; - // //return new Add_op(add_dec); - // } - // } - - // private static class TermVisitor extends modelicaBaseVisitor { - // @Override - // public String visitTerm(modelicaParser.TermContext ctx) { - // Mul_opVisitor mul_opVisitor = new Mul_opVisitor(); - // List mul_op_1 = ctx.mul_op() == null ? null : ctx.mul_op() - // .stream() - // .map(mul_op -> mul_op.accept(mul_opVisitor)) - // .collect(toList()); - // FactorVisitor factorVisitor = new FactorVisitor(); - // List factors = ctx.factor() - // .stream() - // .map(factor -> factor.accept(factorVisitor)) - // .collect(toList()); - // StringBuilder temStr = new StringBuilder(); - // temStr.append(factors.get(0)); - // if (mul_op_1 != null) { - // for (int i=0; i { - // @Override - // public String visitMul_op(modelicaParser.Mul_opContext ctx) { - // String mulOpe = ctx.getText(); - // return mulOpe; - // //return new Mul_op(mul_dec); - // } - // } - - // private static class FactorVisitor extends modelicaBaseVisitor { - // @Override - // public String visitFactor(modelicaParser.FactorContext ctx) { - // PrimaryVisitor primaryVisitor = new PrimaryVisitor(); - // List primarys = ctx.primary() - // .stream() - // .map(primary -> primary.accept(primaryVisitor)) - // .collect(toList()); - // String caret = - // ctx.SYMBOL_CARET()==null ? null : ctx.SYMBOL_CARET().getText(); - // String dotCaret = - // ctx.SYMBOL_DOTCARET()==null ? null : ctx.SYMBOL_DOTCARET().getText(); - // String facStr = primarys.get(0); - // if (primarys.size()>1) { - // StringBuilder temStr = new StringBuilder(); - // if (caret != null) { - // facStr = temStr.append(primarys.get(0)).append(caret) - // .append(primarys.get(1)) - // .toString(); - // } else { - // facStr = temStr.append(primarys.get(0)).append(dotCaret) - // .append(primarys.get(1)) - // .toString(); - // } - // } - // return facStr; - // // return new Factor(primarys, caret, dotCaret); - // } - // } - - // private static class PrimaryVisitor extends modelicaBaseVisitor { - // @Override - // public String visitPrimary(modelicaParser.PrimaryContext ctx) { - // String num_dec = - // ctx.UNSIGNED_NUMBER() == null ? null : ctx.UNSIGNED_NUMBER().getText(); - // String str_dec = - // ctx.STRING() == null ? null : ctx.STRING().getText(); - // String false_dec = - // ctx.FALSE() == null ? null : ctx.FALSE().getText(); - // String true_dec = - // ctx.TRUE() == null ? null : ctx.TRUE().getText(); - // String der_der = - // ctx.DER() == null ? null : ctx.DER().getText(); - // String init_dec = - // ctx.INITIAL() == null ? null : ctx.INITIAL().getText(); - // String end_dec = - // ctx.END() == null ? null : ctx.END().getText(); - // NameVisitor nameVisitor = new NameVisitor(); - // String name1 = - // ctx.name() == null ? null : ctx.name().accept(nameVisitor); - // Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); - // String function_call_args1 = - // ctx.function_call_args() == null ? null : ctx.function_call_args().accept(function_call_argsVisitor); - // Component_referenceVisitor component_referenceVisitor = new Component_referenceVisitor(); - // String component_reference1 = - // ctx.component_reference() == null ? null : ctx.component_reference().accept(component_referenceVisitor); - // Output_expression_listVisitor output_expression_listVisitor = new Output_expression_listVisitor(); - // String output_expression_list1 = - // ctx.output_expression_list() == null ? null : ctx.output_expression_list().accept(output_expression_listVisitor); - // Expression_listVisitor expression_listVisitor = new Expression_listVisitor(); - // List expression_list_1 = ctx.expression_list() == null ? null : ctx.expression_list() - // .stream() - // .map(expression_list -> expression_list.accept(expression_listVisitor)) - // .collect(toList()); - // List semiColon = ctx.SYMBOL_SEMICOLON() == null ? null : ctx.SYMBOL_SEMICOLON() - // .stream() - // .map(SYMBOL_SEMICOLON -> SYMBOL_SEMICOLON.getText()) - // .collect(toList()); - // Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); - // String function_arguments1 = - // ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); - // StringBuilder temStr = new StringBuilder(); - // String priStr = num_dec; - // if (str_dec != null) {priStr = str_dec;} - // else if (false_dec != null) {priStr = false_dec;} - // else if (true_dec != null) {priStr = true_dec;} - // else if (function_call_args1 != null) { - // if (name1 != null) { - // priStr = temStr.append(name1).append(" ").append(function_call_args1).toString();} - // else if (der_der != null) { - // priStr = temStr.append(der_der).append(" ").append(function_call_args1).toString();} - // else { - // priStr = temStr.append(init_dec).append(" ").append(function_call_args1).toString();} - // } - // else if (component_reference1 != null) { - // priStr = component_reference1;} - // else if (output_expression_list1 != null) { - // priStr = temStr.append("(").append(output_expression_list1).append(")").toString();} - // else if (expression_list_1.size() > 0 ) { - // temStr.append(expression_list_1.get(0)); - // if (semiColon != null) { - // for (int i=0; i { - // @Override - // public String visitName(modelicaParser.NameContext ctx) { - // List dots = ctx.SYMBOL_DOT()==null ? null : ctx.SYMBOL_DOT() - // .stream() - // .map(SYMBOL_DOT -> SYMBOL_DOT.getText()) - // .collect(toList()); - // List ident = ctx.IDENT() - // .stream() - // .map(IDENT -> IDENT.getText()) - // .collect(toList()); - // StringBuilder temStr = new StringBuilder(); - // if (dots == null) { - // temStr.append(ident.get(0)); - // } else { - // if (dots.size() == ident.size()) { - // for (int i=0; i { - // @Override - // public String visitComponent_reference(modelicaParser.Component_referenceContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // // return new Component_reference(ident, dots, array_subscripts_1); - // } - // } - - // private static class Function_call_argsVisitor extends modelicaBaseVisitor { - // @Override - // public String visitFunction_call_args(modelicaParser.Function_call_argsContext ctx) { - // Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); - // String function_arguments = - // ctx.function_arguments() == null ? "" : ctx.function_arguments().accept(function_argumentsVisitor); - // StringBuilder temStr = new StringBuilder(); - // String funCalArgs = temStr.append("(").append(function_arguments).append(")") - // .toString(); - // return funCalArgs; - // //return new Function_call_args(function_arguments); - // } - // } - - // private static class Function_argumentsVisitor extends modelicaBaseVisitor { - // @Override - // public String visitFunction_arguments(modelicaParser.Function_argumentsContext ctx) { - // Function_argumentVisitor function_argumentVisitor = new Function_argumentVisitor(); - // String function_argument = - // ctx.function_argument() == null ? null : ctx.function_argument().accept(function_argumentVisitor); - // Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); - // String function_arguments = - // ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); - // String for_dec = - // ctx.FOR() == null ? null : ctx.FOR().getText(); - // For_indicesVisitor for_indicesVisitor = new For_indicesVisitor(); - // String for_indices = - // ctx.for_indices() == null ? null : ctx.for_indices().accept(for_indicesVisitor); - // Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); - // String named_arguments = - // ctx.named_arguments() == null ? null : ctx.named_arguments().accept(named_argumentsVisitor); - // String funArgsStr = named_arguments; - // if (function_argument != null) { - // StringBuilder temStr1 = new StringBuilder(); - // if (function_arguments != null) { - // temStr1.append(",").append(function_arguments); - // } else if (for_indices != null) { - // temStr1.append("for ").append(for_indices); - // } - // StringBuilder temStr2 = new StringBuilder(); - // funArgsStr = temStr2.append(function_argument) - // .append(temStr1.toString()) - // .toString(); - // } - // return funArgsStr; - // //return new Function_arguments(function_argument, function_arguments, for_dec, for_indices, named_arguments); - // } - // } - - // private static class Named_argumentsVisitor extends modelicaBaseVisitor { - // @Override - // public String visitNamed_arguments(modelicaParser.Named_argumentsContext ctx) { - // Named_argumentVisitor named_argumentVisitor = new Named_argumentVisitor(); - // String named_argument = - // ctx.named_argument().accept(named_argumentVisitor); - // Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); - // String named_arguments = - // ctx.named_arguments() == null ? null : ctx.named_arguments().accept(named_argumentsVisitor); - // String comma = - // ctx.SYMBOL_COMMA()==null ? null : ctx.SYMBOL_COMMA().getText(); - // String namedArgsStr = named_argument; - // if (comma != null) { - // StringBuilder temStr = new StringBuilder(); - // namedArgsStr = temStr.append(namedArgsStr).append(",") - // .append(named_arguments) - // .toString(); - // } - // return namedArgsStr; - // //return new Named_arguments(named_argument,named_arguments); - // } - // } - - // private static class Named_argumentVisitor extends modelicaBaseVisitor { - // @Override - // public String visitNamed_argument(modelicaParser.Named_argumentContext ctx) { - // String ident = ctx.IDENT().getText(); - // Function_argumentVisitor function_argumentVisitor = new Function_argumentVisitor(); - // String function_argument = - // ctx.function_argument().accept(function_argumentVisitor); - // StringBuilder temStr = new StringBuilder(); - // String namedArgStr = temStr.append(ident).append("=") - // .append(function_argument) - // .toString(); - // return namedArgStr; - // //return new Named_argument(ident, function_argument); - // } - // } - - // private static class Function_argumentVisitor extends modelicaBaseVisitor { - // @Override - // public String visitFunction_argument(modelicaParser.Function_argumentContext ctx) { - // String fun_dec = - // ctx.FUNCTION() == null ? null : ctx.FUNCTION().getText(); - // NameVisitor nameVisitor = new NameVisitor(); - // String name = - // ctx.name() == null ? null : ctx.name().accept(nameVisitor); - // Named_argumentsVisitor named_argumentsVisitor = new Named_argumentsVisitor(); - // String named_arguments = - // ctx.named_arguments() == null ? "" : ctx.named_arguments().accept(named_argumentsVisitor); - // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - // String expression = - // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - // String funArgStr = expression; - // if (fun_dec != null) { - // StringBuilder temStr = new StringBuilder(); - // funArgStr = temStr.append(fun_dec).append(" ").append(name) - // .append("(").append(named_arguments).append(")") - // .toString(); - // } - // return funArgStr; - // //return new Function_argument(fun_dec, name, named_arguments, expression); - // } - // } - - // private static class Output_expression_listVisitor extends modelicaBaseVisitor { - // @Override - // public String visitOutput_expression_list(modelicaParser.Output_expression_listContext ctx) { - // String temStr = ""; - // if (ctx.getText().isEmpty()) { - // temStr = null; - // } else { - // int a = ctx.start.getStartIndex(); - // int b = ctx.stop.getStopIndex(); - // Interval interval = new Interval(a,b); - // CharStream charStr = ctx.start.getInputStream(); - // temStr = charStr.getText(interval).trim(); - // } - // return temStr; - // //return new Output_expression_list(expression_1); - // } - // } - - // private static class Expression_listVisitor extends modelicaBaseVisitor { - // @Override - // public String visitExpression_list(modelicaParser.Expression_listContext ctx) { - // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - // List expression_1 = ctx.expression() - // .stream() - // .map(expression -> expression.accept(expressionVisitor)) - // .collect(toList()); - // StringBuilder temStr = new StringBuilder(); - // temStr.append(expression_1.get(0)); - // if (expression_1.size()>1) { - // for (int i=1; i { - // @Override - // public String visitArray_subscripts(modelicaParser.Array_subscriptsContext ctx) { - // SubscriptVisitor subscriptVisitor = new SubscriptVisitor(); - // List subscript_1 = ctx.subscript() - // .stream() - // .map(subscript -> subscript.accept(subscriptVisitor)) - // .collect(toList()); - // StringBuilder temStr1 = new StringBuilder(); - // String arraySubStr = temStr1.append("[") - // .append(subscript_1.get(0)) - // .append("]") - // .toString(); - // if (subscript_1.size() > 1) { - // StringBuilder temStr2 = new StringBuilder(); - // temStr2.append(subscript_1.get(0)); - // for (int i=1; i { - // @Override - // public String visitSubscript(modelicaParser.SubscriptContext ctx) { - // String colon = - // ctx.SYMBOL_COLON() == null ? null : ctx.SYMBOL_COLON().getText(); - // ExpressionVisitor expressionVisitor = new ExpressionVisitor(); - // String expression = - // ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - // String subStr = - // colon != null ? colon : expression; - // return subStr; - // //return new Subscript(expression); - // } - // } - - // public static class CommentVisitor extends modelicaBaseVisitor { - // String string_comment1; - // String annotation1; - // @Override - // public Comment visitComment(modelicaParser.CommentContext ctx) { - // String_commentVisitor string_commentVisitor = new String_commentVisitor(); - // String string_comment1 = - // ctx.string_comment() == null ? null : ctx.string_comment().accept(string_commentVisitor); - // AnnotationVisitor annotationVisitor = new AnnotationVisitor(); - // String annotation1 = - // ctx.annotation() == null ? null : ctx.annotation().accept(annotationVisitor); - // this.string_comment1 = string_comment1; - // this.annotation1 = annotation1; - // return new Comment(string_comment1, annotation1); - // } - // } - - // public static class String_commentVisitor extends modelicaBaseVisitor { - // @Override - // public String visitString_comment(modelicaParser.String_commentContext ctx) { - // List str_dec = ctx.STRING() == null ? null : ctx.STRING() - // .stream() - // .map(STRING -> STRING.getText()) - // .collect(toList()); - // String strCom = ""; - // if (str_dec.size() == 1) { - // strCom = str_dec.get(0); - // } else if (str_dec.size() > 1) { - // StringBuilder temStr = new StringBuilder(); - // temStr.append(str_dec.get(0)); - // for (int i=1; i { - // @Override - // public String visitAnnotation(modelicaParser.AnnotationContext ctx) { - // String ann_dec = ctx.ANNOTATION().getText(); - // Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); - // String class_modification = ctx.class_modification().accept(class_modificationVisitor); - // return class_modification; - // //return new Annotation(ann_dec, class_modification); - // } - // } } From e4703f453171064b1c1afb541e8ffecd85045493 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Fri, 2 Jul 2021 10:14:41 -0700 Subject: [PATCH 04/29] fixing empty list error --- .../main/java/gov/lbl/parser/parser/CompositionVisitor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java index 37014dc2..801c432b 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java @@ -22,7 +22,7 @@ public Composition visitComposition(modelicaParser.CompositionContext ctx) { List element_lists_types = new ArrayList(); element_lists_types.add("None"); - for (int i=1; i PROTECTED.getText()) .collect(toList()); - List public_element_lists = public_dec.size() == 0 ? null : new ArrayList(); - List protected_element_lists = protected_dec.size() == 0 ? null : new ArrayList(); + List public_element_lists = public_dec == null ? null : new ArrayList(); + List protected_element_lists = protected_dec == null ? null : new ArrayList(); for(int i=1; i Date: Fri, 2 Jul 2021 12:47:27 -0700 Subject: [PATCH 05/29] adding exception handling for null objects --- .../parser/Arithmetic_expressionVisitor.java | 12 +++--- .../lbl/parser/parser/CompositionVisitor.java | 2 +- .../parser/Der_class_specifierVisitor.java | 10 ++--- .../lbl/parser/parser/ExpressionVisitor.java | 25 ++++++----- .../gov/lbl/parser/parser/FactorVisitor.java | 10 +++-- .../gov/lbl/parser/parser/NameVisitor.java | 42 ++++--------------- .../parser/Simple_expressionVisitor.java | 18 +++++--- .../parser/Stored_definitionVisitor.java | 6 ++- .../parser/parser/String_commentVisitor.java | 18 ++++---- .../parser/parser/When_equationVisitor.java | 10 +++-- .../parser/parser/When_statementVisitor.java | 11 ++--- 11 files changed, 79 insertions(+), 85 deletions(-) diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java index a279f475..c52b3b3b 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Arithmetic_expressionVisitor.java @@ -27,11 +27,13 @@ public Arithmetic_expression visitArithmetic_expression(modelicaParser.Arithmeti .collect(toList()); List arithmetic_term_list = new ArrayList(); - if (add_ops.size() == (terms.size() - 1)) { - arithmetic_term_list.add(new Arithmetic_term(null, terms.get(0))); - } - for (int i=0; i 0) { if (annotations.size() == 2) { external_annotation = annotations.get(0); annotation = annotations.get(1); diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Der_class_specifierVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Der_class_specifierVisitor.java index 839abd29..2246f93f 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Der_class_specifierVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Der_class_specifierVisitor.java @@ -14,11 +14,11 @@ public class Der_class_specifierVisitor extends modelicaBaseVisitor { @Override public Der_class_specifier visitDer_class_specifier(modelicaParser.Der_class_specifierContext ctx) { - List idents = ctx.IDENT() - .stream() - .map(IDENT -> IDENT.getText()) - .collect(toList()); - String identifier = idents.get(0); + List idents = ctx.IDENT() == null ? null : ctx.IDENT() + .stream() + .map(IDENT -> IDENT.getText()) + .collect(toList()); + String identifier = idents == null? "" : idents.get(0); List identifiers = idents.subList(1, idents.size()); NameVisitor nameVisitor = new NameVisitor(); diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java index da45a9e2..b9b22941 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/ExpressionVisitor.java @@ -27,16 +27,21 @@ public Expression visitExpression(modelicaParser.ExpressionContext ctx) { If_expression if_expression = null; List if_elseif = new ArrayList(); - for (int i = 0; i 2) { - // expressions always have else? - Expression else_expression = expressions.get(expressions.size()-1); - - if_expression = new If_expression(if_elseif, else_expression); + if (expressions != null) { + for (int i = 0; i 2) { + // expressions always have else? + Expression else_expression = expressions.get(expressions.size()-1); + + if_expression = new If_expression(if_elseif, else_expression); + } + else { + if_expression = new If_expression(if_elseif, null); + } } return new Expression(simple_expression, if_expression); diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java index e962c0ee..10b6933f 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/FactorVisitor.java @@ -21,9 +21,11 @@ public Factor visitFactor(modelicaParser.FactorContext ctx) { String op = ctx.SYMBOL_CARET()==null ? ( ctx.SYMBOL_DOTCARET() == null ? "" : ctx.SYMBOL_DOTCARET().getText()) : ctx.SYMBOL_CARET().getText(); - Primary primary1 = primarys.get(0); - Primary primary2 = primarys.size() == 2 ? primarys.get(1) : null; - - return new Factor(primary1, op, primary2); + if (primarys != null) { + Primary primary1 = primarys.get(0); + Primary primary2 = primarys.size() == 2 ? primarys.get(1) : null; + return new Factor(primary1, op, primary2); + } + return new Factor(null, op, null); } } \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/NameVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/NameVisitor.java index c0e6c3e0..536a7704 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/NameVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/NameVisitor.java @@ -22,42 +22,14 @@ public Name visitName(modelicaParser.NameContext ctx) { .collect(toList()); List name_parts = new ArrayList(); - if (identifiers.size() == dots.size()+1) { - name_parts.add(new Name_part(false, identifiers.get(0))); + if (dots != null && identifiers != null) { + if (identifiers.size() == dots.size()+1) { + name_parts.add(new Name_part(false, identifiers.get(0))); + } + for (int i=1; i name_parts = new ArrayList(); -// // for (int i=0; i log_expr.accept(logical_expressionVisitor)) .collect(toList()); - Logical_expression logical_expression1 = logical_expressions.get(0); + Logical_expression logical_expression1 = null; Logical_expression logical_expression2 = null; Logical_expression logical_expression3 = null; - if (logical_expressions.size() > 1) { - logical_expression2 = logical_expressions.get(1); - } - if (logical_expressions.size() > 2) { - logical_expression3 = logical_expressions.get(2); + + if (logical_expressions != null) { + logical_expression1 = logical_expressions.get(0); + + if (logical_expressions.size() > 1) { + logical_expression2 = logical_expressions.get(1); + } + if (logical_expressions.size() > 2) { + logical_expression3 = logical_expressions.get(2); + } } + return new Simple_expression(logical_expression1, logical_expression2, logical_expression3); } } \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java index 8b429639..6d10d5af 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java @@ -25,8 +25,10 @@ public Stored_definition visitStored_definition(modelicaParser.Stored_definition .collect(toList()); Boolean is_final = false; - if (final_dec.size() > 0) { - is_final = true; + if (final_dec != null) { + if (final_dec.size() > 0) { + is_final = true; + } } Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/String_commentVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/String_commentVisitor.java index 8b626875..5b1e3422 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/String_commentVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/String_commentVisitor.java @@ -13,15 +13,17 @@ public String visitString_comment(modelicaParser.String_commentContext ctx) { .map(STRING -> STRING.getText()) .collect(toList()); String strCom = ""; - if (str_dec.size() == 1) { - strCom = str_dec.get(0); - } else if (str_dec.size() > 1) { - StringBuilder temStr = new StringBuilder(); - temStr.append(str_dec.get(0)); - for (int i=1; i 1) { + StringBuilder temStr = new StringBuilder(); + temStr.append(str_dec.get(0)); + for (int i=1; i eqn.accept(equationVisitor)) .collect(toList()); - List when_elsewhen = new ArrayList(); - for (int i = 0; i< expressions.size(); i++) { + List when_elsewhen = new ArrayList(); + if (expressions != null) { + for (int i = 0; i< expressions.size(); i++) { - //check? - when_elsewhen.add(new When_elsewhen_equation(expressions.get(i), equations.subList(i, i+1))); + //check? + when_elsewhen.add(new When_elsewhen_equation(expressions.get(i), equations.subList(i, i+1))); + } } return new When_equation(when_elsewhen); diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/When_statementVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/When_statementVisitor.java index 0db6f5c4..da1b5317 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/When_statementVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/When_statementVisitor.java @@ -27,13 +27,14 @@ public When_statement visitWhen_statement(modelicaParser.When_statementContext c .map(stmt -> stmt.accept(statementVisitor)) .collect(toList()); - List when_elsewhen = new ArrayList(); - for (int i = 0; i< expressions.size(); i++) { + List when_elsewhen = new ArrayList(); + if (expressions != null) { + for (int i = 0; i< expressions.size(); i++) { - //check? - when_elsewhen.add(new When_elsewhen_statement(expressions.get(i), statements.subList(i, i+1))); + //check? + when_elsewhen.add(new When_elsewhen_statement(expressions.get(i), statements.subList(i, i+1))); + } } - return new When_statement(when_elsewhen); } } \ No newline at end of file From bf04d782869ef2f49ac8370876a7080ffae12c5c Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Tue, 28 Sep 2021 16:06:38 -0700 Subject: [PATCH 06/29] adding null check for element replaceable --- .../gov/lbl/parser/parser/Element_redeclarationVisitor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Element_redeclarationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Element_redeclarationVisitor.java index 0fabe960..ca6f134d 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Element_redeclarationVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Element_redeclarationVisitor.java @@ -20,7 +20,7 @@ public Element_redeclaration visitElement_redeclaration(modelicaParser.Element_r Component_clause1 component_clause1 = ctx.component_clause1() == null ? null : ctx.component_clause1().accept(component_clause1Visitor); Element_replaceableVisitor element_replaceableVisitor = new Element_replaceableVisitor(); - Element_replaceable element_replaceable = ctx.element_replaceable().accept(element_replaceableVisitor); + Element_replaceable element_replaceable = ctx.element_replaceable() == null ? null : ctx.element_replaceable().accept(element_replaceableVisitor); return new Element_redeclaration(each, is_final, short_class_definition, component_clause1, element_replaceable); } From c8952c2e5852f47b635874fba1f76f89fa8ad69b Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Mon, 11 Oct 2021 12:26:20 -0700 Subject: [PATCH 07/29] updating grammar for stored definition and fixing raw-json generation --- .../antlr4/gov/lbl/antlr4/visitor/modelica.g4 | 2 +- .../src/main/java/gov/lbl/parser/Main.java | 2 +- .../gov/lbl/parser/domain/Composition.java | 6 ++ .../parser/Stored_definitionVisitor.java | 4 +- lib/check_checksum.js | 93 +++++++++++++++++++ lib/util.js | 6 +- 6 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 lib/check_checksum.js diff --git a/java/antlrVisitor/src/main/antlr4/gov/lbl/antlr4/visitor/modelica.g4 b/java/antlrVisitor/src/main/antlr4/gov/lbl/antlr4/visitor/modelica.g4 index 41db038f..a9f3b104 100644 --- a/java/antlrVisitor/src/main/antlr4/gov/lbl/antlr4/visitor/modelica.g4 +++ b/java/antlrVisitor/src/main/antlr4/gov/lbl/antlr4/visitor/modelica.g4 @@ -27,7 +27,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. grammar modelica; stored_definition - : (WITHIN (name)? SYMBOL_SEMICOLON)* ((FINAL)? class_definition SYMBOL_SEMICOLON)* + : (WITHIN (name)? SYMBOL_SEMICOLON)? ((FINAL)? class_definition SYMBOL_SEMICOLON)* ; class_definition diff --git a/java/parser/src/main/java/gov/lbl/parser/Main.java b/java/parser/src/main/java/gov/lbl/parser/Main.java index 07423143..b18a5a86 100644 --- a/java/parser/src/main/java/gov/lbl/parser/Main.java +++ b/java/parser/src/main/java/gov/lbl/parser/Main.java @@ -129,7 +129,7 @@ private List moParser(String[] args) throws Exception { runLog.add(e.getMessage()); throw new Exception(e); } - Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create(); + Gson gson = new GsonBuilder().disableHtmlEscaping().create(); //Gson gson = new Gson(); jsonOut = gson.toJson(antlrParseOut); if (args.length>2) { diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java index bf7e2318..d82838a9 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java @@ -11,6 +11,12 @@ public class Composition { private External_composition external_composition; private Annotation annotation; + // composition: list(composition_obj) + // composition_obj { + // type: element_list/public_ele/proto... + // json: {} + // } + public Composition(Element_list element_list, Collection public_element_lists, Collection protected_element_lists, Collection equation_sections, Collection algorithm_sections, External_composition external_composition, Annotation annotation) { this.element_list = element_list; diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java index 6d10d5af..fed82200 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java @@ -14,9 +14,7 @@ public class Stored_definitionVisitor extends modelicaBaseVisitor names = ctx.name().stream().map(name -> nameVisitor.visitName(name)).collect(toList()); - - Name name = names.get(0); + Name name = ctx.name() == null ? null : ctx.name().accept(nameVisitor); String within = name.getName(); List final_dec = ctx.FINAL() == null ? null : ctx.FINAL() diff --git a/lib/check_checksum.js b/lib/check_checksum.js new file mode 100644 index 00000000..d7399b43 --- /dev/null +++ b/lib/check_checksum.js @@ -0,0 +1,93 @@ +const crypto = require('crypto'); +const fs = require('fs'); +const path = require('path'); + +function check_if_json_exists(mo_file_path, raw_json=false, output_dir=null) { + if (output_dir == null) { + if (raw_json) { + output_dir = path.join(__dirname, 'raw-json') + } + else { + output_dir = path.join(__dirname, 'json') + } + + } + mo_file_paths = mo_file_path.split(path.sep); + mo_file_name = mo_file_paths[mo_file_paths.length - 1].split(".mo")[0]; + // TODO: current file name is package name along with package (folder structure). check if this changes later + json_file_name = mo_file_name+".json"; + json_file_path = path.join(output_dir, json_file_name); + + if (fs.existsSync(json_file_path)) { + return [true, json_file_path]; + } + return [false, null]; +} + +function get_checksum_from_json(json_file_path) { + var checksum_from_json; + try { + var file_content = fs.readFileSync(json_file_path, 'utf8'); + var json_output = JSON.parse(file_content); + + // TODO: change based on new data model + checksum_from_json = json_output[0]['checksum']; + if (checksum_from_json == null) { + console.log("no checksum in current json file"); + return null; + } + } catch (err) { + console.log("Error parsing json file:", err); + throw ("Error reading file :", err); + } + return checksum_from_json; +} + +async function get_mo_checksum(mo_file_path) { + //source: https://wellingguzman.com/notes/node-checksum + return new Promise(function (resolve, reject) { + const hash = crypto.createHash('md5'); + const input = fs.createReadStream(mo_file_path); + + input.on('error', reject); + + input.on('data', function (chunk) { + hash.update(chunk); + }); + + input.on('close', function () { + resolve(hash.digest('hex')); + }); + }); +} + +async function main(mo_file_path, raw_json=false) { + output = check_if_json_exists(file=mo_file_path, raw_json=false); + + file_exists = output[0] + + if (file_exists) { + json_file_path = output[1] + var output = get_checksum_from_json(json_file_path=json_file_path); + + if (output != null) { + checksum_from_json = output; + } else { + checksum_from_json = null; + } + } + + let res = await get_mo_checksum(mo_file_path) + + if (res == checksum_from_json) { + console.log("true") + } else { + console.log("different checksum") + } + + return res +} + + +var mo_file_path = 'test/FromModelica/Parameter1.mo'; +main(mo_file_path) \ No newline at end of file diff --git a/lib/util.js b/lib/util.js index e18ec85d..cec5bf1b 100644 --- a/lib/util.js +++ b/lib/util.js @@ -371,13 +371,13 @@ function getFileNameInJsonOutput (json) { var className var fileName // First, check if there is a 'within xxxx;' - var within = getProperty(['within', 0], json) + var within = getProperty(['within'], json) // Get the model name var shortClass = getProperty( - ['class_definition', 0, 'class_specifier', 'short_class_specifier', 'className'], json) + ['class_definition', 0, 'class_specifier', 'short_class_specifier', 'identifier'], json) var shortName = shortClass !== null ? shortClass : getProperty( - ['class_definition', 0, 'class_specifier', 'long_class_specifier', 'name'], json) + ['class_definition', 0, 'class_specifier', 'long_class_specifier', 'identifier'], json) if (shortName) { className = (within) ? within + '.' + shortName : shortName } From 9f072f78e5a4afa38082b59b1d22d81fff5fc9ab Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Tue, 12 Oct 2021 14:18:34 -0700 Subject: [PATCH 08/29] refactored composition to preserve order of elements --- .../gov/lbl/parser/domain/Composition.java | 13 +-- .../lbl/parser/domain/Element_section.java | 18 ++++ .../lbl/parser/parser/CompositionVisitor.java | 93 +++++++++---------- 3 files changed, 64 insertions(+), 60 deletions(-) create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Element_section.java diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java index d82838a9..ff50c934 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java @@ -4,10 +4,7 @@ public class Composition { private Element_list element_list; - private Collection public_element_lists; - private Collection protected_element_lists; - private Collection equation_sections; - private Collection algorithm_sections; + private Collection element_sections; private External_composition external_composition; private Annotation annotation; @@ -17,13 +14,9 @@ public class Composition { // json: {} // } - public Composition(Element_list element_list, Collection public_element_lists, Collection protected_element_lists, Collection equation_sections, - Collection algorithm_sections, External_composition external_composition, Annotation annotation) { + public Composition(Element_list element_list, Collection element_sections, External_composition external_composition, Annotation annotation) { this.element_list = element_list; - this.public_element_lists = (public_element_lists.size() > 0) ? public_element_lists : null; - this.protected_element_lists = (protected_element_lists.size() > 0) ? protected_element_lists : null; - this.equation_sections = (equation_sections.size() > 0) ? equation_sections : null; - this.algorithm_sections = (algorithm_sections.size() > 0) ? algorithm_sections : null; + this.element_sections = (element_sections.size() > 0) ? element_sections : null; this.external_composition = external_composition; this.annotation = annotation; } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Element_section.java b/java/parser/src/main/java/gov/lbl/parser/domain/Element_section.java new file mode 100644 index 00000000..a10ee354 --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Element_section.java @@ -0,0 +1,18 @@ +package gov.lbl.parser.domain; + +import java.util.Collection; + +public class Element_section { + private Element_list public_element_list; + private Element_list protected_element_list; + private Equation_section equation_section; + private Algorithm_section algorithm_section; + + public Element_section(Element_list public_element_list, Element_list protected_element_list, + Equation_section equation_section, Algorithm_section algorithm_sections) { + this.public_element_list = public_element_list; + this.protected_element_list = protected_element_list; + this.equation_section = equation_section; + this.algorithm_section = algorithm_sections; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java index 4030c2f7..b58a5a31 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java @@ -2,12 +2,19 @@ import java.util.List; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.TerminalNode; + import gov.lbl.antlr4.visitor.modelicaBaseVisitor; import gov.lbl.antlr4.visitor.modelicaParser; import gov.lbl.parser.domain.Algorithm_section; import gov.lbl.parser.domain.Annotation; import gov.lbl.parser.domain.Composition; +import gov.lbl.parser.domain.Element; import gov.lbl.parser.domain.Element_list; +import gov.lbl.parser.domain.Element_section; +import gov.lbl.parser.domain.Equation; import gov.lbl.parser.domain.Equation_section; import gov.lbl.parser.domain.External_composition; import gov.lbl.parser.domain.External_function_call; @@ -19,64 +26,50 @@ public class CompositionVisitor extends modelicaBaseVisitor { @Override public Composition visitComposition(modelicaParser.CompositionContext ctx) { - List element_lists_types = new ArrayList(); - element_lists_types.add("None"); - - for (int i=1; i element_sections = new ArrayList(); Element_listVisitor element_listVisitor = new Element_listVisitor(); + ElementVisitor element_visitor = new ElementVisitor(); Equation_sectionVisitor equation_sectionVisitor = new Equation_sectionVisitor(); + EquationVisitor equationVisitor = new EquationVisitor(); Algorithm_sectionVisitor algorithm_sectionVisitor = new Algorithm_sectionVisitor(); - - List element_lists = ctx.element_list() - .stream() - .map(element_list -> element_list.accept(element_listVisitor)) - .collect(toList()); - - Element_list element_list = element_lists.get(0); - List public_dec = ctx.PUBLIC() == null ? null : ctx.PUBLIC() - .stream() - .map(PUBLIC -> PUBLIC.getText()) - .collect(toList()); + List children = ctx.children; + List tokens = null; + String previous_element_list_modifier = null; - List protected_dec = ctx.PUBLIC() == null ? null : ctx.PROTECTED() - .stream() - .map(PROTECTED -> PROTECTED.getText()) - .collect(toList()); - - List public_element_lists = public_dec == null ? null : new ArrayList(); - List protected_element_lists = protected_dec == null ? null : new ArrayList(); - - for(int i=1; i equation_sections = ctx.equation_section() == null ? null : ctx.equation_section() - .stream() - .map(equation_section -> equation_section.accept(equation_sectionVisitor)) - .collect(toList());; - List algorithm_sections = ctx.algorithm_section() == null ? null : ctx.algorithm_section() - .stream() - .map(algorithm_section -> algorithm_section.accept(algorithm_sectionVisitor)) - .collect(toList());; - Boolean external = ctx.EXTERNAL() == null ? false : true; String language_specification = ctx.language_specification() == null ? "" : ctx.language_specification().getText(); @@ -106,6 +99,6 @@ else if (public_protected_type.equals("public")) { } External_composition external_composition = new External_composition(language_specification, external_function_call, external_annotation); - return new Composition(element_list, public_element_lists, protected_element_lists, equation_sections, algorithm_sections, external_composition, annotation); + return new Composition(element_list, element_sections, external_composition, annotation); } } \ No newline at end of file From ce974162a2aab6040133b645d2a8abaeabc95c15 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Tue, 12 Oct 2021 14:36:02 -0700 Subject: [PATCH 09/29] better handling of null objects --- .../java/gov/lbl/parser/domain/Argument_list.java | 2 +- .../java/gov/lbl/parser/domain/Composition.java | 8 +------- .../main/java/gov/lbl/parser/domain/Enum_list.java | 2 +- .../src/main/java/gov/lbl/parser/domain/Name.java | 13 ++++++++----- .../gov/lbl/parser/parser/CompositionVisitor.java | 1 - 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Argument_list.java b/java/parser/src/main/java/gov/lbl/parser/domain/Argument_list.java index 42ac4eb0..58d2692f 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Argument_list.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Argument_list.java @@ -6,6 +6,6 @@ public class Argument_list { private Collection arguments; public Argument_list(Collection arguments) { - this.arguments = arguments.size() > 0 ? arguments : null; + this.arguments = arguments; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java index ff50c934..afb525e6 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Composition.java @@ -8,15 +8,9 @@ public class Composition { private External_composition external_composition; private Annotation annotation; - // composition: list(composition_obj) - // composition_obj { - // type: element_list/public_ele/proto... - // json: {} - // } - public Composition(Element_list element_list, Collection element_sections, External_composition external_composition, Annotation annotation) { this.element_list = element_list; - this.element_sections = (element_sections.size() > 0) ? element_sections : null; + this.element_sections = element_sections; this.external_composition = external_composition; this.annotation = annotation; } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Enum_list.java b/java/parser/src/main/java/gov/lbl/parser/domain/Enum_list.java index 71d3f439..fa7ebee3 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Enum_list.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Enum_list.java @@ -5,6 +5,6 @@ public class Enum_list { private Collection enumeration_literal_list; public Enum_list(Collection enumeration_literal_list) { - this.enumeration_literal_list = (enumeration_literal_list.size() > 0) ? enumeration_literal_list : null; + this.enumeration_literal_list = enumeration_literal_list; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Name.java b/java/parser/src/main/java/gov/lbl/parser/domain/Name.java index d53e6116..d03a2ca7 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Name.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Name.java @@ -15,12 +15,15 @@ public List get_Name_parts() { public String getName() { StringBuilder name = new StringBuilder(); - for (int j=0; j element_sections = new ArrayList(); Element_listVisitor element_listVisitor = new Element_listVisitor(); - ElementVisitor element_visitor = new ElementVisitor(); Equation_sectionVisitor equation_sectionVisitor = new Equation_sectionVisitor(); EquationVisitor equationVisitor = new EquationVisitor(); Algorithm_sectionVisitor algorithm_sectionVisitor = new Algorithm_sectionVisitor(); From 26bf77375bee32ea0174055e3e191ca07d9581d4 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Wed, 13 Oct 2021 14:44:03 -0700 Subject: [PATCH 10/29] updated to include final keyword for each class_definition --- .../parser/domain/Final_class_definition.java | 11 +++++ .../main/java/gov/lbl/parser/domain/Name.java | 4 +- .../lbl/parser/domain/Stored_definition.java | 9 ++--- .../lbl/parser/parser/CompositionVisitor.java | 1 - .../parser/Stored_definitionVisitor.java | 40 +++++++++++-------- lib/util.js | 4 +- 6 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 java/parser/src/main/java/gov/lbl/parser/domain/Final_class_definition.java diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Final_class_definition.java b/java/parser/src/main/java/gov/lbl/parser/domain/Final_class_definition.java new file mode 100644 index 00000000..48d68f6a --- /dev/null +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Final_class_definition.java @@ -0,0 +1,11 @@ +package gov.lbl.parser.domain; + +public class Final_class_definition { + private Boolean is_final; + private Class_definition class_definition; + + public Final_class_definition(Boolean is_final, Class_definition class_definition) { + this.is_final = is_final; + this.class_definition = class_definition; + } +} diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Name.java b/java/parser/src/main/java/gov/lbl/parser/domain/Name.java index d03a2ca7..26b5b8d9 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Name.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Name.java @@ -17,10 +17,10 @@ public String getName() { StringBuilder name = new StringBuilder(); if (this.name_parts != null) { for (int j=0; j class_definition; + private Collection final_class_definitions; - public Stored_definition(String within, Boolean is_final, - Collection class_definition) { + public Stored_definition(String within, Collection final_class_definitions) { this.within = within; - this.is_final = is_final; - this.class_definition = (class_definition.size() > 0 ? class_definition : null); + this.final_class_definitions = final_class_definitions; } } diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java index 857c894f..69c6bf38 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java @@ -35,7 +35,6 @@ public Composition visitComposition(modelicaParser.CompositionContext ctx) { Algorithm_sectionVisitor algorithm_sectionVisitor = new Algorithm_sectionVisitor(); List children = ctx.children; - List tokens = null; String previous_element_list_modifier = null; for (ParseTree o : children) { diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java index fed82200..a93a8242 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Stored_definitionVisitor.java @@ -2,11 +2,16 @@ import java.util.List; +import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.TerminalNode; + import gov.lbl.antlr4.visitor.modelicaBaseVisitor; import gov.lbl.antlr4.visitor.modelicaParser; import gov.lbl.parser.domain.Class_definition; +import gov.lbl.parser.domain.Final_class_definition; import gov.lbl.parser.domain.Name; -import static java.util.stream.Collectors.toList; + +import java.util.ArrayList; import gov.lbl.parser.domain.Stored_definition; @@ -14,26 +19,27 @@ public class Stored_definitionVisitor extends modelicaBaseVisitor final_class_definitions = new ArrayList<>(); - List final_dec = ctx.FINAL() == null ? null : ctx.FINAL() - .stream() - .map(FINAL -> FINAL.getText()) - .collect(toList()); - - Boolean is_final = false; - if (final_dec != null) { - if (final_dec.size() > 0) { - is_final = true; - } + List children = ctx.children; + Boolean prev_is_final = false; + + for (ParseTree o : children) { + if ((o instanceof modelicaParser.Class_definitionContext)) { + Class_definition class_definition = o.accept(class_definitionVisitor); + final_class_definitions.add(new Final_class_definition(prev_is_final, class_definition)); + prev_is_final = false; + } else if ((o instanceof TerminalNode)) { + if (o.getText().equals("final")) { + prev_is_final = true; + } + } } - Class_definitionVisitor class_definitionVisitor = new Class_definitionVisitor(); - List class_definitions = ctx.class_definition() - .stream() - .map(class_definition -> class_definitionVisitor.visitClass_definition(class_definition)) - .collect(toList()); - return new Stored_definition(within, is_final, class_definitions); + return new Stored_definition(within, final_class_definitions); } } \ No newline at end of file diff --git a/lib/util.js b/lib/util.js index cec5bf1b..68d0cf75 100644 --- a/lib/util.js +++ b/lib/util.js @@ -374,10 +374,10 @@ function getFileNameInJsonOutput (json) { var within = getProperty(['within'], json) // Get the model name var shortClass = getProperty( - ['class_definition', 0, 'class_specifier', 'short_class_specifier', 'identifier'], json) + ['final_class_definitions', 0, 'class_definition', 'class_specifier', 'short_class_specifier', 'identifier'], json) var shortName = shortClass !== null ? shortClass : getProperty( - ['class_definition', 0, 'class_specifier', 'long_class_specifier', 'identifier'], json) + ['final_class_definitions', 0, 'class_definition', 'class_specifier', 'long_class_specifier', 'identifier'], json) if (shortName) { className = (within) ? within + '.' + shortName : shortName } From 9d6280f0db9ad1682aeecf9f23d5ee8fcfc11f59 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Thu, 14 Oct 2021 09:53:48 -0700 Subject: [PATCH 11/29] removing empty external_composition --- .../lbl/parser/parser/CompositionVisitor.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java index 69c6bf38..3ca98f57 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java @@ -67,20 +67,16 @@ public Composition visitComposition(modelicaParser.CompositionContext ctx) { //nothing here } } - - Boolean external = ctx.EXTERNAL() == null ? false : true; - String language_specification = ctx.language_specification() == null ? "" : ctx.language_specification().getText(); - - External_function_callVisitor external_function_callVisitor = new External_function_callVisitor(); - External_function_call external_function_call = ctx.external_function_call() == null ? null : ctx.external_function_call().accept(external_function_callVisitor); - AnnotationVisitor annotationVisitor = new AnnotationVisitor(); List annotations = ctx.annotation() == null ? null : ctx.annotation() .stream() .map(single_annotation -> single_annotation.accept(annotationVisitor)) .collect(toList());; + Boolean external = ctx.EXTERNAL() == null ? false : true; + Annotation external_annotation = null; Annotation annotation = null; + if (annotations != null && annotations.size() > 0) { if (annotations.size() == 2) { external_annotation = annotations.get(0); @@ -95,7 +91,14 @@ public Composition visitComposition(modelicaParser.CompositionContext ctx) { } } } - External_composition external_composition = new External_composition(language_specification, external_function_call, external_annotation); + + External_composition external_composition = null; + if (external) { + String language_specification = ctx.language_specification() == null ? "" : ctx.language_specification().getText(); + External_function_callVisitor external_function_callVisitor = new External_function_callVisitor(); + External_function_call external_function_call = ctx.external_function_call() == null ? null : ctx.external_function_call().accept(external_function_callVisitor); + external_composition = new External_composition(language_specification, external_function_call, external_annotation); + } return new Composition(element_list, element_sections, external_composition, annotation); } From dd7161a04558ec4d29a0063d24731622d7baab65 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Thu, 14 Oct 2021 13:38:27 -0700 Subject: [PATCH 12/29] handling end keyword in primary --- java/parser/src/main/java/gov/lbl/parser/domain/Primary.java | 4 +++- .../src/main/java/gov/lbl/parser/parser/PrimaryVisitor.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Primary.java b/java/parser/src/main/java/gov/lbl/parser/domain/Primary.java index d7b27ee1..3505fb30 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Primary.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Primary.java @@ -12,9 +12,10 @@ public class Primary { private Output_expression_list output_expression_list; private Collection expression_lists; private Function_arguments function_arguments; + private Boolean end; public Primary(Double unsigned_number, String primary_string, Boolean is_false, Boolean is_true, Function_call_primary function_call_primary, Component_reference component_reference, - Output_expression_list output_expression_list, Collection expression_lists, Function_arguments function_arguments){ + Output_expression_list output_expression_list, Collection expression_lists, Function_arguments function_arguments, Boolean end){ this.unsigned_number = unsigned_number; this.primary_string = primary_string; this.is_false = is_false; @@ -24,5 +25,6 @@ public Primary(Double unsigned_number, String primary_string, Boolean is_false, this.output_expression_list = output_expression_list; this.expression_lists = expression_lists; this.function_arguments = function_arguments; + this.end = end; } } \ No newline at end of file diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/PrimaryVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/PrimaryVisitor.java index 607a11b3..f52e4490 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/PrimaryVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/PrimaryVisitor.java @@ -46,7 +46,9 @@ public Primary visitPrimary(modelicaParser.PrimaryContext ctx) { Function_argumentsVisitor function_argumentsVisitor = new Function_argumentsVisitor(); Function_arguments function_arguments = ctx.function_arguments() == null ? null : ctx.function_arguments().accept(function_argumentsVisitor); + + Boolean end = ctx.END() == null ? false : true; - return new Primary(unsigned_number, primary_string, is_false, is_true, function_call_primary, component_reference, output_expression_list, expression_lists, function_arguments); + return new Primary(unsigned_number, primary_string, is_false, is_true, function_call_primary, component_reference, output_expression_list, expression_lists, function_arguments, end); } } \ No newline at end of file From fb4272002dffa292fbceb349da005b28e700b53d Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Wed, 20 Oct 2021 16:10:16 -0700 Subject: [PATCH 13/29] adding initial files for json to modelica translation --- j2m.js | 15 +++++ json2mo/algorithm_sectionParser.js | 21 +++++++ json2mo/annotationParser.js | 13 +++++ json2mo/argumentParser.js | 14 +++++ json2mo/argument_listParser.js | 17 ++++++ json2mo/array_subscriptsParser.js | 23 ++++++++ json2mo/assignment_equationParser.js | 16 ++++++ json2mo/assignment_statementParser.js | 16 ++++++ ...ment_with_function_call_statementParser.js | 22 +++++++ json2mo/base_prefixParser.js | 10 ++++ json2mo/class_definitionParser.js | 22 +++++++ json2mo/class_modificationParser.js | 13 +++++ json2mo/class_specifierParser.js | 27 +++++++++ json2mo/commentParser.js | 16 ++++++ json2mo/component_clause1Parser.js | 19 +++++++ json2mo/component_clauseParser.js | 23 ++++++++ json2mo/component_declaration1Parser.js | 15 +++++ json2mo/component_declarationParser.js | 19 +++++++ json2mo/component_listParser.js | 13 +++++ json2mo/component_referenceParser.js | 25 ++++++++ json2mo/compositionParser.js | 28 +++++++++ json2mo/condition_attributeParser.js | 12 ++++ json2mo/connect_clauseParser.js | 18 ++++++ json2mo/constraining_clauseParser.js | 18 ++++++ json2mo/declarationParser.js | 19 +++++++ json2mo/der_class_specifierParser.js | 18 ++++++ json2mo/der_class_specifier_valueParser.js | 26 +++++++++ json2mo/elementParser.js | 57 +++++++++++++++++++ json2mo/element_listParser.js | 14 +++++ json2mo/element_modificationParser.js | 19 +++++++ ...ement_modification_or_replaceableParser.js | 24 ++++++++ json2mo/element_redeclarationParser.js | 31 ++++++++++ json2mo/element_replaceableParser.js | 19 +++++++ json2mo/element_sectionParser.js | 24 ++++++++ json2mo/enum_listParser.js | 16 ++++++ json2mo/enumeration_literalParser.js | 16 ++++++ json2mo/equationParser.js | 33 +++++++++++ json2mo/equation_sectionParser.js | 23 ++++++++ json2mo/expressionParser.js | 16 ++++++ json2mo/expression_listParser.js | 17 ++++++ json2mo/extends_clauseParser.js | 21 +++++++ json2mo/external_compositionParser.js | 21 +++++++ json2mo/external_function_callParser.js | 22 +++++++ json2mo/final_class_definitionParser.js | 17 ++++++ json2mo/for_equationParser.js | 21 +++++++ json2mo/for_indicesParser.js | 25 ++++++++ json2mo/for_statementParser.js | 21 +++++++ json2mo/function_argumentParser.js | 26 +++++++++ json2mo/function_argumentsParser.js | 33 +++++++++++ json2mo/function_call_argsParser.js | 34 +++++++++++ json2mo/function_call_equationParser.js | 17 ++++++ json2mo/function_call_statementParser.js | 15 +++++ json2mo/if_elseif_equationParser.js | 26 +++++++++ json2mo/if_elseif_expressionParser.js | 18 ++++++ json2mo/if_elseif_statementParser.js | 26 +++++++++ json2mo/if_equationParser.js | 31 ++++++++++ json2mo/if_expressionParser.js | 22 +++++++ json2mo/if_statementParser.js | 31 ++++++++++ json2mo/import_clauseParser.js | 32 +++++++++++ json2mo/import_listParser.js | 15 +++++ json2mo/long_class_specifierParser.js | 43 ++++++++++++++ json2mo/modificationParser.js | 25 ++++++++ json2mo/nameParser.js | 9 +++ json2mo/named_argumentParser.js | 16 ++++++ json2mo/output_expression_listParser.js | 17 ++++++ json2mo/short_class_definitionParser.js | 15 +++++ json2mo/short_class_specifierParser.js | 16 ++++++ json2mo/short_class_specifier_valueParser.js | 37 ++++++++++++ json2mo/simple_expressionParser.js | 11 ++++ json2mo/statementParser.js | 44 ++++++++++++++ json2mo/stored_definitonParser.js | 21 +++++++ json2mo/type_specifierParser.js | 12 ++++ json2mo/when_equationParser.js | 36 ++++++++++++ json2mo/when_statementParser.js | 36 ++++++++++++ json2mo/while_statementParser.js | 21 +++++++ 75 files changed, 1640 insertions(+) create mode 100644 j2m.js create mode 100644 json2mo/algorithm_sectionParser.js create mode 100644 json2mo/annotationParser.js create mode 100644 json2mo/argumentParser.js create mode 100644 json2mo/argument_listParser.js create mode 100644 json2mo/array_subscriptsParser.js create mode 100644 json2mo/assignment_equationParser.js create mode 100644 json2mo/assignment_statementParser.js create mode 100644 json2mo/assignment_with_function_call_statementParser.js create mode 100644 json2mo/base_prefixParser.js create mode 100644 json2mo/class_definitionParser.js create mode 100644 json2mo/class_modificationParser.js create mode 100644 json2mo/class_specifierParser.js create mode 100644 json2mo/commentParser.js create mode 100644 json2mo/component_clause1Parser.js create mode 100644 json2mo/component_clauseParser.js create mode 100644 json2mo/component_declaration1Parser.js create mode 100644 json2mo/component_declarationParser.js create mode 100644 json2mo/component_listParser.js create mode 100644 json2mo/component_referenceParser.js create mode 100644 json2mo/compositionParser.js create mode 100644 json2mo/condition_attributeParser.js create mode 100644 json2mo/connect_clauseParser.js create mode 100644 json2mo/constraining_clauseParser.js create mode 100644 json2mo/declarationParser.js create mode 100644 json2mo/der_class_specifierParser.js create mode 100644 json2mo/der_class_specifier_valueParser.js create mode 100644 json2mo/elementParser.js create mode 100644 json2mo/element_listParser.js create mode 100644 json2mo/element_modificationParser.js create mode 100644 json2mo/element_modification_or_replaceableParser.js create mode 100644 json2mo/element_redeclarationParser.js create mode 100644 json2mo/element_replaceableParser.js create mode 100644 json2mo/element_sectionParser.js create mode 100644 json2mo/enum_listParser.js create mode 100644 json2mo/enumeration_literalParser.js create mode 100644 json2mo/equationParser.js create mode 100644 json2mo/equation_sectionParser.js create mode 100644 json2mo/expressionParser.js create mode 100644 json2mo/expression_listParser.js create mode 100644 json2mo/extends_clauseParser.js create mode 100644 json2mo/external_compositionParser.js create mode 100644 json2mo/external_function_callParser.js create mode 100644 json2mo/final_class_definitionParser.js create mode 100644 json2mo/for_equationParser.js create mode 100644 json2mo/for_indicesParser.js create mode 100644 json2mo/for_statementParser.js create mode 100644 json2mo/function_argumentParser.js create mode 100644 json2mo/function_argumentsParser.js create mode 100644 json2mo/function_call_argsParser.js create mode 100644 json2mo/function_call_equationParser.js create mode 100644 json2mo/function_call_statementParser.js create mode 100644 json2mo/if_elseif_equationParser.js create mode 100644 json2mo/if_elseif_expressionParser.js create mode 100644 json2mo/if_elseif_statementParser.js create mode 100644 json2mo/if_equationParser.js create mode 100644 json2mo/if_expressionParser.js create mode 100644 json2mo/if_statementParser.js create mode 100644 json2mo/import_clauseParser.js create mode 100644 json2mo/import_listParser.js create mode 100644 json2mo/long_class_specifierParser.js create mode 100644 json2mo/modificationParser.js create mode 100644 json2mo/nameParser.js create mode 100644 json2mo/named_argumentParser.js create mode 100644 json2mo/output_expression_listParser.js create mode 100644 json2mo/short_class_definitionParser.js create mode 100644 json2mo/short_class_specifierParser.js create mode 100644 json2mo/short_class_specifier_valueParser.js create mode 100644 json2mo/simple_expressionParser.js create mode 100644 json2mo/statementParser.js create mode 100644 json2mo/stored_definitonParser.js create mode 100644 json2mo/type_specifierParser.js create mode 100644 json2mo/when_equationParser.js create mode 100644 json2mo/when_statementParser.js create mode 100644 json2mo/while_statementParser.js diff --git a/j2m.js b/j2m.js new file mode 100644 index 00000000..5a84156f --- /dev/null +++ b/j2m.js @@ -0,0 +1,15 @@ +const path = require('path'); +const fs = require('fs'); +const stored_definitonParser = require('./json2mo/stored_definitonParser'); + +function convertToModeica(jsonFile) { + var fileContent = fs.readFileSync(jsonFile, 'utf8'); + //TODO: the [0] should change with the new simplified json + var jsonOutput = JSON.parse(fileContent)[0]; + + moOutput = stored_definitonParser.parse(jsonOutput); + return moOutput; +} + +// console.log(convertToModeica('raw-json/FromModelica.ExtendsClause_1.json')); +console.log(convertToModeica('raw-json/FromModelica.Modulation.json')); \ No newline at end of file diff --git a/json2mo/algorithm_sectionParser.js b/json2mo/algorithm_sectionParser.js new file mode 100644 index 00000000..38d9c880 --- /dev/null +++ b/json2mo/algorithm_sectionParser.js @@ -0,0 +1,21 @@ +function parse(content) { + const statementParser = require('./statementParser'); + + var moOutput = ""; + if (content.initial != null) { + if (content.initial) { + moOutput+="initial " + } + } + moOutput+="algorithm \n" + var statements = content.statements; + if (statements != null) { + statements.forEach(statement => { + moOutput+=statementParser.parse(statement); + moOutput+=";\n" + }); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/annotationParser.js b/json2mo/annotationParser.js new file mode 100644 index 00000000..5c7dd4e0 --- /dev/null +++ b/json2mo/annotationParser.js @@ -0,0 +1,13 @@ +function parse(content) { + const util = require('util'); + const class_modificationParser = require('./class_modificationParser'); + + var moOutput = ""; + moOutput+="annotation "; + if (content.class_modification != null) { + moOutput+=class_modificationParser.parse(content.class_modification); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/argumentParser.js b/json2mo/argumentParser.js new file mode 100644 index 00000000..1ea9b8e2 --- /dev/null +++ b/json2mo/argumentParser.js @@ -0,0 +1,14 @@ +function parse(content) { + const element_modification_or_replaceableParser = require('./element_modification_or_replaceableParser'); + const element_redeclarationParser = require('./element_redeclarationParser'); + + var moOutput = ""; + if (content.element_modification_or_replaceable != null) { + moOutput+=element_modification_or_replaceableParser.parse(content.element_modification_or_replaceable) + } else if (content.element_redeclaration != null) { + moOutput+=element_redeclarationParser.parse(content.element_redeclaration) + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/argument_listParser.js b/json2mo/argument_listParser.js new file mode 100644 index 00000000..953ca7c7 --- /dev/null +++ b/json2mo/argument_listParser.js @@ -0,0 +1,17 @@ +function parse(content) { + const util = require('util'); + const argumentParser = require('./argumentParser'); + var moOutput = ""; + var arguments = content.arguments; + + if (arguments != null) { + arguments.forEach(argument => { + moOutput+=argumentParser.parse(argument); + moOutput+=", "; + }); + moOutput = moOutput.slice(0, -2); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/array_subscriptsParser.js b/json2mo/array_subscriptsParser.js new file mode 100644 index 00000000..a399eac7 --- /dev/null +++ b/json2mo/array_subscriptsParser.js @@ -0,0 +1,23 @@ +function parse(content) { + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + var arrary_subscripts = content; + moOutput+="[" + + if (arrary_subscripts != null) { + array_subscripts.forEach(array_subscript => { + if (array_subscript.colon_op != null) { + if (array_subscript.colon_op) { + moOutput+=":"; + } + } else if (array_subscript.expression != null) { + moOutput+=expressionParser.parser(array_subscript.expression); + } + }); + } + moOutput+="] "; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/assignment_equationParser.js b/json2mo/assignment_equationParser.js new file mode 100644 index 00000000..017a7287 --- /dev/null +++ b/json2mo/assignment_equationParser.js @@ -0,0 +1,16 @@ +function parse(content) { + const simple_expressionParser = require('./simple_expressionParser'); + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + if (content.lhs != null) { + moOutput+=simple_expressionParser.parse(content.lhs) + } + moOutput+="=" + if (content.rhs != null) { + moOutput+=expressionParser.parse(content.rhs) + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/assignment_statementParser.js b/json2mo/assignment_statementParser.js new file mode 100644 index 00000000..504db228 --- /dev/null +++ b/json2mo/assignment_statementParser.js @@ -0,0 +1,16 @@ +function parse(content) { + const component_referenceParser = require('./component_referenceParser'); + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + if (content.identifier != null) { + moOutput+=component_referenceParser.parse(content.identifier) + } + moOutput+=":=" + if (content.value != null) { + moOutput+=expressionParser.parse(content.value) + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/assignment_with_function_call_statementParser.js b/json2mo/assignment_with_function_call_statementParser.js new file mode 100644 index 00000000..011b02b9 --- /dev/null +++ b/json2mo/assignment_with_function_call_statementParser.js @@ -0,0 +1,22 @@ +function parse(content) { + const component_referenceParser = require('./component_referenceParser'); + const output_expression_listParser = require('./output_expression_listParser'); + const function_call_argsParser = require('./function_call_argsParser'); + + var moOutput = ""; + moOutput+="("; + if (content.output_expression_list != null) { + moOutput+=output_expression_listParser.parse(content.output_expression_list); + } + moOutput+=")"; + moOutput+=":="; + if (content.function_name != null) { + moOutput+=component_referenceParser.parse(content.function_name); + } + if (content.function_call_args != null) { + moOutput+=function_call_argsParser.parse(content.function_call_args); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/base_prefixParser.js b/json2mo/base_prefixParser.js new file mode 100644 index 00000000..6975dfcb --- /dev/null +++ b/json2mo/base_prefixParser.js @@ -0,0 +1,10 @@ +function parse(content) { + const util = require('util'); + var moOutput = ""; + if (content.type_prefix != null) { + moOutput+=util.format("%s ", content.type_prefix); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/class_definitionParser.js b/json2mo/class_definitionParser.js new file mode 100644 index 00000000..5b629e1e --- /dev/null +++ b/json2mo/class_definitionParser.js @@ -0,0 +1,22 @@ +function parse(content) { + const util = require('util'); + const class_specifierParser = require('./class_specifierParser'); + var encapsulated = content.encapsulated; + var class_prefixes = content.class_prefixes; + var moOutput = ""; + + if (encapsulated != null) { + if (encapsulated) { + moOutput = "encapsulated "; + } + } + + if (class_prefixes != null) { + moOutput += util.format("%s ", class_prefixes); + } + + moOutput+=class_specifierParser.parse(content.class_specifier); + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/class_modificationParser.js b/json2mo/class_modificationParser.js new file mode 100644 index 00000000..229aba30 --- /dev/null +++ b/json2mo/class_modificationParser.js @@ -0,0 +1,13 @@ +function parse(content) { + const argument_listParser = require('./argument_listParser'); + + var moOutput = ""; + moOutput+="("; + if (content.argument_list != null) { + moOutput+=argument_listParser.parse(content.argument_list); + } + moOutput+=")" + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/class_specifierParser.js b/json2mo/class_specifierParser.js new file mode 100644 index 00000000..60b76936 --- /dev/null +++ b/json2mo/class_specifierParser.js @@ -0,0 +1,27 @@ +function parse(content) { + const long_class_specifierParser = require('./long_class_specifierParser'); + const short_class_specifierParser = require('./short_class_specifierParser'); + const der_class_specifierParser = require('./der_class_specifierParser'); + + var long_class_specifier = content.long_class_specifier; + var short_class_specifier = content.short_class_specifier; + var der_class_specifier = content.der_class_specifier; + + var moOutput = ""; + + if (long_class_specifier != null) { + moOutput+=long_class_specifierParser.parse(long_class_specifier); + } + + if (short_class_specifier != null) { + moOutput+=short_class_specifierParser.parse(short_class_specifier); + } + + if (der_class_specifier != null) { + moOutput+=der_class_specifierParser.parse(der_class_specifier); + } + + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/commentParser.js b/json2mo/commentParser.js new file mode 100644 index 00000000..a68801c3 --- /dev/null +++ b/json2mo/commentParser.js @@ -0,0 +1,16 @@ +function parse(content) { + const util = require('util'); + const annotationParser = require('./annotationParser'); + + var moOutput = ""; + if (content.string_comment != null) { + moOutput+=util.format("%s ", content.string_comment); + } + if (content.annotation != null) { + moOutput+=annotationParser.parse(content.annotation); + } + moOutput+="\n"; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/component_clause1Parser.js b/json2mo/component_clause1Parser.js new file mode 100644 index 00000000..2c5ba47c --- /dev/null +++ b/json2mo/component_clause1Parser.js @@ -0,0 +1,19 @@ +function parse(content) { + const util = require('util'); + const type_specifierParser = require('./type_specifierParser'); + const component_declaration1Parser = require('./component_declaration1Parser'); + + var moOutput = ""; + if (content.type_prefix != null) { + moOutput+=util.format("%s ", content.type_prefix); + } + if (content.type_specifier != null) { + moOutput+=type_specifierParser.parse(content.type_specifier); + } + if (content.component_declaration1 != null) { + moOutput+=component_declaration1Parser.parse(content.component_declaration1); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/component_clauseParser.js b/json2mo/component_clauseParser.js new file mode 100644 index 00000000..52f210a7 --- /dev/null +++ b/json2mo/component_clauseParser.js @@ -0,0 +1,23 @@ +function parse(content) { + const type_specifierParser = require('./type_specifierParser'); + const array_subscriptsParser = require('./array_subscriptsParser'); + const component_listParser = require('./component_listParser'); + + var moOutput = ""; + + if (content.type_prefix != null) { + moOutput+=util.format("%s ", content.type_prefix); + } + if (content.type_specifier != null) { + moOutput+=type_specifierParser.parse(content.type_specifier); + } + if (content.array_subscripts != null) { + moOutput+=array_subscriptsParser.parse(content.array_subscripts); + } + if (content.component_list != null) { + moOutput+=component_listParser.parse(content.component_list); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/component_declaration1Parser.js b/json2mo/component_declaration1Parser.js new file mode 100644 index 00000000..af8b165e --- /dev/null +++ b/json2mo/component_declaration1Parser.js @@ -0,0 +1,15 @@ +function parse(content) { + const util = require('util'); + const declarationParser = require('./declarationParser'); + const commentParser = require('./commentParser'); + + var moOutput = ""; + if (content.declaration != null) { + moOutput+=declarationParser.parse(content.declaration); + } + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment); + } + return moOutput; +} +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/component_declarationParser.js b/json2mo/component_declarationParser.js new file mode 100644 index 00000000..4e6597a7 --- /dev/null +++ b/json2mo/component_declarationParser.js @@ -0,0 +1,19 @@ +function parse(content) { + const declarationParser = require('./declarationParser'); + const condition_attributeParser = require('./condition_attributeParser'); + const commentParser = require('./commentParser'); + + var moOutput = ""; + if (content.declaration != null) { + moOutput+=declarationParser.parse(content.declaration); + } + if (content.condition_attribute != null) { + moOutput+=condition_attributeParser.parser(content.condition_attribute); + } + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/component_listParser.js b/json2mo/component_listParser.js new file mode 100644 index 00000000..d9676b16 --- /dev/null +++ b/json2mo/component_listParser.js @@ -0,0 +1,13 @@ +function parse(content) { + const component_declarationParser = require('./component_declarationParser'); + + var moOutput = ""; + var component_declaration_list = content.component_declaration_list; + + component_declaration_list.forEach(component_declaration => { + moOutput+=component_declarationParser.parse(component_declaration); + }); + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/component_referenceParser.js b/json2mo/component_referenceParser.js new file mode 100644 index 00000000..29ea7495 --- /dev/null +++ b/json2mo/component_referenceParser.js @@ -0,0 +1,25 @@ +function parse(content) { + const util = require('util'); + const arrary_subscriptsParser = require('./arrary_subscriptsParser'); + + var moOutput = ""; + var component_reference_parts = content; //only if simplified-json + + component_reference_parts.forEach(component_reference_part => { + if (component_reference_part.dot_op != null) { + if(component_reference_part.dot_op) { + moOutput+="." + } + } + if (component_reference_part.identifier != null) { + moOutput+=util.format("%s", component_reference_part.identifier); + } + if (component_reference_part.arrary_subscripts != null) { + moOutput+=arrary_subscriptsParser.parse(component_reference_part.arrary_subscripts); + } + }); + moOutput+=" "; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/compositionParser.js b/json2mo/compositionParser.js new file mode 100644 index 00000000..8a6a70fa --- /dev/null +++ b/json2mo/compositionParser.js @@ -0,0 +1,28 @@ +function parse(content) { + const element_listParser = require('./element_listParser'); + const element_sectionParser = require('./element_sectionParser'); + const external_compositionParser = require('./external_compositionParser'); + const annotationParser = require('./annotationParser'); + + var moOutput = ""; + + if (content.element_list != null) { + moOutput+=element_listParser.parse(content.element_list); + } + if (content.element_sections != null) { + var element_sections = content.element_sections; + element_sections.forEach(element_section => { + moOutput+=element_sectionParser.parse(element_section); + }); + } + if (content.external_composition != null) { + console.log(content.external_composition) + moOutput+=external_compositionParser.parse(content.external_composition); + } + if (content.annotation != null) { + moOutput+=annotationParser.parse(content.annotation); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/condition_attributeParser.js b/json2mo/condition_attributeParser.js new file mode 100644 index 00000000..0945944c --- /dev/null +++ b/json2mo/condition_attributeParser.js @@ -0,0 +1,12 @@ +function parse(content) { + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + moOutput+="if " + if (content.expression != null) { + moOutput+=expressionParser.parse(content.expression); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/connect_clauseParser.js b/json2mo/connect_clauseParser.js new file mode 100644 index 00000000..820db6e1 --- /dev/null +++ b/json2mo/connect_clauseParser.js @@ -0,0 +1,18 @@ +function parse(content) { + const util = require('util'); + const component_referenceParser = require('./component_referenceParser'); + + var moOutput = ""; + moOutput+="connect("; + if (content.from != null) { + moOutput+=component_referenceParser.parse(content.from); + } + if (content.to != null) { + moOutput+=", " + moOutput+=component_referenceParser.parse(content.to); + } + moOutput+=")\n"; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/constraining_clauseParser.js b/json2mo/constraining_clauseParser.js new file mode 100644 index 00000000..f822ca7a --- /dev/null +++ b/json2mo/constraining_clauseParser.js @@ -0,0 +1,18 @@ +function parse(content) { + const nameParser = require('./nameParser'); + const class_modificationParser = require('./class_modificationParser'); + + var moOutput = ""; + moOutput+="constraintedby "; + + var name=""; + if (content.name != null) { + moOutput+= nameParser.parse(content.name); + } + + if (content.class_modification != null) { + moOutput+=class_modificationParser.parse(content.class_modification); + } + return moOutput; +} +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/declarationParser.js b/json2mo/declarationParser.js new file mode 100644 index 00000000..b661b093 --- /dev/null +++ b/json2mo/declarationParser.js @@ -0,0 +1,19 @@ +function parse(content) { + const util = require('util'); + const array_subscriptsParser = require('./array_subscriptsParser'); + const modificationParser = require('./modificationParser'); + + var moOutput = ""; + if (content.identifier != null) { + moOutput+=util.format("%s ", content.identifier); + } + if (content.array_subscripts != null) { + moOutput+=array_subscriptsParser.parse(content.array_subscripts); + } + if (content.modification != null) { + moOutput+=modificationParser.parse(content.modification); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/der_class_specifierParser.js b/json2mo/der_class_specifierParser.js new file mode 100644 index 00000000..0edb9904 --- /dev/null +++ b/json2mo/der_class_specifierParser.js @@ -0,0 +1,18 @@ +function parse(content) { + const util = require('util'); + const der_class_specifier_valueParser = require('./der_class_specifier_valueParser'); + + var moOutput = ""; + var identifier = content.identifier; + + if (identifier != null) { + moOutput+=util.format("%s= ", identifier); + } + + if (content.der_class_specifier_value != null) { + moOutput+=der_class_specifier_valueParser.parse(content.der_class_specifier_value); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/der_class_specifier_valueParser.js b/json2mo/der_class_specifier_valueParser.js new file mode 100644 index 00000000..42ea2b98 --- /dev/null +++ b/json2mo/der_class_specifier_valueParser.js @@ -0,0 +1,26 @@ +function parse(content) { + const util = require('util'); + const nameParser = require('./nameParser'); + const commentParser = require('./commentParser'); + + var moOutput = "der("; + if (content.type_specifier != null) { + moOutput+=nameParser.parse(content.type_specifier); + } + + var identifiers = content.identifiers; + if (identifiers != null) { + identifiers.forEach(identifier => { + moOutput+=util.format("%s, ", identifier) + }) + moOutput = moOutput.slice(0, -2); + moOutput+=") " + } + + if (content.comment != null) { + moOutput+=commentParser.parse(content.content); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/elementParser.js b/json2mo/elementParser.js new file mode 100644 index 00000000..858eff74 --- /dev/null +++ b/json2mo/elementParser.js @@ -0,0 +1,57 @@ +function parse(content) { + const class_definitionParser = require('./class_definitionParser'); + const import_clauseParser = require('./import_clauseParser'); + const extends_clauseParser = require('./extends_clauseParser'); + const component_clauseParser = require('./component_clauseParser'); + const constraining_clauseParser = require('./constraining_clauseParser'); + const commentParser = require('./commentParser'); + + var moOutput = ""; + if (content.import_clause != null) { + moOutput+=import_clauseParser.parse(content.import_clause); + } else if (content.extends_clause != null) { + moOutput+=extends_clauseParser.parse(content.extends_clause); + } else { + if (content.redeclare != null) { + if (content.redeclare) { + moOutput+="redeclare " + } + } + if (content.is_final != null) { + if (content.is_final) { + moOutput+="final " + } + } + if (content.inner != null) { + if (content.inner) { + moOutput+="inner " + } + } + if (content.outer != null) { + if (content.outer) { + moOutput+="outer " + } + } + if (content.replaceable != null) { + if (content.replaceable) { + moOutput+="replaceable " + if (content.class_definition != null) { + moOutput+=class_definitionParser.parse(content.class_definition); + } else if (content.component_clause != null) { + moOutput+=component_clauseParser.parse(content.component_clause); + } + + if (content.constraining_clause != null) { + moOutput+="\n" + moOutput+=constraining_clauseParser.parse(content.constraining_clause); + } + + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment); + } + } + } + } + return moOutput; +} +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/element_listParser.js b/json2mo/element_listParser.js new file mode 100644 index 00000000..a01d0371 --- /dev/null +++ b/json2mo/element_listParser.js @@ -0,0 +1,14 @@ +function parse(content) { + const elementParser = require('./elementParser'); + + var moOutput = ""; + var elements = content.elements + if (elements != null) { + elements.forEach(element => { + moOutput+=elementParser.parse(element); + }); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/element_modificationParser.js b/json2mo/element_modificationParser.js new file mode 100644 index 00000000..6fe6b23d --- /dev/null +++ b/json2mo/element_modificationParser.js @@ -0,0 +1,19 @@ +function parse(content) { + const util = require('util'); + const nameParser = require('./nameParser'); + const modificationParser = require('./modificationParser'); + + var moOutput = ""; + if (content.name != null) { + moOutput+=nameParser.parse(content.name); + } + if (content.modification != null) { + moOutput+=modificationParser.parse(content.modification); + } + if (content.string_comment != null) { + moOutput+=util.format("%s", content.string_comment); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/element_modification_or_replaceableParser.js b/json2mo/element_modification_or_replaceableParser.js new file mode 100644 index 00000000..a9daceb1 --- /dev/null +++ b/json2mo/element_modification_or_replaceableParser.js @@ -0,0 +1,24 @@ +function parse(content) { + const element_modificationParser = require('./element_modificationParser'); + const element_replaceableParser = require('./element_replaceableParser'); + + var moOutput = ""; + if (content.each != null) { + if (content.each){ + moOutput+="each "; + } + } + if (content.is_final != null) { + if (content.is_final){ + moOutput+="final "; + } + } + if (content.element_modification != null) { + moOutput+=element_modificationParser.parse(content.element_modification); + } else if (content.element_replaceable != null) { + moOutput+=element_replaceableParser.parse(content.element_replaceable); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/element_redeclarationParser.js b/json2mo/element_redeclarationParser.js new file mode 100644 index 00000000..3546671d --- /dev/null +++ b/json2mo/element_redeclarationParser.js @@ -0,0 +1,31 @@ +function parse(content) { + const short_class_definitionParser = require('./short_class_definitionParser'); + const component_clause1Parser = require('./component_clause1Parser'); + const element_replaceableParser = require('./element_replaceableParser'); + + var moOutput = ""; + moOutput+="redeclare "; + + if (content.each != null) { + if (content.each){ + moOutput+="each "; + } + } + if (content.is_final != null) { + if (content.is_final){ + moOutput+="final "; + } + } + if (content.element_replaceable != null) { + moOutput+=element_replaceableParser.parse(content.element_replaceable); + } else { + if (content.short_class_definition != null) { + moOutput+=short_class_definitionParser.parse(content.short_class_definition); + } else if (content.component_clause1 != null) { + moOutput+=component_clause1Parser.parse(content.component_clause1); + } + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/element_replaceableParser.js b/json2mo/element_replaceableParser.js new file mode 100644 index 00000000..637f3788 --- /dev/null +++ b/json2mo/element_replaceableParser.js @@ -0,0 +1,19 @@ +function parse(content) { + const short_class_definitionParser = require('./short_class_definitionParser'); + const component_clause1Parser = require('./component_clause1Parser'); + const constraining_clauseParser = require('./constraining_clauseParser'); + + var moOutput = ""; + moOutput+="replaceable "; + if (content.short_class_definition != null) { + moOutput+=short_class_definitionParser.parse(content.short_class_definition); + } else if (content.component_clause1 != null) { + moOutput+=component_clause1Parser.parse(content.component_clause1); + } + if (content.constraining_clause != null) { + moOutput+=constraining_clauseParser.parse(content.constraining_clause); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/element_sectionParser.js b/json2mo/element_sectionParser.js new file mode 100644 index 00000000..2258c0ff --- /dev/null +++ b/json2mo/element_sectionParser.js @@ -0,0 +1,24 @@ +function parse(content) { + const element_listParser = require('./element_listParser'); + const equation_sectionParser = require('./equation_sectionParser'); + const algorithm_sectionParser = require('./algorithm_sectionParser'); + + var moOutput = ""; + + if (content.public_element_list != null) { + moOutput+="public\n" + moOutput+=element_listParser.parse(content.public_element_list); + } else if (content.protected_element_list != null) { + moOutput+="protected\n" + moOutput+=element_listParser.parse(content.protected_element_list); + } + else if (content.equation_section != null) { + moOutput+=equation_sectionParser.parse(content.equation_section); + } + else if (content.algorithm_section != null) { + moOutput+=algorithm_sectionParser.parse(content.algorithm_section); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/enum_listParser.js b/json2mo/enum_listParser.js new file mode 100644 index 00000000..bd13f4c9 --- /dev/null +++ b/json2mo/enum_listParser.js @@ -0,0 +1,16 @@ +function parse(content) { + const enumeration_literalParser = require('./enumeration_literalParser'); + + var moOutput = ""; + var enum_list = content.enum_list + if (enum_list != null) { + enum_list.forEach(enumeration_literal => { + moOutput+=enumeration_literalParser.parse(enumeration_literal); + moOutput+=", "; + }); + } + moOutput = moOutput.slice(0, -2); + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/enumeration_literalParser.js b/json2mo/enumeration_literalParser.js new file mode 100644 index 00000000..03288b5b --- /dev/null +++ b/json2mo/enumeration_literalParser.js @@ -0,0 +1,16 @@ +function parse(content) { + const util = require('util'); + const commentParser = require('./commentParser'); + + var moOutput = ""; + + if (enumeration_literal.identifier != null) { + moOutput+=util.format("%s ", enumeration_literal.identifier); + } + if (enumeration_literal.comment != null) { + moOutput+=commentParser.parse(enumeration_literal.comment); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/equationParser.js b/json2mo/equationParser.js new file mode 100644 index 00000000..0643e287 --- /dev/null +++ b/json2mo/equationParser.js @@ -0,0 +1,33 @@ +function parse(content) { + const util = require('util'); + const assignment_equationParser = require('./assignment_equationParser'); + const if_equationParser = require('./if_equationParser'); + const for_equationParser = require('./for_equationParser'); + const connect_clauseParser = require('./connect_clauseParser'); + const when_equationParser = require('./when_equationParser'); + const function_call_equationParser = require('./function_call_equationParser'); + const commentParser = require('./commentParser'); + + var moOutput = ""; + if (content.assignment_equation != null) { + moOutput+=assignment_equationParser.parse(content.assignment_equation); + } else if (content.if_equation != null) { + moOutput+=if_equationParser.parse(content.if_equation); + } else if (content.for_equation != null) { + moOutput+=for_equationParser.parse(content.for_equation); + } else if (content.connect_clause != null) { + moOutput+=connect_clauseParser.parse(content.connect_clause); + } else if (content.when_equation != null) { + moOutput+=when_equationParser.parse(content.when_equation); + } else if (content.function_call_equation != null) { + moOutput+=function_call_equationParser.parse(content.function_call_equation); + } + + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment); + } + + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/equation_sectionParser.js b/json2mo/equation_sectionParser.js new file mode 100644 index 00000000..a7ccfd39 --- /dev/null +++ b/json2mo/equation_sectionParser.js @@ -0,0 +1,23 @@ +function parse(content) { + const util = require('util'); + const equationParser = require('./equationParser'); + + var moOutput = ""; + if (content.initial != null) { + if (content.initial) { + moOutput+="initial " + } + } + moOutput+="equation \n" + var equations = content.equations; + if (equations != null) { + equations.forEach(equation => { + moOutput+=equationParser.parse(equation); + moOutput+=equation; + moOutput+=";\n" + }); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/expressionParser.js b/json2mo/expressionParser.js new file mode 100644 index 00000000..33d0b8f2 --- /dev/null +++ b/json2mo/expressionParser.js @@ -0,0 +1,16 @@ +function parse(content) { + const util = require('util'); + const simple_expressionParser = require('./simple_expressionParser'); + const if_expressionParser = require('./if_expressionParser'); + var moOutput = ""; + + if (content.if_expression != null) { + moOutput+=if_expressionParser.parse(content.if_expression); + } else if (content.simple_expression != null) { + moOutput+=simple_expressionParser.parse(content.simple_expression); + } + + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/expression_listParser.js b/json2mo/expression_listParser.js new file mode 100644 index 00000000..c0d2310b --- /dev/null +++ b/json2mo/expression_listParser.js @@ -0,0 +1,17 @@ +function parse(content) { + const util = require('util'); + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + var expression_list = content; + if (expression_list != null) { + expression_list.forEach(expression => { + moOutput+=expressionParser.parse(expression); + moOutput+=", "; + }); + moOutput = moOutput.slice(0, -1); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/extends_clauseParser.js b/json2mo/extends_clauseParser.js new file mode 100644 index 00000000..358f165a --- /dev/null +++ b/json2mo/extends_clauseParser.js @@ -0,0 +1,21 @@ +function parse(content) { + const nameParser = require('./nameParser'); + const class_modificationParser = require('./class_modificationParser'); + const annotationParser = require('./annotationParser'); + + var moOutput = ""; + moOutput+="extends "; + + if (content.name != null) { + moOutput+=nameParser.parse(content.name); + } + if (content.class_modification != null) { + moOutput+=class_modificationParser.parse(content.class_modification); + } + if (content.annotation != null) { + moOutput+=annotationParser.parse(content.annotation); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/external_compositionParser.js b/json2mo/external_compositionParser.js new file mode 100644 index 00000000..a025b990 --- /dev/null +++ b/json2mo/external_compositionParser.js @@ -0,0 +1,21 @@ +function parse(content) { + const util = require('util'); + const external_function_callParser = require('./external_function_callParser'); + const annotationParser = require('./annotationParser'); + + var moOutput = ""; + moOutput+="external " + if (content.language_specification != null) { + moOutput+=util.format("%s ", content.language_specification); + } + if (content.external_function_call != null) { + moOutput+=external_function_callParser.parse(content.external_function_call); + } + if (content.external_annotation != null) { + moOutput+=annotationParser.parse(content.external_annotation); + } + moOutput+=";\n"; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/external_function_callParser.js b/json2mo/external_function_callParser.js new file mode 100644 index 00000000..117f27d4 --- /dev/null +++ b/json2mo/external_function_callParser.js @@ -0,0 +1,22 @@ +function parse(content) { + const util = require('util'); + const component_referenceParser = require('./component_referenceParser'); + const expression_listParser = require('./expression_listParser'); + + var moOutput = ""; + + if (content.component_reference != null) { + moOutput+=component_referenceParser.parse(contnnt.component_reference); + moOutput+="= "; + } + if (content.identifier != null) { + moOutput+="identifier (" + } + if (content.expression_list != null) { + moOutput+=expression_listParser.parse(content.expression_list); + } + moOutput+=")\n"; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/final_class_definitionParser.js b/json2mo/final_class_definitionParser.js new file mode 100644 index 00000000..b0faf2e7 --- /dev/null +++ b/json2mo/final_class_definitionParser.js @@ -0,0 +1,17 @@ +function parse(content) { + const class_definitionParser = require('./class_definitionParser'); + var is_final = content.is_final; + var moOutput = ""; + + if (is_final != null) { + if (is_final) { + moOutput+= "final "; + } + } + if (content.class_definition != null) { + moOutput+=class_definitionParser.parse(content.class_definition); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/for_equationParser.js b/json2mo/for_equationParser.js new file mode 100644 index 00000000..649344db --- /dev/null +++ b/json2mo/for_equationParser.js @@ -0,0 +1,21 @@ +function parse(content) { + const for_indicesParser = require('./for_indicesParser'); + const equationParser = require('./equationParser'); + + var moOutput = ""; + moOutput+="for " + if (content.for_indices != null) { + moOutput+=for_indicesParser.parse(content.for_indices); + } + moOutput+="loop \n" + + loop_equations = content.loop_equations + loop_equations.forEach(loop_equation => { + moOutput+=equationParser.parse(loop_equation); + moOutput+=';\n'; + }); + moOutput+="end for"; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/for_indicesParser.js b/json2mo/for_indicesParser.js new file mode 100644 index 00000000..c6e760dd --- /dev/null +++ b/json2mo/for_indicesParser.js @@ -0,0 +1,25 @@ +function parse(content) { + const util = require('util'); + const expressionParser = require('./expressionParser'); + // const for_indexParser = require('./for_indexParser'); //only for raw-json + + var moOutput = ""; + var indices = content; //if raw-json, then use content.indices + if (indices!=null) { + indices.forEach(index => { + if (index.identifier != null) { + moOutput+=util.format("%s ",index.identifier); + } + if (index.expression != null) { + moOutput+="in " + moOutput+=expressionParser.parse(index.expression); + } + moOutput+=","; + }); + moOutput=moOutput.slice(0, -1); + } + + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/for_statementParser.js b/json2mo/for_statementParser.js new file mode 100644 index 00000000..bf5aebd5 --- /dev/null +++ b/json2mo/for_statementParser.js @@ -0,0 +1,21 @@ +function parse(content) { + const for_indicesParser = require('./for_indicesParser'); + const statementParser = require('./statementParser'); + + var moOutput = ""; + moOutput+="for " + if (content.for_indices != null) { + moOutput+=for_indicesParser.parse(content.for_indices); + } + moOutput+="loop \n" + + loop_statements = content.loop_statements + loop_statements.forEach(loop_statement => { + moOutput+=statementParser.parse(loop_statement); + moOutput+=';\n'; + }); + moOutput+="end for"; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/function_argumentParser.js b/json2mo/function_argumentParser.js new file mode 100644 index 00000000..e16a5d24 --- /dev/null +++ b/json2mo/function_argumentParser.js @@ -0,0 +1,26 @@ +function parse(content) { + const nameParser = require('./nameParser'); + const named_argumentParser = require('./named_argumentParser'); + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + + if (content.function_name!= null) { + moOutput+="function "; + moOutput+=nameParser.parse(content.function_name); + moOutput+="("; + var named_arguments = content.named_arguments; + if (named_arguments != null) { + named_arguments.forEach(named_argument => { + moOutput+=named_argumentParser.parse(named_argument); + }); + } + moOutput+=") "; + } else if (content.expression != null) { + moOutput+=expressionParser.parser(content.expression); + } + + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/function_argumentsParser.js b/json2mo/function_argumentsParser.js new file mode 100644 index 00000000..42282736 --- /dev/null +++ b/json2mo/function_argumentsParser.js @@ -0,0 +1,33 @@ +function parse(content) { + const named_argumentParser = require('./named_argumentParser'); + const function_argumentParser = require('./function_argumentParser'); + const for_indicesParser = require('./for_indicesParser'); + var moOutput = ""; + moOutput+="("; + + var named_arguments = content.named_arguments; //only in simplified-json + + if (named_arguments != null) { + named_arguments.forEach(named_argument => { + moOutput+=named_argumentParser.parse(named_argument); + moOutput+=", " + }); + moOutput=moOutput.slice(0, -1); + } else { + if (content.function_argument != null) { + moOutput+=function_argumentParser.parse(content.function_argument); + + if (content.function_arguments != null) { + moOutput+=", " + moOutput+=this.parse(content.function_arguments); + } else if ( content.for_indices != null) { + moOutput+=" for "; + moOutput+=for_indicesParser.parse(content.for_indices); + } + } + } + moOutput+=")"; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/function_call_argsParser.js b/json2mo/function_call_argsParser.js new file mode 100644 index 00000000..dbc27b11 --- /dev/null +++ b/json2mo/function_call_argsParser.js @@ -0,0 +1,34 @@ +function parse(content) { + const named_argumentParser = require('./named_argumentParser'); + const function_argumentParser = require('./function_argumentParser'); + const function_argumentsParser = require('./function_argumentsParser'); + const for_indicesParser = require('./for_indicesParser'); + var moOutput = ""; + moOutput+="("; + + var named_arguments = content.named_arguments; //only in simplified-json + + if (named_arguments != null) { + named_arguments.forEach(named_argument => { + moOutput+=named_argumentParser.parse(named_argument); + moOutput+=", " + }); + moOutput=moOutput.slice(0, -1); + } else { + if (content.function_argument != null) { + moOutput+=function_argumentParser.parse(content.function_argument); + + if (content.function_arguments != null) { + moOutput+=", " + moOutput+=function_argumentsParser.parse(content.function_arguments); + } else if ( content.for_indices != null) { + moOutput+=" for "; + moOutput+=for_indicesParser.parse(content.for_indices); + } + } + } + moOutput+=")"; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/function_call_equationParser.js b/json2mo/function_call_equationParser.js new file mode 100644 index 00000000..24ba0bcd --- /dev/null +++ b/json2mo/function_call_equationParser.js @@ -0,0 +1,17 @@ +function parse(content) { + const nameParser = require('./nameParser'); + const function_call_argsParser = require('./function_call_argsParser'); + + var moOutput = ""; + + if (content.function_name != null) { + moOutput+=nameParser.parse(content.function_name); + } + + if (content.function_call_args != null) { + moOutput+=function_call_argsParser.parse(content.function_call_args); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/function_call_statementParser.js b/json2mo/function_call_statementParser.js new file mode 100644 index 00000000..1a3e6a4b --- /dev/null +++ b/json2mo/function_call_statementParser.js @@ -0,0 +1,15 @@ +function parse(content) { + const component_referenceParser = require('./component_referenceParser'); + const function_call_argsParser = require('./function_call_argsParser'); + + var moOutput = ""; + if (content.function_name != null) { + moOutput+=component_referenceParser.parse(content.function_name) + } + if (content.function_call_args != null) { + moOutput+=function_call_argsParser.parse(content.function_call_args) + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/if_elseif_equationParser.js b/json2mo/if_elseif_equationParser.js new file mode 100644 index 00000000..8a5ef553 --- /dev/null +++ b/json2mo/if_elseif_equationParser.js @@ -0,0 +1,26 @@ +function parse(content) { + const expressionParser = require('./expressionParser'); + const equationParser = require('./equationParser'); + + var moOutput = ""; + + if (content.condition != null) { + moOutput+=expressionParser.parse(content.condition); + } + + var then_equations = content.then; + if (then_equations != null) { + thenOutput= ""; + then_equations.forEach(then_equation => { + thenOutput+=equationParser.parser(then_equation); + thenOutput+=";\n" + }); + if (thenOutput != "") { + moOutput+="then \n"; + moOutput+=thenOutput + } + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/if_elseif_expressionParser.js b/json2mo/if_elseif_expressionParser.js new file mode 100644 index 00000000..f34b1d5e --- /dev/null +++ b/json2mo/if_elseif_expressionParser.js @@ -0,0 +1,18 @@ +function parse(content) { + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + + if (content.condition != null) { + moOutput+=expressionParser.parse(content.condition); + } + moOutput+="then \n"; + + if (content.then != null) { + moOutput+=expressionParser.parser(content.then); + thenOutput+=";\n" + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/if_elseif_statementParser.js b/json2mo/if_elseif_statementParser.js new file mode 100644 index 00000000..c48d1c8c --- /dev/null +++ b/json2mo/if_elseif_statementParser.js @@ -0,0 +1,26 @@ +function parse(content) { + const expressionParser = require('./expressionParser'); + const statementParser = require('./statementParser'); + + var moOutput = ""; + + if (content.condition != null) { + moOutput+=expressionParser.parse(content.condition); + } + + var then_statements = content.then; + if (then_statements != null) { + thenOutput= ""; + then_statements.forEach(then_statement => { + thenOutput+=statementParser.parser(then_statement); + thenOutput+=";\n" + }); + if (thenOutput != "") { + moOutput+="then \n"; + moOutput+=thenOutput; + } + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/if_equationParser.js b/json2mo/if_equationParser.js new file mode 100644 index 00000000..e3e6cf4f --- /dev/null +++ b/json2mo/if_equationParser.js @@ -0,0 +1,31 @@ +function parse(content) { + const if_elseif_equationParser = require('./if_elseif_equationParser'); + const equationParser = require('./equationParser'); + + var moOutput = ""; + var if_elseifs = content.if_elseif + if (if_elseifs != null) { + if_elseifs.forEach(if_elseif_equation => { + moOutput+="elseif " + moOutput+=if_elseif_equationParser.parse(if_elseif_equation); + }); + } + moOutput = moOutput.slice(4, moOutput.length); //to remove 1st else of elseif so that we get "if" + + var else_equations = content.else_equation; + if (else_equations != null) { + elseOutput= ""; + else_equations.forEach(else_equation => { + elseOutput+=equationParser.parser(else_equation); + elseOutput+=";\n" + }); + if (elseOutput != "") { + moOutput+="else \n"; + moOutput+=elseOutput + } + } + moOutput+="end if\n" + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/if_expressionParser.js b/json2mo/if_expressionParser.js new file mode 100644 index 00000000..65e9529c --- /dev/null +++ b/json2mo/if_expressionParser.js @@ -0,0 +1,22 @@ +function parse(content) { + const if_elseif_expressionParser = require('./if_elseif_expressionParser'); + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + var if_elseifs = content.if_elseif + if (if_elseifs != null) { + if_elseifs.forEach(if_elseif_expression => { + moOutput+="elseif " + moOutput+=if_elseif_expressionParser.parse(if_elseif_expression); + }); + } + moOutput = moOutput.slice(4, moOutput.length); //to remove 1st else of elseif so that we get "if" + + if (content.else_expression != null) { + moOutput+="else \n"; + moOutput+=expressionParser.parse(content.else_expression); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/if_statementParser.js b/json2mo/if_statementParser.js new file mode 100644 index 00000000..67e41d8d --- /dev/null +++ b/json2mo/if_statementParser.js @@ -0,0 +1,31 @@ +function parse(content) { + const if_elseif_statementParser = require('./if_elseif_statementParser'); + const statementParser = require('./statementParser'); + + var moOutput = ""; + var if_elseifs = content.if_elseif + if (if_elseifs != null) { + if_elseifs.forEach(if_elseif_statement => { + moOutput+="elseif " + moOutput+=if_elseif_statementParser.parse(if_elseif_statement); + }); + } + moOutput = moOutput.slice(4, moOutput.length); //to remove 1st else of elseif so that we get "if" + + var else_statements = content.else_statement; + if (else_statements != null) { + elseOutput= ""; + else_statements.forEach(else_statement => { + elseOutput+=statementParser.parser(else_statement); + elseOutput+=";\n" + }); + if (elseOutput != "") { + moOutput+="else \n"; + moOutput+=elseOutput + } + } + moOutput+="end if\n" + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/import_clauseParser.js b/json2mo/import_clauseParser.js new file mode 100644 index 00000000..336e9a36 --- /dev/null +++ b/json2mo/import_clauseParser.js @@ -0,0 +1,32 @@ +function parse(content) { + const util = require('util'); + const nameParser = require('./nameParser'); + const commentParser = require('./commentParser'); + const import_listParser = require('./import_listParser'); + + var moOutput = ""; + moOutput+="import "; + + var name=""; + if (content.name != null) { + name = nameParser.parse(content.name); + } + + if (content.identifier != null) { + moOutput+=util.format("%s = %s ", identifier, name); + } else if (content.dot_star != null) { + if (content.dot_star) { + moOutput=util.format("%s", name) + ".* "; + } + } else if (content.import_list != null) { + moOutput+=util.format("%s", name)+".{"+import_listParser.parse(content.import_list)+"} " + } else { + moOutput+=util.format("%s ", name); + } + + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment); + } + return moOutput; +} +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/import_listParser.js b/json2mo/import_listParser.js new file mode 100644 index 00000000..de043273 --- /dev/null +++ b/json2mo/import_listParser.js @@ -0,0 +1,15 @@ +function parse(content) { + const util = require('util'); + + var moOutput = ""; + var identifier_list = content.identifier_list; + if (identifier_list != null) { + identifier_list.forEach(identifier => { + moOutput+=util.format("%s, ", identifier); + }); + } + moOutput = moOutput.slice(0, -2); + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/long_class_specifierParser.js b/json2mo/long_class_specifierParser.js new file mode 100644 index 00000000..a66670f5 --- /dev/null +++ b/json2mo/long_class_specifierParser.js @@ -0,0 +1,43 @@ +function parse(content) { + const util = require('util'); + const compositionParser = require('./compositionParser'); + const class_modificationParser = require('./class_modificationParser'); + + var identifier = content.identifier; + //TODO: change this + var string_comment = content.string_comment; + var is_extends = content.is_extends; + + var moOutput = ""; + + if (is_extends != null) { + if (is_extends) { + moOutput+= "extends "; + } + } + + if (identifier != null) { + moOutput+=util.format("%s", identifier); + } + + if (is_extends != null) { + if (is_extends) { + if (content.class_modification != null) { + moOutput+= class_modificationParser.parse(content.class_modification); + } + } + } + + if (string_comment != null) { + moOutput+=util.format("\n%s\n", string_comment); + } + + if (content.composition!=null) { + moOutput+=compositionParser.parse(content.composition); + } + + moOutput+=util.format("end %s;", identifier); + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/modificationParser.js b/json2mo/modificationParser.js new file mode 100644 index 00000000..104abfe0 --- /dev/null +++ b/json2mo/modificationParser.js @@ -0,0 +1,25 @@ +function parse(content) { + const class_modificationParser = require('./class_modificationParser'); + const expressionParser = require('./expressionParser'); + var moOutput = ""; + + if (content.class_modification != null) { + moOutput+=class_modificationParser.parse(content.class_modification); + } + + if (content.equal != null) { + if (content.equal) { + moOutput+= "= "; + } + } else if (content.colon_equal != null) { + if (content.colon_equal) { + moOutput+= ":= "; + } + } + if (content.expression != null) { + moOutput+=expressionParser.parse(content.expression); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/nameParser.js b/json2mo/nameParser.js new file mode 100644 index 00000000..36d462f9 --- /dev/null +++ b/json2mo/nameParser.js @@ -0,0 +1,9 @@ +function parse(content) { + const util = require('util'); + + var moOutput = ""; + moOutput+=util.format("%s ", content); + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/named_argumentParser.js b/json2mo/named_argumentParser.js new file mode 100644 index 00000000..984f9ddc --- /dev/null +++ b/json2mo/named_argumentParser.js @@ -0,0 +1,16 @@ +function parse(content) { + const util = require('util'); + const function_argumentParser = require('./function_argumentParser'); + + var moOutput = ""; + if (content.identifier != null) { + moOutput+=util.format("%s ", content.identifier); + } + if (content.value != null) { + moOutput+=function_argumentParser.parse(content.value); + } + + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/output_expression_listParser.js b/json2mo/output_expression_listParser.js new file mode 100644 index 00000000..08049fe1 --- /dev/null +++ b/json2mo/output_expression_listParser.js @@ -0,0 +1,17 @@ +function parse(content) { + const util = require('util'); + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + var output_expression_list = content; + if (output_expression_list != null) { + output_expression_list.forEach(expression => { + moOutput+=expressionParser.parse(expression); + moOutput+=", "; + }); + moOutput = moOutput.slice(0, -1); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/short_class_definitionParser.js b/json2mo/short_class_definitionParser.js new file mode 100644 index 00000000..a3c37904 --- /dev/null +++ b/json2mo/short_class_definitionParser.js @@ -0,0 +1,15 @@ +function parse(content) { + const util = require('util'); + const short_class_specifierParser = require('./short_class_specifierParser'); + + var moOutput = ""; + if (content.class_prefixes != null) { + moOutput+=util.format("%s ", class_prefixes); + } + if (content.short_class_specifier != null) { + moOutput+=short_class_specifierParser.parse(content.short_class_specifier); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/short_class_specifierParser.js b/json2mo/short_class_specifierParser.js new file mode 100644 index 00000000..aab29efa --- /dev/null +++ b/json2mo/short_class_specifierParser.js @@ -0,0 +1,16 @@ +function parse(content) { + const util = require('util'); + const short_class_specifier_valueParser = require('./short_class_specifier_valueParser'); + + var moOutput = ""; + var identifier = content.identifier; + + if (identifier != null) { + moOutput+=util.format("%s= ", identifier); + } + + moOutput+=short_class_specifier_valueParser.parse(content.short_class_specifier_value); + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/short_class_specifier_valueParser.js b/json2mo/short_class_specifier_valueParser.js new file mode 100644 index 00000000..d61da7c5 --- /dev/null +++ b/json2mo/short_class_specifier_valueParser.js @@ -0,0 +1,37 @@ +function parse(content) { + const base_prefixParser = require('./base_prefixParser'); + const nameParser = require('./nameParser'); + const array_subscriptsParser = require('./array_subscriptsParser'); + const class_modificationParser = require('./class_modificationParser'); + const commentParser = require('./commentParser'); + const enum_listParser = require('./enum_listParser'); + + var moOutput = ""; + + if (content.base_prefix == null) { + moOutput+="enumeration ("; + if (content.enum_list != null) { + moOutput+=enum_listParser.parse(content.enum_list) + } else { + moOutput+=":" + } + moOutput+=") " + } else { + moOutput+=base_prefixParser.parse(content.base_prefix); + if (content.name != null) { + moOutput+=nameParser.parse(content.name); + } + if (content.array_subscripts != null) { + moOutput+=array_subscriptsParser.parse(content.array_subscripts); + } + if(content.class_modification != null) { + moOutput+=class_modificationParser.parse(content.class_modification); + } + } + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/simple_expressionParser.js b/json2mo/simple_expressionParser.js new file mode 100644 index 00000000..563753e5 --- /dev/null +++ b/json2mo/simple_expressionParser.js @@ -0,0 +1,11 @@ +function parse(content) { + const util = require('util'); + + var moOutput = ""; + if (content!=null) { + moOutput+=util.format("%s ", JSON.stringify(content)); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/statementParser.js b/json2mo/statementParser.js new file mode 100644 index 00000000..045f028d --- /dev/null +++ b/json2mo/statementParser.js @@ -0,0 +1,44 @@ +function parse(content) { + const util = require('util'); + const assignment_statementParser = require('./assignment_statementParser'); + const function_call_statementParser = require('./function_call_statementParser'); + const assignment_with_function_call_statementParser = require('./assignment_with_function_call_statementParser'); + const if_statementParser = require('./if_statementParser'); + const for_statementParser = require('./for_statementParser'); + const while_statementParser = require('./while_statementParser'); + const when_statementParser = require('./when_statementParser'); + const commentParser = require('./commentParser'); + + var moOutput = ""; + if (content.assignment_statement != null) { + moOutput+=assignment_statementParser.parse(content.assignment_statement); + } else if (content.function_call_statement != null) { + moOutput+=function_call_statementParser.parse(content.function_call_statement); + } else if (content.assignment_with_function_call_statement != null) { + moOutput+=assignment_with_function_call_statementParser.parse(content.assignment_with_function_call_statement); + } else if (content.is_break != null) { + if (content.is_break) { + moOutput+="break\n"; + } + } else if (content.is_return != null) { + if (content.is_return) { + moOutput+="return\n"; + } + } else if (content.if_statement != null) { + moOutput+=if_statementParser.parse(content.if_statement); + } else if (content.for_statement != null) { + moOutput+=for_statementParser.parse(content.for_statement); + } else if (content.while_statement != null) { + moOutput+=while_statementParser.parse(content.while_statement); + } else if (content.when_statement != null) { + moOutput+=when_statementParser.parse(content.when_statement); + } + + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment); + } + + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/stored_definitonParser.js b/json2mo/stored_definitonParser.js new file mode 100644 index 00000000..9571f170 --- /dev/null +++ b/json2mo/stored_definitonParser.js @@ -0,0 +1,21 @@ +function parse(content) { + const util = require('util'); + const final_class_definitionParser = require('./final_class_definitionParser'); + + var within = content.within; + + var moOutput = ""; + if (within != null) { + moOutput+=util.format("within %s;\n", within) + } + + if (content.final_class_definitions != null) { + content.final_class_definitions.forEach(final_class_definition => { + moOutput+=final_class_definitionParser.parse(final_class_definition); + moOutput+="\n"; + }); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/type_specifierParser.js b/json2mo/type_specifierParser.js new file mode 100644 index 00000000..6c9527af --- /dev/null +++ b/json2mo/type_specifierParser.js @@ -0,0 +1,12 @@ +function parse(content) { + const util = require('util'); + const nameParser = require('./nameParser'); + + var moOutput = ""; + if (content.name != null) { + moOutput+=nameParser.parse(content.name); + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/when_equationParser.js b/json2mo/when_equationParser.js new file mode 100644 index 00000000..2b1929c2 --- /dev/null +++ b/json2mo/when_equationParser.js @@ -0,0 +1,36 @@ +function parse(content) { + const expressionParser = require('./expressionParser'); + const equationParser = require('./equationParser'); + + var moOutput = ""; + var when_elsewhens = content //different if it was raw-json + + if (when_elsewhens != null) { + + when_elsewhens.forEach(when_elsewhen => { + moOutput+="elsewhen " + if (when_elsewhen.condition != null) { + moOutput+=expressionParser.parse(when_elsewhen.condition); + } + moOutput+="\n"; + then_equations = when_elsewhen.then; + thenOutput = ""; + if (then_equations!=null) { + then_equations.forEach(then_equation => { + thenOutput+=equationParser.parse(then_equation); + thenOutput+=";\n"; + }); + } + + if (thenOutput != "") { + moOutput+="then \n"; + moOutput+=thenOutput; + } + }); + moOutput=moOutput.slice(4, moOutput.length); + } + moOutput+="end when \n" + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/when_statementParser.js b/json2mo/when_statementParser.js new file mode 100644 index 00000000..5db973b7 --- /dev/null +++ b/json2mo/when_statementParser.js @@ -0,0 +1,36 @@ +function parse(content) { + const expressionParser = require('./expressionParser'); + const statementParser = require('./statementParser'); + + var moOutput = ""; + var when_elsewhens = content //different if it was raw-json + + if (when_elsewhens != null) { + + when_elsewhens.forEach(when_elsewhen => { + moOutput+="elsewhen " + if (when_elsewhen.condition != null) { + moOutput+=expressionParser.parse(when_elsewhen.condition); + } + moOutput+="\n"; + then_statements = when_elsewhen.then; + thenOutput = ""; + if (then_statements!=null) { + then_statements.forEach(then_statement => { + thenOutput+=statementParser.parse(then_statement); + thenOutput+=";\n"; + }); + } + + if (thenOutput != "") { + moOutput+="then \n"; + moOutput+=thenOutput; + } + }); + moOutput=moOutput.slice(4, moOutput.length); + } + moOutput+="end when \n" + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/while_statementParser.js b/json2mo/while_statementParser.js new file mode 100644 index 00000000..fb0eac41 --- /dev/null +++ b/json2mo/while_statementParser.js @@ -0,0 +1,21 @@ +function parse(content) { + const expressionParser = require('./expressionParser'); + const statementParser = require('./statementParser'); + + var moOutput = ""; + moOutput+="while " + if (content.condition != null) { //in simplified json + moOutput+=expressionParser.parse(content.condition); + } + moOutput+="loop \n" + + loop_statements = content.loop_statements + loop_statements.forEach(loop_statement => { + moOutput+=statementParser.parse(loop_statement); + moOutput+=';\n'; + }); + moOutput+="end while"; + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file From 4a1fc98afcc39bd1ac92e1df201215373d9cd615 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Fri, 5 Nov 2021 09:40:04 -0700 Subject: [PATCH 14/29] parsing both simplified and raw-json back to mo --- json2mo/algorithm_sectionParser.js | 4 +- json2mo/annotationParser.js | 12 +++-- json2mo/argumentParser.js | 6 +-- json2mo/argument_listParser.js | 20 ++++---- json2mo/array_subscriptsParser.js | 45 ++++++++++++------ json2mo/class_definitionParser.js | 5 +- json2mo/class_modificationParser.js | 26 +++++++--- json2mo/class_specifierParser.js | 10 ++-- json2mo/commentParser.js | 25 +++++++--- json2mo/component_clause1Parser.js | 8 ++-- json2mo/component_clauseParser.js | 11 +++-- json2mo/component_declaration1Parser.js | 6 +-- json2mo/component_declarationParser.js | 8 ++-- json2mo/component_listParser.js | 29 ++++++++++-- json2mo/component_referenceParser.js | 47 ++++++++++++------- json2mo/component_reference_partParser.js | 23 +++++++++ json2mo/compositionParser.js | 12 ++--- json2mo/condition_attributeParser.js | 4 +- json2mo/connect_clauseParser.js | 6 +-- json2mo/constraining_clauseParser.js | 6 +-- json2mo/declarationParser.js | 6 +-- json2mo/der_class_specifierParser.js | 4 +- json2mo/der_class_specifier_valueParser.js | 16 +++++-- json2mo/elementParser.js | 26 +++++++--- json2mo/element_listParser.js | 24 +++++++--- json2mo/element_modificationParser.js | 8 ++-- ...ement_modification_or_replaceableParser.js | 6 +-- json2mo/element_redeclarationParser.js | 8 ++-- json2mo/element_replaceableParser.js | 8 ++-- json2mo/element_sectionParser.js | 10 ++-- json2mo/equationParser.js | 25 ++++++---- json2mo/equation_sectionParser.js | 5 +- json2mo/expressionParser.js | 6 +-- json2mo/expression_listParser.js | 4 +- json2mo/extends_clauseParser.js | 8 ++-- json2mo/external_compositionParser.js | 6 +-- json2mo/external_function_callParser.js | 6 +-- json2mo/final_class_definitionParser.js | 23 +++++++-- json2mo/for_equationParser.js | 6 +-- json2mo/for_indexParser.js | 19 ++++++++ json2mo/for_indicesParser.js | 44 ++++++++++------- json2mo/for_statementParser.js | 6 +-- json2mo/import_clauseParser.js | 21 +++++++-- json2mo/import_listParser.js | 2 +- json2mo/long_class_specifierParser.js | 20 +++++--- json2mo/modificationParser.js | 8 ++-- json2mo/nameParser.js | 14 +++++- json2mo/name_partParser.js | 19 ++++++++ json2mo/short_class_specifierParser.js | 4 +- json2mo/short_class_specifier_valueParser.js | 23 +++++---- json2mo/simple_expressionParser.js | 2 +- json2mo/statementParser.js | 27 ++++++----- json2mo/stored_definitonParser.js | 21 ++++++--- json2mo/subscriptParser.js | 18 +++++++ json2mo/type_specifierParser.js | 12 +++-- 55 files changed, 523 insertions(+), 255 deletions(-) create mode 100644 json2mo/component_reference_partParser.js create mode 100644 json2mo/for_indexParser.js create mode 100644 json2mo/name_partParser.js create mode 100644 json2mo/subscriptParser.js diff --git a/json2mo/algorithm_sectionParser.js b/json2mo/algorithm_sectionParser.js index 38d9c880..fc71e8ed 100644 --- a/json2mo/algorithm_sectionParser.js +++ b/json2mo/algorithm_sectionParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const statementParser = require('./statementParser'); var moOutput = ""; @@ -11,7 +11,7 @@ function parse(content) { var statements = content.statements; if (statements != null) { statements.forEach(statement => { - moOutput+=statementParser.parse(statement); + moOutput+=statementParser.parse(statement, rawJson); moOutput+=";\n" }); } diff --git a/json2mo/annotationParser.js b/json2mo/annotationParser.js index 5c7dd4e0..fa750d3f 100644 --- a/json2mo/annotationParser.js +++ b/json2mo/annotationParser.js @@ -1,12 +1,18 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const class_modificationParser = require('./class_modificationParser'); var moOutput = ""; moOutput+="annotation "; - if (content.class_modification != null) { - moOutput+=class_modificationParser.parse(content.class_modification); + if (rawJson) { + if (content.class_modification != null) { + moOutput+=class_modificationParser.parse(content.class_modification, rawJson); + } + } else { + var class_modification = content; + moOutput+=class_modificationParser.parse(class_modification, rawJson); } + return moOutput; } diff --git a/json2mo/argumentParser.js b/json2mo/argumentParser.js index 1ea9b8e2..9f41d024 100644 --- a/json2mo/argumentParser.js +++ b/json2mo/argumentParser.js @@ -1,12 +1,12 @@ -function parse(content) { +function parse(content, rawJson=false) { const element_modification_or_replaceableParser = require('./element_modification_or_replaceableParser'); const element_redeclarationParser = require('./element_redeclarationParser'); var moOutput = ""; if (content.element_modification_or_replaceable != null) { - moOutput+=element_modification_or_replaceableParser.parse(content.element_modification_or_replaceable) + moOutput+=element_modification_or_replaceableParser.parse(content.element_modification_or_replaceable, rawJson) } else if (content.element_redeclaration != null) { - moOutput+=element_redeclarationParser.parse(content.element_redeclaration) + moOutput+=element_redeclarationParser.parse(content.element_redeclaration, rawJson) } return moOutput; } diff --git a/json2mo/argument_listParser.js b/json2mo/argument_listParser.js index 953ca7c7..4ac8b7aa 100644 --- a/json2mo/argument_listParser.js +++ b/json2mo/argument_listParser.js @@ -1,16 +1,18 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const argumentParser = require('./argumentParser'); var moOutput = ""; - var arguments = content.arguments; + if (rawJson) { + var arguments = content.arguments; - if (arguments != null) { - arguments.forEach(argument => { - moOutput+=argumentParser.parse(argument); - moOutput+=", "; - }); - moOutput = moOutput.slice(0, -2); - } + if (arguments != null) { + arguments.forEach(argument => { + moOutput+=argumentParser.parse(argument, rawJson); + moOutput+=", "; + }); + moOutput = moOutput.slice(0, -2); + } + } return moOutput; } diff --git a/json2mo/array_subscriptsParser.js b/json2mo/array_subscriptsParser.js index a399eac7..52aebb41 100644 --- a/json2mo/array_subscriptsParser.js +++ b/json2mo/array_subscriptsParser.js @@ -1,22 +1,39 @@ -function parse(content) { +function parse(content, rawJson=false) { const expressionParser = require('./expressionParser'); + const subscriptParser = require('./subscriptParser'); var moOutput = ""; - var arrary_subscripts = content; - moOutput+="[" - if (arrary_subscripts != null) { - array_subscripts.forEach(array_subscript => { - if (array_subscript.colon_op != null) { - if (array_subscript.colon_op) { - moOutput+=":"; + if (rawJson) { + moOutput+="[" + var subscripts = content.subscripts; + if (subscripts != null) { + subscripts.forEach(subscript => { + moOutput+=subscriptParser.parse(subscript, rawJson); + moOutput+=", " + }); + moOutput = moOutput.slice(0, -2); + } + moOutput+="] " + } else { + var arrary_subscripts = content; + moOutput+="[" + + if (arrary_subscripts != null) { + array_subscripts.forEach(array_subscript => { + if (array_subscript.colon_op != null) { + if (array_subscript.colon_op) { + moOutput+=":"; + } + } else if (array_subscript.expression != null) { + moOutput+=expressionParser.parser(array_subscript.expression, rawJson); } - } else if (array_subscript.expression != null) { - moOutput+=expressionParser.parser(array_subscript.expression); - } - }); - } - moOutput+="] "; + moOutput+=", " + }); + moOutput = moOutput.slice(0, -2); + } + moOutput+="] "; + } return moOutput; } diff --git a/json2mo/class_definitionParser.js b/json2mo/class_definitionParser.js index 5b629e1e..0e3dbe3e 100644 --- a/json2mo/class_definitionParser.js +++ b/json2mo/class_definitionParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const class_specifierParser = require('./class_specifierParser'); var encapsulated = content.encapsulated; @@ -14,8 +14,7 @@ function parse(content) { if (class_prefixes != null) { moOutput += util.format("%s ", class_prefixes); } - - moOutput+=class_specifierParser.parse(content.class_specifier); + moOutput+=class_specifierParser.parse(content.class_specifier, rawJson); return moOutput; } diff --git a/json2mo/class_modificationParser.js b/json2mo/class_modificationParser.js index 229aba30..53249d47 100644 --- a/json2mo/class_modificationParser.js +++ b/json2mo/class_modificationParser.js @@ -1,12 +1,26 @@ -function parse(content) { +function parse(content, rawJson=false) { const argument_listParser = require('./argument_listParser'); - + const argumentParser = require('./argumentParser'); + var moOutput = ""; - moOutput+="("; - if (content.argument_list != null) { - moOutput+=argument_listParser.parse(content.argument_list); + if (rawJson) { + moOutput+="("; + if (content.argument_list != null) { + moOutput+=argument_listParser.parse(content.argument_list, rawJson); + } + moOutput+=")" + } else { + var argument_list = content; + moOutput+="("; + + argument_list.forEach(argument => { + moOutput+=argumentParser.parse(argument, rawJson); + moOutput+=", "; + }); + + moOutput = moOutput.slice(0, -2); + moOutput+=")" } - moOutput+=")" return moOutput; } diff --git a/json2mo/class_specifierParser.js b/json2mo/class_specifierParser.js index 60b76936..1509a6b3 100644 --- a/json2mo/class_specifierParser.js +++ b/json2mo/class_specifierParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const long_class_specifierParser = require('./long_class_specifierParser'); const short_class_specifierParser = require('./short_class_specifierParser'); const der_class_specifierParser = require('./der_class_specifierParser'); @@ -10,15 +10,15 @@ function parse(content) { var moOutput = ""; if (long_class_specifier != null) { - moOutput+=long_class_specifierParser.parse(long_class_specifier); + moOutput+=long_class_specifierParser.parse(long_class_specifier, rawJson); } - + if (short_class_specifier != null) { - moOutput+=short_class_specifierParser.parse(short_class_specifier); + moOutput+=short_class_specifierParser.parse(short_class_specifier, rawJson); } if (der_class_specifier != null) { - moOutput+=der_class_specifierParser.parse(der_class_specifier); + moOutput+=der_class_specifierParser.parse(der_class_specifier, rawJson); } return moOutput; diff --git a/json2mo/commentParser.js b/json2mo/commentParser.js index a68801c3..332776f1 100644 --- a/json2mo/commentParser.js +++ b/json2mo/commentParser.js @@ -1,15 +1,26 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const annotationParser = require('./annotationParser'); var moOutput = ""; - if (content.string_comment != null) { - moOutput+=util.format("%s ", content.string_comment); + if (rawJson) { + if (content.string_comment != null) { + moOutput+=util.format("%s ", content.string_comment); + } + if (content.annotation != null) { + moOutput+=annotationParser.parse(content.annotation, rawJson); + } + moOutput+="\n"; + } else { + if (content.description_string != null) { + moOutput+=util.format("%s ", content.description_string); + } + if (content.annotation != null) { + moOutput+=annotationParser.parse(content.annotation, rawJson); + } + moOutput+="\n"; } - if (content.annotation != null) { - moOutput+=annotationParser.parse(content.annotation); - } - moOutput+="\n"; + return moOutput; } diff --git a/json2mo/component_clause1Parser.js b/json2mo/component_clause1Parser.js index 2c5ba47c..96f43eea 100644 --- a/json2mo/component_clause1Parser.js +++ b/json2mo/component_clause1Parser.js @@ -1,17 +1,17 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const type_specifierParser = require('./type_specifierParser'); const component_declaration1Parser = require('./component_declaration1Parser'); var moOutput = ""; if (content.type_prefix != null) { - moOutput+=util.format("%s ", content.type_prefix); + moOutput+=util.format("%s ", content.type_prefix, rawJson); } if (content.type_specifier != null) { - moOutput+=type_specifierParser.parse(content.type_specifier); + moOutput+=type_specifierParser.parse(content.type_specifier, rawJson); } if (content.component_declaration1 != null) { - moOutput+=component_declaration1Parser.parse(content.component_declaration1); + moOutput+=component_declaration1Parser.parse(content.component_declaration1, rawJson); } return moOutput; } diff --git a/json2mo/component_clauseParser.js b/json2mo/component_clauseParser.js index 52f210a7..95271b23 100644 --- a/json2mo/component_clauseParser.js +++ b/json2mo/component_clauseParser.js @@ -1,21 +1,22 @@ -function parse(content) { +function parse(content, rawJson=false) { const type_specifierParser = require('./type_specifierParser'); const array_subscriptsParser = require('./array_subscriptsParser'); const component_listParser = require('./component_listParser'); - + const util = require('util'); + var moOutput = ""; if (content.type_prefix != null) { moOutput+=util.format("%s ", content.type_prefix); } if (content.type_specifier != null) { - moOutput+=type_specifierParser.parse(content.type_specifier); + moOutput+=type_specifierParser.parse(content.type_specifier, rawJson); } if (content.array_subscripts != null) { - moOutput+=array_subscriptsParser.parse(content.array_subscripts); + moOutput+=array_subscriptsParser.parse(content.array_subscripts, rawJson); } if (content.component_list != null) { - moOutput+=component_listParser.parse(content.component_list); + moOutput+=component_listParser.parse(content.component_list, rawJson); } return moOutput; } diff --git a/json2mo/component_declaration1Parser.js b/json2mo/component_declaration1Parser.js index af8b165e..78b44610 100644 --- a/json2mo/component_declaration1Parser.js +++ b/json2mo/component_declaration1Parser.js @@ -1,14 +1,14 @@ -function parse(content) { +function parse(content, rawJson) { const util = require('util'); const declarationParser = require('./declarationParser'); const commentParser = require('./commentParser'); var moOutput = ""; if (content.declaration != null) { - moOutput+=declarationParser.parse(content.declaration); + moOutput+=declarationParser.parse(content.declaration, rawJson); } if (content.comment != null) { - moOutput+=commentParser.parse(content.comment); + moOutput+=commentParser.parse(content.comment, rawJson); } return moOutput; } diff --git a/json2mo/component_declarationParser.js b/json2mo/component_declarationParser.js index 4e6597a7..c2f8ffe4 100644 --- a/json2mo/component_declarationParser.js +++ b/json2mo/component_declarationParser.js @@ -1,17 +1,17 @@ -function parse(content) { +function parse(content, rawJson=false) { const declarationParser = require('./declarationParser'); const condition_attributeParser = require('./condition_attributeParser'); const commentParser = require('./commentParser'); var moOutput = ""; if (content.declaration != null) { - moOutput+=declarationParser.parse(content.declaration); + moOutput+=declarationParser.parse(content.declaration, rawJson); } if (content.condition_attribute != null) { - moOutput+=condition_attributeParser.parser(content.condition_attribute); + moOutput+=condition_attributeParser.parser(content.condition_attribute, rawJson); } if (content.comment != null) { - moOutput+=commentParser.parse(content.comment); + moOutput+=commentParser.parse(content.comment, rawJson); } return moOutput; } diff --git a/json2mo/component_listParser.js b/json2mo/component_listParser.js index d9676b16..e23b4f4e 100644 --- a/json2mo/component_listParser.js +++ b/json2mo/component_listParser.js @@ -1,12 +1,31 @@ -function parse(content) { +function parse(content, rawJson=false) { const component_declarationParser = require('./component_declarationParser'); + const declarationParser = require('./declarationParser'); + const condition_attributeParser = require('./condition_attributeParser'); + const commentParser = require('./commentParser'); var moOutput = ""; - var component_declaration_list = content.component_declaration_list; + if (rawJson) { + var component_declaration_list = content.component_declaration_list; - component_declaration_list.forEach(component_declaration => { - moOutput+=component_declarationParser.parse(component_declaration); - }); + component_declaration_list.forEach(component_declaration => { + moOutput+=component_declarationParser.parse(component_declaration, rawJson); + }); + } else { + var component_declaration_list = content; + component_declaration_list.forEach(component_declaration => { + if (component_declaration.declaration != null) { + moOutput+=declarationParser.parse(component_declaration.declaration, rawJson); + } + if (component_declaration.condition_attribute != null) { + moOutput+=condition_attributeParser.parser(component_declaration.condition_attribute, rawJson); + } + if (component_declaration.description != null) { + moOutput+=commentParser.parse(component_declaration.description, rawJson); + } + }); + } + return moOutput; } diff --git a/json2mo/component_referenceParser.js b/json2mo/component_referenceParser.js index 29ea7495..3ddc55a9 100644 --- a/json2mo/component_referenceParser.js +++ b/json2mo/component_referenceParser.js @@ -1,25 +1,36 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); - const arrary_subscriptsParser = require('./arrary_subscriptsParser'); + const array_subscriptsParser = require('./array_subscriptsParser'); + const component_reference_partParser = require('./component_reference_partParser'); var moOutput = ""; - var component_reference_parts = content; //only if simplified-json - - component_reference_parts.forEach(component_reference_part => { - if (component_reference_part.dot_op != null) { - if(component_reference_part.dot_op) { - moOutput+="." - } - } - if (component_reference_part.identifier != null) { - moOutput+=util.format("%s", component_reference_part.identifier); - } - if (component_reference_part.arrary_subscripts != null) { - moOutput+=arrary_subscriptsParser.parse(component_reference_part.arrary_subscripts); + + if (!rawJson) { + var component_reference_parts = content; + component_reference_parts.forEach(component_reference_part => { + if (component_reference_part.dot_op != null) { + if(component_reference_part.dot_op) { + moOutput+="." + } + } + if (component_reference_part.identifier != null) { + moOutput+=util.format("%s", component_reference_part.identifier); + } + if (component_reference_part.array_subscripts != null) { + moOutput+=array_subscriptsParser.parse(component_reference_part.array_subscripts, rawJson); + } + }); + return moOutput; + } else { + var component_reference_parts = content.component_reference_parts + if (component_reference_parts != null) { + component_reference_parts.forEach(component_reference_part => { + moOutput+=component_reference_partParser.parse(component_reference_part, rawJson) + }); } - }); - moOutput+=" "; - return moOutput; + return moOutput; + } + } module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/component_reference_partParser.js b/json2mo/component_reference_partParser.js new file mode 100644 index 00000000..5df145f7 --- /dev/null +++ b/json2mo/component_reference_partParser.js @@ -0,0 +1,23 @@ +function parse(content, rawJson=false) { + const util = require('util'); + const array_subscriptsParser = require('./array_subscriptsParser'); + + var moOutput = ""; + + if (rawJson) { + if (content.dot_op != null) { + if(content.dot_op) { + moOutput+="." + } + } + if (content.identifier != null) { + moOutput+=util.format("%s", content.identifier); + } + if (content.array_subscripts != null) { + moOutput+=array_subscriptsParser.parse(content.array_subscripts, rawJson); + } + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/compositionParser.js b/json2mo/compositionParser.js index 8a6a70fa..6d705089 100644 --- a/json2mo/compositionParser.js +++ b/json2mo/compositionParser.js @@ -1,26 +1,24 @@ -function parse(content) { +function parse(content, rawJson=false) { const element_listParser = require('./element_listParser'); const element_sectionParser = require('./element_sectionParser'); const external_compositionParser = require('./external_compositionParser'); const annotationParser = require('./annotationParser'); var moOutput = ""; - if (content.element_list != null) { - moOutput+=element_listParser.parse(content.element_list); + moOutput+=element_listParser.parse(content.element_list, rawJson); } if (content.element_sections != null) { var element_sections = content.element_sections; element_sections.forEach(element_section => { - moOutput+=element_sectionParser.parse(element_section); + moOutput+=element_sectionParser.parse(element_section, rawJson); }); } if (content.external_composition != null) { - console.log(content.external_composition) - moOutput+=external_compositionParser.parse(content.external_composition); + moOutput+=external_compositionParser.parse(content.external_composition, rawJson); } if (content.annotation != null) { - moOutput+=annotationParser.parse(content.annotation); + moOutput+=annotationParser.parse(content.annotation, rawJson); } return moOutput; } diff --git a/json2mo/condition_attributeParser.js b/json2mo/condition_attributeParser.js index 0945944c..6cd887a2 100644 --- a/json2mo/condition_attributeParser.js +++ b/json2mo/condition_attributeParser.js @@ -1,10 +1,10 @@ -function parse(content) { +function parse(content, rawJson=false) { const expressionParser = require('./expressionParser'); var moOutput = ""; moOutput+="if " if (content.expression != null) { - moOutput+=expressionParser.parse(content.expression); + moOutput+=expressionParser.parse(content.expression, rawJson); } return moOutput; } diff --git a/json2mo/connect_clauseParser.js b/json2mo/connect_clauseParser.js index 820db6e1..1ee4951c 100644 --- a/json2mo/connect_clauseParser.js +++ b/json2mo/connect_clauseParser.js @@ -1,15 +1,15 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const component_referenceParser = require('./component_referenceParser'); var moOutput = ""; moOutput+="connect("; if (content.from != null) { - moOutput+=component_referenceParser.parse(content.from); + moOutput+=component_referenceParser.parse(content.from, rawJson); } if (content.to != null) { moOutput+=", " - moOutput+=component_referenceParser.parse(content.to); + moOutput+=component_referenceParser.parse(content.to, rawJson); } moOutput+=")\n"; return moOutput; diff --git a/json2mo/constraining_clauseParser.js b/json2mo/constraining_clauseParser.js index f822ca7a..a1aad6c3 100644 --- a/json2mo/constraining_clauseParser.js +++ b/json2mo/constraining_clauseParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const nameParser = require('./nameParser'); const class_modificationParser = require('./class_modificationParser'); @@ -7,11 +7,11 @@ function parse(content) { var name=""; if (content.name != null) { - moOutput+= nameParser.parse(content.name); + moOutput+= nameParser.parse(content.name, rawJson); } if (content.class_modification != null) { - moOutput+=class_modificationParser.parse(content.class_modification); + moOutput+=class_modificationParser.parse(content.class_modification, rawJson); } return moOutput; } diff --git a/json2mo/declarationParser.js b/json2mo/declarationParser.js index b661b093..76765165 100644 --- a/json2mo/declarationParser.js +++ b/json2mo/declarationParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const array_subscriptsParser = require('./array_subscriptsParser'); const modificationParser = require('./modificationParser'); @@ -8,10 +8,10 @@ function parse(content) { moOutput+=util.format("%s ", content.identifier); } if (content.array_subscripts != null) { - moOutput+=array_subscriptsParser.parse(content.array_subscripts); + moOutput+=array_subscriptsParser.parse(content.array_subscripts, rawJson); } if (content.modification != null) { - moOutput+=modificationParser.parse(content.modification); + moOutput+=modificationParser.parse(content.modification, rawJson); } return moOutput; } diff --git a/json2mo/der_class_specifierParser.js b/json2mo/der_class_specifierParser.js index 0edb9904..1f854587 100644 --- a/json2mo/der_class_specifierParser.js +++ b/json2mo/der_class_specifierParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const der_class_specifier_valueParser = require('./der_class_specifier_valueParser'); @@ -10,7 +10,7 @@ function parse(content) { } if (content.der_class_specifier_value != null) { - moOutput+=der_class_specifier_valueParser.parse(content.der_class_specifier_value); + moOutput+=der_class_specifier_valueParser.parse(content.der_class_specifier_value, rawJson); } return moOutput; } diff --git a/json2mo/der_class_specifier_valueParser.js b/json2mo/der_class_specifier_valueParser.js index 42ea2b98..52a36c68 100644 --- a/json2mo/der_class_specifier_valueParser.js +++ b/json2mo/der_class_specifier_valueParser.js @@ -1,11 +1,11 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const nameParser = require('./nameParser'); const commentParser = require('./commentParser'); var moOutput = "der("; if (content.type_specifier != null) { - moOutput+=nameParser.parse(content.type_specifier); + moOutput+=nameParser.parse(content.type_specifier, rawJson); } var identifiers = content.identifiers; @@ -16,10 +16,16 @@ function parse(content) { moOutput = moOutput.slice(0, -2); moOutput+=") " } - - if (content.comment != null) { - moOutput+=commentParser.parse(content.content); + if (rawJson) { + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment, rawJson); + } + } else { + if (content.description != null) { + moOutput+=commentParser.parse(content.description, rawJson); + } } + return moOutput; } diff --git a/json2mo/elementParser.js b/json2mo/elementParser.js index 858eff74..c4238978 100644 --- a/json2mo/elementParser.js +++ b/json2mo/elementParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const class_definitionParser = require('./class_definitionParser'); const import_clauseParser = require('./import_clauseParser'); const extends_clauseParser = require('./extends_clauseParser'); @@ -8,9 +8,9 @@ function parse(content) { var moOutput = ""; if (content.import_clause != null) { - moOutput+=import_clauseParser.parse(content.import_clause); + moOutput+=import_clauseParser.parse(content.import_clause, rawJson); } else if (content.extends_clause != null) { - moOutput+=extends_clauseParser.parse(content.extends_clause); + moOutput+=extends_clauseParser.parse(content.extends_clause, rawJson); } else { if (content.redeclare != null) { if (content.redeclare) { @@ -36,19 +36,31 @@ function parse(content) { if (content.replaceable) { moOutput+="replaceable " if (content.class_definition != null) { - moOutput+=class_definitionParser.parse(content.class_definition); + moOutput+=class_definitionParser.parse(content.class_definition, rawJson); } else if (content.component_clause != null) { - moOutput+=component_clauseParser.parse(content.component_clause); + moOutput+=component_clauseParser.parse(content.component_clause, rawJson); } if (content.constraining_clause != null) { moOutput+="\n" - moOutput+=constraining_clauseParser.parse(content.constraining_clause); + moOutput+=constraining_clauseParser.parse(content.constraining_clause, rawJson); } if (content.comment != null) { - moOutput+=commentParser.parse(content.comment); + moOutput+=commentParser.parse(content.comment, rawJson); } + } else { + if (content.class_definition != null) { + moOutput+=class_definitionParser.parse(content.class_definition, rawJson); + } else if (content.component_clause != null) { + moOutput+=component_clauseParser.parse(content.component_clause, rawJson); + } + } + } else { + if (content.class_definition != null) { + moOutput+=class_definitionParser.parse(content.class_definition, rawJson); + } else if (content.component_clause != null) { + moOutput+=component_clauseParser.parse(content.component_clause, rawJson); } } } diff --git a/json2mo/element_listParser.js b/json2mo/element_listParser.js index a01d0371..f4a54795 100644 --- a/json2mo/element_listParser.js +++ b/json2mo/element_listParser.js @@ -1,13 +1,23 @@ -function parse(content) { +function parse(content, rawJson=false) { const elementParser = require('./elementParser'); - + var moOutput = ""; - var elements = content.elements - if (elements != null) { - elements.forEach(element => { - moOutput+=elementParser.parse(element); - }); + if (rawJson) { + var elements = content.elements + if (elements != null) { + elements.forEach(element => { + moOutput+=elementParser.parse(element, rawJson); + }); + } + } else { + var elements = content; + if (elements != null) { + elements.forEach(element => { + moOutput+=elementParser.parse(element, rawJson); + }); + } } + return moOutput; } diff --git a/json2mo/element_modificationParser.js b/json2mo/element_modificationParser.js index 6fe6b23d..d1b0729d 100644 --- a/json2mo/element_modificationParser.js +++ b/json2mo/element_modificationParser.js @@ -1,17 +1,17 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const nameParser = require('./nameParser'); const modificationParser = require('./modificationParser'); var moOutput = ""; if (content.name != null) { - moOutput+=nameParser.parse(content.name); + moOutput+=nameParser.parse(content.name, rawJson); } if (content.modification != null) { - moOutput+=modificationParser.parse(content.modification); + moOutput+=modificationParser.parse(content.modification, rawJson); } if (content.string_comment != null) { - moOutput+=util.format("%s", content.string_comment); + moOutput+=util.format("%s", content.string_comment, rawJson); } return moOutput; } diff --git a/json2mo/element_modification_or_replaceableParser.js b/json2mo/element_modification_or_replaceableParser.js index a9daceb1..fcbe3db1 100644 --- a/json2mo/element_modification_or_replaceableParser.js +++ b/json2mo/element_modification_or_replaceableParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const element_modificationParser = require('./element_modificationParser'); const element_replaceableParser = require('./element_replaceableParser'); @@ -14,9 +14,9 @@ function parse(content) { } } if (content.element_modification != null) { - moOutput+=element_modificationParser.parse(content.element_modification); + moOutput+=element_modificationParser.parse(content.element_modification, rawJson); } else if (content.element_replaceable != null) { - moOutput+=element_replaceableParser.parse(content.element_replaceable); + moOutput+=element_replaceableParser.parse(content.element_replaceable, rawJson); } return moOutput; } diff --git a/json2mo/element_redeclarationParser.js b/json2mo/element_redeclarationParser.js index 3546671d..c15da9ca 100644 --- a/json2mo/element_redeclarationParser.js +++ b/json2mo/element_redeclarationParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson) { const short_class_definitionParser = require('./short_class_definitionParser'); const component_clause1Parser = require('./component_clause1Parser'); const element_replaceableParser = require('./element_replaceableParser'); @@ -17,12 +17,12 @@ function parse(content) { } } if (content.element_replaceable != null) { - moOutput+=element_replaceableParser.parse(content.element_replaceable); + moOutput+=element_replaceableParser.parse(content.element_replaceable, rawJson); } else { if (content.short_class_definition != null) { - moOutput+=short_class_definitionParser.parse(content.short_class_definition); + moOutput+=short_class_definitionParser.parse(content.short_class_definition, rawJson); } else if (content.component_clause1 != null) { - moOutput+=component_clause1Parser.parse(content.component_clause1); + moOutput+=component_clause1Parser.parse(content.component_clause1, rawJson); } } return moOutput; diff --git a/json2mo/element_replaceableParser.js b/json2mo/element_replaceableParser.js index 637f3788..283fdb79 100644 --- a/json2mo/element_replaceableParser.js +++ b/json2mo/element_replaceableParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const short_class_definitionParser = require('./short_class_definitionParser'); const component_clause1Parser = require('./component_clause1Parser'); const constraining_clauseParser = require('./constraining_clauseParser'); @@ -6,12 +6,12 @@ function parse(content) { var moOutput = ""; moOutput+="replaceable "; if (content.short_class_definition != null) { - moOutput+=short_class_definitionParser.parse(content.short_class_definition); + moOutput+=short_class_definitionParser.parse(content.short_class_definition, rawJson); } else if (content.component_clause1 != null) { - moOutput+=component_clause1Parser.parse(content.component_clause1); + moOutput+=component_clause1Parser.parse(content.component_clause1, rawJson); } if (content.constraining_clause != null) { - moOutput+=constraining_clauseParser.parse(content.constraining_clause); + moOutput+=constraining_clauseParser.parse(content.constraining_clause, rawJson); } return moOutput; } diff --git a/json2mo/element_sectionParser.js b/json2mo/element_sectionParser.js index 2258c0ff..4b961ad3 100644 --- a/json2mo/element_sectionParser.js +++ b/json2mo/element_sectionParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const element_listParser = require('./element_listParser'); const equation_sectionParser = require('./equation_sectionParser'); const algorithm_sectionParser = require('./algorithm_sectionParser'); @@ -7,16 +7,16 @@ function parse(content) { if (content.public_element_list != null) { moOutput+="public\n" - moOutput+=element_listParser.parse(content.public_element_list); + moOutput+=element_listParser.parse(content.public_element_list, rawJson); } else if (content.protected_element_list != null) { moOutput+="protected\n" - moOutput+=element_listParser.parse(content.protected_element_list); + moOutput+=element_listParser.parse(content.protected_element_list, rawJson); } else if (content.equation_section != null) { - moOutput+=equation_sectionParser.parse(content.equation_section); + moOutput+=equation_sectionParser.parse(content.equation_section, rawJson); } else if (content.algorithm_section != null) { - moOutput+=algorithm_sectionParser.parse(content.algorithm_section); + moOutput+=algorithm_sectionParser.parse(content.algorithm_section, rawJson); } return moOutput; } diff --git a/json2mo/equationParser.js b/json2mo/equationParser.js index 0643e287..dff6d5ea 100644 --- a/json2mo/equationParser.js +++ b/json2mo/equationParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const assignment_equationParser = require('./assignment_equationParser'); const if_equationParser = require('./if_equationParser'); @@ -10,22 +10,29 @@ function parse(content) { var moOutput = ""; if (content.assignment_equation != null) { - moOutput+=assignment_equationParser.parse(content.assignment_equation); + moOutput+=assignment_equationParser.parse(content.assignment_equation, rawJson); } else if (content.if_equation != null) { - moOutput+=if_equationParser.parse(content.if_equation); + moOutput+=if_equationParser.parse(content.if_equation, rawJson); } else if (content.for_equation != null) { - moOutput+=for_equationParser.parse(content.for_equation); + moOutput+=for_equationParser.parse(content.for_equation, rawJson); } else if (content.connect_clause != null) { - moOutput+=connect_clauseParser.parse(content.connect_clause); + moOutput+=connect_clauseParser.parse(content.connect_clause, rawJson); } else if (content.when_equation != null) { - moOutput+=when_equationParser.parse(content.when_equation); + moOutput+=when_equationParser.parse(content.when_equation, rawJson); } else if (content.function_call_equation != null) { - moOutput+=function_call_equationParser.parse(content.function_call_equation); + moOutput+=function_call_equationParser.parse(content.function_call_equation, rawJson); } - if (content.comment != null) { - moOutput+=commentParser.parse(content.comment); + if (rawJson) { + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment, rawJson); + } + } else { + if (content.description != null) { + moOutput+=commentParser.parse(content.description, rawJson); + } } + return moOutput; } diff --git a/json2mo/equation_sectionParser.js b/json2mo/equation_sectionParser.js index a7ccfd39..88168960 100644 --- a/json2mo/equation_sectionParser.js +++ b/json2mo/equation_sectionParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const equationParser = require('./equationParser'); @@ -12,8 +12,7 @@ function parse(content) { var equations = content.equations; if (equations != null) { equations.forEach(equation => { - moOutput+=equationParser.parse(equation); - moOutput+=equation; + moOutput+=equationParser.parse(equation, rawJson); moOutput+=";\n" }); } diff --git a/json2mo/expressionParser.js b/json2mo/expressionParser.js index 33d0b8f2..90e1da90 100644 --- a/json2mo/expressionParser.js +++ b/json2mo/expressionParser.js @@ -1,13 +1,13 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const simple_expressionParser = require('./simple_expressionParser'); const if_expressionParser = require('./if_expressionParser'); var moOutput = ""; if (content.if_expression != null) { - moOutput+=if_expressionParser.parse(content.if_expression); + moOutput+=if_expressionParser.parse(content.if_expression, rawJson); } else if (content.simple_expression != null) { - moOutput+=simple_expressionParser.parse(content.simple_expression); + moOutput+=simple_expressionParser.parse(content.simple_expression, rawJson); } return moOutput; diff --git a/json2mo/expression_listParser.js b/json2mo/expression_listParser.js index c0d2310b..5ea3dab2 100644 --- a/json2mo/expression_listParser.js +++ b/json2mo/expression_listParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const expressionParser = require('./expressionParser'); @@ -6,7 +6,7 @@ function parse(content) { var expression_list = content; if (expression_list != null) { expression_list.forEach(expression => { - moOutput+=expressionParser.parse(expression); + moOutput+=expressionParser.parse(expression, rawJson); moOutput+=", "; }); moOutput = moOutput.slice(0, -1); diff --git a/json2mo/extends_clauseParser.js b/json2mo/extends_clauseParser.js index 358f165a..6011a8f0 100644 --- a/json2mo/extends_clauseParser.js +++ b/json2mo/extends_clauseParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const nameParser = require('./nameParser'); const class_modificationParser = require('./class_modificationParser'); const annotationParser = require('./annotationParser'); @@ -7,13 +7,13 @@ function parse(content) { moOutput+="extends "; if (content.name != null) { - moOutput+=nameParser.parse(content.name); + moOutput+=nameParser.parse(content.name, rawJson); } if (content.class_modification != null) { - moOutput+=class_modificationParser.parse(content.class_modification); + moOutput+=class_modificationParser.parse(content.class_modification, rawJson); } if (content.annotation != null) { - moOutput+=annotationParser.parse(content.annotation); + moOutput+=annotationParser.parse(content.annotation, rawJson); } return moOutput; } diff --git a/json2mo/external_compositionParser.js b/json2mo/external_compositionParser.js index a025b990..e20efe3d 100644 --- a/json2mo/external_compositionParser.js +++ b/json2mo/external_compositionParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const external_function_callParser = require('./external_function_callParser'); const annotationParser = require('./annotationParser'); @@ -9,10 +9,10 @@ function parse(content) { moOutput+=util.format("%s ", content.language_specification); } if (content.external_function_call != null) { - moOutput+=external_function_callParser.parse(content.external_function_call); + moOutput+=external_function_callParser.parse(content.external_function_call, rawJson); } if (content.external_annotation != null) { - moOutput+=annotationParser.parse(content.external_annotation); + moOutput+=annotationParser.parse(content.external_annotation, rawJson); } moOutput+=";\n"; return moOutput; diff --git a/json2mo/external_function_callParser.js b/json2mo/external_function_callParser.js index 117f27d4..355f1f0f 100644 --- a/json2mo/external_function_callParser.js +++ b/json2mo/external_function_callParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const component_referenceParser = require('./component_referenceParser'); const expression_listParser = require('./expression_listParser'); @@ -6,14 +6,14 @@ function parse(content) { var moOutput = ""; if (content.component_reference != null) { - moOutput+=component_referenceParser.parse(contnnt.component_reference); + moOutput+=component_referenceParser.parse(contnnt.component_reference, rawJson); moOutput+="= "; } if (content.identifier != null) { moOutput+="identifier (" } if (content.expression_list != null) { - moOutput+=expression_listParser.parse(content.expression_list); + moOutput+=expression_listParser.parse(content.expression_list, rawJson); } moOutput+=")\n"; return moOutput; diff --git a/json2mo/final_class_definitionParser.js b/json2mo/final_class_definitionParser.js index b0faf2e7..90736a17 100644 --- a/json2mo/final_class_definitionParser.js +++ b/json2mo/final_class_definitionParser.js @@ -1,16 +1,29 @@ -function parse(content) { +function parse(content, rawJson=false) { const class_definitionParser = require('./class_definitionParser'); - var is_final = content.is_final; + var moOutput = ""; + var is_final = false; + if (rawJson){ + is_final = content.is_final; + } else { + is_final = content.final; + } if (is_final != null) { if (is_final) { moOutput+= "final "; } } - if (content.class_definition != null) { - moOutput+=class_definitionParser.parse(content.class_definition); - } + + if (rawJson) { + if (content.class_definition != null) { + moOutput+=class_definitionParser.parse(content.class_definition, rawJson); + } + } else { + var class_definition = content; + moOutput+=class_definitionParser.parse(class_definition, rawJson); + } + return moOutput; } diff --git a/json2mo/for_equationParser.js b/json2mo/for_equationParser.js index 649344db..7c86cab6 100644 --- a/json2mo/for_equationParser.js +++ b/json2mo/for_equationParser.js @@ -1,17 +1,17 @@ -function parse(content) { +function parse(content, rawJson=false) { const for_indicesParser = require('./for_indicesParser'); const equationParser = require('./equationParser'); var moOutput = ""; moOutput+="for " if (content.for_indices != null) { - moOutput+=for_indicesParser.parse(content.for_indices); + moOutput+=for_indicesParser.parse(content.for_indices, rawJson); } moOutput+="loop \n" loop_equations = content.loop_equations loop_equations.forEach(loop_equation => { - moOutput+=equationParser.parse(loop_equation); + moOutput+=equationParser.parse(loop_equation, rawJson); moOutput+=';\n'; }); moOutput+="end for"; diff --git a/json2mo/for_indexParser.js b/json2mo/for_indexParser.js new file mode 100644 index 00000000..c9f46c49 --- /dev/null +++ b/json2mo/for_indexParser.js @@ -0,0 +1,19 @@ +function parse(content, rawJson=false) { + const util = require('util'); + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + if (rawJson) { + if (content.identifier != null) { + moOutput+=util.format("%s ", content.identifier); + } + if (content.expression != null) { + moOutput+="in " + moOutput+=expressionParser.parse(content.expression, rawJson); + } + moOutput+=","; + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/for_indicesParser.js b/json2mo/for_indicesParser.js index c6e760dd..c6a1e0f1 100644 --- a/json2mo/for_indicesParser.js +++ b/json2mo/for_indicesParser.js @@ -1,24 +1,34 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const expressionParser = require('./expressionParser'); - // const for_indexParser = require('./for_indexParser'); //only for raw-json + const for_indexParser = require('./for_indexParser'); //only for raw-json var moOutput = ""; - var indices = content; //if raw-json, then use content.indices - if (indices!=null) { - indices.forEach(index => { - if (index.identifier != null) { - moOutput+=util.format("%s ",index.identifier); - } - if (index.expression != null) { - moOutput+="in " - moOutput+=expressionParser.parse(index.expression); - } - moOutput+=","; - }); - moOutput=moOutput.slice(0, -1); - } - + if (rawJson) { + var indices = content.indices + if (indices != null) { + indices.forEach(for_index => { + moOutput+=for_indexParser.parse(for_index, rawJson); + moOutput+=","; + }); + moOutput = moOutput.slice(0, -1); + } + } else { + var indices = content; + if (indices!=null) { + indices.forEach(index => { + if (index.identifier != null) { + moOutput+=util.format("%s ",index.identifier); + } + if (index.expression != null) { + moOutput+="in " + moOutput+=expressionParser.parse(index.expression, rawJson); + } + moOutput+=","; + }); + moOutput=moOutput.slice(0, -1); + } + } return moOutput; } diff --git a/json2mo/for_statementParser.js b/json2mo/for_statementParser.js index bf5aebd5..13973205 100644 --- a/json2mo/for_statementParser.js +++ b/json2mo/for_statementParser.js @@ -1,17 +1,17 @@ -function parse(content) { +function parse(content, rawJson=false) { const for_indicesParser = require('./for_indicesParser'); const statementParser = require('./statementParser'); var moOutput = ""; moOutput+="for " if (content.for_indices != null) { - moOutput+=for_indicesParser.parse(content.for_indices); + moOutput+=for_indicesParser.parse(content.for_indices, rawJson); } moOutput+="loop \n" loop_statements = content.loop_statements loop_statements.forEach(loop_statement => { - moOutput+=statementParser.parse(loop_statement); + moOutput+=statementParser.parse(loop_statement, rawJson); moOutput+=';\n'; }); moOutput+="end for"; diff --git a/json2mo/import_clauseParser.js b/json2mo/import_clauseParser.js index 336e9a36..91602e46 100644 --- a/json2mo/import_clauseParser.js +++ b/json2mo/import_clauseParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const nameParser = require('./nameParser'); const commentParser = require('./commentParser'); @@ -9,7 +9,7 @@ function parse(content) { var name=""; if (content.name != null) { - name = nameParser.parse(content.name); + name = nameParser.parse(content.name, rawJson); } if (content.identifier != null) { @@ -19,14 +19,25 @@ function parse(content) { moOutput=util.format("%s", name) + ".* "; } } else if (content.import_list != null) { - moOutput+=util.format("%s", name)+".{"+import_listParser.parse(content.import_list)+"} " + if (rawJson) { + moOutput+=util.format("%s", name)+".{"+import_listParser.parse(content.import_list, rawJson)+"} "; + } else { + moOutput+=util.format("%s", name)+util.format(".{%s} ", content.import_list); + } } else { moOutput+=util.format("%s ", name); } - if (content.comment != null) { - moOutput+=commentParser.parse(content.comment); + if (description) { + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment); + } + } else { + if (content.description != null) { + moOutput+=commentParser.parse(content.description); + } } + return moOutput; } module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/import_listParser.js b/json2mo/import_listParser.js index de043273..90741bf4 100644 --- a/json2mo/import_listParser.js +++ b/json2mo/import_listParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); var moOutput = ""; diff --git a/json2mo/long_class_specifierParser.js b/json2mo/long_class_specifierParser.js index a66670f5..abaea443 100644 --- a/json2mo/long_class_specifierParser.js +++ b/json2mo/long_class_specifierParser.js @@ -1,11 +1,9 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const compositionParser = require('./compositionParser'); const class_modificationParser = require('./class_modificationParser'); var identifier = content.identifier; - //TODO: change this - var string_comment = content.string_comment; var is_extends = content.is_extends; var moOutput = ""; @@ -23,17 +21,25 @@ function parse(content) { if (is_extends != null) { if (is_extends) { if (content.class_modification != null) { - moOutput+= class_modificationParser.parse(content.class_modification); + moOutput+= class_modificationParser.parse(content.class_modification, rawJson); } } } - if (string_comment != null) { - moOutput+=util.format("\n%s\n", string_comment); + if (rawJson) { + var string_comment = content.string_comment; + if (string_comment != null) { + moOutput+=util.format("\n%s\n", string_comment); + } + } else { + var description_string = content.description_string; + if (description_string != null) { + moOutput+=util.format("\n%s\n", description_string); + } } if (content.composition!=null) { - moOutput+=compositionParser.parse(content.composition); + moOutput+=compositionParser.parse(content.composition, rawJson); } moOutput+=util.format("end %s;", identifier); diff --git a/json2mo/modificationParser.js b/json2mo/modificationParser.js index 104abfe0..88a3c4cf 100644 --- a/json2mo/modificationParser.js +++ b/json2mo/modificationParser.js @@ -1,10 +1,10 @@ -function parse(content) { +function parse(content, rawJson=false) { const class_modificationParser = require('./class_modificationParser'); const expressionParser = require('./expressionParser'); var moOutput = ""; - + if (content.class_modification != null) { - moOutput+=class_modificationParser.parse(content.class_modification); + moOutput+=class_modificationParser.parse(content.class_modification, rawJson); } if (content.equal != null) { @@ -17,7 +17,7 @@ function parse(content) { } } if (content.expression != null) { - moOutput+=expressionParser.parse(content.expression); + moOutput+=expressionParser.parse(content.expression, rawJson); } return moOutput; } diff --git a/json2mo/nameParser.js b/json2mo/nameParser.js index 36d462f9..4e26d602 100644 --- a/json2mo/nameParser.js +++ b/json2mo/nameParser.js @@ -1,8 +1,18 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); + const name_partParser = require('./name_partParser'); var moOutput = ""; - moOutput+=util.format("%s ", content); + if (rawJson) { + var name_parts = content.name_parts; + if (name_parts != null) { + name_parts.forEach(name_part => { + moOutput+=name_partParser.parse(name_part, rawJson); + }); + } + } else { + moOutput+=util.format("%s ", content); + } return moOutput; } diff --git a/json2mo/name_partParser.js b/json2mo/name_partParser.js new file mode 100644 index 00000000..866dba1e --- /dev/null +++ b/json2mo/name_partParser.js @@ -0,0 +1,19 @@ +function parse(content, rawJson=false) { + const util = require('util'); + + var moOutput = ""; + if (rawJson) { + if (content.dot_op != null) { + if (content.dot_op) { + moOutput+="." + } + } + + if (content.identifier != null) { + moOutput+=content.identifier; + } + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/short_class_specifierParser.js b/json2mo/short_class_specifierParser.js index aab29efa..bf837537 100644 --- a/json2mo/short_class_specifierParser.js +++ b/json2mo/short_class_specifierParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const short_class_specifier_valueParser = require('./short_class_specifier_valueParser'); @@ -9,7 +9,7 @@ function parse(content) { moOutput+=util.format("%s= ", identifier); } - moOutput+=short_class_specifier_valueParser.parse(content.short_class_specifier_value); + moOutput+=short_class_specifier_valueParser.parse(content.short_class_specifier_value, rawJson); return moOutput; } diff --git a/json2mo/short_class_specifier_valueParser.js b/json2mo/short_class_specifier_valueParser.js index d61da7c5..ffae3ec3 100644 --- a/json2mo/short_class_specifier_valueParser.js +++ b/json2mo/short_class_specifier_valueParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const base_prefixParser = require('./base_prefixParser'); const nameParser = require('./nameParser'); const array_subscriptsParser = require('./array_subscriptsParser'); @@ -11,26 +11,33 @@ function parse(content) { if (content.base_prefix == null) { moOutput+="enumeration ("; if (content.enum_list != null) { - moOutput+=enum_listParser.parse(content.enum_list) + moOutput+=enum_listParser.parse(content.enum_list, rawJson) } else { moOutput+=":" } moOutput+=") " } else { - moOutput+=base_prefixParser.parse(content.base_prefix); + moOutput+=base_prefixParser.parse(content.base_prefix, rawJson); if (content.name != null) { - moOutput+=nameParser.parse(content.name); + moOutput+=nameParser.parse(content.name, rawJson); } if (content.array_subscripts != null) { - moOutput+=array_subscriptsParser.parse(content.array_subscripts); + moOutput+=array_subscriptsParser.parse(content.array_subscripts, rawJson); } if(content.class_modification != null) { - moOutput+=class_modificationParser.parse(content.class_modification); + moOutput+=class_modificationParser.parse(content.class_modification, rawJson); } } - if (content.comment != null) { - moOutput+=commentParser.parse(content.comment); + if (rawJson) { + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment, rawJson); + } + } else { + if (content.description != null) { + moOutput+=commentParser.parse(content.description, rawJson); + } } + return moOutput; } diff --git a/json2mo/simple_expressionParser.js b/json2mo/simple_expressionParser.js index 563753e5..e46d380e 100644 --- a/json2mo/simple_expressionParser.js +++ b/json2mo/simple_expressionParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); var moOutput = ""; diff --git a/json2mo/statementParser.js b/json2mo/statementParser.js index 045f028d..d35a223b 100644 --- a/json2mo/statementParser.js +++ b/json2mo/statementParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson) { const util = require('util'); const assignment_statementParser = require('./assignment_statementParser'); const function_call_statementParser = require('./function_call_statementParser'); @@ -11,11 +11,11 @@ function parse(content) { var moOutput = ""; if (content.assignment_statement != null) { - moOutput+=assignment_statementParser.parse(content.assignment_statement); + moOutput+=assignment_statementParser.parse(content.assignment_statement, rawJson); } else if (content.function_call_statement != null) { - moOutput+=function_call_statementParser.parse(content.function_call_statement); + moOutput+=function_call_statementParser.parse(content.function_call_statement, rawJson); } else if (content.assignment_with_function_call_statement != null) { - moOutput+=assignment_with_function_call_statementParser.parse(content.assignment_with_function_call_statement); + moOutput+=assignment_with_function_call_statementParser.parse(content.assignment_with_function_call_statement, rawJson); } else if (content.is_break != null) { if (content.is_break) { moOutput+="break\n"; @@ -25,19 +25,24 @@ function parse(content) { moOutput+="return\n"; } } else if (content.if_statement != null) { - moOutput+=if_statementParser.parse(content.if_statement); + moOutput+=if_statementParser.parse(content.if_statement, rawJson); } else if (content.for_statement != null) { - moOutput+=for_statementParser.parse(content.for_statement); + moOutput+=for_statementParser.parse(content.for_statement, rawJson); } else if (content.while_statement != null) { - moOutput+=while_statementParser.parse(content.while_statement); + moOutput+=while_statementParser.parse(content.while_statement, rawJson); } else if (content.when_statement != null) { - moOutput+=when_statementParser.parse(content.when_statement); + moOutput+=when_statementParser.parse(content.when_statement, rawJson); } - if (content.comment != null) { - moOutput+=commentParser.parse(content.comment); + if (rawJson) { + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment, rawJson); + } + } else { + if (content.description != null) { + moOutput+=commentParser.parse(content.description, rawJson) + } } - return moOutput; } diff --git a/json2mo/stored_definitonParser.js b/json2mo/stored_definitonParser.js index 9571f170..5114dadb 100644 --- a/json2mo/stored_definitonParser.js +++ b/json2mo/stored_definitonParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const final_class_definitionParser = require('./final_class_definitionParser'); @@ -9,11 +9,20 @@ function parse(content) { moOutput+=util.format("within %s;\n", within) } - if (content.final_class_definitions != null) { - content.final_class_definitions.forEach(final_class_definition => { - moOutput+=final_class_definitionParser.parse(final_class_definition); - moOutput+="\n"; - }); + if (rawJson) { + if (content.final_class_definitions != null) { + content.final_class_definitions.forEach(final_class_definition => { + moOutput+=final_class_definitionParser.parse(final_class_definition, rawJson); + moOutput+="\n"; + }); + } + } else { + if (content.class_definition != null) { + content.class_definition.forEach(final_class_definition => { + moOutput+=final_class_definitionParser.parse(final_class_definition, rawJson); + moOutput+="\n"; + }); + } } return moOutput; } diff --git a/json2mo/subscriptParser.js b/json2mo/subscriptParser.js new file mode 100644 index 00000000..19962efe --- /dev/null +++ b/json2mo/subscriptParser.js @@ -0,0 +1,18 @@ +function parse(content, rawJson=false) { + const expressionParser = require('./expressionParser'); + + var moOutput = ""; + + if (rawJson) { + moOutput+="[" + + if (content.colon_op != null) { + moOutput+=":"; + } else if (content.expression != null) { + moOutput+=expressionParser.parser(array_subscript.expression, rawJson); + } + } + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/type_specifierParser.js b/json2mo/type_specifierParser.js index 6c9527af..255e9687 100644 --- a/json2mo/type_specifierParser.js +++ b/json2mo/type_specifierParser.js @@ -1,11 +1,17 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const nameParser = require('./nameParser'); var moOutput = ""; - if (content.name != null) { - moOutput+=nameParser.parse(content.name); + if (rawJson) { + if (content.name != null) { + moOutput+=nameParser.parse(content.name, rawJson); + } + } else { + var name = content; + moOutput+=util.format("%s ", name); } + return moOutput; } From 145991c740486a7c222a46d6805d48a1b01e8348 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Fri, 5 Nov 2021 09:42:09 -0700 Subject: [PATCH 15/29] updating starting script --- j2m.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/j2m.js b/j2m.js index 5a84156f..b46fa4eb 100644 --- a/j2m.js +++ b/j2m.js @@ -2,14 +2,19 @@ const path = require('path'); const fs = require('fs'); const stored_definitonParser = require('./json2mo/stored_definitonParser'); -function convertToModeica(jsonFile) { +function convertToModelica(jsonFile, rawJson=false) { var fileContent = fs.readFileSync(jsonFile, 'utf8'); //TODO: the [0] should change with the new simplified json - var jsonOutput = JSON.parse(fileContent)[0]; - - moOutput = stored_definitonParser.parse(jsonOutput); + var jsonOutput; + if (rawJson) { + jsonOutput = JSON.parse(fileContent)[0]; + } else { + jsonOutput = JSON.parse(fileContent); + } + moOutput = stored_definitonParser.parse(jsonOutput, rawJson); return moOutput; } // console.log(convertToModeica('raw-json/FromModelica.ExtendsClause_1.json')); -console.log(convertToModeica('raw-json/FromModelica.Modulation.json')); \ No newline at end of file +// console.log(convertToModelica('raw-json/FromModelica.Modulation.json', rawJson=true)); +console.log(convertToModelica('json/Modulation.json', rawJson=false)); \ No newline at end of file From d4bd10ddd4fe3053d98140ea44f76c6d95ae2dec Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Fri, 5 Nov 2021 09:43:20 -0700 Subject: [PATCH 16/29] replacing empty elements with null --- .../java/gov/lbl/parser/parser/EquationVisitor.java | 10 ++++++++-- .../java/gov/lbl/parser/parser/StatementVisitor.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/EquationVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/EquationVisitor.java index 449ad8f5..d0e25055 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/EquationVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/EquationVisitor.java @@ -25,7 +25,10 @@ public Equation visitEquation(modelicaParser.EquationContext ctx) { ExpressionVisitor expressionVisitor = new ExpressionVisitor(); Expression rhs = ctx.expression() == null ? null : ctx.expression().accept(expressionVisitor); - Assignment_equation assignment_equation = new Assignment_equation(lhs, rhs); + Assignment_equation assignment_equation = null; + if (lhs != null && rhs != null) { + assignment_equation = new Assignment_equation(lhs, rhs); + } If_equationVisitor if_equationVisitor = new If_equationVisitor(); If_equation if_equation = ctx.if_equation() == null ? null : ctx.if_equation().accept(if_equationVisitor); @@ -45,7 +48,10 @@ public Equation visitEquation(modelicaParser.EquationContext ctx) { Function_call_argsVisitor function_call_argsVisitor = new Function_call_argsVisitor(); Function_call_args function_call_args = ctx.function_call_args() == null ? null : ctx.function_call_args().accept(function_call_argsVisitor); - Function_call_equation function_call_equation = new Function_call_equation(function_name, function_call_args); + Function_call_equation function_call_equation = null; + if (function_name != null && function_call_args != null) { + function_call_equation = new Function_call_equation(function_name, function_call_args); + } CommentVisitor commentVisitor = new CommentVisitor(); Comment comment = ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/StatementVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/StatementVisitor.java index f8b86b94..85660b1c 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/StatementVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/StatementVisitor.java @@ -60,7 +60,7 @@ else if (component_reference != null && function_call_args != null) { When_statement when_statement = ctx.when_statement() == null ? null : ctx.when_statement().accept(when_statementVisitor); CommentVisitor commentVisitor = new CommentVisitor(); - Comment comment = ctx.comment().accept(commentVisitor); + Comment comment = ctx.comment() == null ? null : ctx.comment().accept(commentVisitor); return new Statement(assignment_statement, function_call_statement, assignment_with_function_call_statement, is_break, is_return, if_statement, for_statement, while_statement, when_statement, comment); } From 0137a44961bfb359dd0f26ca6884c1ce6559e780 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Mon, 8 Nov 2021 10:15:38 -0800 Subject: [PATCH 17/29] updating j2m parsers --- json2mo/commentParser.js | 2 -- json2mo/compositionParser.js | 1 + json2mo/equation_sectionParser.js | 7 ++++++- json2mo/nameParser.js | 1 + json2mo/simple_expressionParser.js | 1 - 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/json2mo/commentParser.js b/json2mo/commentParser.js index 332776f1..7ce79548 100644 --- a/json2mo/commentParser.js +++ b/json2mo/commentParser.js @@ -10,7 +10,6 @@ function parse(content, rawJson=false) { if (content.annotation != null) { moOutput+=annotationParser.parse(content.annotation, rawJson); } - moOutput+="\n"; } else { if (content.description_string != null) { moOutput+=util.format("%s ", content.description_string); @@ -18,7 +17,6 @@ function parse(content, rawJson=false) { if (content.annotation != null) { moOutput+=annotationParser.parse(content.annotation, rawJson); } - moOutput+="\n"; } return moOutput; diff --git a/json2mo/compositionParser.js b/json2mo/compositionParser.js index 6d705089..1b6e4d08 100644 --- a/json2mo/compositionParser.js +++ b/json2mo/compositionParser.js @@ -19,6 +19,7 @@ function parse(content, rawJson=false) { } if (content.annotation != null) { moOutput+=annotationParser.parse(content.annotation, rawJson); + moOutput+="\n"; } return moOutput; } diff --git a/json2mo/equation_sectionParser.js b/json2mo/equation_sectionParser.js index 88168960..899d7d1f 100644 --- a/json2mo/equation_sectionParser.js +++ b/json2mo/equation_sectionParser.js @@ -9,7 +9,12 @@ function parse(content, rawJson=false) { } } moOutput+="equation \n" - var equations = content.equations; + var equations; + if (rawJson) { + equations = content.equations; + } else { + equations = content.equation; + } if (equations != null) { equations.forEach(equation => { moOutput+=equationParser.parse(equation, rawJson); diff --git a/json2mo/nameParser.js b/json2mo/nameParser.js index 4e26d602..575dfd43 100644 --- a/json2mo/nameParser.js +++ b/json2mo/nameParser.js @@ -10,6 +10,7 @@ function parse(content, rawJson=false) { moOutput+=name_partParser.parse(name_part, rawJson); }); } + moOutput+=" "; } else { moOutput+=util.format("%s ", content); } diff --git a/json2mo/simple_expressionParser.js b/json2mo/simple_expressionParser.js index e46d380e..1bf231fe 100644 --- a/json2mo/simple_expressionParser.js +++ b/json2mo/simple_expressionParser.js @@ -1,6 +1,5 @@ function parse(content, rawJson=false) { const util = require('util'); - var moOutput = ""; if (content!=null) { moOutput+=util.format("%s ", JSON.stringify(content)); From 29a36250a2b09dcd8915bb7bee1c2525e833a84c Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Mon, 8 Nov 2021 10:22:25 -0800 Subject: [PATCH 18/29] fixing error in checksum generation script --- lib/check_checksum.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/check_checksum.js b/lib/check_checksum.js index d7399b43..0a14ecd2 100644 --- a/lib/check_checksum.js +++ b/lib/check_checksum.js @@ -25,7 +25,7 @@ function check_if_json_exists(mo_file_path, raw_json=false, output_dir=null) { } function get_checksum_from_json(json_file_path) { - var checksum_from_json; + var checksum_from_json = null; try { var file_content = fs.readFileSync(json_file_path, 'utf8'); var json_output = JSON.parse(file_content); @@ -66,6 +66,7 @@ async function main(mo_file_path, raw_json=false) { file_exists = output[0] + var checksum_from_json; if (file_exists) { json_file_path = output[1] var output = get_checksum_from_json(json_file_path=json_file_path); @@ -79,15 +80,19 @@ async function main(mo_file_path, raw_json=false) { let res = await get_mo_checksum(mo_file_path) - if (res == checksum_from_json) { - console.log("true") + if (checksum_from_json != null) { + if (res == checksum_from_json) { + console.log("true") + } else { + console.log("different checksum") + } } else { - console.log("different checksum") + console.log("different checksum"); } + return res } - -var mo_file_path = 'test/FromModelica/Parameter1.mo'; +var mo_file_path = '../test/FromModelica/Parameter1.mo'; main(mo_file_path) \ No newline at end of file From ce0e9c3baaaf8477ef92aaa074ab5af3bbc69343 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Tue, 9 Nov 2021 10:57:01 -0800 Subject: [PATCH 19/29] fixing some errors in the component_reference visitor --- .../domain/Component_reference_part.java | 24 ++++++ .../parser/Component_referenceVisitor.java | 83 +++++++++---------- .../lbl/parser/parser/CompositionVisitor.java | 4 - 3 files changed, 64 insertions(+), 47 deletions(-) diff --git a/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference_part.java b/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference_part.java index fb0ab41c..ee0feb32 100644 --- a/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference_part.java +++ b/java/parser/src/main/java/gov/lbl/parser/domain/Component_reference_part.java @@ -10,4 +10,28 @@ public Component_reference_part(Boolean dot_op, String identifier, Array_subscri this.identifier = identifier; this.array_subscripts = array_subscripts; } + + public Boolean get_dot_op() { + return this.dot_op; + } + + public String get_identifier() { + return this.identifier; + } + + public Array_subscripts get_array_subscripts() { + return this.array_subscripts; + } + + public void set_dot_op(Boolean dot_op) { + this.dot_op = dot_op; + } + + public void set_identifier(String identifier) { + this.identifier = identifier; + } + + public void set_array_subscripts(Array_subscripts array_subscripts) { + this.array_subscripts = array_subscripts; + } } diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Component_referenceVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Component_referenceVisitor.java index b757fa3b..aa864c90 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Component_referenceVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Component_referenceVisitor.java @@ -6,63 +6,60 @@ import gov.lbl.parser.domain.Component_reference; import gov.lbl.parser.domain.Component_reference_part; -import static java.util.stream.Collectors.toList; - import java.util.ArrayList; import java.util.List; +import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.TerminalNode; + public class Component_referenceVisitor extends modelicaBaseVisitor { @Override public Component_reference visitComponent_reference(modelicaParser.Component_referenceContext ctx) { - List identifiers = ctx.IDENT() == null ? null : ctx.IDENT() - .stream() - .map(identifier -> identifier.getText()) - .collect(toList()); Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); - List array_subscripts_list = ctx.array_subscripts() == null ? null : ctx.array_subscripts() - .stream() - .map(array_subscripts -> array_subscripts.accept(array_subscriptsVisitor)) - .collect(toList()); - List array_subscripts_exists = new ArrayList<>(); - Boolean first_dot = false; - String context_str = ctx.getText(); - if (ctx.getText().charAt(0) == '.') { - first_dot = true; - context_str = context_str.substring(1); - } + List component_reference_parts = new ArrayList(); - String[] comp_refs = context_str.split("\\."); - for (int i=0; i children = ctx.children; + Boolean dot_op = false; + Component_reference_part component_reference_part = null; + for (ParseTree o : children) { + if (o instanceof TerminalNode) { + if (o.getText().equals(".")) { + if (component_reference_part == null) { + component_reference_part = new Component_reference_part(null, null, null); + } else if (component_reference_part.get_identifier() != null) { + component_reference_parts.add(component_reference_part); + component_reference_part = new Component_reference_part(null, null, null); + } + dot_op = true; + component_reference_part.set_dot_op(dot_op); + } else { + if (component_reference_part == null) { + component_reference_part = new Component_reference_part(null, null, null); + dot_op = false; + } else { + component_reference_parts.add(component_reference_part); + component_reference_part = new Component_reference_part(null, null, null); + dot_op = false; + } + component_reference_part.set_dot_op(dot_op); + component_reference_part.set_identifier(o.getText()); + } } - else { - array_subscripts_exists.add(false); + else if (o instanceof modelicaParser.Array_subscriptsContext) { + if (component_reference_part == null) { + component_reference_part = new Component_reference_part(null, null, null); + component_reference_part.set_dot_op(false); + component_reference_part.set_identifier(""); + } + Array_subscripts array_subscripts = o.accept(array_subscriptsVisitor); + component_reference_part.set_array_subscripts(array_subscripts); } } - - List component_reference_parts = new ArrayList(); - int array_sbuscript_index = 0; - for(int i=0;i0 && comp_refs.length > 1) { - dot_op = true; - } - - Array_subscripts array_subscripts = null; - if (array_subscripts_exists.get(i)) { - array_subscripts = array_subscripts_list.get(array_sbuscript_index); - array_sbuscript_index+=1; - } - component_reference_parts.add(new Component_reference_part(dot_op, identifier, array_subscripts)); + if (component_reference_part != null) { + component_reference_parts.add(component_reference_part); } return new Component_reference(component_reference_parts); } diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java index 3ca98f57..d1068ed5 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/CompositionVisitor.java @@ -2,7 +2,6 @@ import java.util.List; -import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.TerminalNode; @@ -11,10 +10,8 @@ import gov.lbl.parser.domain.Algorithm_section; import gov.lbl.parser.domain.Annotation; import gov.lbl.parser.domain.Composition; -import gov.lbl.parser.domain.Element; import gov.lbl.parser.domain.Element_list; import gov.lbl.parser.domain.Element_section; -import gov.lbl.parser.domain.Equation; import gov.lbl.parser.domain.Equation_section; import gov.lbl.parser.domain.External_composition; import gov.lbl.parser.domain.External_function_call; @@ -31,7 +28,6 @@ public Composition visitComposition(modelicaParser.CompositionContext ctx) { Element_listVisitor element_listVisitor = new Element_listVisitor(); Equation_sectionVisitor equation_sectionVisitor = new Equation_sectionVisitor(); - EquationVisitor equationVisitor = new EquationVisitor(); Algorithm_sectionVisitor algorithm_sectionVisitor = new Algorithm_sectionVisitor(); List children = ctx.children; From 9b859f909a1257dcd3baee0efb9fe3f63c440abf Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Wed, 10 Nov 2021 08:14:13 -0800 Subject: [PATCH 20/29] removing quotes and fixing spacing in mo file --- json2mo/annotationParser.js | 4 ++-- json2mo/argument_listParser.js | 2 +- json2mo/array_subscriptsParser.js | 2 +- json2mo/commentParser.js | 5 +++-- json2mo/component_clause1Parser.js | 2 +- json2mo/simple_expressionParser.js | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/json2mo/annotationParser.js b/json2mo/annotationParser.js index fa750d3f..da092ef2 100644 --- a/json2mo/annotationParser.js +++ b/json2mo/annotationParser.js @@ -3,7 +3,7 @@ function parse(content, rawJson=false) { const class_modificationParser = require('./class_modificationParser'); var moOutput = ""; - moOutput+="annotation "; + moOutput+="\tannotation "; if (rawJson) { if (content.class_modification != null) { moOutput+=class_modificationParser.parse(content.class_modification, rawJson); @@ -12,7 +12,7 @@ function parse(content, rawJson=false) { var class_modification = content; moOutput+=class_modificationParser.parse(class_modification, rawJson); } - + moOutput+="\n" return moOutput; } diff --git a/json2mo/argument_listParser.js b/json2mo/argument_listParser.js index 4ac8b7aa..a45e1934 100644 --- a/json2mo/argument_listParser.js +++ b/json2mo/argument_listParser.js @@ -8,7 +8,7 @@ function parse(content, rawJson=false) { if (arguments != null) { arguments.forEach(argument => { moOutput+=argumentParser.parse(argument, rawJson); - moOutput+=", "; + moOutput+=","; }); moOutput = moOutput.slice(0, -2); } diff --git a/json2mo/array_subscriptsParser.js b/json2mo/array_subscriptsParser.js index 52aebb41..8f37c541 100644 --- a/json2mo/array_subscriptsParser.js +++ b/json2mo/array_subscriptsParser.js @@ -10,7 +10,7 @@ function parse(content, rawJson=false) { if (subscripts != null) { subscripts.forEach(subscript => { moOutput+=subscriptParser.parse(subscript, rawJson); - moOutput+=", " + moOutput+="," }); moOutput = moOutput.slice(0, -2); } diff --git a/json2mo/commentParser.js b/json2mo/commentParser.js index 7ce79548..082986e8 100644 --- a/json2mo/commentParser.js +++ b/json2mo/commentParser.js @@ -3,16 +3,17 @@ function parse(content, rawJson=false) { const annotationParser = require('./annotationParser'); var moOutput = ""; + moOutput+="\n\t" if (rawJson) { if (content.string_comment != null) { - moOutput+=util.format("%s ", content.string_comment); + moOutput+=util.format("\"%s\"", content.string_comment); } if (content.annotation != null) { moOutput+=annotationParser.parse(content.annotation, rawJson); } } else { if (content.description_string != null) { - moOutput+=util.format("%s ", content.description_string); + moOutput+=util.format("\"%s\"\n", content.description_string); } if (content.annotation != null) { moOutput+=annotationParser.parse(content.annotation, rawJson); diff --git a/json2mo/component_clause1Parser.js b/json2mo/component_clause1Parser.js index 96f43eea..6db640ac 100644 --- a/json2mo/component_clause1Parser.js +++ b/json2mo/component_clause1Parser.js @@ -5,7 +5,7 @@ function parse(content, rawJson=false) { var moOutput = ""; if (content.type_prefix != null) { - moOutput+=util.format("%s ", content.type_prefix, rawJson); + moOutput+=util.format("%s", content.type_prefix, rawJson); } if (content.type_specifier != null) { moOutput+=type_specifierParser.parse(content.type_specifier, rawJson); diff --git a/json2mo/simple_expressionParser.js b/json2mo/simple_expressionParser.js index 1bf231fe..1ec7167b 100644 --- a/json2mo/simple_expressionParser.js +++ b/json2mo/simple_expressionParser.js @@ -2,7 +2,7 @@ function parse(content, rawJson=false) { const util = require('util'); var moOutput = ""; if (content!=null) { - moOutput+=util.format("%s ", JSON.stringify(content)); + moOutput+=util.format("%s ", content); } return moOutput; } From f82c92ccdada7c4d28fcb36acd20e66f410f0bd9 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Wed, 10 Nov 2021 08:17:20 -0800 Subject: [PATCH 21/29] handling null name --- .../gov/lbl/parser/parser/Short_class_specifierVisitor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_specifierVisitor.java b/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_specifierVisitor.java index c0610642..f954543d 100644 --- a/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_specifierVisitor.java +++ b/java/parser/src/main/java/gov/lbl/parser/parser/Short_class_specifierVisitor.java @@ -21,7 +21,7 @@ public Short_class_specifier visitShort_class_specifier(modelicaParser.Short_cla Array_subscriptsVisitor array_subscriptsVisitor = new Array_subscriptsVisitor(); Array_subscripts array_subscripts = ctx.array_subscripts() == null ? null : ctx.array_subscripts().accept(array_subscriptsVisitor); NameVisitor nameVisitor = new NameVisitor(); - Name name = ctx.name().accept(nameVisitor); + Name name = ctx.name() == null ? null : ctx.name().accept(nameVisitor); Class_modificationVisitor class_modificationVisitor = new Class_modificationVisitor(); Class_modification class_modification = ctx.class_modification() == null ? null : ctx.class_modification().accept(class_modificationVisitor); CommentVisitor commentVisitor = new CommentVisitor(); From 7ba3a6c45db0519a8af1cbaf971e03a772dfaf37 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Wed, 10 Nov 2021 16:53:23 -0800 Subject: [PATCH 22/29] adding rawjson/sim-json flags to all translators --- j2m.js | 2 +- json2mo/algorithm_sectionParser.js | 8 ++- json2mo/assignment_equationParser.js | 6 +-- json2mo/assignment_statementParser.js | 6 +-- ...ment_with_function_call_statementParser.js | 8 +-- json2mo/base_prefixParser.js | 14 +++-- json2mo/commentParser.js | 6 +-- json2mo/component_clause1Parser.js | 30 ++++++++--- json2mo/component_clauseParser.js | 11 +++- json2mo/component_declaration1Parser.js | 13 ++++- json2mo/component_referenceParser.js | 20 ++++--- json2mo/connect_clauseParser.js | 2 +- json2mo/constraining_clauseParser.js | 1 - json2mo/der_class_specifierParser.js | 14 +++-- json2mo/der_class_specifier_valueParser.js | 8 ++- json2mo/elementParser.js | 26 +++++++-- json2mo/element_modificationParser.js | 1 + json2mo/enum_listParser.js | 16 ++++-- json2mo/enumeration_literalParser.js | 13 +++-- json2mo/equation_sectionParser.js | 1 + json2mo/expressionParser.js | 2 +- json2mo/expression_listParser.js | 7 ++- json2mo/external_function_callParser.js | 4 +- json2mo/for_equationParser.js | 2 + json2mo/function_argumentParser.js | 26 +++++---- json2mo/function_argumentsParser.js | 54 ++++++++++++------- json2mo/function_call_argsParser.js | 42 +++++++++------ json2mo/function_call_equationParser.js | 6 +-- json2mo/function_call_statementParser.js | 6 +-- json2mo/if_elseif_equationParser.js | 6 +-- json2mo/if_elseif_expressionParser.js | 6 +-- json2mo/if_elseif_statementParser.js | 6 +-- json2mo/if_equationParser.js | 6 +-- json2mo/if_expressionParser.js | 6 +-- json2mo/if_statementParser.js | 6 +-- json2mo/import_clauseParser.js | 6 +-- json2mo/modificationParser.js | 4 +- json2mo/named_argumentParser.js | 6 +-- json2mo/named_argumentsParser.js | 19 +++++++ json2mo/output_expression_listParser.js | 20 ++++--- json2mo/short_class_definitionParser.js | 4 +- json2mo/short_class_specifierParser.js | 12 ++++- json2mo/simple_expressionParser.js | 6 ++- json2mo/statementParser.js | 1 - json2mo/when_equationParser.js | 13 +++-- json2mo/when_statementParser.js | 13 +++-- json2mo/while_statementParser.js | 6 +-- 47 files changed, 336 insertions(+), 165 deletions(-) create mode 100644 json2mo/named_argumentsParser.js diff --git a/j2m.js b/j2m.js index b46fa4eb..7f5e45fd 100644 --- a/j2m.js +++ b/j2m.js @@ -17,4 +17,4 @@ function convertToModelica(jsonFile, rawJson=false) { // console.log(convertToModeica('raw-json/FromModelica.ExtendsClause_1.json')); // console.log(convertToModelica('raw-json/FromModelica.Modulation.json', rawJson=true)); -console.log(convertToModelica('json/Modulation.json', rawJson=false)); \ No newline at end of file +console.log(convertToModelica('json/Modulation_2.json', rawJson=false)); \ No newline at end of file diff --git a/json2mo/algorithm_sectionParser.js b/json2mo/algorithm_sectionParser.js index fc71e8ed..97544279 100644 --- a/json2mo/algorithm_sectionParser.js +++ b/json2mo/algorithm_sectionParser.js @@ -8,7 +8,13 @@ function parse(content, rawJson=false) { } } moOutput+="algorithm \n" - var statements = content.statements; + var statements = null; + if (rawJson) { + statements = content.statements; + } else { + statements = content.statement; + } + if (statements != null) { statements.forEach(statement => { moOutput+=statementParser.parse(statement, rawJson); diff --git a/json2mo/assignment_equationParser.js b/json2mo/assignment_equationParser.js index 017a7287..b243731f 100644 --- a/json2mo/assignment_equationParser.js +++ b/json2mo/assignment_equationParser.js @@ -1,14 +1,14 @@ -function parse(content) { +function parse(content, rawJson=false) { const simple_expressionParser = require('./simple_expressionParser'); const expressionParser = require('./expressionParser'); var moOutput = ""; if (content.lhs != null) { - moOutput+=simple_expressionParser.parse(content.lhs) + moOutput+=simple_expressionParser.parse(content.lhs, rawJson); } moOutput+="=" if (content.rhs != null) { - moOutput+=expressionParser.parse(content.rhs) + moOutput+=expressionParser.parse(content.rhs, rawJson); } return moOutput; } diff --git a/json2mo/assignment_statementParser.js b/json2mo/assignment_statementParser.js index 504db228..d3dc0f80 100644 --- a/json2mo/assignment_statementParser.js +++ b/json2mo/assignment_statementParser.js @@ -1,14 +1,14 @@ -function parse(content) { +function parse(content, rawJson=false) { const component_referenceParser = require('./component_referenceParser'); const expressionParser = require('./expressionParser'); var moOutput = ""; if (content.identifier != null) { - moOutput+=component_referenceParser.parse(content.identifier) + moOutput+=component_referenceParser.parse(content.identifier, rawJson) } moOutput+=":=" if (content.value != null) { - moOutput+=expressionParser.parse(content.value) + moOutput+=expressionParser.parse(content.value, rawJson) } return moOutput; } diff --git a/json2mo/assignment_with_function_call_statementParser.js b/json2mo/assignment_with_function_call_statementParser.js index 011b02b9..63262494 100644 --- a/json2mo/assignment_with_function_call_statementParser.js +++ b/json2mo/assignment_with_function_call_statementParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const component_referenceParser = require('./component_referenceParser'); const output_expression_listParser = require('./output_expression_listParser'); const function_call_argsParser = require('./function_call_argsParser'); @@ -6,15 +6,15 @@ function parse(content) { var moOutput = ""; moOutput+="("; if (content.output_expression_list != null) { - moOutput+=output_expression_listParser.parse(content.output_expression_list); + moOutput+=output_expression_listParser.parse(content.output_expression_list, rawJson); } moOutput+=")"; moOutput+=":="; if (content.function_name != null) { - moOutput+=component_referenceParser.parse(content.function_name); + moOutput+=component_referenceParser.parse(content.function_name, rawJson); } if (content.function_call_args != null) { - moOutput+=function_call_argsParser.parse(content.function_call_args); + moOutput+=function_call_argsParser.parse(content.function_call_args, rawJson); } return moOutput; } diff --git a/json2mo/base_prefixParser.js b/json2mo/base_prefixParser.js index 6975dfcb..ce873be5 100644 --- a/json2mo/base_prefixParser.js +++ b/json2mo/base_prefixParser.js @@ -1,9 +1,17 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); var moOutput = ""; - if (content.type_prefix != null) { - moOutput+=util.format("%s ", content.type_prefix); + if (rawJson) { + if (content.type_prefix != null) { + moOutput+=util.format("%s ", content.type_prefix); + } + } else { + var base_prefix = content; + if (base_prefix != null) { + moOutput+=util.format("%s ", base_prefix); + } } + return moOutput; } diff --git a/json2mo/commentParser.js b/json2mo/commentParser.js index 082986e8..070d6172 100644 --- a/json2mo/commentParser.js +++ b/json2mo/commentParser.js @@ -3,17 +3,17 @@ function parse(content, rawJson=false) { const annotationParser = require('./annotationParser'); var moOutput = ""; - moOutput+="\n\t" + moOutput+="\n" if (rawJson) { if (content.string_comment != null) { - moOutput+=util.format("\"%s\"", content.string_comment); + moOutput+=util.format("\"\t%s\"", content.string_comment); } if (content.annotation != null) { moOutput+=annotationParser.parse(content.annotation, rawJson); } } else { if (content.description_string != null) { - moOutput+=util.format("\"%s\"\n", content.description_string); + moOutput+=util.format("\t\"%s\"\n", content.description_string); } if (content.annotation != null) { moOutput+=annotationParser.parse(content.annotation, rawJson); diff --git a/json2mo/component_clause1Parser.js b/json2mo/component_clause1Parser.js index 6db640ac..4ca585da 100644 --- a/json2mo/component_clause1Parser.js +++ b/json2mo/component_clause1Parser.js @@ -4,15 +4,29 @@ function parse(content, rawJson=false) { const component_declaration1Parser = require('./component_declaration1Parser'); var moOutput = ""; - if (content.type_prefix != null) { - moOutput+=util.format("%s", content.type_prefix, rawJson); - } - if (content.type_specifier != null) { - moOutput+=type_specifierParser.parse(content.type_specifier, rawJson); - } - if (content.component_declaration1 != null) { - moOutput+=component_declaration1Parser.parse(content.component_declaration1, rawJson); + if (rawJson) { + if (content.type_prefix != null) { + moOutput+=util.format("%s ", content.type_prefix); + } + if (content.type_specifier != null) { + moOutput+=type_specifierParser.parse(content.type_specifier, rawJson); + } + if (content.component_declaration1 != null) { + moOutput+=component_declaration1Parser.parse(content.component_declaration1, rawJson); + } + } else { + if (content.type_prefix != null) { + moOutput+=util.format("%s ", content.type_prefix); + } + if (content.type_specifier != null) { + moOutput+=util.format("%s ", content.type_specifier); + } + if (content.component_declaration1 != null) { + moOutput+=component_declaration1Parser.parse(content.component_declaration1, rawJson); + } } + + return moOutput; } diff --git a/json2mo/component_clauseParser.js b/json2mo/component_clauseParser.js index 95271b23..b36065d4 100644 --- a/json2mo/component_clauseParser.js +++ b/json2mo/component_clauseParser.js @@ -9,9 +9,16 @@ function parse(content, rawJson=false) { if (content.type_prefix != null) { moOutput+=util.format("%s ", content.type_prefix); } - if (content.type_specifier != null) { - moOutput+=type_specifierParser.parse(content.type_specifier, rawJson); + if (rawJson) { + if (content.type_specifier != null) { + moOutput+=type_specifierParser.parse(content.type_specifier, rawJson); + } + } else { + if (content.type_specifier != null) { + moOutput+=util.format("%s ", content.type_specifier); + } } + if (content.array_subscripts != null) { moOutput+=array_subscriptsParser.parse(content.array_subscripts, rawJson); } diff --git a/json2mo/component_declaration1Parser.js b/json2mo/component_declaration1Parser.js index 78b44610..9221b00c 100644 --- a/json2mo/component_declaration1Parser.js +++ b/json2mo/component_declaration1Parser.js @@ -1,3 +1,5 @@ +const e = require('express'); + function parse(content, rawJson) { const util = require('util'); const declarationParser = require('./declarationParser'); @@ -7,9 +9,16 @@ function parse(content, rawJson) { if (content.declaration != null) { moOutput+=declarationParser.parse(content.declaration, rawJson); } - if (content.comment != null) { - moOutput+=commentParser.parse(content.comment, rawJson); + if (rawJson) { + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment, rawJson); + } + } else { + if (content.description != null) { + moOutput+=commentParser.parse(content.description, rawJson); + } } + return moOutput; } module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/component_referenceParser.js b/json2mo/component_referenceParser.js index 3ddc55a9..5c903996 100644 --- a/json2mo/component_referenceParser.js +++ b/json2mo/component_referenceParser.js @@ -5,7 +5,14 @@ function parse(content, rawJson=false) { var moOutput = ""; - if (!rawJson) { + if (rawJson) { + var component_reference_parts = content.component_reference_parts + if (component_reference_parts != null) { + component_reference_parts.forEach(component_reference_part => { + moOutput+=component_reference_partParser.parse(component_reference_part, rawJson) + }); + } + } else { var component_reference_parts = content; component_reference_parts.forEach(component_reference_part => { if (component_reference_part.dot_op != null) { @@ -20,17 +27,8 @@ function parse(content, rawJson=false) { moOutput+=array_subscriptsParser.parse(component_reference_part.array_subscripts, rawJson); } }); - return moOutput; - } else { - var component_reference_parts = content.component_reference_parts - if (component_reference_parts != null) { - component_reference_parts.forEach(component_reference_part => { - moOutput+=component_reference_partParser.parse(component_reference_part, rawJson) - }); - } - return moOutput; } - + return moOutput; } module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/connect_clauseParser.js b/json2mo/connect_clauseParser.js index 1ee4951c..49890e79 100644 --- a/json2mo/connect_clauseParser.js +++ b/json2mo/connect_clauseParser.js @@ -11,7 +11,7 @@ function parse(content, rawJson=false) { moOutput+=", " moOutput+=component_referenceParser.parse(content.to, rawJson); } - moOutput+=")\n"; + moOutput+=")"; return moOutput; } diff --git a/json2mo/constraining_clauseParser.js b/json2mo/constraining_clauseParser.js index a1aad6c3..1dd3b004 100644 --- a/json2mo/constraining_clauseParser.js +++ b/json2mo/constraining_clauseParser.js @@ -5,7 +5,6 @@ function parse(content, rawJson=false) { var moOutput = ""; moOutput+="constraintedby "; - var name=""; if (content.name != null) { moOutput+= nameParser.parse(content.name, rawJson); } diff --git a/json2mo/der_class_specifierParser.js b/json2mo/der_class_specifierParser.js index 1f854587..d90dc7d4 100644 --- a/json2mo/der_class_specifierParser.js +++ b/json2mo/der_class_specifierParser.js @@ -9,9 +9,17 @@ function parse(content, rawJson=false) { moOutput+=util.format("%s= ", identifier); } - if (content.der_class_specifier_value != null) { - moOutput+=der_class_specifier_valueParser.parse(content.der_class_specifier_value, rawJson); - } + if (rawJson) { + if (content.der_class_specifier_value != null) { + moOutput+=der_class_specifier_valueParser.parse(content.der_class_specifier_value, rawJson); + } + } else { + if (content.value != null) { + moOutput+=der_class_specifier_valueParser.parse(content.value, rawJson); + } + } + + return moOutput; } diff --git a/json2mo/der_class_specifier_valueParser.js b/json2mo/der_class_specifier_valueParser.js index 52a36c68..f30c194e 100644 --- a/json2mo/der_class_specifier_valueParser.js +++ b/json2mo/der_class_specifier_valueParser.js @@ -7,8 +7,12 @@ function parse(content, rawJson=false) { if (content.type_specifier != null) { moOutput+=nameParser.parse(content.type_specifier, rawJson); } - - var identifiers = content.identifiers; + var identifiers = null; + if (rawJson) { + identifiers = content.identifiers; + } else { + identifiers = content.identifier; + } if (identifiers != null) { identifiers.forEach(identifier => { moOutput+=util.format("%s, ", identifier) diff --git a/json2mo/elementParser.js b/json2mo/elementParser.js index c4238978..5e62c897 100644 --- a/json2mo/elementParser.js +++ b/json2mo/elementParser.js @@ -17,11 +17,20 @@ function parse(content, rawJson=false) { moOutput+="redeclare " } } - if (content.is_final != null) { - if (content.is_final) { - moOutput+="final " + if (rawJson) { + if (content.is_final != null) { + if (content.is_final) { + moOutput+="final " + } + } + } else { + if (content.final != null) { + if (content.final) { + moOutput+="final " + } } } + if (content.inner != null) { if (content.inner) { moOutput+="inner " @@ -46,9 +55,16 @@ function parse(content, rawJson=false) { moOutput+=constraining_clauseParser.parse(content.constraining_clause, rawJson); } - if (content.comment != null) { - moOutput+=commentParser.parse(content.comment, rawJson); + if (rawJson) { + if (content.comment != null) { + moOutput+=commentParser.parse(content.comment, rawJson); + } + } else { + if (content.description != null) { + moOutput+=commentParser.parse(content.description, rawJson); + } } + } else { if (content.class_definition != null) { moOutput+=class_definitionParser.parse(content.class_definition, rawJson); diff --git a/json2mo/element_modificationParser.js b/json2mo/element_modificationParser.js index d1b0729d..696b267b 100644 --- a/json2mo/element_modificationParser.js +++ b/json2mo/element_modificationParser.js @@ -6,6 +6,7 @@ function parse(content, rawJson=false) { var moOutput = ""; if (content.name != null) { moOutput+=nameParser.parse(content.name, rawJson); + moOutput = moOutput.slice(0, -1); } if (content.modification != null) { moOutput+=modificationParser.parse(content.modification, rawJson); diff --git a/json2mo/enum_listParser.js b/json2mo/enum_listParser.js index bd13f4c9..8ec1ff22 100644 --- a/json2mo/enum_listParser.js +++ b/json2mo/enum_listParser.js @@ -1,11 +1,17 @@ -function parse(content) { +function parse(content, rawJson=false) { const enumeration_literalParser = require('./enumeration_literalParser'); var moOutput = ""; - var enum_list = content.enum_list - if (enum_list != null) { - enum_list.forEach(enumeration_literal => { - moOutput+=enumeration_literalParser.parse(enumeration_literal); + var enum_list = null; + if (rawJson) { + enumeration_literals = content.enumeration_literal + } else { + enumeration_literals = content; + } + + if (enumeration_literals != null) { + enumeration_literals.forEach(enumeration_literal => { + moOutput+=enumeration_literalParser.parse(enumeration_literal, rawJson); moOutput+=", "; }); } diff --git a/json2mo/enumeration_literalParser.js b/json2mo/enumeration_literalParser.js index 03288b5b..c2c0b17f 100644 --- a/json2mo/enumeration_literalParser.js +++ b/json2mo/enumeration_literalParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const commentParser = require('./commentParser'); @@ -7,9 +7,16 @@ function parse(content) { if (enumeration_literal.identifier != null) { moOutput+=util.format("%s ", enumeration_literal.identifier); } - if (enumeration_literal.comment != null) { - moOutput+=commentParser.parse(enumeration_literal.comment); + if (rawJson) { + if (enumeration_literal.comment != null) { + moOutput+=commentParser.parse(enumeration_literal.comment); + } + } else { + if (enumeration_literal.description != null) { + moOutput+=commentParser.parse(enumeration_literal.description); + } } + return moOutput; } diff --git a/json2mo/equation_sectionParser.js b/json2mo/equation_sectionParser.js index 899d7d1f..8697e262 100644 --- a/json2mo/equation_sectionParser.js +++ b/json2mo/equation_sectionParser.js @@ -18,6 +18,7 @@ function parse(content, rawJson=false) { if (equations != null) { equations.forEach(equation => { moOutput+=equationParser.parse(equation, rawJson); + moOutput=moOutput.slice(0,-1); //to remove last new line and to add semicolon moOutput+=";\n" }); } diff --git a/json2mo/expressionParser.js b/json2mo/expressionParser.js index 90e1da90..f78e90fa 100644 --- a/json2mo/expressionParser.js +++ b/json2mo/expressionParser.js @@ -6,7 +6,7 @@ function parse(content, rawJson=false) { if (content.if_expression != null) { moOutput+=if_expressionParser.parse(content.if_expression, rawJson); - } else if (content.simple_expression != null) { + } else if (content.simple_expression != null) { moOutput+=simple_expressionParser.parse(content.simple_expression, rawJson); } diff --git a/json2mo/expression_listParser.js b/json2mo/expression_listParser.js index 5ea3dab2..5193e631 100644 --- a/json2mo/expression_listParser.js +++ b/json2mo/expression_listParser.js @@ -3,7 +3,12 @@ function parse(content, rawJson=false) { const expressionParser = require('./expressionParser'); var moOutput = ""; - var expression_list = content; + var expression_list = null; + if (rawJson){ + expression_list = content.expressions; + } else { + expression_list = content; + } if (expression_list != null) { expression_list.forEach(expression => { moOutput+=expressionParser.parse(expression, rawJson); diff --git a/json2mo/external_function_callParser.js b/json2mo/external_function_callParser.js index 355f1f0f..85ed8824 100644 --- a/json2mo/external_function_callParser.js +++ b/json2mo/external_function_callParser.js @@ -6,11 +6,11 @@ function parse(content, rawJson=false) { var moOutput = ""; if (content.component_reference != null) { - moOutput+=component_referenceParser.parse(contnnt.component_reference, rawJson); + moOutput+=component_referenceParser.parse(content.component_reference, rawJson); moOutput+="= "; } if (content.identifier != null) { - moOutput+="identifier (" + moOutput+=util.format("%s (", content.identifier); } if (content.expression_list != null) { moOutput+=expression_listParser.parse(content.expression_list, rawJson); diff --git a/json2mo/for_equationParser.js b/json2mo/for_equationParser.js index 7c86cab6..12b899b8 100644 --- a/json2mo/for_equationParser.js +++ b/json2mo/for_equationParser.js @@ -4,9 +4,11 @@ function parse(content, rawJson=false) { var moOutput = ""; moOutput+="for " + if (content.for_indices != null) { moOutput+=for_indicesParser.parse(content.for_indices, rawJson); } + moOutput+="loop \n" loop_equations = content.loop_equations diff --git a/json2mo/function_argumentParser.js b/json2mo/function_argumentParser.js index e16a5d24..e525db02 100644 --- a/json2mo/function_argumentParser.js +++ b/json2mo/function_argumentParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const nameParser = require('./nameParser'); const named_argumentParser = require('./named_argumentParser'); const expressionParser = require('./expressionParser'); @@ -7,17 +7,25 @@ function parse(content) { if (content.function_name!= null) { moOutput+="function "; - moOutput+=nameParser.parse(content.function_name); + moOutput+=nameParser.parse(content.function_name, rawJson); moOutput+="("; - var named_arguments = content.named_arguments; - if (named_arguments != null) { - named_arguments.forEach(named_argument => { - moOutput+=named_argumentParser.parse(named_argument); - }); - } + + if (rawJson) { + if (content.named_arguments != null) { + moOutput+=named_argumentsParser.parse(content.named_arguments, rawJson); + } + } else { + var named_arguments = content.named_arguments; + if (named_arguments != null) { + named_arguments.forEach(named_argument => { + moOutput+=named_argumentParser.parse(named_argument, rawJson); + }); + } + } + moOutput+=") "; } else if (content.expression != null) { - moOutput+=expressionParser.parser(content.expression); + moOutput+=expressionParser.parser(content.expression, rawJson); } return moOutput; diff --git a/json2mo/function_argumentsParser.js b/json2mo/function_argumentsParser.js index 42282736..5cc52124 100644 --- a/json2mo/function_argumentsParser.js +++ b/json2mo/function_argumentsParser.js @@ -1,32 +1,50 @@ -function parse(content) { +function parse(content, rawJson=false) { + const named_argumentsParser = require('./named_argumentsParser'); const named_argumentParser = require('./named_argumentParser'); + const function_argumentsParser = require('./function_argumentsParser'); const function_argumentParser = require('./function_argumentParser'); const for_indicesParser = require('./for_indicesParser'); var moOutput = ""; - moOutput+="("; - var named_arguments = content.named_arguments; //only in simplified-json + if (rawJson) { + if (content.named_arguments != null) { + moOutput+=named_argumentsParser.parse(content.named_arguments, rawJson); + } else { + if (content.function_argument != null) { + moOutput+=function_argumentParser.parse(content.function_argument, rawJson); + } - if (named_arguments != null) { - named_arguments.forEach(named_argument => { - moOutput+=named_argumentParser.parse(named_argument); - moOutput+=", " - }); - moOutput=moOutput.slice(0, -1); + if (content.function_arguments != null) { + moOutput+="," + moOutput+=function_argumentsParser.parse(content.function_arguments, rawJson) + } else if (content.for_indices != null) { + moOutput+="for " + moOutput+=for_indicesParser.parse(cotnent.for_indices, rawJson); + } + } } else { - if (content.function_argument != null) { - moOutput+=function_argumentParser.parse(content.function_argument); + var named_arguments = content.named_arguments; //only in simplified-json - if (content.function_arguments != null) { + if (named_arguments != null) { + named_arguments.forEach(named_argument => { + moOutput+=named_argumentParser.parse(named_argument, rawJson); moOutput+=", " - moOutput+=this.parse(content.function_arguments); - } else if ( content.for_indices != null) { - moOutput+=" for "; - moOutput+=for_indicesParser.parse(content.for_indices); + }); + moOutput=moOutput.slice(0, -1); + } else { + if (content.function_argument != null) { + moOutput+=function_argumentParser.parse(content.function_argument, rawJson); + + if (content.function_arguments != null) { + moOutput+=", " + moOutput+=this.parse(content.function_arguments, rawJson); + } else if ( content.for_indices != null) { + moOutput+=" for "; + moOutput+=for_indicesParser.parse(content.for_indices, rawJson); + } } } - } - moOutput+=")"; + } return moOutput; } diff --git a/json2mo/function_call_argsParser.js b/json2mo/function_call_argsParser.js index dbc27b11..41c93f51 100644 --- a/json2mo/function_call_argsParser.js +++ b/json2mo/function_call_argsParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const named_argumentParser = require('./named_argumentParser'); const function_argumentParser = require('./function_argumentParser'); const function_argumentsParser = require('./function_argumentsParser'); @@ -6,27 +6,35 @@ function parse(content) { var moOutput = ""; moOutput+="("; - var named_arguments = content.named_arguments; //only in simplified-json - - if (named_arguments != null) { - named_arguments.forEach(named_argument => { - moOutput+=named_argumentParser.parse(named_argument); - moOutput+=", " - }); - moOutput=moOutput.slice(0, -1); + if (rawJson) { + if (content.function_arguments != null) { + moOutput+=function_argumentsParser.parse(content.function_arguments, rawJson); + } } else { - if (content.function_argument != null) { - moOutput+=function_argumentParser.parse(content.function_argument); + var named_arguments = content.named_arguments; //only in simplified-json - if (content.function_arguments != null) { - moOutput+=", " - moOutput+=function_argumentsParser.parse(content.function_arguments); - } else if ( content.for_indices != null) { - moOutput+=" for "; - moOutput+=for_indicesParser.parse(content.for_indices); + if (named_arguments != null) { + named_arguments.forEach(named_argument => { + moOutput+=named_argumentParser.parse(named_argument, rawJson); + moOutput+="," + }); + moOutput=moOutput.slice(0, -1); + } else { + if (content.function_argument != null) { + moOutput+=function_argumentParser.parse(content.function_argument, rawJson); + + if (content.function_arguments != null) { + moOutput+=", " + moOutput+=function_argumentsParser.parse(content.function_arguments, rawJson); + } else if ( content.for_indices != null) { + moOutput+=" for "; + moOutput+=for_indicesParser.parse(content.for_indices, rawJson); + } } } } + + moOutput+=")"; return moOutput; } diff --git a/json2mo/function_call_equationParser.js b/json2mo/function_call_equationParser.js index 24ba0bcd..7f081085 100644 --- a/json2mo/function_call_equationParser.js +++ b/json2mo/function_call_equationParser.js @@ -1,15 +1,15 @@ -function parse(content) { +function parse(content, rawJson=false) { const nameParser = require('./nameParser'); const function_call_argsParser = require('./function_call_argsParser'); var moOutput = ""; if (content.function_name != null) { - moOutput+=nameParser.parse(content.function_name); + moOutput+=nameParser.parse(content.function_name, rawJson); } if (content.function_call_args != null) { - moOutput+=function_call_argsParser.parse(content.function_call_args); + moOutput+=function_call_argsParser.parse(content.function_call_args, rawJson); } return moOutput; } diff --git a/json2mo/function_call_statementParser.js b/json2mo/function_call_statementParser.js index 1a3e6a4b..6951ce78 100644 --- a/json2mo/function_call_statementParser.js +++ b/json2mo/function_call_statementParser.js @@ -1,13 +1,13 @@ -function parse(content) { +function parse(content, rawJson=false) { const component_referenceParser = require('./component_referenceParser'); const function_call_argsParser = require('./function_call_argsParser'); var moOutput = ""; if (content.function_name != null) { - moOutput+=component_referenceParser.parse(content.function_name) + moOutput+=component_referenceParser.parse(content.function_name, rawJson) } if (content.function_call_args != null) { - moOutput+=function_call_argsParser.parse(content.function_call_args) + moOutput+=function_call_argsParser.parse(content.function_call_args, rawJson) } return moOutput; } diff --git a/json2mo/if_elseif_equationParser.js b/json2mo/if_elseif_equationParser.js index 8a5ef553..30c9239c 100644 --- a/json2mo/if_elseif_equationParser.js +++ b/json2mo/if_elseif_equationParser.js @@ -1,18 +1,18 @@ -function parse(content) { +function parse(content, rawJson=false) { const expressionParser = require('./expressionParser'); const equationParser = require('./equationParser'); var moOutput = ""; if (content.condition != null) { - moOutput+=expressionParser.parse(content.condition); + moOutput+=expressionParser.parse(content.condition, rawJson); } var then_equations = content.then; if (then_equations != null) { thenOutput= ""; then_equations.forEach(then_equation => { - thenOutput+=equationParser.parser(then_equation); + thenOutput+=equationParser.parser(then_equation, rawJson); thenOutput+=";\n" }); if (thenOutput != "") { diff --git a/json2mo/if_elseif_expressionParser.js b/json2mo/if_elseif_expressionParser.js index f34b1d5e..b9acf1ba 100644 --- a/json2mo/if_elseif_expressionParser.js +++ b/json2mo/if_elseif_expressionParser.js @@ -1,15 +1,15 @@ -function parse(content) { +function parse(content, rawJson=false) { const expressionParser = require('./expressionParser'); var moOutput = ""; if (content.condition != null) { - moOutput+=expressionParser.parse(content.condition); + moOutput+=expressionParser.parse(content.condition, rawJson); } moOutput+="then \n"; if (content.then != null) { - moOutput+=expressionParser.parser(content.then); + moOutput+=expressionParser.parser(content.then, rawJson); thenOutput+=";\n" } return moOutput; diff --git a/json2mo/if_elseif_statementParser.js b/json2mo/if_elseif_statementParser.js index c48d1c8c..91933abc 100644 --- a/json2mo/if_elseif_statementParser.js +++ b/json2mo/if_elseif_statementParser.js @@ -1,18 +1,18 @@ -function parse(content) { +function parse(content, rawJson=false) { const expressionParser = require('./expressionParser'); const statementParser = require('./statementParser'); var moOutput = ""; if (content.condition != null) { - moOutput+=expressionParser.parse(content.condition); + moOutput+=expressionParser.parse(content.condition, rawJson); } var then_statements = content.then; if (then_statements != null) { thenOutput= ""; then_statements.forEach(then_statement => { - thenOutput+=statementParser.parser(then_statement); + thenOutput+=statementParser.parser(then_statement, rawJson); thenOutput+=";\n" }); if (thenOutput != "") { diff --git a/json2mo/if_equationParser.js b/json2mo/if_equationParser.js index e3e6cf4f..6beb92b8 100644 --- a/json2mo/if_equationParser.js +++ b/json2mo/if_equationParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const if_elseif_equationParser = require('./if_elseif_equationParser'); const equationParser = require('./equationParser'); @@ -7,7 +7,7 @@ function parse(content) { if (if_elseifs != null) { if_elseifs.forEach(if_elseif_equation => { moOutput+="elseif " - moOutput+=if_elseif_equationParser.parse(if_elseif_equation); + moOutput+=if_elseif_equationParser.parse(if_elseif_equation, rawJson); }); } moOutput = moOutput.slice(4, moOutput.length); //to remove 1st else of elseif so that we get "if" @@ -16,7 +16,7 @@ function parse(content) { if (else_equations != null) { elseOutput= ""; else_equations.forEach(else_equation => { - elseOutput+=equationParser.parser(else_equation); + elseOutput+=equationParser.parser(else_equation, rawJson); elseOutput+=";\n" }); if (elseOutput != "") { diff --git a/json2mo/if_expressionParser.js b/json2mo/if_expressionParser.js index 65e9529c..8f8b3fa9 100644 --- a/json2mo/if_expressionParser.js +++ b/json2mo/if_expressionParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const if_elseif_expressionParser = require('./if_elseif_expressionParser'); const expressionParser = require('./expressionParser'); @@ -7,14 +7,14 @@ function parse(content) { if (if_elseifs != null) { if_elseifs.forEach(if_elseif_expression => { moOutput+="elseif " - moOutput+=if_elseif_expressionParser.parse(if_elseif_expression); + moOutput+=if_elseif_expressionParser.parse(if_elseif_expression, rawJson); }); } moOutput = moOutput.slice(4, moOutput.length); //to remove 1st else of elseif so that we get "if" if (content.else_expression != null) { moOutput+="else \n"; - moOutput+=expressionParser.parse(content.else_expression); + moOutput+=expressionParser.parse(content.else_expression, rawJson); } return moOutput; } diff --git a/json2mo/if_statementParser.js b/json2mo/if_statementParser.js index 67e41d8d..98a49a2d 100644 --- a/json2mo/if_statementParser.js +++ b/json2mo/if_statementParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const if_elseif_statementParser = require('./if_elseif_statementParser'); const statementParser = require('./statementParser'); @@ -7,7 +7,7 @@ function parse(content) { if (if_elseifs != null) { if_elseifs.forEach(if_elseif_statement => { moOutput+="elseif " - moOutput+=if_elseif_statementParser.parse(if_elseif_statement); + moOutput+=if_elseif_statementParser.parse(if_elseif_statement, rawJson); }); } moOutput = moOutput.slice(4, moOutput.length); //to remove 1st else of elseif so that we get "if" @@ -16,7 +16,7 @@ function parse(content) { if (else_statements != null) { elseOutput= ""; else_statements.forEach(else_statement => { - elseOutput+=statementParser.parser(else_statement); + elseOutput+=statementParser.parser(else_statement, rawJson); elseOutput+=";\n" }); if (elseOutput != "") { diff --git a/json2mo/import_clauseParser.js b/json2mo/import_clauseParser.js index 91602e46..eaec6b3c 100644 --- a/json2mo/import_clauseParser.js +++ b/json2mo/import_clauseParser.js @@ -28,13 +28,13 @@ function parse(content, rawJson=false) { moOutput+=util.format("%s ", name); } - if (description) { + if (rawJson) { if (content.comment != null) { - moOutput+=commentParser.parse(content.comment); + moOutput+=commentParser.parse(content.comment, rawJson); } } else { if (content.description != null) { - moOutput+=commentParser.parse(content.description); + moOutput+=commentParser.parse(content.description, rawJson); } } diff --git a/json2mo/modificationParser.js b/json2mo/modificationParser.js index 88a3c4cf..be2ae8a4 100644 --- a/json2mo/modificationParser.js +++ b/json2mo/modificationParser.js @@ -9,11 +9,11 @@ function parse(content, rawJson=false) { if (content.equal != null) { if (content.equal) { - moOutput+= "= "; + moOutput+= "="; } } else if (content.colon_equal != null) { if (content.colon_equal) { - moOutput+= ":= "; + moOutput+= ":="; } } if (content.expression != null) { diff --git a/json2mo/named_argumentParser.js b/json2mo/named_argumentParser.js index 984f9ddc..a4ca71cc 100644 --- a/json2mo/named_argumentParser.js +++ b/json2mo/named_argumentParser.js @@ -1,13 +1,13 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const function_argumentParser = require('./function_argumentParser'); var moOutput = ""; if (content.identifier != null) { - moOutput+=util.format("%s ", content.identifier); + moOutput+=util.format("%s=", content.identifier); } if (content.value != null) { - moOutput+=function_argumentParser.parse(content.value); + moOutput+=function_argumentParser.parse(content.value, rawJson); } return moOutput; diff --git a/json2mo/named_argumentsParser.js b/json2mo/named_argumentsParser.js new file mode 100644 index 00000000..6493c3cf --- /dev/null +++ b/json2mo/named_argumentsParser.js @@ -0,0 +1,19 @@ +function parse(content, rawJson=false) { + const named_argumentParser = require('./named_argumentParser'); + + var moOutput = ""; + + if (rawJson) { + if (content.named_argument != null) { + moOutput+=named_argumentParser.parse(content.named_argument, rawJson); + } + if (content.named_arguments != null) { + moOutput+="," + moOutput+=this.parse(content.named_arguments, rawJson); + } + } + + return moOutput; +} + +module.exports = {parse}; \ No newline at end of file diff --git a/json2mo/output_expression_listParser.js b/json2mo/output_expression_listParser.js index 08049fe1..da4ffdb3 100644 --- a/json2mo/output_expression_listParser.js +++ b/json2mo/output_expression_listParser.js @@ -1,17 +1,23 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const expressionParser = require('./expressionParser'); var moOutput = ""; - var output_expression_list = content; - if (output_expression_list != null) { - output_expression_list.forEach(expression => { - moOutput+=expressionParser.parse(expression); + var output_expressions = null; + if (rawJson) { + output_expressions = content.output_expressions; + } else { + output_expressions = content; + } + if (output_expressions != null) { + output_expressions.forEach(expression => { + moOutput+=expressionParser.parse(expression, rawJson); moOutput+=", "; }); moOutput = moOutput.slice(0, -1); - } + } return moOutput; } -module.exports = {parse}; \ No newline at end of file +module.exports = { +}; \ No newline at end of file diff --git a/json2mo/short_class_definitionParser.js b/json2mo/short_class_definitionParser.js index a3c37904..ae7f554b 100644 --- a/json2mo/short_class_definitionParser.js +++ b/json2mo/short_class_definitionParser.js @@ -1,4 +1,4 @@ -function parse(content) { +function parse(content, rawJson=false) { const util = require('util'); const short_class_specifierParser = require('./short_class_specifierParser'); @@ -7,7 +7,7 @@ function parse(content) { moOutput+=util.format("%s ", class_prefixes); } if (content.short_class_specifier != null) { - moOutput+=short_class_specifierParser.parse(content.short_class_specifier); + moOutput+=short_class_specifierParser.parse(content.short_class_specifier, rawJson); } return moOutput; } diff --git a/json2mo/short_class_specifierParser.js b/json2mo/short_class_specifierParser.js index bf837537..0a34a620 100644 --- a/json2mo/short_class_specifierParser.js +++ b/json2mo/short_class_specifierParser.js @@ -8,8 +8,16 @@ function parse(content, rawJson=false) { if (identifier != null) { moOutput+=util.format("%s= ", identifier); } - - moOutput+=short_class_specifier_valueParser.parse(content.short_class_specifier_value, rawJson); + if (rawJson) { + if (content.short_class_specifier_value != null) { + moOutput+=short_class_specifier_valueParser.parse(content.short_class_specifier_value, rawJson); + } + } else { + if (content.value != null) { + moOutput+=short_class_specifier_valueParser.parse(content.value, rawJson); + } + } + return moOutput; } diff --git a/json2mo/simple_expressionParser.js b/json2mo/simple_expressionParser.js index 1ec7167b..141946dc 100644 --- a/json2mo/simple_expressionParser.js +++ b/json2mo/simple_expressionParser.js @@ -2,7 +2,11 @@ function parse(content, rawJson=false) { const util = require('util'); var moOutput = ""; if (content!=null) { - moOutput+=util.format("%s ", content); + if (rawJson) { + moOutput+=util.format("%s", JSON.stringify(content)); + } else { + moOutput+=util.format("%s", content); + } } return moOutput; } diff --git a/json2mo/statementParser.js b/json2mo/statementParser.js index d35a223b..5e4914a6 100644 --- a/json2mo/statementParser.js +++ b/json2mo/statementParser.js @@ -1,5 +1,4 @@ function parse(content, rawJson) { - const util = require('util'); const assignment_statementParser = require('./assignment_statementParser'); const function_call_statementParser = require('./function_call_statementParser'); const assignment_with_function_call_statementParser = require('./assignment_with_function_call_statementParser'); diff --git a/json2mo/when_equationParser.js b/json2mo/when_equationParser.js index 2b1929c2..93673b60 100644 --- a/json2mo/when_equationParser.js +++ b/json2mo/when_equationParser.js @@ -1,23 +1,28 @@ -function parse(content) { +function parse(content, rawJson=false) { const expressionParser = require('./expressionParser'); const equationParser = require('./equationParser'); var moOutput = ""; - var when_elsewhens = content //different if it was raw-json + var when_elsewhens = null; + if (rawJson) { + when_elsewhens = content.when_elsewhen; + } else { + when_elsewhens = content; + } if (when_elsewhens != null) { when_elsewhens.forEach(when_elsewhen => { moOutput+="elsewhen " if (when_elsewhen.condition != null) { - moOutput+=expressionParser.parse(when_elsewhen.condition); + moOutput+=expressionParser.parse(when_elsewhen.condition, rawJson); } moOutput+="\n"; then_equations = when_elsewhen.then; thenOutput = ""; if (then_equations!=null) { then_equations.forEach(then_equation => { - thenOutput+=equationParser.parse(then_equation); + thenOutput+=equationParser.parse(then_equation, rawJson); thenOutput+=";\n"; }); } diff --git a/json2mo/when_statementParser.js b/json2mo/when_statementParser.js index 5db973b7..c1140ba1 100644 --- a/json2mo/when_statementParser.js +++ b/json2mo/when_statementParser.js @@ -1,23 +1,28 @@ -function parse(content) { +function parse(content, rawJson=false) { const expressionParser = require('./expressionParser'); const statementParser = require('./statementParser'); var moOutput = ""; - var when_elsewhens = content //different if it was raw-json + var when_elsewhens = null; + if (rawJson) { + when_elsewhens = content.when_elsewhen; + } else { + when_elsewhens = content; + } if (when_elsewhens != null) { when_elsewhens.forEach(when_elsewhen => { moOutput+="elsewhen " if (when_elsewhen.condition != null) { - moOutput+=expressionParser.parse(when_elsewhen.condition); + moOutput+=expressionParser.parse(when_elsewhen.condition, rawJson); } moOutput+="\n"; then_statements = when_elsewhen.then; thenOutput = ""; if (then_statements!=null) { then_statements.forEach(then_statement => { - thenOutput+=statementParser.parse(then_statement); + thenOutput+=statementParser.parse(then_statement, rawJson); thenOutput+=";\n"; }); } diff --git a/json2mo/while_statementParser.js b/json2mo/while_statementParser.js index fb0eac41..09de0cca 100644 --- a/json2mo/while_statementParser.js +++ b/json2mo/while_statementParser.js @@ -1,17 +1,17 @@ -function parse(content) { +function parse(content, rawJson=false) { const expressionParser = require('./expressionParser'); const statementParser = require('./statementParser'); var moOutput = ""; moOutput+="while " if (content.condition != null) { //in simplified json - moOutput+=expressionParser.parse(content.condition); + moOutput+=expressionParser.parse(content.condition, rawJson); } moOutput+="loop \n" loop_statements = content.loop_statements loop_statements.forEach(loop_statement => { - moOutput+=statementParser.parse(loop_statement); + moOutput+=statementParser.parse(loop_statement, rawJson); moOutput+=';\n'; }); moOutput+="end while"; From c5722e271c142dbe5c2bd07bdd208d7cd368506f Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Mon, 15 Nov 2021 17:53:15 -0800 Subject: [PATCH 23/29] incorporating json2mo within the app.js pipeline --- app.js | 50 +++++++++++++++++++++++++++++++------------------- j2m.js | 20 -------------------- lib/parser.js | 26 ++++++++++++++++++++++++++ lib/util.js | 6 ++++-- 4 files changed, 61 insertions(+), 41 deletions(-) delete mode 100644 j2m.js diff --git a/app.js b/app.js index da245381..d873b8a0 100644 --- a/app.js +++ b/app.js @@ -17,7 +17,7 @@ parser.addArgument( [ '-o', '--output' ], { help: 'Specify output format.', - choices: ['html', 'raw-json', 'json', 'docx', 'svg'], + choices: ['html', 'raw-json', 'json', 'docx', 'svg', 'modelica'], defaultValue: 'html' } ) @@ -40,7 +40,7 @@ parser.addArgument( parser.addArgument( [ '-f', '--file' ], { - help: 'Filename or packagename that contains the top-level Modelica class.', + help: 'Filename or packagename that contains the top-level Modelica class or a json file (for generating .mo file)', required: true } ) @@ -82,26 +82,38 @@ if (args.mode === 'modelica' && args.output === 'svg') { throw new Error('svg output option has not been enabled in modelica mode.') } -// Get mo files array -var moFiles = ut.getMoFiles(args.file) +if (args.output === 'modelica' && !args.file.endsWith(".json")) { + throw new Error('modelica output requires a input file (-f) to be a json file') +} + +if (args.output != 'modelica' && args.file.endsWith(".json")) { + throw new Error('modelica output (-o) is required for an json input file') +} -// Parse the json representation for moFiles -var json = pa.getJsons(moFiles, args.mode, args.output, args.directory) +if (args.output === 'modelica') { + var moContent = pa.convertToModelica(args.file, args.directory, false); +} else { + // Get mo files array + var moFiles = ut.getMoFiles(args.file) -// // Get the name array of output files -// var outFile = ut.getOutFile(args.mode, args.file, args.output, args.directory, moFiles, json) + // Parse the json representation for moFiles + var json = pa.getJsons(moFiles, args.mode, args.output, args.directory) -// pa.exportJSON(json, outFile, args.output, args.mode, args.directory) + // // Get the name array of output files + // var outFile = ut.getOutFile(args.mode, args.file, args.output, args.directory, moFiles, json) -// var schema -// if (args.mode === 'cdl') { -// schema = path.join(`${__dirname}`, 'schema-CDL.json') -// } else { -// schema = path.join(`${__dirname}`, 'schema-modelica.json') -// } + // pa.exportJSON(json, outFile, args.output, args.mode, args.directory) -// setTimeout(function () { ut.jsonSchemaValidate(args.mode, outFile[0], args.output, schema) }, 100) + // var schema + // if (args.mode === 'cdl') { + // schema = path.join(`${__dirname}`, 'schema-CDL.json') + // } else { + // schema = path.join(`${__dirname}`, 'schema-modelica.json') + // } -// if (args.strict === 'true' && pa.warnCounter > 0) { -// process.exit(1) -// } + // setTimeout(function () { ut.jsonSchemaValidate(args.mode, outFile[0], args.output, schema) }, 100) + + // if (args.strict === 'true' && pa.warnCounter > 0) { + // process.exit(1) + // } +} diff --git a/j2m.js b/j2m.js deleted file mode 100644 index 7f5e45fd..00000000 --- a/j2m.js +++ /dev/null @@ -1,20 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const stored_definitonParser = require('./json2mo/stored_definitonParser'); - -function convertToModelica(jsonFile, rawJson=false) { - var fileContent = fs.readFileSync(jsonFile, 'utf8'); - //TODO: the [0] should change with the new simplified json - var jsonOutput; - if (rawJson) { - jsonOutput = JSON.parse(fileContent)[0]; - } else { - jsonOutput = JSON.parse(fileContent); - } - moOutput = stored_definitonParser.parse(jsonOutput, rawJson); - return moOutput; -} - -// console.log(convertToModeica('raw-json/FromModelica.ExtendsClause_1.json')); -// console.log(convertToModelica('raw-json/FromModelica.Modulation.json', rawJson=true)); -console.log(convertToModelica('json/Modulation_2.json', rawJson=false)); \ No newline at end of file diff --git a/lib/parser.js b/lib/parser.js index d3a1cb29..a4b5ce7b 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -12,6 +12,8 @@ var fs = require('fs') var logger = require('winston') const { raw } = require('express') +const stored_definitonParser = require('../json2mo/stored_definitonParser') + var warnCounter = 0 /** Run the parser for the top-level `moFiles`, @@ -324,5 +326,29 @@ function elementReplaceable (eleRep) { return eleLis } +/** + * Converts json file to modelica output + * @param jsonFile path to json file to be converted + * @param rawJson if true, json file is a raw-json output; else simplified json output + * @returns string content of modelica file + */ +function convertToModelica(jsonFile, outDir, rawJson=false) { + var fileContent = fs.readFileSync(jsonFile, 'utf8'); + + var jsonOutput; + if (rawJson) { + jsonOutput = JSON.parse(fileContent)[0]; + } else { + jsonOutput = JSON.parse(fileContent); + } + moOutput = stored_definitonParser.parse(jsonOutput, rawJson); + + // find the output file path + var outputFileName = ut.getOutputFile(jsonFile, 'modelica', outDir) + ut.writeFile(outputFileName, moOutput) + return moOutput; +} + module.exports.getJsons = getJsons +module.exports.convertToModelica = convertToModelica diff --git a/lib/util.js b/lib/util.js index b81c04d2..983163c5 100644 --- a/lib/util.js +++ b/lib/util.js @@ -141,9 +141,9 @@ function getFiles (dir, fileList) { } // Get the output file path -function getOutputFile (moFile, outputFormat, dir) { +function getOutputFile (inputFile, outputFormat, dir) { // get the modelica file path from the Json output, it is relative path - var relPat = relativePath(moFile) + var relPat = relativePath(inputFile) var outFile if (outputFormat === 'json' || outputFormat === 'raw-json') { outFile = relPat.replace('.mo', '.json') @@ -151,6 +151,8 @@ function getOutputFile (moFile, outputFormat, dir) { outFile = relPat.replace('.mo', '.html') } else if (outputFormat === 'docx') { outFile = relPat.replace('.mo', '.docx') + } else if (outputFormat === 'modelica') { + outFile = inputFile.replace(".json", ".mo") } return path.join(dir, outputFormat, outFile) } From 7ace6c73cdaf997c2dcffd17d46c9889bbb4d138 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Thu, 26 Oct 2023 06:46:27 -0700 Subject: [PATCH 24/29] removing schema validation and fixing errors --- Makefile | 9 --------- app.js | 21 +++++++++++---------- json2mo/conditionAttribute.js | 2 +- json2mo/equationSection.js | 2 +- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 476f05e1..5bcc947a 100644 --- a/Makefile +++ b/Makefile @@ -45,15 +45,6 @@ generate-reference-output: node app.js -l warn -f $${ff} -o json -d ./test/reference; \ node app.js -l warn -f $${ff} -o semantic -d ./test/reference; \ done) - cd test/reference/json && \ - (for ff in `find ./test/FromModelica -name '*.json'`; do \ - node ../../../app.js -l warn -f $${ff} -o modelica -d ../../../test/reference/reverse; \ - done) - cd test/reference/reverse/modelica && \ - (for ff in `find . -name '*.mo'`; do \ - node ../../../../app.js -l warn -f $${ff} -o json -d .. ; \ - done) - clean-node-packages: rm -rf node-modules diff --git a/app.js b/app.js index c86f20c7..3e257feb 100644 --- a/app.js +++ b/app.js @@ -120,15 +120,16 @@ if (args.output === 'json') { } else { schema = path.join(`${__dirname}`, 'schema-modelica.json') } - let jsonFiles = ut.findFilesInDir(path.join(args.directory, 'json'), '.json') + console.log('parsing mode: ', schema) + // let jsonFiles = ut.findFilesInDir(path.join(args.directory, 'json'), '.json') // exclude CDL folder and possibly Modelica folder - const pathSep = path.sep - const cdlPath = path.join(pathSep, 'CDL', pathSep) - const modelicaPath = path.join('Modelica', pathSep) - jsonFiles = jsonFiles.filter(obj => !(obj.includes(cdlPath) || obj.includes(modelicaPath))) - // validate json schema - for (let i = 0; i < jsonFiles.length; i++) { - const eachFile = jsonFiles[i] - setTimeout(function () { ut.jsonSchemaValidation(args.mode, eachFile, 'json', schema) }, 100) - } + // const pathSep = path.sep + // const cdlPath = path.join(pathSep, 'CDL', pathSep) + // const modelicaPath = path.join('Modelica', pathSep) + // jsonFiles = jsonFiles.filter(obj => !(obj.includes(cdlPath) || obj.includes(modelicaPath))) + // // validate json schema + // for (let i = 0; i < jsonFiles.length; i++) { + // const eachFile = jsonFiles[i] + // setTimeout(function () { ut.jsonSchemaValidation(args.mode, eachFile, 'json', schema) }, 100) + // } } diff --git a/json2mo/conditionAttribute.js b/json2mo/conditionAttribute.js index 9fd2db87..e705a211 100644 --- a/json2mo/conditionAttribute.js +++ b/json2mo/conditionAttribute.js @@ -8,7 +8,7 @@ function parse (content, rawJson = false) { moOutput += expressionParser.parse(content.expression, rawJson) } } else { - const expression = content + const expression = content.expression if (expression != null) { moOutput += expressionParser.parse(expression, rawJson) } diff --git a/json2mo/equationSection.js b/json2mo/equationSection.js index 54978991..b52c07f5 100644 --- a/json2mo/equationSection.js +++ b/json2mo/equationSection.js @@ -7,7 +7,7 @@ function parse (content, rawJson = false) { moOutput += 'initial ' } } - moOutput += 'equation' + moOutput += 'equation\n' let equations if (rawJson) { equations = content.equations From 80c38bb56f016d07bbd39dc07c65dd7ca116034f Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Tue, 28 Nov 2023 15:29:58 -0800 Subject: [PATCH 25/29] fixing errors with json2mo translators --- json2mo/elementModification.js | 4 ++-- json2mo/graphic.js | 6 +++--- json2mo/longClassSpecifier.js | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/json2mo/elementModification.js b/json2mo/elementModification.js index c290a6a0..7011dea9 100644 --- a/json2mo/elementModification.js +++ b/json2mo/elementModification.js @@ -24,8 +24,8 @@ function parse (content, rawJson = false) { if (content.modification != null) { moOutput += modificationParser.parse(content.modification, rawJson) } - if (content.string_comment != null) { - moOutput += util.format('%s', content.string_comment, rawJson) + if (content.description_string != null) { + moOutput += util.format(' "%s" ', content.description_string) } } return moOutput diff --git a/json2mo/graphic.js b/json2mo/graphic.js index 6e39a0be..afcd9f57 100644 --- a/json2mo/graphic.js +++ b/json2mo/graphic.js @@ -103,8 +103,8 @@ function graphicsParse (obj) { for (let i = 0; i < obj.length; i++) { const ithEle = obj[i] const name = ithEle.name - const attibutes = ithEle.attribute - const graComIte = commonGraphicItems(attibutes) + const attributes = ithEle.attribute + const graComIte = commonGraphicItems(attributes) strArr.push(name + '(' + graComIte.join(',') + ')') } return 'graphics=' + '{' + strArr.join(',') + '}' @@ -228,7 +228,7 @@ function commonGraphicItems (obj) { strArr.push('fontSize=' + util.format('%s', fontSize)) } if (textColor != null) { - strArr.push('textColor=' + colorParse(extent)) + strArr.push('textColor=' + colorParse(textColor)) } if (horizontalAlignment != null) { strArr.push('horizontalAlignment=' + util.format('%s', horizontalAlignment)) diff --git a/json2mo/longClassSpecifier.js b/json2mo/longClassSpecifier.js index 201d7ff4..471ba3f8 100644 --- a/json2mo/longClassSpecifier.js +++ b/json2mo/longClassSpecifier.js @@ -25,16 +25,17 @@ function parse (content, rawJson = false) { } } } + moOutput += '\n' if (rawJson) { const stringComment = content.string_comment if (stringComment != null) { - moOutput += util.format('\n%s\n', stringComment) + moOutput += util.format('%s\n', stringComment) } } else { const descriptionString = content.description_string if (descriptionString != null) { - moOutput += util.format('\n"%s"\n', descriptionString) + moOutput += util.format('"%s"\n', descriptionString) } } From aa030c40bf12e2af1a50be4e78996f04288899e6 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Tue, 28 Nov 2023 15:30:24 -0800 Subject: [PATCH 26/29] adding file to run unit tests for json2mo --- test/test_json2mo.js | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/test_json2mo.js diff --git a/test/test_json2mo.js b/test/test_json2mo.js new file mode 100644 index 00000000..a9f21992 --- /dev/null +++ b/test/test_json2mo.js @@ -0,0 +1,68 @@ +const as = require('assert') +const mo = require('mocha') +const sinon = require('sinon') +const path = require('path') +const glob = require('glob-promise') +const fs = require('fs') +const pa = require('../lib/parser.js') + +mo.afterEach(() => { + sinon.restore() +}) + +function getFiles (topFolder, fileType) { + let pattern + // get all test modelica files to convert to json + pattern = path.join(__dirname, topFolder, '*.'+fileType) + return glob.sync(pattern) +} + +mo.describe('testing json2mo', function () { + mo.describe('testing parsing test/reference/json folder', function () { + mo.it('testing structure', function () { + fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }); + fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }); + + // convert mo to json + inputMoFiles = getFiles(topFolder='FromModelica', fileType='mo').splice(3) + pa.getJsons(inputMoFiles, 'modelica', 'json', path.join('test', 'reverse'), 'false') + + // convert json back to mo + jsonOp1Files = getFiles(topFolder=path.join('reverse', 'json', 'test', 'FromModelica'), fileType='json') + jsonOp1Files.forEach(json1FilePath => { + json1FilePath = path.join('test', json1FilePath.split(__dirname)[1]) + pa.convertToModelica(json1FilePath, path.join('test', 'reverse'), false) + }) + + // convert modelica back to json + generatedMoFiles = getFiles(topFolder=path.join('reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica'), fileType='mo') + pa.getJsons(generatedMoFiles, 'modelica', 'json', path.join('test', 'reverse2'), 'false') + + jsonOp2Files = getFiles(topFolder=path.join('reverse2', 'json', 'test', 'FromModelica'), fileType='json') + + jsonOp1Files.forEach(file1 => { + tokens = file1.split(path.sep) + filename = tokens[tokens.length - 1] + console.log("checking for ", filename) + + originalJsonFilePath = path.join(__dirname, 'reverse', 'json', 'test', 'FromModelica', filename) + originalJson = JSON.parse(fs.readFileSync(originalJsonFilePath), 'utf8') + + newJsonFilePath = path.join(__dirname, 'reverse2', 'json', 'test', 'reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica', filename) + newJson = JSON.parse(fs.readFileSync(newJsonFilePath), 'utf8') + + newJson['modelicaFile'] = originalJson['modelicaFile'] + newJson['fullMoFilePath'] = originalJson['fullMoFilePath'] + newJson['checksum'] = originalJson['checksum'] + + const tempOld = JSON.stringify(originalJson).trim() + const tempNew = JSON.stringify(newJson).trim() + + as.deepEqual(tempNew.length, tempOld.length, 'JSON result different') + }) + + fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }); + fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }); + }) + }) +}) \ No newline at end of file From b7c48aa2d74629d1e9054160f6c57383d3e53e45 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Thu, 30 Nov 2023 09:38:21 -0800 Subject: [PATCH 27/29] fix standard issues --- test/test_json2mo.js | 49 +++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/test/test_json2mo.js b/test/test_json2mo.js index a9f21992..9a7ce5ed 100644 --- a/test/test_json2mo.js +++ b/test/test_json2mo.js @@ -11,58 +11,55 @@ mo.afterEach(() => { }) function getFiles (topFolder, fileType) { - let pattern // get all test modelica files to convert to json - pattern = path.join(__dirname, topFolder, '*.'+fileType) + const pattern = path.join(__dirname, topFolder, '*.' + fileType) return glob.sync(pattern) } - + mo.describe('testing json2mo', function () { mo.describe('testing parsing test/reference/json folder', function () { mo.it('testing structure', function () { - fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }); - fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }); + fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }) + fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }) // convert mo to json - inputMoFiles = getFiles(topFolder='FromModelica', fileType='mo').splice(3) + const inputMoFiles = getFiles('FromModelica', 'mo').splice(3) pa.getJsons(inputMoFiles, 'modelica', 'json', path.join('test', 'reverse'), 'false') // convert json back to mo - jsonOp1Files = getFiles(topFolder=path.join('reverse', 'json', 'test', 'FromModelica'), fileType='json') + const jsonOp1Files = getFiles(path.join('reverse', 'json', 'test', 'FromModelica'), 'json') jsonOp1Files.forEach(json1FilePath => { json1FilePath = path.join('test', json1FilePath.split(__dirname)[1]) pa.convertToModelica(json1FilePath, path.join('test', 'reverse'), false) }) - + // convert modelica back to json - generatedMoFiles = getFiles(topFolder=path.join('reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica'), fileType='mo') + const generatedMoFiles = getFiles(path.join('reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica'), 'mo') pa.getJsons(generatedMoFiles, 'modelica', 'json', path.join('test', 'reverse2'), 'false') - jsonOp2Files = getFiles(topFolder=path.join('reverse2', 'json', 'test', 'FromModelica'), fileType='json') - jsonOp1Files.forEach(file1 => { - tokens = file1.split(path.sep) - filename = tokens[tokens.length - 1] - console.log("checking for ", filename) - - originalJsonFilePath = path.join(__dirname, 'reverse', 'json', 'test', 'FromModelica', filename) - originalJson = JSON.parse(fs.readFileSync(originalJsonFilePath), 'utf8') + const tokens = file1.split(path.sep) + const filename = tokens[tokens.length - 1] + console.log('checking for ', filename) - newJsonFilePath = path.join(__dirname, 'reverse2', 'json', 'test', 'reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica', filename) - newJson = JSON.parse(fs.readFileSync(newJsonFilePath), 'utf8') + const originalJsonFilePath = path.join(__dirname, 'reverse', 'json', 'test', 'FromModelica', filename) + const originalJson = JSON.parse(fs.readFileSync(originalJsonFilePath), 'utf8') - newJson['modelicaFile'] = originalJson['modelicaFile'] - newJson['fullMoFilePath'] = originalJson['fullMoFilePath'] - newJson['checksum'] = originalJson['checksum'] + const newJsonFilePath = path.join(__dirname, 'reverse2', 'json', 'test', 'reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica', filename) + const newJson = JSON.parse(fs.readFileSync(newJsonFilePath), 'utf8') + + newJson.modelicaFile = originalJson.modelicaFile + newJson.fullMoFilePath = originalJson.fullMoFilePath + newJson.checksum = originalJson.checksum const tempOld = JSON.stringify(originalJson).trim() const tempNew = JSON.stringify(newJson).trim() - + as.deepEqual(tempNew.length, tempOld.length, 'JSON result different') }) - fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }); - fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }); + fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }) + fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }) }) }) -}) \ No newline at end of file +}) From 1b371c2c16c9f518dd15109feb0fe410b4c890ac Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Thu, 30 Nov 2023 09:58:17 -0800 Subject: [PATCH 28/29] Update README.md to include json2mo parsing --- README.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 71c36015..57d8b5e2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ See the directory `test/FromModelica` from __modelica-json__ for simple examples ## 2. Installation and help +__modelica-json__ requires both Java and Node.js. +This pacakged has been tested with Java (JDK 21, JRE 8u391 and Node.js 18). + ### Linux First, set the MODELICAPATH environment variable by adding the following line to your ~/.bashrc file: @@ -65,18 +68,18 @@ make clean-installation - Finally, to install dependencies and compile the Java files, run `InstallOnWindows.bat`. -To test the installation, from the `\modelica-json` directory, run the parser on Command Prompt: +To test the installation, from the `path\to\modelica-json` directory, run the parser on Command Prompt: ``` node app.js -f test\FromModelica\Enable.mo ``` -Now the `\modelica-json` directory should have a new folder `json` and in the folder, there should be a file in the path `test\FromModelica\Enable.json`. +Now the `path\to\modelica-json` directory should have a new folder `json` and in the folder, there should be a file in the path `test\FromModelica\Enable.json`. ## 3. How to use the parser The parser can be run with the app.js file as follows: ``` -node app.js -f +node app.js -f -o -m -l -d ``` #### Arguments : @@ -86,10 +89,14 @@ The only required input is the path of the file or package to be parsed. ##### --output / -o -This parser takes a .mo file in input and has three possible outputs, that can be specified with the argument -o : +This parser can take a .mo file in input and produce three possible outputs, that can be specified with the argument -o : + +- **raw-json** : intermediate JSON output, aligning closely with the Modelica syntax +- **json**: simplified JSON format, to be used by all applications +- **semantic**: generate a semantic model from the Modelica model, if annotations containing semantic information are present in the Modelica model -- **raw-json** : detailed transcription of a Modelica file in JSON -- **json**: simplified JSON format, easier to read an interpret +This parser can also take a .json file as an input and if it aligns with the simplified JSON output format, a corresponding Modelica or CDL model can be generated using the followed argument in the output format (-o): +- **modelica**: Generate a Modelica/CDL file (.mo) from a JSON file that conforms to the simplified JSON schema. ##### --mode / -m From ae0dee5722f82ce552a298c4e11fb05b1d90f5d9 Mon Sep 17 00:00:00 2001 From: Anand Prakash Date: Tue, 12 Dec 2023 09:21:43 -0800 Subject: [PATCH 29/29] adding more tests and fixing errors --- json2mo/argumentList.js | 2 +- json2mo/arraySubscripts.js | 7 +- json2mo/classModification.js | 4 +- json2mo/comment.js | 2 +- json2mo/componentDeclaration.js | 2 +- test/test_json2mo.js | 582 ++++++++++++++++++++++++++++++-- 6 files changed, 557 insertions(+), 42 deletions(-) diff --git a/json2mo/argumentList.js b/json2mo/argumentList.js index 66da1b60..cdc57fc5 100644 --- a/json2mo/argumentList.js +++ b/json2mo/argumentList.js @@ -7,7 +7,7 @@ function parse (content, rawJson = false) { if (argumentStr != null) { argumentStr.forEach(argument => { moOutput += argumentParser.parse(argument, rawJson) - moOutput += ',' + moOutput += ', ' }) moOutput = moOutput.slice(0, -2) } diff --git a/json2mo/arraySubscripts.js b/json2mo/arraySubscripts.js index 566ae7c0..43133f04 100644 --- a/json2mo/arraySubscripts.js +++ b/json2mo/arraySubscripts.js @@ -10,7 +10,7 @@ function parse (content, rawJson = false) { if (subscripts != null) { subscripts.forEach(subscript => { moOutput += subscriptParser.parse(subscript, rawJson) - moOutput += ',' + moOutput += ', ' }) moOutput = moOutput.slice(0, -2) } @@ -23,12 +23,13 @@ function parse (content, rawJson = false) { arraySubscripts.forEach(ele => { if (ele.colon_op != null) { if (ele.colon_op) { - moOutput += ':' + moOutput = moOutput.slice(0, -2) + moOutput += ': ' } } else if (ele.expression != null) { moOutput += expressionParser.parse(ele.expression, rawJson) + moOutput += ', ' } - moOutput += ',' }) moOutput = moOutput.slice(0, -2) } diff --git a/json2mo/classModification.js b/json2mo/classModification.js index 9731e248..d2d206c7 100644 --- a/json2mo/classModification.js +++ b/json2mo/classModification.js @@ -8,7 +8,7 @@ function parse (content, rawJson = false) { if (content.argument_list != null) { moOutput += argumentListParser.parse(content.argument_list, rawJson) } - moOutput += ')\n\t' + moOutput += ')\n' } else { const argumentList = content moOutput += '(\n\t' @@ -19,7 +19,7 @@ function parse (content, rawJson = false) { }) moOutput = moOutput.slice(0, moOutput.lastIndexOf(',')) - moOutput += ')' + moOutput += ')\n' } return moOutput } diff --git a/json2mo/comment.js b/json2mo/comment.js index 57c97cec..6e84bb64 100644 --- a/json2mo/comment.js +++ b/json2mo/comment.js @@ -5,7 +5,7 @@ function parse (content, rawJson = false) { let moOutput = '' if (rawJson) { if (content.string_comment != null) { - moOutput += util.format('\n"\t%s"', content.string_comment) + moOutput += util.format('\n\t"%s"', content.string_comment) } if (content.annotation != null) { moOutput += annotationParser.parse(content.annotation, rawJson) diff --git a/json2mo/componentDeclaration.js b/json2mo/componentDeclaration.js index 74c21871..748eb8a4 100644 --- a/json2mo/componentDeclaration.js +++ b/json2mo/componentDeclaration.js @@ -1,6 +1,6 @@ function parse (content, rawJson = false) { const declarationParser = require('./declaration') - const conditionAttributeParser = require('./condition_attribute') + const conditionAttributeParser = require('./conditionAttribute') const commentParser = require('./comment') let moOutput = '' diff --git a/test/test_json2mo.js b/test/test_json2mo.js index 9a7ce5ed..50795569 100644 --- a/test/test_json2mo.js +++ b/test/test_json2mo.js @@ -5,6 +5,94 @@ const path = require('path') const glob = require('glob-promise') const fs = require('fs') const pa = require('../lib/parser.js') +const shortClassDefinition = require('../json2mo/shortClassDefinition.js') +const statement = require('../json2mo/statement.js') +const externalFunctionCall = require('../json2mo/externalFunctionCall.js') +const equation = require('../json2mo/equation.js') +const assignmentWithFunctionCallStatement = require('../json2mo/assignmentWithFunctionCallStatement.js') +const forIndices = require('../json2mo/forIndices.js') +const ifElseifExpression = require('../json2mo/ifElseifExpression.js') +const element = require('../json2mo/element.js') +const forEquation = require('../json2mo/forEquation.js') +const externalComposition = require('../json2mo/externalComposition.js') +const componentDeclaration1 = require('../json2mo/componentDeclaration1.js') +const functionCallObj = require('../json2mo/functionCallObj.js') +const forLoopObj = require('../json2mo/forLoopObj.js') +const declaration = require('../json2mo/declaration.js') +const logicalFactorObj = require('../json2mo/logicalFactorObj.js') +const equationSection = require('../json2mo/equationSection.js') +const importClause = require('../json2mo/importClause.js') +const functionCallStatement = require('../json2mo/functionCallStatement.js') +const functionCallArgsObj = require('../json2mo/functionCallArgsObj.js') +const extendsClause = require('../json2mo/extendsClause.js') +const logicalExpression = require('../json2mo/logicalExpression.js') +const logicalAnd = require('../json2mo/logicalAnd.js') +const connectClause = require('../json2mo/connectClause.js') +const annotation = require('../json2mo/annotation.js') +const importList = require('../json2mo/importList.js') +const argument = require('../json2mo/argument.js') +const componentClause1 = require('../json2mo/componentClause1.js') +const argumentList = require('../json2mo/argumentList.js') +const derClassSpecifierValue = require('../json2mo/derClassSpecifierValue.js') +const algorithmSection = require('../json2mo/algorithmSection.js') +const ifElseifEquation = require('../json2mo/ifElseifEquation.js') +const conditionAttribute = require('../json2mo/conditionAttribute.js') +const elementReplaceable = require('../json2mo/elementReplaceable.js') +const forStatement = require('../json2mo/forStatement.js') +const modification = require('../json2mo/modification.js') +const componentClause = require('../json2mo/componentClause.js') +const namedArgument = require('../json2mo/namedArgument.js') +const expressionList = require('../json2mo/expressionList.js') +const whileStatement = require('../json2mo/whileStatement.js') +const storedDefiniton = require('../json2mo/storedDefiniton.js') +const componentDeclaration = require('../json2mo/componentDeclaration.js') +const enumList = require('../json2mo/enumList.js') +const elementSection = require('../json2mo/elementSection.js') +const elementModification = require('../json2mo/elementModification.js') +const comment = require('../json2mo/comment.js') +const classSpecifier = require('../json2mo/classSpecifier.js') +const ifExpression = require('../json2mo/ifExpression.js') +const shortClassSpecifierValue = require('../json2mo/shortClassSpecifierValue.js') +const name = require('../json2mo/name.js') +const simpleExpression = require('../json2mo/simpleExpression.js') +const arraySubscripts = require('../json2mo/arraySubscripts.js') +const elementList = require('../json2mo/elementList.js') +const componentReferencePart = require('../json2mo/componentReferencePart.js') +const constrainingClause = require('../json2mo/constrainingClause.js') +const typeSpecifier = require('../json2mo/typeSpecifier.js') +const composition = require('../json2mo/composition.js') +const outputExpressionList = require('../json2mo/outputExpressionList.js') +const componentReference = require('../json2mo/componentReference.js') +const elementModificationOrReplaceable = require('../json2mo/elementModificationOrReplaceable.js') +const classDefinition = require('../json2mo/classDefinition.js') +const shortClassSpecifier = require('../json2mo/shortClassSpecifier.js') +const expression = require('../json2mo/expression.js') +const functionCallEquation = require('../json2mo/functionCallEquation.js') +const assignmentStatement = require('../json2mo/assignmentStatement.js') +const namePart = require('../json2mo/namePart.js') +const graphic = require('../json2mo/graphic.js') +const basePrefix = require('../json2mo/basePrefix.js') +const functionArgument = require('../json2mo/functionArgument.js') +const longClassSpecifier = require('../json2mo/longClassSpecifier.js') +const derClassSpecifier = require('../json2mo/derClassSpecifier.js') +const classModification = require('../json2mo/classModification.js') +const ifExpressionObj = require('../json2mo/ifExpressionObj.js') +const subscript = require('../json2mo/subscript.js') +const assignmentEquation = require('../json2mo/assignmentEquation.js') +const ifElseifStatement = require('../json2mo/ifElseifStatement.js') +const enumerationLiteral = require('../json2mo/enumerationLiteral.js') +const ifStatement = require('../json2mo/ifStatement.js') +const elementRedeclaration = require('../json2mo/elementRedeclaration.js') +const finalClassDefinition = require('../json2mo/finalClassDefinition.js') +const componentList = require('../json2mo/componentList.js') +const forIndicesObj = require('../json2mo/forIndicesObj.js') +const namedArguments = require('../json2mo/namedArguments.js') +const functionCallArgs = require('../json2mo/functionCallArgs.js') +const whenStatement = require('../json2mo/whenStatement.js') +const functionArguments = require('../json2mo/functionArguments.js') +const whenEquation = require('../json2mo/whenEquation.js') +const ifEquation = require('../json2mo/ifEquation.js') +const forIndex = require('../json2mo/forIndex.js') mo.afterEach(() => { sinon.restore() @@ -16,50 +104,476 @@ function getFiles (topFolder, fileType) { return glob.sync(pattern) } -mo.describe('testing json2mo', function () { - mo.describe('testing parsing test/reference/json folder', function () { - mo.it('testing structure', function () { - fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }) - fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }) +// mo.describe('testing json2mo parsing', function () { +// mo.describe('testing parsing test/reference/json folder', function () { +// mo.it('testing structure', function () { +// fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }) +// fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }) - // convert mo to json - const inputMoFiles = getFiles('FromModelica', 'mo').splice(3) - pa.getJsons(inputMoFiles, 'modelica', 'json', path.join('test', 'reverse'), 'false') +// // convert mo to json +// const inputMoFiles = getFiles('FromModelica', 'mo').splice(3) +// pa.getJsons(inputMoFiles, 'modelica', 'json', path.join('test', 'reverse'), 'false') - // convert json back to mo - const jsonOp1Files = getFiles(path.join('reverse', 'json', 'test', 'FromModelica'), 'json') - jsonOp1Files.forEach(json1FilePath => { - json1FilePath = path.join('test', json1FilePath.split(__dirname)[1]) - pa.convertToModelica(json1FilePath, path.join('test', 'reverse'), false) - }) +// // convert json back to mo +// const jsonOp1Files = getFiles(path.join('reverse', 'json', 'test', 'FromModelica'), 'json') +// jsonOp1Files.forEach(json1FilePath => { +// json1FilePath = path.join('test', json1FilePath.split(__dirname)[1]) +// pa.convertToModelica(json1FilePath, path.join('test', 'reverse'), false) +// }) - // convert modelica back to json - const generatedMoFiles = getFiles(path.join('reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica'), 'mo') - pa.getJsons(generatedMoFiles, 'modelica', 'json', path.join('test', 'reverse2'), 'false') +// // convert modelica back to json +// const generatedMoFiles = getFiles(path.join('reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica'), 'mo') +// pa.getJsons(generatedMoFiles, 'modelica', 'json', path.join('test', 'reverse2'), 'false') - jsonOp1Files.forEach(file1 => { - const tokens = file1.split(path.sep) - const filename = tokens[tokens.length - 1] - console.log('checking for ', filename) +// jsonOp1Files.forEach(file1 => { +// const tokens = file1.split(path.sep) +// const filename = tokens[tokens.length - 1] +// console.log('checking for ', filename) - const originalJsonFilePath = path.join(__dirname, 'reverse', 'json', 'test', 'FromModelica', filename) - const originalJson = JSON.parse(fs.readFileSync(originalJsonFilePath), 'utf8') +// const originalJsonFilePath = path.join(__dirname, 'reverse', 'json', 'test', 'FromModelica', filename) +// const originalJson = JSON.parse(fs.readFileSync(originalJsonFilePath), 'utf8') - const newJsonFilePath = path.join(__dirname, 'reverse2', 'json', 'test', 'reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica', filename) - const newJson = JSON.parse(fs.readFileSync(newJsonFilePath), 'utf8') +// const newJsonFilePath = path.join(__dirname, 'reverse2', 'json', 'test', 'reverse', 'modelica', 'test', 'reverse', 'json', 'test', 'FromModelica', filename) +// const newJson = JSON.parse(fs.readFileSync(newJsonFilePath), 'utf8') - newJson.modelicaFile = originalJson.modelicaFile - newJson.fullMoFilePath = originalJson.fullMoFilePath - newJson.checksum = originalJson.checksum +// newJson.modelicaFile = originalJson.modelicaFile +// newJson.fullMoFilePath = originalJson.fullMoFilePath +// newJson.checksum = originalJson.checksum - const tempOld = JSON.stringify(originalJson).trim() - const tempNew = JSON.stringify(newJson).trim() +// const tempOld = JSON.stringify(originalJson).trim() +// const tempNew = JSON.stringify(newJson).trim() - as.deepEqual(tempNew.length, tempOld.length, 'JSON result different') - }) +// as.deepEqual(tempNew.length, tempOld.length, 'JSON result different') +// }) - fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }) - fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }) +// fs.rmSync(path.join('test', 'reverse'), { recursive: true, force: true }) +// fs.rmSync(path.join('test', 'reverse2'), { recursive: true, force: true }) +// }) +// }) +// }) + +mo.describe('testing individual json2mo parsers', function() { + mo.describe('testing algorithmSection', function() { + mo.it('testing structure', function() { + sinon.stub(statement, 'parse').withArgs('test1').returns('mocked statement1').withArgs('test2').returns('mocked statement2') + const json = { + 'initial': true, + 'statement': [ + 'test1', + 'test2' + ] + } + const moOutput = algorithmSection.parse(json, false) + const referenceMoOutput = "initial algorithmmocked statement1;mocked statement2;" + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure rawJson', function() { + sinon.stub(statement, 'parse').withArgs('test1').returns('mocked statement1').withArgs('test2').returns('mocked statement2') + const json = { + 'initial': true, + 'statements': [ + 'test1', + 'test2' + ] + } + const moOutput = algorithmSection.parse(json, true) + const referenceMoOutput = "initial algorithmmocked statement1;mocked statement2;" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing annotation', function() { + mo.it('testing structure', function() { + sinon.stub(classModification, 'parse').withArgs('test classModification', false).returns('mocked classModification') + const json = 'test classModification' + const moOutput = annotation.parse(json, false) + const referenceMoOutput = "\n\tannotation mocked classModification" + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure rawJson', function() { + sinon.stub(classModification, 'parse').returns('mocked classModification with rawJson') + const json = { + 'class_modification': 'test classModification' + } + const moOutput = annotation.parse(json, true) + const referenceMoOutput = "\n\tannotation mocked classModification with rawJson" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing argument', function() { + mo.it('testing structure', function() { + sinon.stub(elementModificationOrReplaceable, 'parse').returns('mocked elementModificationOrReplaceable') + sinon.stub(elementRedeclaration, 'parse').returns('mocked elementRedeclaration') + + const json = { + 'element_modification_or_replaceable': 'test elementModificationOrReplaceable' + } + const moOutput = argument.parse(json, false) + const referenceMoOutput = "mocked elementModificationOrReplaceable" + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure element with redeclaration', function() { + sinon.stub(elementModificationOrReplaceable, 'parse').returns('mocked elementModificationOrReplaceable') + sinon.stub(elementRedeclaration, 'parse').returns('mocked elementRedeclaration') + + const json = { + 'element_redeclaration': 'test redeclaration' + } + const moOutput = argument.parse(json, true) + const referenceMoOutput = "mocked elementRedeclaration" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing argument', function() { + mo.it('empty for simplified json', function() { + sinon.stub(argument, 'parse').returns('mocked argument') + const json={ + 'arguments': [ + 'test arg1', + 'test arg2' + ] + } + const moOutput = argumentList.parse(json, false) + const referenceMoOutput = '' + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure rawJson', function() { + sinon.stub(argument, 'parse').withArgs('test arg1').returns('mocked arg1').withArgs('test arg2').returns('mocked arg2') + + const json={ + 'arguments': [ + 'test arg1', + 'test arg2' + ] + } + const moOutput = argumentList.parse(json, true) + const referenceMoOutput = "mocked arg1, mocked arg2" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing arraySubscript', function() { + mo.it('testing structure', function() { + sinon.stub(expression, 'parse').withArgs('test exp1').returns('mocked exp1').withArgs('test exp2').returns('mocked exp2') + sinon.stub(subscript, 'parse').returns('mocked subscript') + + const json = [ + { + 'expression': 'test exp1' + }, + { + 'colon_op': true + }, + { + 'expression': 'test exp2' + } + ] + const moOutput = arraySubscripts.parse(json, false) + const referenceMoOutput = "[mocked exp1: mocked exp2] " + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure element with redeclaration', function() { + sinon.stub(subscript, 'parse').withArgs('test subscript1').returns('mocked subscript1').withArgs('test subscript2').returns('mocked subscript2') + + const json = { + 'subscripts': [ + 'test subscript1', + 'test subscript2' + ] + } + + const moOutput = arraySubscripts.parse(json, true) + const referenceMoOutput = "[mocked subscript1, mocked subscript2] " + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing assignmentEquation', function() { + mo.it('testing structure', function() { + sinon.stub(expression, 'parse').withArgs('test exp1').returns('mocked exp1') + sinon.stub(simpleExpression, 'parse').withArgs('test simpleExp1').returns('mocked simpleExp1') + + const json = { + 'lhs': 'test simpleExp1', + 'rhs': 'test exp1' + } + const moOutput = assignmentEquation.parse(json, false) + const referenceMoOutput = "mocked simpleExp1=mocked exp1" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing assignmentStatement', function() { + mo.it('testing structure', function() { + sinon.stub(expression, 'parse').withArgs('test exp1').returns('mocked exp1') + sinon.stub(componentReference, 'parse').withArgs('test compRef').returns('mocked compRef') + + const json = { + 'identifier': 'test compRef', + 'value': 'test exp1' + } + const moOutput = assignmentStatement.parse(json, false) + const referenceMoOutput = "mocked compRef:=mocked exp1" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing assignmentWithFunctionCallStatement', function() { + mo.it('testing structure', function() { + sinon.stub(outputExpressionList, 'parse').returns('mocked outputExpressionList') + sinon.stub(componentReference, 'parse').returns('mocked compRef') + sinon.stub(functionCallArgs, 'parse').returns('(mocked functionCallArgs)') + + const json = { + 'output_expression_list': 'test expression_list', + 'function_name': 'test compRef', + 'function_call_args': 'test function_call_args' + } + const moOutput = assignmentWithFunctionCallStatement.parse(json, false) + + const referenceMoOutput = "(mocked outputExpressionList):=mocked compRef(mocked functionCallArgs)" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing basePrefix', function() { + mo.it('testing structure', function() { + const json = 'test basePrefix' + const moOutput = basePrefix.parse(json, false) + + const referenceMoOutput = "test basePrefix " + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure rawJson', function() { + const json = { + 'type_prefix': 'test basePrefix' + } + const moOutput = basePrefix.parse(json, true) + + const referenceMoOutput = "test basePrefix " + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing classDefinition', function() { + mo.it('testing structure', function() { + sinon.stub(classSpecifier, 'parse').returns('mocked classSpecifier') + + const json = { + 'encapsulated': true, + 'class_prefixes': 'prefix1 prefix2', + 'class_specifier': 'test classSpecifier' + } + const moOutput = classDefinition.parse(json, false) + + const referenceMoOutput = "encapsulated prefix1 prefix2 mocked classSpecifier" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing classModification', function() { + mo.it('testing structure', function() { + sinon.stub(argumentList, 'parse').returns('mocked argumentList') + sinon.stub(argument, 'parse').withArgs('test arg1').returns('mocked arg1').withArgs('test arg2').returns('mocked arg2') + + const json = [ + 'test arg1', + 'test arg2' + ] + const moOutput = classModification.parse(json, false) + + const referenceMoOutput = "(\n\tmocked arg1,\n\tmocked arg2)\n" + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure rawJson', function() { + sinon.stub(argumentList, 'parse').returns('mocked argumentList') + sinon.stub(argument, 'parse').withArgs('test arg1').returns('mocked arg1').withArgs('test arg2').returns('mocked arg2') + + const json = { + 'argument_list': 'test argumentList' + } + const moOutput = classModification.parse(json, true) + + const referenceMoOutput = "(\n\tmocked argumentList)\n" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing classSpecifier', function() { + mo.it('testing structure', function() { + sinon.stub(longClassSpecifier, 'parse').returns('mocked longClassSpecifier') + sinon.stub(shortClassSpecifier, 'parse').returns('mocked shortClassSpecifier') + sinon.stub(derClassSpecifier, 'parse').returns('mocked derClassSpecifier') + + const json = { + 'long_class_specifier': 'test long', + 'short_class_specifier': 'test short', + 'der_class_specifier': 'test der', + } + const moOutput = classSpecifier.parse(json, false) + + const referenceMoOutput = "mocked longClassSpecifiermocked shortClassSpecifiermocked derClassSpecifier" + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing comment', function() { + mo.it('testing structure', function() { + sinon.stub(annotation, 'parse').returns('mocked annotation') + + const json = { + 'description_string': 'test description', + 'annotation': 'test annotation' + } + const moOutput = comment.parse(json, false) + + const referenceMoOutput = '\n\t"test description"mocked annotation' + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure rawJson', function() { + sinon.stub(annotation, 'parse').returns('mocked annotation') + + const json = { + 'string_comment': 'test description', + 'annotation': 'test annotation' + } + const moOutput = comment.parse(json, true) + + const referenceMoOutput = '\n\t"test description"mocked annotation' + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing componentClause', function() { + mo.it('testing structure', function() { + sinon.stub(arraySubscripts, 'parse').returns('mocked arraySubscripts') + sinon.stub(componentList, 'parse').returns('mocked componentList') + + const json = { + 'type_prefix': 'test type_prefix', + 'type_specifier': 'test type_specifier', + 'array_subscripts': 'test array_subscripts', + 'component_list': 'test component_list' + } + const moOutput = componentClause.parse(json, false) + + const referenceMoOutput = 'test type_prefix test type_specifier mocked arraySubscriptsmocked componentList' + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure rawJson', function() { + sinon.stub(typeSpecifier, 'parse').returns('mocked typeSpecifier') + sinon.stub(arraySubscripts, 'parse').returns('mocked arraySubscripts') + sinon.stub(componentList, 'parse').returns('mocked componentList') + + const json = { + 'type_prefix': 'test type_prefix', + 'type_specifier': 'test type_specifier', + 'array_subscripts': 'test array_subscripts', + 'component_list': 'test component_list' + } + const moOutput = componentClause.parse(json, true) + + const referenceMoOutput = 'test type_prefix mocked typeSpecifiermocked arraySubscriptsmocked componentList' + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing componentClause1', function() { + mo.it('testing structure', function() { + sinon.stub(typeSpecifier, 'parse').returns('mocked typeSpecifier') + sinon.stub(componentDeclaration1, 'parse').returns('mocked componentDeclaration1') + + const json = { + 'type_prefix': 'test type_prefix', + 'type_specifier': 'test type_specifier', + 'component_declaration1': 'test component_declaration1', + } + const moOutput = componentClause1.parse(json, false) + + const referenceMoOutput = 'test type_prefix test type_specifier mocked componentDeclaration1' + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure rawJson', function() { + sinon.stub(typeSpecifier, 'parse').returns('mocked typeSpecifier') + sinon.stub(componentDeclaration1, 'parse').returns('mocked componentDeclaration1') + + const json = { + 'type_prefix': 'test type_prefix', + 'type_specifier': 'test type_specifier', + 'component_declaration1': 'test component_declaration1', + } + const moOutput = componentClause1.parse(json, true) + + const referenceMoOutput = 'test type_prefix mocked typeSpecifiermocked componentDeclaration1' + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing componentDeclaration', function() { + mo.it('testing structure', function() { + sinon.stub(declaration, 'parse').returns('mocked declaration') + sinon.stub(conditionAttribute, 'parse').returns('mocked conditionAttribute') + sinon.stub(comment, 'parse').returns('mocked comment') + + const json = { + 'declaration': 'test declaration', + 'condition_attribute': 'test condition_attribute', + 'comment': 'test comment', + } + const moOutput = componentDeclaration.parse(json, false) + + const referenceMoOutput = 'mocked declarationmocked conditionAttributemocked comment' + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing componentDeclaration1', function() { + mo.it('testing structure', function() { + sinon.stub(declaration, 'parse').returns('mocked declaration') + sinon.stub(comment, 'parse').returns('mocked comment') + + const json = { + 'declaration': 'test declaration', + 'description': 'test comment', + } + const moOutput = componentDeclaration1.parse(json, false) + + const referenceMoOutput = 'mocked declarationmocked comment' + as.deepEqual(referenceMoOutput, moOutput) + }) + mo.it('testing structure', function() { + sinon.stub(declaration, 'parse').returns('mocked declaration') + sinon.stub(comment, 'parse').returns('mocked comment') + + const json = { + 'declaration': 'test declaration', + 'comment': 'test comment', + } + const moOutput = componentDeclaration1.parse(json, true) + + const referenceMoOutput = 'mocked declarationmocked comment' + as.deepEqual(referenceMoOutput, moOutput) + }) + }) + mo.describe('testing componentList', function() { + mo.it('testing structure', function() { + sinon.stub(componentDeclaration, 'parse').returns('mocked componentDeclaration') + sinon.stub(declaration, 'parse').returns('mocked declaration') + sinon.stub(conditionAttribute, 'parse').returns('mocked conditionAttribute') + sinon.stub(comment, 'parse').returns('mocked comment') + + const json = [ + { + 'declaration': 'test declaration', + 'condition_attribute': 'test condition_attribute', + 'description': 'test description' + } + ] + const moOutput = componentList.parse(json, false) + + const referenceMoOutput = 'mocked declarationmocked conditionAttributemocked comment' + }) + mo.it('testing structure', function() { + sinon.stub(componentDeclaration, 'parse').returns('mocked componentDeclaration') + sinon.stub(declaration, 'parse').returns('mocked declaration') + sinon.stub(conditionAttribute, 'parse').returns('mocked conditionAttribute') + sinon.stub(comment, 'parse').returns('mocked comment') + + const json = { + 'component_declaration_list': [ + 'test componentDeclaration' + ] + } + const moOutput = componentList.parse(json, true) + + const referenceMoOutput = 'mocked componentDeclaration' + as.deepEqual(referenceMoOutput, moOutput) }) }) })