diff --git a/.rubocop.yml b/.rubocop.yml index 6da549fa..8e612531 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,19 +1,14 @@ +require: + - rubocop-performance + inherit_from: - - .rubocop_todo.yml - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml + - .rubocop_todo.yml -AllCops: - TargetRubyVersion: 2.7 - NewCops: enable - SuggestExtensions: false +Naming/VariableName: Exclude: - - 'vendor/**/*' - - 'expressir.gemspec' - - 'tmp/**/*' - - 'pkg/**/*' - - 'exe/format-test' - - 'lib/expressir/express/**/*' - - 'lib/expressir/model/**/*' - + - lib/expressir/express/visitor.rb Layout/LineLength: Max: 160 +AllCops: + TargetRubyVersion: 2.7 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2a0e1a1a..19c05eb4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,21 +1,84 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-11-19 15:15:51 UTC using RuboCop version 1.68.0. +# on 2024-11-26 21:06:12 UTC using RuboCop version 1.68.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 1 +# Configuration parameters: AllowedParentClasses. +Lint/MissingSuper: + Exclude: + - 'lib/expressir/model/cache.rb' + +# Offense count: 3 +Lint/ShadowingOuterLocalVariable: + Exclude: + - 'lib/expressir/express/visitor.rb' + +# Offense count: 2 # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. -# URISchemes: http, https -Layout/LineLength: +# Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. +Lint/UnusedMethodArgument: Exclude: - - 'exe/expressir-format-test' + - 'lib/expressir/express/parser.rb' + +# Offense count: 54 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max. +Metrics/AbcSize: + Exclude: + - 'lib/expressir/express/formatter.rb' + - 'lib/expressir/express/hyperlink_formatter.rb' + - 'lib/expressir/express/resolve_references_model_visitor.rb' + - 'lib/expressir/express/visitor.rb' + - 'lib/expressir/model/declarations/function.rb' + - 'lib/expressir/model/declarations/procedure.rb' + - 'lib/expressir/model/declarations/rule.rb' + - 'lib/expressir/model/declarations/schema.rb' + - 'lib/expressir/model/model_element.rb' # Offense count: 1 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. # AllowedMethods: refine Metrics/BlockLength: - Max: 36 + Max: 29 + +# Offense count: 40 +# Configuration parameters: AllowedMethods, AllowedPatterns, Max. +Metrics/CyclomaticComplexity: + Exclude: + - 'lib/expressir/express/formatter.rb' + - 'lib/expressir/express/visitor.rb' + - 'lib/expressir/model/declarations/function.rb' + - 'lib/expressir/model/declarations/procedure.rb' + - 'lib/expressir/model/declarations/rule.rb' + - 'lib/expressir/model/declarations/schema.rb' + - 'lib/expressir/model/model_element.rb' + +# Offense count: 74 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 135 + +# Offense count: 36 +# Configuration parameters: AllowedMethods, AllowedPatterns, Max. +Metrics/PerceivedComplexity: + Exclude: + - 'lib/expressir/express/formatter.rb' + - 'lib/expressir/express/visitor.rb' + - 'lib/expressir/model/declarations/function.rb' + - 'lib/expressir/model/declarations/procedure.rb' + - 'lib/expressir/model/declarations/rule.rb' + - 'lib/expressir/model/declarations/schema.rb' + - 'lib/expressir/model/model_element.rb' + +# Offense count: 5 +Performance/FixedSize: + Exclude: + - 'lib/expressir/express/formatter.rb' + +# Offense count: 1 +Style/MissingRespondToMissing: + Exclude: + - 'lib/expressir/express/visitor.rb' diff --git a/Gemfile b/Gemfile index 543182c0..ee1f92d9 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ gem "pry" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 1.21" -gem "rubocop-performance", require: false +gem "rubocop-performance" gem "rubocop-rake", require: false gem "rubocop-rspec", require: false gem "webrick", "~> 1.7" diff --git a/exe/expressir-format-test b/exe/expressir-format-test index 69197818..a2833cde 100755 --- a/exe/expressir-format-test +++ b/exe/expressir-format-test @@ -49,7 +49,8 @@ exp_files = [ "../iso-10303-stepmod/data/resources/security_classification_schema/security_classification_schema_annotated.exp", "../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp", # full test (6m18s + 8s = 6m26s) - # *`bundle exec ../stepmod-utils/exe/stepmod-find-express-files ../iso-10303-stepmod`.strip.split("\n").map{|file| File.exists?(file.sub(/\.exp$/, '_annotated.exp')) ? file.sub(/\.exp$/, '_annotated.exp') : file} + # *`bundle exec ../stepmod-utils/exe/stepmod-find-express-files ../iso-10303-stepmod`.strip + # .split("\n").map{|file| File.exists?(file.sub(/\.exp$/, '_annotated.exp')) ? file.sub(/\.exp$/, '_annotated.exp') : file} ] start = Time.now diff --git a/expressir.gemspec b/expressir.gemspec index 81f32495..758281f0 100644 --- a/expressir.gemspec +++ b/expressir.gemspec @@ -16,7 +16,6 @@ Gem::Specification.new do |spec| spec.bindir = "exe" spec.require_paths = ["lib"] - spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0") spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage @@ -33,7 +32,7 @@ Gem::Specification.new do |spec| spec.test_files = `git ls-files -- {spec}/*`.split("\n") - spec.add_dependency "thor", "~> 1.0" - spec.add_dependency "parslet", "~> 2.0" spec.add_dependency "liquid" + spec.add_dependency "parslet", "~> 2.0" + spec.add_dependency "thor", "~> 1.0" end diff --git a/lib/expressir/express/cache.rb b/lib/expressir/express/cache.rb index 208298c0..1666c587 100644 --- a/lib/expressir/express/cache.rb +++ b/lib/expressir/express/cache.rb @@ -1,6 +1,6 @@ -require 'yaml' -require 'zlib' -require 'expressir/model' +require "yaml" +require "zlib" +require "expressir/model" module Expressir module Express @@ -16,7 +16,7 @@ def self.to_file(file, content, root_path: nil, test_overwrite_version: nil) cache = Model::Cache.new( version: version, - content: content + content: content, ) hash = cache.to_hash(root_path: root_path) @@ -37,7 +37,7 @@ def self.from_file(file, root_path: nil, test_overwrite_version: nil) yaml_compressed = File.binread(file) yaml = Zlib::Inflate.inflate(yaml_compressed) - hash = YAML.load(yaml) + hash = YAML.safe_load(yaml) cache = Model::ModelElement.from_hash(hash, root_path: root_path) if cache.version != version @@ -48,4 +48,4 @@ def self.from_file(file, root_path: nil, test_overwrite_version: nil) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/express/formatter.rb b/lib/expressir/express/formatter.rb index 4d2f2dfa..87ab4fce 100644 --- a/lib/expressir/express/formatter.rb +++ b/lib/expressir/express/formatter.rb @@ -3,7 +3,7 @@ module Expressir module Express class Formatter - INDENT_CHAR = " " + INDENT_CHAR = " ".freeze INDENT_WIDTH = 2 INDENT = INDENT_CHAR * INDENT_WIDTH OPERATOR_PRECEDENCE = { @@ -28,11 +28,11 @@ class Formatter Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL => 4, Model::Expressions::BinaryExpression::IN => 4, Model::Expressions::BinaryExpression::LIKE => 4, - } + }.freeze SUPERTYPE_OPERATOR_PRECEDENCE = { Model::SupertypeExpressions::BinarySupertypeExpression::AND => 1, Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR => 2, - } + }.freeze private_constant :INDENT_CHAR private_constant :INDENT_WIDTH @@ -44,7 +44,7 @@ class Formatter # @param [Model::ModelElement] node # @return [String] def self.format(node) - formatter = self.new + formatter = new formatter.format(node) end @@ -52,138 +52,139 @@ def self.format(node) # @param [Model::ModelElement] node # @return [String] def format(node) - if node.is_a? Model::Repository + case node + when Model::Repository format_repository(node) - elsif node.is_a? Model::Declarations::Attribute + when Model::Declarations::Attribute format_declarations_attribute(node) - elsif node.is_a? Model::Declarations::Constant + when Model::Declarations::Constant format_declarations_constant(node) - elsif node.is_a? Model::Declarations::Entity + when Model::Declarations::Entity format_declarations_entity(node) - elsif node.is_a? Model::Declarations::Function + when Model::Declarations::Function format_declarations_function(node) - elsif node.is_a? Model::Declarations::Interface + when Model::Declarations::Interface format_declarations_interface(node) - elsif node.is_a? Model::Declarations::InterfaceItem + when Model::Declarations::InterfaceItem format_declarations_interface_item(node) - elsif node.is_a? Model::Declarations::Parameter + when Model::Declarations::Parameter format_declarations_parameter(node) - elsif node.is_a? Model::Declarations::Procedure + when Model::Declarations::Procedure format_declarations_procedure(node) - elsif node.is_a? Model::Declarations::Rule + when Model::Declarations::Rule format_declarations_rule(node) - elsif node.is_a? Model::Declarations::Schema + when Model::Declarations::Schema format_declarations_schema(node) - elsif node.is_a? Model::Declarations::SchemaVersion + when Model::Declarations::SchemaVersion format_declarations_schema_version(node) - elsif node.is_a? Model::Declarations::SubtypeConstraint + when Model::Declarations::SubtypeConstraint format_declarations_subtype_constraint(node) - elsif node.is_a? Model::Declarations::Type + when Model::Declarations::Type format_declarations_type(node) - elsif node.is_a? Model::Declarations::UniqueRule + when Model::Declarations::UniqueRule format_declarations_unique_rule(node) - elsif node.is_a? Model::Declarations::Variable + when Model::Declarations::Variable format_declarations_variable(node) - elsif node.is_a? Model::Declarations::WhereRule + when Model::Declarations::WhereRule format_declarations_where_rule(node) - elsif node.is_a? Model::DataTypes::Aggregate + when Model::DataTypes::Aggregate format_data_types_aggregate(node) - elsif node.is_a? Model::DataTypes::Array + when Model::DataTypes::Array format_data_types_array(node) - elsif node.is_a? Model::DataTypes::Bag + when Model::DataTypes::Bag format_data_types_bag(node) - elsif node.is_a? Model::DataTypes::Binary + when Model::DataTypes::Binary format_data_types_binary(node) - elsif node.is_a? Model::DataTypes::Boolean + when Model::DataTypes::Boolean format_data_types_boolean(node) - elsif node.is_a? Model::DataTypes::Enumeration + when Model::DataTypes::Enumeration format_data_types_enumeration(node) - elsif node.is_a? Model::DataTypes::EnumerationItem + when Model::DataTypes::EnumerationItem format_data_types_enumeration_item(node) - elsif node.is_a? Model::DataTypes::GenericEntity + when Model::DataTypes::GenericEntity format_data_types_generic_entity(node) - elsif node.is_a? Model::DataTypes::Generic + when Model::DataTypes::Generic format_data_types_generic(node) - elsif node.is_a? Model::DataTypes::Integer + when Model::DataTypes::Integer format_data_types_integer(node) - elsif node.is_a? Model::DataTypes::List + when Model::DataTypes::List format_data_types_list(node) - elsif node.is_a? Model::DataTypes::Logical + when Model::DataTypes::Logical format_data_types_logical(node) - elsif node.is_a? Model::DataTypes::Number + when Model::DataTypes::Number format_data_types_number(node) - elsif node.is_a? Model::DataTypes::Real + when Model::DataTypes::Real format_data_types_real(node) - elsif node.is_a? Model::DataTypes::Select + when Model::DataTypes::Select format_data_types_select(node) - elsif node.is_a? Model::DataTypes::Set + when Model::DataTypes::Set format_data_types_set(node) - elsif node.is_a? Model::DataTypes::String + when Model::DataTypes::String format_data_types_string(node) - elsif node.is_a? Model::Expressions::AggregateInitializer + when Model::Expressions::AggregateInitializer format_expressions_aggregate_initializer(node) - elsif node.is_a? Model::Expressions::AggregateInitializerItem + when Model::Expressions::AggregateInitializerItem format_expressions_aggregate_initializer_item(node) - elsif node.is_a? Model::Expressions::BinaryExpression + when Model::Expressions::BinaryExpression format_expressions_binary_expression(node) - elsif node.is_a? Model::Expressions::EntityConstructor + when Model::Expressions::EntityConstructor format_expressions_entity_constructor(node) - elsif node.is_a? Model::Expressions::FunctionCall + when Model::Expressions::FunctionCall format_expressions_function_call(node) - elsif node.is_a? Model::Expressions::Interval + when Model::Expressions::Interval format_expressions_interval(node) - elsif node.is_a? Model::Expressions::QueryExpression + when Model::Expressions::QueryExpression format_expressions_query_expression(node) - elsif node.is_a? Model::Expressions::UnaryExpression + when Model::Expressions::UnaryExpression format_expressions_unary_expression(node) - elsif node.is_a? Model::Literals::Binary + when Model::Literals::Binary format_literals_binary(node) - elsif node.is_a? Model::Literals::Integer + when Model::Literals::Integer format_literals_integer(node) - elsif node.is_a? Model::Literals::Logical + when Model::Literals::Logical format_literals_logical(node) - elsif node.is_a? Model::Literals::Real + when Model::Literals::Real format_literals_real(node) - elsif node.is_a? Model::Literals::String + when Model::Literals::String format_literals_string(node) - elsif node.is_a? Model::References::AttributeReference + when Model::References::AttributeReference format_references_attribute_reference(node) - elsif node.is_a? Model::References::GroupReference + when Model::References::GroupReference format_references_group_reference(node) - elsif node.is_a? Model::References::IndexReference + when Model::References::IndexReference format_references_index_reference(node) - elsif node.is_a? Model::References::SimpleReference + when Model::References::SimpleReference format_references_simple_reference(node) - elsif node.is_a? Model::Statements::Alias + when Model::Statements::Alias format_statements_alias(node) - elsif node.is_a? Model::Statements::Assignment + when Model::Statements::Assignment format_statements_assignment(node) - elsif node.is_a? Model::Statements::Case + when Model::Statements::Case format_statements_case(node) - elsif node.is_a? Model::Statements::CaseAction + when Model::Statements::CaseAction format_statements_case_action(node) - elsif node.is_a? Model::Statements::Compound + when Model::Statements::Compound format_statements_compound(node) - elsif node.is_a? Model::Statements::Escape + when Model::Statements::Escape format_statements_escape(node) - elsif node.is_a? Model::Statements::If + when Model::Statements::If format_statements_if(node) - elsif node.is_a? Model::Statements::Null + when Model::Statements::Null format_statements_null(node) - elsif node.is_a? Model::Statements::ProcedureCall + when Model::Statements::ProcedureCall format_statements_procedure_call(node) - elsif node.is_a? Model::Statements::Repeat + when Model::Statements::Repeat format_statements_repeat(node) - elsif node.is_a? Model::Statements::Return + when Model::Statements::Return format_statements_return(node) - elsif node.is_a? Model::Statements::Skip + when Model::Statements::Skip format_statements_skip(node) - elsif node.is_a? Model::SupertypeExpressions::BinarySupertypeExpression + when Model::SupertypeExpressions::BinarySupertypeExpression format_supertype_expressions_binary_supertype_expression(node) - elsif node.is_a? Model::SupertypeExpressions::OneofSupertypeExpression + when Model::SupertypeExpressions::OneofSupertypeExpression format_supertype_expressions_oneof_supertype_expression(node) else - STDERR.puts "#{node.class.name} format not implemented" + warn "#{node.class.name} format not implemented" "" end end @@ -197,47 +198,47 @@ def format_repository(node) def format_declarations_attribute(node) [ *if node.supertype_attribute - [ - format(node.supertype_attribute), - " ", - ].join("") - end, - *if node.supertype_attribute and node.id - [ - "RENAMED", - " ", - ].join("") - end, + [ + format(node.supertype_attribute), + " ", + ].join("") + end, + *if node.supertype_attribute && node.id + [ + "RENAMED", + " ", + ].join("") + end, *if node.id - [ - node.id, - " ", - ].join("") - end, + [ + node.id, + " ", + ].join("") + end, ":", *if node.optional - [ - " ", - "OPTIONAL", - ].join("") - end, + [ + " ", + "OPTIONAL", + ].join("") + end, " ", format(node.type), *if node.kind == Model::Declarations::Attribute::DERIVED - [ - " ", - ":=", - " ", - format(node.expression), - ].join("") - elsif node.kind == Model::Declarations::Attribute::INVERSE - [ - " ", - "FOR", - " ", - format(node.expression), - ].join("") - end, + [ + " ", + ":=", + " ", + format(node.expression), + ].join("") + elsif node.kind == Model::Declarations::Attribute::INVERSE + [ + " ", + "FOR", + " ", + format(node.expression), + ].join("") + end, ";", ].join("") end @@ -267,89 +268,89 @@ def format_declarations_entity(node) "ENTITY", " ", node.id, - *if node.abstract and !node.supertype_expression - [ - "\n", - indent([ - "ABSTRACT", - " ", - "SUPERTYPE", - ].join("")), - ].join("") - end, - *if node.abstract and node.supertype_expression - [ - "\n", - indent([ - "ABSTRACT", - " ", - "SUPERTYPE", - " ", - "OF", - " ", - "(", - format(node.supertype_expression), - ")", - ].join("")), - ].join("") - end, - *if !node.abstract and node.supertype_expression - [ - "\n", - indent([ - "SUPERTYPE", - " ", - "OF", - " ", - "(", - format(node.supertype_expression), - ")", - ].join("")), - ].join("") - end, - *if node.subtype_of.length > 0 - [ - "\n", - indent([ - "SUBTYPE", - " ", - "OF", - " ", - "(", - node.subtype_of.map { |x| format(x) }.join(", "), - ")", - ].join("")), - ].join("") - end, + *if node.abstract && !node.supertype_expression + [ + "\n", + indent([ + "ABSTRACT", + " ", + "SUPERTYPE", + ].join("")), + ].join("") + end, + *if node.abstract && node.supertype_expression + [ + "\n", + indent([ + "ABSTRACT", + " ", + "SUPERTYPE", + " ", + "OF", + " ", + "(", + format(node.supertype_expression), + ")", + ].join("")), + ].join("") + end, + *if !node.abstract && node.supertype_expression + [ + "\n", + indent([ + "SUPERTYPE", + " ", + "OF", + " ", + "(", + format(node.supertype_expression), + ")", + ].join("")), + ].join("") + end, + *if node.subtype_of.length.positive? + [ + "\n", + indent([ + "SUBTYPE", + " ", + "OF", + " ", + "(", + node.subtype_of.map { |x| format(x) }.join(", "), + ")", + ].join("")), + ].join("") + end, ";", ].join(""), - *if explicit_attributes and explicit_attributes.length > 0 - indent(explicit_attributes.map { |x| format(x) }.join("\n")) - end, - *if derived_attributes and derived_attributes.length > 0 - [ - "DERIVE", - indent(derived_attributes.map { |x| format(x) }.join("\n")), - ] - end, - *if inverse_attributes and inverse_attributes.length > 0 - [ - "INVERSE", - indent(inverse_attributes.map { |x| format(x) }.join("\n")), - ] - end, - *if node.unique_rules.length > 0 - [ - "UNIQUE", - indent(node.unique_rules.map { |x| format(x) }.join("\n")), - ] - end, - *if node.where_rules.length > 0 - [ - "WHERE", - indent(node.where_rules.map { |x| format(x) }.join("\n")), - ] - end, + *if explicit_attributes&.length&.positive? + indent(explicit_attributes.map { |x| format(x) }.join("\n")) + end, + *if derived_attributes&.length&.positive? + [ + "DERIVE", + indent(derived_attributes.map { |x| format(x) }.join("\n")), + ] + end, + *if inverse_attributes&.length&.positive? + [ + "INVERSE", + indent(inverse_attributes.map { |x| format(x) }.join("\n")), + ] + end, + *if node.unique_rules.length.positive? + [ + "UNIQUE", + indent(node.unique_rules.map { |x| format(x) }.join("\n")), + ] + end, + *if node.where_rules.length.positive? + [ + "WHERE", + indent(node.where_rules.map { |x| format(x) }.join("\n")), + ] + end, [ "END_ENTITY", ";", @@ -363,58 +364,58 @@ def format_declarations_function(node) "FUNCTION", " ", node.id, - *if node.parameters.length > 0 - parameter_indent = INDENT_CHAR * "FUNCTION #{node.id}(".length - [ - "(", - node.parameters.map { |x| format(x) }.join(";\n#{parameter_indent}"), - ")", - ].join("") - end, + *if node.parameters.length.positive? + parameter_indent = INDENT_CHAR * "FUNCTION #{node.id}(".length + [ + "(", + node.parameters.map { |x| format(x) }.join(";\n#{parameter_indent}"), + ")", + ].join("") + end, " ", ":", " ", format(node.return_type), ";", ].join(""), - *if node.types.length > 0 - indent(node.types.map { |x| format(x) }.join("\n")) - end, - *if node.entities.length > 0 - indent(node.entities.map { |x| format(x) }.join("\n")) - end, - *if node.subtype_constraints.length > 0 - indent(node.subtype_constraints.map { |x| format(x) }.join("\n")) - end, - *if node.functions.length > 0 - indent(node.functions.map { |x| format(x) }.join("\n")) - end, - *if node.procedures.length > 0 - indent(node.procedures.map { |x| format(x) }.join("\n")) - end, - *if node.constants.length > 0 - indent([ - "CONSTANT", - indent(node.constants.map { |x| format(x) }.join("\n")), - [ - "END_CONSTANT", - ";", - ].join(""), - ].join("\n")) - end, - *if node.variables.length > 0 - indent([ - "LOCAL", - indent(node.variables.map { |x| format(x) }.join("\n")), - [ - "END_LOCAL", - ";", - ].join(""), - ].join("\n")) - end, - *if node.statements.length > 0 - indent(node.statements.map { |x| format(x) }.join("\n")) - end, + *if node.types.length.positive? + indent(node.types.map { |x| format(x) }.join("\n")) + end, + *if node.entities.length.positive? + indent(node.entities.map { |x| format(x) }.join("\n")) + end, + *if node.subtype_constraints.length.positive? + indent(node.subtype_constraints.map { |x| format(x) }.join("\n")) + end, + *if node.functions.length.positive? + indent(node.functions.map { |x| format(x) }.join("\n")) + end, + *if node.procedures.length.positive? + indent(node.procedures.map { |x| format(x) }.join("\n")) + end, + *if node.constants.length.positive? + indent([ + "CONSTANT", + indent(node.constants.map { |x| format(x) }.join("\n")), + [ + "END_CONSTANT", + ";", + ].join(""), + ].join("\n")) + end, + *if node.variables.length.positive? + indent([ + "LOCAL", + indent(node.variables.map { |x| format(x) }.join("\n")), + [ + "END_LOCAL", + ";", + ].join(""), + ].join("\n")) + end, + *if node.statements.length.positive? + indent(node.statements.map { |x| format(x) }.join("\n")) + end, [ "END_FUNCTION", ";", @@ -432,17 +433,17 @@ def format_declarations_interface(node) "FROM", " ", format(node.schema), - *if node.items.length > 0 - item_indent = INDENT_CHAR * "(".length - [ - "\n", - indent([ - "(", - node.items.map { |x| format(x) }.join(",\n#{item_indent}"), - ")", - ].join("")), - ].join("") - end, + *if node.items.length.positive? + item_indent = INDENT_CHAR * "(".length + [ + "\n", + indent([ + "(", + node.items.map { |x| format(x) }.join(",\n#{item_indent}"), + ")", + ].join("")), + ].join("") + end, ";", ].join("") end @@ -451,24 +452,24 @@ def format_declarations_interface_item(node) [ format(node.ref), *if node.id - [ - " ", - "AS", - " ", - node.id, - ] - end, + [ + " ", + "AS", + " ", + node.id, + ] + end, ].join("") end def format_declarations_parameter(node) [ *if node.var - [ - "VAR", - " ", - ].join("") - end, + [ + "VAR", + " ", + ].join("") + end, node.id, " ", ":", @@ -483,54 +484,54 @@ def format_declarations_procedure(node) "PROCEDURE", " ", node.id, - *if node.parameters.length > 0 - parameter_indent = INDENT_CHAR * "PROCEDURE #{node.id}(".length - [ - "(", - node.parameters.map { |x| format(x) }.join(";\n#{parameter_indent}"), - ")", - ].join("") - end, + *if node.parameters.length.positive? + parameter_indent = INDENT_CHAR * "PROCEDURE #{node.id}(".length + [ + "(", + node.parameters.map { |x| format(x) }.join(";\n#{parameter_indent}"), + ")", + ].join("") + end, ";", ].join(""), - *if node.types.length > 0 - indent(node.types.map { |x| format(x) }.join("\n")) - end, - *if node.entities.length > 0 - indent(node.entities.map { |x| format(x) }.join("\n")) - end, - *if node.subtype_constraints.length > 0 - indent(node.subtype_constraints.map { |x| format(x) }.join("\n")) - end, - *if node.functions.length > 0 - indent(node.functions.map { |x| format(x) }.join("\n")) - end, - *if node.procedures.length > 0 - indent(node.procedures.map { |x| format(x) }.join("\n")) - end, - *if node.constants.length > 0 - indent([ - "CONSTANT", - indent(node.constants.map { |x| format(x) }.join("\n")), - [ - "END_CONSTANT", - ";", - ].join(""), - ].join("\n")) - end, - *if node.variables.length > 0 - indent([ - "LOCAL", - indent(node.variables.map { |x| format(x) }.join("\n")), - [ - "END_LOCAL", - ";", - ].join(""), - ].join("\n")) - end, - *if node.statements.length > 0 - indent(node.statements.map { |x| format(x) }.join("\n")) - end, + *if node.types.length.positive? + indent(node.types.map { |x| format(x) }.join("\n")) + end, + *if node.entities.length.positive? + indent(node.entities.map { |x| format(x) }.join("\n")) + end, + *if node.subtype_constraints.length.positive? + indent(node.subtype_constraints.map { |x| format(x) }.join("\n")) + end, + *if node.functions.length.positive? + indent(node.functions.map { |x| format(x) }.join("\n")) + end, + *if node.procedures.length.positive? + indent(node.procedures.map { |x| format(x) }.join("\n")) + end, + *if node.constants.length.positive? + indent([ + "CONSTANT", + indent(node.constants.map { |x| format(x) }.join("\n")), + [ + "END_CONSTANT", + ";", + ].join(""), + ].join("\n")) + end, + *if node.variables.length.positive? + indent([ + "LOCAL", + indent(node.variables.map { |x| format(x) }.join("\n")), + [ + "END_LOCAL", + ";", + ].join(""), + ].join("\n")) + end, + *if node.statements.length.positive? + indent(node.statements.map { |x| format(x) }.join("\n")) + end, [ "END_PROCEDURE", ";", @@ -552,50 +553,50 @@ def format_declarations_rule(node) ")", ";", ].join(""), - *if node.types.length > 0 - indent(node.types.map { |x| format(x) }.join("\n")) - end, - *if node.entities.length > 0 - indent(node.entities.map { |x| format(x) }.join("\n")) - end, - *if node.subtype_constraints.length > 0 - indent(node.subtype_constraints.map { |x| format(x) }.join("\n")) - end, - *if node.functions.length > 0 - indent(node.functions.map { |x| format(x) }.join("\n")) - end, - *if node.procedures.length > 0 - indent(node.procedures.map { |x| format(x) }.join("\n")) - end, - *if node.constants.length > 0 - indent([ - "CONSTANT", - indent(node.constants.map { |x| format(x) }.join("\n")), - [ - "END_CONSTANT", - ";", - ].join(""), - ].join("\n")) - end, - *if node.variables.length > 0 - indent([ - "LOCAL", - indent(node.variables.map { |x| format(x) }.join("\n")), - [ - "END_LOCAL", - ";", - ].join(""), - ].join("\n")) - end, - *if node.statements.length > 0 - indent(node.statements.map { |x| format(x) }.join("\n")) - end, - *if node.where_rules.length > 0 - [ - "WHERE", - indent(node.where_rules.map { |x| format(x) }.join("\n")), - ] - end, + *if node.types.length.positive? + indent(node.types.map { |x| format(x) }.join("\n")) + end, + *if node.entities.length.positive? + indent(node.entities.map { |x| format(x) }.join("\n")) + end, + *if node.subtype_constraints.length.positive? + indent(node.subtype_constraints.map { |x| format(x) }.join("\n")) + end, + *if node.functions.length.positive? + indent(node.functions.map { |x| format(x) }.join("\n")) + end, + *if node.procedures.length.positive? + indent(node.procedures.map { |x| format(x) }.join("\n")) + end, + *if node.constants.length.positive? + indent([ + "CONSTANT", + indent(node.constants.map { |x| format(x) }.join("\n")), + [ + "END_CONSTANT", + ";", + ].join(""), + ].join("\n")) + end, + *if node.variables.length.positive? + indent([ + "LOCAL", + indent(node.variables.map { |x| format(x) }.join("\n")), + [ + "END_LOCAL", + ";", + ].join(""), + ].join("\n")) + end, + *if node.statements.length.positive? + indent(node.statements.map { |x| format(x) }.join("\n")) + end, + *if node.where_rules.length.positive? + [ + "WHERE", + indent(node.where_rules.map { |x| format(x) }.join("\n")), + ] + end, [ "END_RULE", ";", @@ -610,63 +611,63 @@ def format_declarations_schema_head(node) " ", node.id, *if node.version - [ - " ", - format(node.version), - ].join("") - end, + [ + " ", + format(node.version), + ].join("") + end, ";", ].join(""), - *if node.interfaces.length > 0 - [ - "", - node.interfaces.map { |x| format(x) }.join("\n"), - ] - end, + *if node.interfaces.length.positive? + [ + "", + node.interfaces.map { |x| format(x) }.join("\n"), + ] + end, ].join("\n") end def format_declarations_schema(node) schema_declarations = [ - *if node.constants.length > 0 - [ - "CONSTANT", - indent(node.constants.map { |x| format(x) }.join("\n")), - [ - "END_CONSTANT", - ";", - ].join(""), - ].join("\n") - end, - *if node.types.length > 0 - node.types.map { |x| format(x) } - end, - *if node.entities.length > 0 - node.entities.map { |x| format(x) } - end, - *if node.subtype_constraints.length > 0 - node.subtype_constraints.map { |x| format(x) } - end, - *if node.functions.length > 0 - node.functions.map { |x| format(x) } - end, - *if node.rules.length > 0 - node.rules.map { |x| format(x) } - end, - *if node.procedures and node.procedures.length > 0 - node.procedures.map { |x| format(x) } - end, + *if node.constants.length.positive? + [ + "CONSTANT", + indent(node.constants.map { |x| format(x) }.join("\n")), + [ + "END_CONSTANT", + ";", + ].join(""), + ].join("\n") + end, + *if node.types.length.positive? + node.types.map { |x| format(x) } + end, + *if node.entities.length.positive? + node.entities.map { |x| format(x) } + end, + *if node.subtype_constraints.length.positive? + node.subtype_constraints.map { |x| format(x) } + end, + *if node.functions.length.positive? + node.functions.map { |x| format(x) } + end, + *if node.rules.length.positive? + node.rules.map { |x| format(x) } + end, + *if node.procedures&.length&.positive? + node.procedures.map { |x| format(x) } + end, ] [ format_declarations_schema_head(node), - *if schema_declarations.length > 0 - [ - "", - schema_declarations.join("\n\n"), - "", - ] - end, + *if schema_declarations.length.positive? + [ + "", + schema_declarations.join("\n\n"), + "", + ] + end, [ "END_SCHEMA", ";", @@ -696,28 +697,28 @@ def format_declarations_subtype_constraint(node) ";", ].join(""), *if node.abstract - indent([ - "ABSTRACT", - " ", - "SUPERTYPE", - ";", - ].join("")) - end, - *if node.total_over.length > 0 - indent([ - "TOTAL_OVER", - "(", - node.total_over.map { |x| format(x) }.join(", "), - ")", - ";", - ].join("")) - end, + indent([ + "ABSTRACT", + " ", + "SUPERTYPE", + ";", + ].join("")) + end, + *if node.total_over.length.positive? + indent([ + "TOTAL_OVER", + "(", + node.total_over.map { |x| format(x) }.join(", "), + ")", + ";", + ].join("")) + end, *if node.supertype_expression - indent([ - format(node.supertype_expression), - ";", - ].join("")) - end, + indent([ + format(node.supertype_expression), + ";", + ].join("")) + end, [ "END_SUBTYPE_CONSTRAINT", ";", @@ -737,12 +738,12 @@ def format_declarations_type(node) format(node.underlying_type), ";", ].join(""), - *if node.where_rules.length > 0 - [ - "WHERE", - indent(node.where_rules.map { |x| format(x) }.join("\n")), - ] - end, + *if node.where_rules.length.positive? + [ + "WHERE", + indent(node.where_rules.map { |x| format(x) }.join("\n")), + ] + end, [ "END_TYPE", ";", @@ -753,12 +754,12 @@ def format_declarations_type(node) def format_declarations_unique_rule(node) [ *if node.id - [ - node.id, - ":", - " ", - ].join("") - end, + [ + node.id, + ":", + " ", + ].join("") + end, node.attributes.map { |x| format(x) }.join(", "), ";", ].join("") @@ -772,13 +773,13 @@ def format_declarations_variable(node) " ", format(node.type), *if node.expression - [ - " ", - ":=", - " ", - format(node.expression), - ].join("") - end, + [ + " ", + ":=", + " ", + format(node.expression), + ].join("") + end, ";", ].join("") end @@ -786,12 +787,12 @@ def format_declarations_variable(node) def format_declarations_where_rule(node) [ *if node.id - [ - node.id, - ":", - " ", - ].join("") - end, + [ + node.id, + ":", + " ", + ].join("") + end, format(node.expression), ";", ].join("") @@ -814,14 +815,19 @@ def format_expressions_aggregate_initializer_item(node) end def format_expressions_binary_expression(node) + op1_bin_exp = node.operand1.is_a?(Model::Expressions::BinaryExpression) && + (OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator]) + op2_bin_exp = node.operand2.is_a?(Model::Expressions::BinaryExpression) && + (OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator]) + [ - *if node.operand1.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator] - "(" - end, + *if op1_bin_exp + "(" + end, format(node.operand1), - *if node.operand1.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand1.operator] > OPERATOR_PRECEDENCE[node.operator] - ")" - end, + *if op1_bin_exp + ")" + end, " ", case node.operator when Model::Expressions::BinaryExpression::ADDITION then "+" @@ -847,13 +853,13 @@ def format_expressions_binary_expression(node) when Model::Expressions::BinaryExpression::XOR then "XOR" end, " ", - *if node.operand2.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator] - "(" - end, + *if op2_bin_exp + "(" + end, format(node.operand2), - *if node.operand2.is_a? Model::Expressions::BinaryExpression and OPERATOR_PRECEDENCE[node.operand2.operator] > OPERATOR_PRECEDENCE[node.operator] - ")" - end, + *if op2_bin_exp + ")" + end, ].join("") end @@ -910,7 +916,7 @@ def format_expressions_query_expression(node) "|", " ", format(node.expression), - *format_remarks(node).instance_eval { |x| x.length > 0 ? ["\n", *x, "\n"] : x }, + *format_remarks(node).instance_eval { |x| x.length.positive? ? ["\n", *x, "\n"] : x }, ")", ].join("") end @@ -926,12 +932,12 @@ def format_expressions_unary_expression(node) " " end, *if node.operand.is_a? Model::Expressions::BinaryExpression - "(" - end, + "(" + end, format(node.operand), *if node.operand.is_a? Model::Expressions::BinaryExpression - ")" - end, + ")" + end, ].join("") end @@ -985,7 +991,7 @@ def format_references_attribute_reference(node) def format_references_group_reference(node) [ format(node.ref), - '\\', + "\\", format(node.entity), ].join("") end @@ -996,11 +1002,11 @@ def format_references_index_reference(node) "[", format(node.index1), *if node.index2 - [ - ":", - format(node.index2), - ].join("") - end, + [ + ":", + format(node.index2), + ].join("") + end, "]", ].join("") end @@ -1021,9 +1027,9 @@ def format_statements_alias(node) format(node.expression), ";", ].join(""), - *if node.statements.length > 0 - indent(node.statements.map { |x| format(x) }.join("\n")) - end, + *if node.statements.length.positive? + indent(node.statements.map { |x| format(x) }.join("\n")) + end, *format_remarks(node), [ "END_ALIAS", @@ -1046,13 +1052,13 @@ def format_statements_assignment(node) def format_statements_procedure_call(node) [ format(node.procedure), - *if node.parameters.length > 0 - [ - "(", - node.parameters.map { |x| format(x) }.join(", "), - ")", - ].join("") - end, + *if node.parameters.length.positive? + [ + "(", + node.parameters.map { |x| format(x) }.join(", "), + ")", + ].join("") + end, ";", ].join("") end @@ -1066,19 +1072,19 @@ def format_statements_case(node) " ", "OF", ].join(""), - *if node.actions.length > 0 - node.actions.map { |x| format(x) } - end, + *if node.actions.length.positive? + node.actions.map { |x| format(x) } + end, *if node.otherwise_statement - [ - [ - "OTHERWISE", - " ", - ":", - ].join(""), - indent(format(node.otherwise_statement)), - ] - end, + [ + [ + "OTHERWISE", + " ", + ":", + ].join(""), + indent(format(node.otherwise_statement)), + ] + end, [ "END_CASE", ";", @@ -1100,9 +1106,9 @@ def format_statements_case_action(node) def format_statements_compound(node) [ "BEGIN", - *if node.statements.length > 0 - indent(node.statements.map { |x| format(x) }.join("\n")) - end, + *if node.statements.length.positive? + indent(node.statements.map { |x| format(x) }.join("\n")) + end, [ "END", ";", @@ -1110,7 +1116,7 @@ def format_statements_compound(node) ].join("\n") end - def format_statements_escape(node) + def format_statements_escape(_node) [ "ESCAPE", ";", @@ -1126,15 +1132,15 @@ def format_statements_if(node) " ", "THEN", ].join(""), - *if node.statements.length > 0 - indent(node.statements.map { |x| format(x) }.join("\n")) - end, - *if node.else_statements.length > 0 - [ - "ELSE", - indent(node.else_statements.map { |x| format(x) }.join("\n")), - ].join("\n") - end, + *if node.statements.length.positive? + indent(node.statements.map { |x| format(x) }.join("\n")) + end, + *if node.else_statements.length.positive? + [ + "ELSE", + indent(node.else_statements.map { |x| format(x) }.join("\n")), + ].join("\n") + end, [ "END_IF", ";", @@ -1142,7 +1148,7 @@ def format_statements_if(node) ].join("\n") end - def format_statements_null(node) + def format_statements_null(_node) ";" end @@ -1151,48 +1157,48 @@ def format_statements_repeat(node) [ "REPEAT", *if node.id - [ - " ", - node.id, - " ", - ":=", - " ", - format(node.bound1), - " ", - "TO", - " ", - format(node.bound2), - *if node.increment - [ - " ", - "BY", - " ", - format(node.increment), - ].join("") - end, - ].join("") - end, + [ + " ", + node.id, + " ", + ":=", + " ", + format(node.bound1), + " ", + "TO", + " ", + format(node.bound2), + *if node.increment + [ + " ", + "BY", + " ", + format(node.increment), + ].join("") + end, + ].join("") + end, *if node.while_expression - [ - " ", - "WHILE", - " ", - format(node.while_expression), - ].join("") - end, + [ + " ", + "WHILE", + " ", + format(node.while_expression), + ].join("") + end, *if node.until_expression - [ - " ", - "UNTIL", - " ", - format(node.until_expression), - ].join("") - end, + [ + " ", + "UNTIL", + " ", + format(node.until_expression), + ].join("") + end, ";", ].join(""), - *if node.statements.length > 0 - indent(node.statements.map { |x| format(x) }.join("\n")) - end, + *if node.statements.length.positive? + indent(node.statements.map { |x| format(x) }.join("\n")) + end, *format_remarks(node), [ "END_REPEAT", @@ -1205,18 +1211,18 @@ def format_statements_return(node) [ "RETURN", *if node.expression - [ - " ", - "(", - format(node.expression), - ")", - ].join("") - end, + [ + " ", + "(", + format(node.expression), + ")", + ].join("") + end, ";", ].join("") end - def format_statements_skip(node) + def format_statements_skip(_node) [ "SKIP", ";", @@ -1224,27 +1230,32 @@ def format_statements_skip(node) end def format_supertype_expressions_binary_supertype_expression(node) + op1_higher_precedence = node.operand1.is_a?(Model::SupertypeExpressions::BinarySupertypeExpression) && + (SUPERTYPE_OPERATOR_PRECEDENCE[node.operand1.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]) + op2_higher_precedence = node.operand2.is_a?(Model::SupertypeExpressions::BinarySupertypeExpression) && + (SUPERTYPE_OPERATOR_PRECEDENCE[node.operand2.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator]) + [ - *if node.operand1.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand1.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator] - "(" - end, + *if op1_higher_precedence + "(" + end, format(node.operand1), - *if node.operand1.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand1.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator] - ")" - end, + *if op1_higher_precedence + ")" + end, " ", case node.operator when Model::SupertypeExpressions::BinarySupertypeExpression::AND then "AND" when Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR then "ANDOR" end, " ", - *if node.operand2.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand2.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator] - "(" - end, + *if op2_higher_precedence + "(" + end, format(node.operand2), - *if node.operand2.is_a? Model::SupertypeExpressions::BinarySupertypeExpression and SUPERTYPE_OPERATOR_PRECEDENCE[node.operand2.operator] > SUPERTYPE_OPERATOR_PRECEDENCE[node.operator] - ")" - end, + *if op2_higher_precedence + ")" + end, ].join("") end @@ -1257,37 +1268,37 @@ def format_supertype_expressions_oneof_supertype_expression(node) ].join("") end - def format_data_types_aggregate(node) + def format_data_types_aggregate(_node) "AGGREGATE" end def format_data_types_array(node) [ "ARRAY", - *if node.bound1 and node.bound2 - [ - " ", - "[", - format(node.bound1), - ":", - format(node.bound2), - "]", - ].join("") - end, + *if node.bound1 && node.bound2 + [ + " ", + "[", + format(node.bound1), + ":", + format(node.bound2), + "]", + ].join("") + end, " ", "OF", *if node.optional - [ - " ", - "OPTIONAL", - ].join("") - end, + [ + " ", + "OPTIONAL", + ].join("") + end, *if node.unique - [ - " ", - "UNIQUE", - ].join("") - end, + [ + " ", + "UNIQUE", + ].join("") + end, " ", format(node.base_type), ].join("") @@ -1296,16 +1307,16 @@ def format_data_types_array(node) def format_data_types_bag(node) [ "BAG", - *if node.bound1 and node.bound2 - [ - " ", - "[", - format(node.bound1), - ":", - format(node.bound2), - "]", - ].join("") - end, + *if node.bound1 && node.bound2 + [ + " ", + "[", + format(node.bound1), + ":", + format(node.bound2), + "]", + ].join("") + end, " ", "OF", " ", @@ -1317,72 +1328,72 @@ def format_data_types_binary(node) [ "BINARY", *if node.width - [ - " ", - "(", - format(node.width), - ")", - ].join("") - end, + [ + " ", + "(", + format(node.width), + ")", + ].join("") + end, *if node.fixed - [ - " ", - "FIXED", - ].join("") - end, + [ + " ", + "FIXED", + ].join("") + end, ].join("") end - def format_data_types_boolean(node) + def format_data_types_boolean(_node) "BOOLEAN" end def format_data_types_enumeration(node) [ *if node.extensible - [ - "EXTENSIBLE", - " ", - ].join("") - end, + [ + "EXTENSIBLE", + " ", + ].join("") + end, "ENUMERATION", *if node.based_on - [ - " ", - "BASED_ON", - " ", - format(node.based_on), - *if node.items.length > 0 - item_indent = INDENT_CHAR * "(".length - [ - " ", - "WITH", - "\n", - indent([ - "(", - node.items.map { |x| format(x) }.join(",\n#{item_indent}"), - ")", - ].join("")), - ].join("") - end, - ].join("") - else - [ - *if node.items.length > 0 - item_indent = INDENT_CHAR * "(".length - [ - " ", - "OF", - "\n", - indent([ - "(", - node.items.map { |x| format(x) }.join(",\n#{item_indent}"), - ")", - ].join("")), - ].join("") - end, - ].join("") - end, + [ + " ", + "BASED_ON", + " ", + format(node.based_on), + *if node.items.length.positive? + item_indent = INDENT_CHAR * "(".length + [ + " ", + "WITH", + "\n", + indent([ + "(", + node.items.map { |x| format(x) }.join(",\n#{item_indent}"), + ")", + ].join("")), + ].join("") + end, + ].join("") + else + [ + *if node.items.length.positive? + item_indent = INDENT_CHAR * "(".length + [ + " ", + "OF", + "\n", + indent([ + "(", + node.items.map { |x| format(x) }.join(",\n#{item_indent}"), + ")", + ].join("")), + ].join("") + end, + ].join("") + end, ].join("") end @@ -1394,11 +1405,11 @@ def format_data_types_generic_entity(node) [ "GENERIC_ENTITY", *if node.id - [ - ":", - node.id, - ] - end, + [ + ":", + node.id, + ] + end, ].join("") end @@ -1406,49 +1417,49 @@ def format_data_types_generic(node) [ "GENERIC", *if node.id - [ - ":", - node.id, - ] - end, + [ + ":", + node.id, + ] + end, ].join("") end - def format_data_types_integer(node) + def format_data_types_integer(_node) "INTEGER" end def format_data_types_list(node) [ "LIST", - *if node.bound1 and node.bound2 - [ - " ", - "[", - format(node.bound1), - ":", - format(node.bound2), - "]", - ].join("") - end, + *if node.bound1 && node.bound2 + [ + " ", + "[", + format(node.bound1), + ":", + format(node.bound2), + "]", + ].join("") + end, " ", "OF", *if node.unique - [ - " ", - "UNIQUE", - ].join("") - end, + [ + " ", + "UNIQUE", + ].join("") + end, " ", format(node.base_type), ].join("") end - def format_data_types_logical(node) + def format_data_types_logical(_node) "LOGICAL" end - def format_data_types_number(node) + def format_data_types_number(_node) "NUMBER" end @@ -1456,82 +1467,82 @@ def format_data_types_real(node) [ "REAL", *if node.precision - [ - " ", - "(", - format(node.precision), - ")", - ].join("") - end, + [ + " ", + "(", + format(node.precision), + ")", + ].join("") + end, ].join("") end def format_data_types_select(node) [ *if node.extensible - [ - "EXTENSIBLE", - " ", - ].join("") - end, + [ + "EXTENSIBLE", + " ", + ].join("") + end, *if node.generic_entity - [ - "GENERIC_ENTITY", - " ", - ].join("") - end, + [ + "GENERIC_ENTITY", + " ", + ].join("") + end, "SELECT", *if node.based_on - [ - " ", - "BASED_ON", - " ", - format(node.based_on), - *if node.items.length > 0 - item_indent = INDENT_CHAR * "(".length - [ - " ", - "WITH", - "\n", - indent([ - "(", - node.items.map { |x| format(x) }.join(",\n#{item_indent}"), - ")", - ].join("")), - ].join("") - end, - ].join("") - else - [ - *if node.items.length > 0 - item_indent = INDENT_CHAR * "(".length - [ - "\n", - indent([ - "(", - node.items.map { |x| format(x) }.join(",\n#{item_indent}"), - ")", - ].join("")), - ].join("") - end, - ].join("") - end, + [ + " ", + "BASED_ON", + " ", + format(node.based_on), + *if node.items.length.positive? + item_indent = INDENT_CHAR * "(".length + [ + " ", + "WITH", + "\n", + indent([ + "(", + node.items.map { |x| format(x) }.join(",\n#{item_indent}"), + ")", + ].join("")), + ].join("") + end, + ].join("") + else + [ + *if node.items.length.positive? + item_indent = INDENT_CHAR * "(".length + [ + "\n", + indent([ + "(", + node.items.map { |x| format(x) }.join(",\n#{item_indent}"), + ")", + ].join("")), + ].join("") + end, + ].join("") + end, ].join("") end def format_data_types_set(node) [ "SET", - *if node.bound1 and node.bound2 - [ - " ", - "[", - format(node.bound1), - ":", - format(node.bound2), - "]", - ].join("") - end, + *if node.bound1 && node.bound2 + [ + " ", + "[", + format(node.bound1), + ":", + format(node.bound2), + "]", + ].join("") + end, " ", "OF", " ", @@ -1543,19 +1554,19 @@ def format_data_types_string(node) [ "STRING", *if node.width - [ - " ", - "(", - format(node.width), - ")", - ].join("") - end, + [ + " ", + "(", + format(node.width), + ")", + ].join("") + end, *if node.fixed - [ - " ", - "FIXED", - ].join("") - end, + [ + " ", + "FIXED", + ].join("") + end, ].join("") end @@ -1600,7 +1611,9 @@ def format_remarks(node) def format_scope_remarks(node) [ *format_remarks(node), - *node.children.select { |x| !x.is_a? Model::DataTypes::EnumerationItem or node.is_a? Model::Declarations::Type }.flat_map { |x| format_scope_remarks(x) }, + *node.children.select do |x| + !x.is_a? Model::DataTypes::EnumerationItem or node.is_a? Model::Declarations::Type + end.flat_map { |x| format_scope_remarks(x) }, ] end end diff --git a/lib/expressir/express/hyperlink_formatter.rb b/lib/expressir/express/hyperlink_formatter.rb index bff47197..2063dbc0 100644 --- a/lib/expressir/express/hyperlink_formatter.rb +++ b/lib/expressir/express/hyperlink_formatter.rb @@ -9,7 +9,7 @@ module HyperlinkFormatter # @!visibility private def self.included(mod) if !mod.superclass.private_method_defined? :format_references_simple_reference - raise 'Missing method' + raise "Missing method" end end @@ -33,4 +33,4 @@ def format_references_simple_reference(node) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/express/model_visitor.rb b/lib/expressir/express/model_visitor.rb index 6e16e949..eb3e0db1 100644 --- a/lib/expressir/express/model_visitor.rb +++ b/lib/expressir/express/model_visitor.rb @@ -21,4 +21,4 @@ def visit(node) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/express/parser.rb b/lib/expressir/express/parser.rb index cfdc8796..79393802 100644 --- a/lib/expressir/express/parser.rb +++ b/lib/expressir/express/parser.rb @@ -30,13 +30,13 @@ def cstr(atom) SUBTYPE_CONSTRAINT SUPERTYPE TAN THEN TO TRUE TYPE TYPEOF TOTAL_OVER UNIQUE UNKNOWN UNTIL USE USEDIN VALUE VALUE_IN VALUE_UNIQUE VAR WITH WHERE WHILE XOR - ] + ].freeze def keyword_rule(str) key_chars = str.to_s.split(//) - key_chars. - collect! { |char| match("[#{char}#{char.downcase}]") }. - reduce(:>>) >> match["a-zA-Z0-9_"].absent? + key_chars + .collect! { |char| match("[#{char}#{char.downcase}]") } + .reduce(:>>) >> match["a-zA-Z0-9_"].absent? end KEYWORDS.each do |keyword| @@ -44,80 +44,121 @@ def keyword_rule(str) rule(sym) { cts(keyword_rule(keyword).as(:str)).as(sym) } end - rule(:abstractEntityDeclaration) { (tABSTRACT).as(:abstractEntityDeclaration) } - rule(:abstractSupertypeDeclaration) { (tABSTRACT >> tSUPERTYPE >> subtypeConstraint.maybe).as(:abstractSupertypeDeclaration) } + rule(:abstractEntityDeclaration) { tABSTRACT.as(:abstractEntityDeclaration) } + rule(:abstractSupertypeDeclaration) do + (tABSTRACT >> tSUPERTYPE >> subtypeConstraint.maybe).as(:abstractSupertypeDeclaration) + end rule(:abstractSupertype) { (tABSTRACT >> tSUPERTYPE >> op_delim).as(:abstractSupertype) } - rule(:actualParameterList) { (op_leftparen >> (parameter >> (op_comma >> parameter).repeat).as(:listOf_parameter) >> op_rightparen).as(:actualParameterList) } + rule(:actualParameterList) do + (op_leftparen >> (parameter >> (op_comma >> parameter).repeat).as(:listOf_parameter) >> op_rightparen) + .as(:actualParameterList) + end rule(:addLikeOp) { (op_plus | op_minus | tOR | tXOR).as(:addLikeOp) } - rule(:aggregateInitializer) { (op_leftbracket >> ((element >> (op_comma >> element).repeat).as(:listOf_element)).maybe >> op_rightbracket).as(:aggregateInitializer) } - rule(:aggregateSource) { (simpleExpression).as(:aggregateSource) } - rule(:aggregateType) { (tAGGREGATE >> (op_colon >> typeLabel).maybe >> tOF >> parameterType).as(:aggregateType) } + rule(:aggregateInitializer) do + (op_leftbracket >> (element >> (op_comma >> element).repeat).as(:listOf_element).maybe >> op_rightbracket) + .as(:aggregateInitializer) + end + rule(:aggregateSource) { simpleExpression.as(:aggregateSource) } + rule(:aggregateType) do + (tAGGREGATE >> (op_colon >> typeLabel).maybe >> tOF >> parameterType).as(:aggregateType) + end rule(:aggregationTypes) { (arrayType | bagType | listType | setType).as(:aggregationTypes) } - rule(:algorithmHead) { (declaration.repeat.as(:declaration) >> constantDecl.maybe >> localDecl.maybe).as(:algorithmHead) } - rule(:aliasStmt) { (tALIAS >> variableId >> tFOR >> generalRef >> qualifier.repeat.as(:qualifier) >> op_delim >> stmt.repeat(1).as(:stmt) >> tEND_ALIAS >> (op_delim.as(:op_delim2))).as(:aliasStmt) } + rule(:algorithmHead) do + (declaration.repeat.as(:declaration) >> constantDecl.maybe >> localDecl.maybe).as(:algorithmHead) + end + rule(:aliasStmt) do + (tALIAS >> variableId >> tFOR >> generalRef >> qualifier.repeat.as(:qualifier) >> + op_delim >> stmt.repeat(1).as(:stmt) >> tEND_ALIAS >> (op_delim.as(:op_delim2))).as(:aliasStmt) + end rule(:anyKeyword) { KEYWORDS.map { |kw| send("t#{kw}") }.inject(:|) } - rule(:arrayType) { (tARRAY >> boundSpec >> tOF >> tOPTIONAL.maybe >> tUNIQUE.maybe >> instantiableType).as(:arrayType) } + rule(:arrayType) do + (tARRAY >> boundSpec >> tOF >> tOPTIONAL.maybe >> tUNIQUE.maybe >> instantiableType).as(:arrayType) + end rule(:assignmentStmt) { (generalRef >> qualifier.repeat.as(:qualifier) >> op_decl >> expression >> op_delim).as(:assignmentStmt) } rule(:attributeDecl) { (attributeId | redeclaredAttribute).as(:attributeDecl) } - rule(:attributeId) { (simpleId).as(:attributeId) } + rule(:attributeId) { simpleId.as(:attributeId) } rule(:attributeQualifier) { (op_period >> attributeRef).as(:attributeQualifier) } - rule(:attributeRef) { (attributeId).as(:attributeRef) } + rule(:attributeRef) { attributeId.as(:attributeRef) } rule(:bagType) { (tBAG >> boundSpec.maybe >> tOF >> instantiableType).as(:bagType) } rule(:binaryLiteral) { cts((str("%") >> bit.repeat(1)).as(:str)).as(:binaryLiteral) } rule(:binaryType) { (tBINARY >> widthSpec.maybe).as(:binaryType) } - rule(:bit) { (match["0-1"]) } - rule(:booleanType) { (tBOOLEAN).as(:booleanType) } - rule(:bound1) { (numericExpression).as(:bound1) } - rule(:bound2) { (numericExpression).as(:bound2) } + rule(:bit) { match["0-1"] } + rule(:booleanType) { tBOOLEAN.as(:booleanType) } + rule(:bound1) { numericExpression.as(:bound1) } + rule(:bound2) { numericExpression.as(:bound2) } rule(:boundSpec) { (op_leftbracket >> bound1 >> op_colon >> bound2 >> op_rightbracket).as(:boundSpec) } rule(:builtInConstant) { (tCONST_E | tPI | tSELF | op_question_mark).as(:builtInConstant) } - rule(:builtInFunction) { (tABS | tACOS | tASIN | tATAN | tBLENGTH | tCOS | tEXISTS | tEXP | tFORMAT | tHIBOUND | tHIINDEX | tLENGTH | tLOBOUND | tLOINDEX | tLOG2 | tLOG10 | tLOG | tNVL | tODD | tROLESOF | tSIN | tSIZEOF | tSQRT | tTAN | tTYPEOF | tUSEDIN | tVALUE_IN | tVALUE_UNIQUE | tVALUE).as(:builtInFunction) } + rule(:builtInFunction) do + ( + tABS | tACOS | tASIN | tATAN | tBLENGTH | tCOS | tEXISTS | tEXP | tFORMAT | tHIBOUND | tHIINDEX | tLENGTH | + tLOBOUND | tLOINDEX | tLOG2 | tLOG10 | tLOG | tNVL | tODD | tROLESOF | tSIN | tSIZEOF | tSQRT | tTAN | + tTYPEOF | tUSEDIN | tVALUE_IN | tVALUE_UNIQUE | tVALUE + ).as(:builtInFunction) + end rule(:builtInProcedure) { (tINSERT | tREMOVE).as(:builtInProcedure) } rule(:caseAction) { ((caseLabel >> (op_comma >> caseLabel).repeat).as(:listOf_caseLabel) >> op_colon >> stmt).as(:caseAction) } - rule(:caseLabel) { (expression).as(:caseLabel) } - rule(:caseStmt) { (tCASE >> selector >> tOF >> caseAction.repeat.as(:caseAction) >> (tOTHERWISE >> op_colon >> stmt).maybe >> tEND_CASE >> op_delim).as(:caseStmt) } + rule(:caseLabel) { expression.as(:caseLabel) } + rule(:caseStmt) do + (tCASE >> selector >> tOF >> caseAction.repeat.as(:caseAction) >> (tOTHERWISE >> op_colon >> stmt).maybe >> tEND_CASE >> op_delim).as(:caseStmt) + end rule(:compoundStmt) { (tBEGIN >> stmt.repeat(1).as(:stmt) >> tEND >> op_delim).as(:compoundStmt) } rule(:concreteTypes) { (aggregationTypes | simpleTypes | typeRef).as(:concreteTypes) } rule(:constantBody) { (constantId >> op_colon >> instantiableType >> op_decl >> expression >> op_delim).as(:constantBody) } rule(:constantDecl) { (tCONSTANT >> constantBody.repeat(1).as(:constantBody) >> tEND_CONSTANT >> op_delim).as(:constantDecl) } rule(:constantFactor) { (builtInConstant | constantRef).as(:constantFactor) } - rule(:constantId) { (simpleId).as(:constantId) } - rule(:constantRef) { (constantId).as(:constantRef) } + rule(:constantId) { simpleId.as(:constantId) } + rule(:constantRef) { constantId.as(:constantRef) } rule(:constructedTypes) { (enumerationType | selectType).as(:constructedTypes) } rule(:declaration) { (entityDecl | functionDecl | procedureDecl | subtypeConstraintDecl | typeDecl).as(:declaration) } rule(:delim) { cts(str(";").as(:delim)) } rule(:deriveClause) { (tDERIVE >> derivedAttr.repeat(1).as(:derivedAttr)).as(:deriveClause) } rule(:derivedAttr) { (attributeDecl >> op_colon >> parameterType >> op_decl >> expression >> op_delim).as(:derivedAttr) } - rule(:digit) { (match["0-9"]) } + rule(:digit) { match["0-9"] } rule(:digits) { (digit >> digit.repeat) } rule(:domainRule) { ((ruleLabelId >> op_colon).maybe >> expression).as(:domainRule) } rule(:element) { (expression >> (op_colon >> repetition).maybe).as(:element) } rule(:embeddedRemark) { (str("(*") >> (str("*)").absent? >> (embeddedRemark | any)).repeat >> str("*)")).as(:embeddedRemark) } rule(:encodedCharacter) { (octet >> octet >> octet >> octet) } rule(:encodedStringLiteral) { cts((str('"') >> (encodedCharacter.repeat(1)) >> str('"')).as(:str)).as(:encodedStringLiteral) } - rule(:entityBody) { (explicitAttr.repeat.as(:explicitAttr) >> deriveClause.maybe >> inverseClause.maybe >> uniqueClause.maybe >> whereClause.maybe).as(:entityBody) } - rule(:entityConstructor) { (entityRef >> op_leftparen >> (expression >> (op_comma >> expression).repeat).as(:listOf_expression).maybe >> op_rightparen).as(:entityConstructor) } + rule(:entityBody) do + (explicitAttr.repeat.as(:explicitAttr) >> deriveClause.maybe >> inverseClause.maybe >> uniqueClause.maybe >> whereClause.maybe).as(:entityBody) + end + rule(:entityConstructor) do + (entityRef >> op_leftparen >> (expression >> (op_comma >> expression).repeat).as(:listOf_expression).maybe >> op_rightparen).as(:entityConstructor) + end rule(:entityDecl) { (entityHead >> entityBody >> tEND_ENTITY >> op_delim).as(:entityDecl) } rule(:entityHead) { (tENTITY >> entityId >> subsuper >> op_delim).as(:entityHead) } - rule(:entityId) { (simpleId).as(:entityId) } - rule(:entityRef) { (entityId).as(:entityRef) } + rule(:entityId) { simpleId.as(:entityId) } + rule(:entityRef) { entityId.as(:entityRef) } rule(:enumerationExtension) { (tBASED_ON >> typeRef >> (tWITH >> enumerationItems).maybe).as(:enumerationExtension) } - rule(:enumerationId) { (simpleId).as(:enumerationId) } - rule(:enumerationItem) { (enumerationId).as(:enumerationItem) } - rule(:enumerationItems) { (op_leftparen >> (enumerationItem >> (op_comma >> enumerationItem).repeat).as(:listOf_enumerationItem) >> op_rightparen).as(:enumerationItems) } - rule(:enumerationRef) { (enumerationId).as(:enumerationRef) } + rule(:enumerationId) { simpleId.as(:enumerationId) } + rule(:enumerationItem) { enumerationId.as(:enumerationItem) } + rule(:enumerationItems) do + (op_leftparen >> (enumerationItem >> (op_comma >> enumerationItem).repeat).as(:listOf_enumerationItem) >> op_rightparen).as(:enumerationItems) + end + rule(:enumerationRef) { enumerationId.as(:enumerationRef) } rule(:enumerationReference) { ((typeRef >> op_period).maybe >> enumerationRef).as(:enumerationReference) } rule(:enumerationType) { (tEXTENSIBLE.maybe >> tENUMERATION >> (tOF >> enumerationItems | enumerationExtension).maybe).as(:enumerationType) } rule(:escapeStmt) { (tESCAPE >> op_delim).as(:escapeStmt) } - rule(:explicitAttr) { ((attributeDecl >> (op_comma >> attributeDecl).repeat).as(:listOf_attributeDecl) >> op_colon >> tOPTIONAL.maybe >> parameterType >> op_delim).as(:explicitAttr) } + rule(:explicitAttr) do + ( + (attributeDecl >> (op_comma >> attributeDecl).repeat).as(:listOf_attributeDecl) >> op_colon >> + tOPTIONAL.maybe >> parameterType >> op_delim + ).as(:explicitAttr) + end rule(:expression) { (simpleExpression >> (relOpExtended >> simpleExpression.as(:rhs)).maybe).as(:expression) } rule(:factor) { (simpleFactor >> (op_double_asterisk >> simpleFactor.as(:rhs)).maybe).as(:factor) } rule(:formalParameter) { ((parameterId >> (op_comma >> parameterId).repeat).as(:listOf_parameterId) >> op_colon >> parameterType).as(:formalParameter) } rule(:functionCall) { ((builtInFunction | functionRef) >> actualParameterList.maybe).as(:functionCall) } rule(:functionDecl) { (functionHead >> algorithmHead >> stmt.repeat(1).as(:stmt) >> tEND_FUNCTION >> op_delim).as(:functionDecl) } - rule(:functionHead) { (tFUNCTION >> functionId >> (op_leftparen >> (formalParameter >> (op_delim >> formalParameter).repeat).as(:listOf_formalParameter) >> op_rightparen).maybe >> op_colon >> parameterType >> (op_delim.as(:op_delim2))).as(:functionHead) } - rule(:functionId) { (simpleId).as(:functionId) } - rule(:functionRef) { (functionId).as(:functionRef) } + rule(:functionHead) do + (tFUNCTION >> functionId >> + (op_leftparen >> (formalParameter >> (op_delim >> formalParameter).repeat).as(:listOf_formalParameter) >> op_rightparen).maybe >> + op_colon >> parameterType >> (op_delim.as(:op_delim2)) + ).as(:functionHead) + end + rule(:functionId) { simpleId.as(:functionId) } + rule(:functionRef) { functionId.as(:functionRef) } rule(:generalAggregationTypes) { (generalArrayType | generalBagType | generalListType | generalSetType).as(:generalAggregationTypes) } rule(:generalArrayType) { (tARRAY >> boundSpec.maybe >> tOF >> tOPTIONAL.maybe >> tUNIQUE.maybe >> parameterType).as(:generalArrayType) } rule(:generalBagType) { (tBAG >> boundSpec.maybe >> tOF >> parameterType).as(:generalBagType) } @@ -129,43 +170,59 @@ def keyword_rule(str) rule(:genericType) { (tGENERIC >> (op_colon >> typeLabel).maybe).as(:genericType) } rule(:groupQualifier) { (op_double_backslash >> entityRef).as(:groupQualifier) } rule(:hexDigit) { match["0-9a-fA-F"] } - rule(:ifStmtElseStatements) { (stmt.repeat(1).as(:stmt)).as(:ifStmtElseStatements) } - rule(:ifStmtStatements) { (stmt.repeat(1).as(:stmt)).as(:ifStmtStatements) } + rule(:ifStmtElseStatements) { stmt.repeat(1).as(:stmt).as(:ifStmtElseStatements) } + rule(:ifStmtStatements) { stmt.repeat(1).as(:stmt).as(:ifStmtStatements) } rule(:ifStmt) { (tIF >> logicalExpression >> tTHEN >> ifStmtStatements >> (tELSE >> ifStmtElseStatements).maybe >> tEND_IF >> op_delim).as(:ifStmt) } rule(:incrementControl) { (variableId >> op_decl >> bound1 >> tTO >> bound2 >> (tBY >> increment).maybe).as(:incrementControl) } - rule(:increment) { (numericExpression).as(:increment) } - rule(:index1) { (index).as(:index1) } - rule(:index2) { (index).as(:index2) } - rule(:index) { (numericExpression).as(:index) } + rule(:increment) { numericExpression.as(:increment) } + rule(:index1) { index.as(:index1) } + rule(:index2) { index.as(:index2) } + rule(:index) { numericExpression.as(:index) } rule(:indexQualifier) { (op_leftbracket >> index1 >> (op_colon >> index2).maybe >> op_rightbracket).as(:indexQualifier) } rule(:instantiableType) { (concreteTypes | entityRef).as(:instantiableType) } rule(:integerLiteral) { cts(digits.as(:str)).as(:integerLiteral) } - rule(:integerType) { (tINTEGER).as(:integerType) } + rule(:integerType) { tINTEGER.as(:integerType) } rule(:interfaceSpecification) { (referenceClause | useClause).as(:interfaceSpecification) } - rule(:intervalHigh) { (simpleExpression).as(:intervalHigh) } - rule(:intervalItem) { (simpleExpression).as(:intervalItem) } - rule(:intervalLow) { (simpleExpression).as(:intervalLow) } - rule(:interval) { (op_left_curly_brace >> intervalLow >> intervalOp >> intervalItem >> (intervalOp.as(:intervalOp2)) >> intervalHigh >> op_right_curly_brace).as(:interval) } + rule(:intervalHigh) { simpleExpression.as(:intervalHigh) } + rule(:intervalItem) { simpleExpression.as(:intervalItem) } + rule(:intervalLow) { simpleExpression.as(:intervalLow) } + rule(:interval) do + (op_left_curly_brace >> intervalLow >> intervalOp >> intervalItem >> (intervalOp.as(:intervalOp2)) >> + intervalHigh >> op_right_curly_brace + ).as(:interval) + end rule(:intervalOp) { (op_less_equal | op_less_than).as(:intervalOp) } - rule(:inverseAttr) { (attributeDecl >> op_colon >> inverseAttrType >> tFOR >> (entityRef >> op_period).maybe >> attributeRef >> op_delim).as(:inverseAttr) } + rule(:inverseAttr) do + (attributeDecl >> op_colon >> inverseAttrType >> tFOR >> (entityRef >> op_period).maybe >> attributeRef >> op_delim).as(:inverseAttr) + end rule(:inverseAttrType) { (((tSET | tBAG) >> boundSpec.maybe >> tOF).maybe >> entityRef).as(:inverseAttrType) } rule(:inverseClause) { (tINVERSE >> inverseAttr.repeat(1).as(:inverseAttr)).as(:inverseClause) } rule(:letter) { match["a-zA-Z"] } rule(:listType) { (tLIST >> boundSpec.maybe >> tOF >> tUNIQUE.maybe >> instantiableType).as(:listType) } rule(:literal) { (binaryLiteral | logicalLiteral | realLiteral | integerLiteral | stringLiteral).as(:literal) } rule(:localDecl) { (tLOCAL >> localVariable.repeat(1).as(:localVariable) >> tEND_LOCAL >> op_delim).as(:localDecl) } - rule(:localVariable) { ((variableId >> (op_comma >> variableId).repeat).as(:listOf_variableId) >> op_colon >> parameterType >> (op_decl >> expression).maybe >> op_delim).as(:localVariable) } - rule(:logicalExpression) { (expression).as(:logicalExpression) } + rule(:localVariable) do + ((variableId >> (op_comma >> variableId).repeat).as(:listOf_variableId) >> + op_colon >> parameterType >> + (op_decl >> expression).maybe >> op_delim + ).as(:localVariable) + end + rule(:logicalExpression) { expression.as(:logicalExpression) } rule(:logicalLiteral) { (tFALSE | tTRUE | tUNKNOWN).as(:logicalLiteral) } - rule(:logicalType) { (tLOGICAL).as(:logicalType) } + rule(:logicalType) { tLOGICAL.as(:logicalType) } rule(:multiplicationLikeOp) { (op_asterisk | op_slash | tDIV | tMOD | tAND | op_double_pipe).as(:multiplicationLikeOp) } rule(:namedTypeOrRename) { (namedTypes >> (tAS >> (entityId | typeId)).maybe).as(:namedTypeOrRename) } rule(:namedTypes) { (entityRef | typeRef).as(:namedTypes) } - rule(:nullStmt) { (op_delim).as(:nullStmt) } - rule(:numberType) { (tNUMBER).as(:numberType) } - rule(:numericExpression) { (simpleExpression).as(:numericExpression) } + rule(:nullStmt) { op_delim.as(:nullStmt) } + rule(:numberType) { tNUMBER.as(:numberType) } + rule(:numericExpression) { simpleExpression.as(:numericExpression) } rule(:octet) { hexDigit >> hexDigit } - rule(:oneOf) { (tONEOF >> op_leftparen >> (supertypeExpression >> (op_comma >> supertypeExpression).repeat).as(:listOf_supertypeExpression) >> op_rightparen).as(:oneOf) } + rule(:oneOf) do + ( + tONEOF >> op_leftparen >> (supertypeExpression >> + (op_comma >> supertypeExpression).repeat).as(:listOf_supertypeExpression) >> op_rightparen + ).as(:oneOf) + end rule(:op_asterisk) { cstr("*").as(:op_asterisk) } rule(:op_colon) { cstr(":").as(:op_colon) } rule(:op_colon_equals_colon) { cstr(":=:").as(:op_colon_equals_colon) } @@ -174,7 +231,7 @@ def keyword_rule(str) rule(:op_decl) { cstr(":=").as(:op_decl) } rule(:op_delim) { cstr(";").as(:op_delim) } rule(:op_double_asterisk) { cstr("**").as(:op_double_asterisk) } - rule(:op_double_backslash) { cstr('\\').as(:op_double_backslash) } + rule(:op_double_backslash) { cstr("\\").as(:op_double_backslash) } rule(:op_double_pipe) { cstr("||").as(:op_double_pipe) } rule(:op_equals) { cstr("=").as(:op_equals) } rule(:op_greater_equal) { cstr(">=").as(:op_greater_equal) } @@ -196,57 +253,97 @@ def keyword_rule(str) rule(:op_right_curly_brace) { cstr("}").as(:op_right_curly_brace) } rule(:op_rightparen) { cstr(")").as(:op_rightparen) } rule(:op_slash) { cstr("/").as(:op_slash) } - rule(:parameter) { (expression).as(:parameter) } - rule(:parameterId) { (simpleId).as(:parameterId) } - rule(:parameterRef) { (parameterId).as(:parameterRef) } + rule(:parameter) { expression.as(:parameter) } + rule(:parameterId) { simpleId.as(:parameterId) } + rule(:parameterRef) { parameterId.as(:parameterRef) } rule(:parameterType) { (generalizedTypes | namedTypes | simpleTypes).as(:parameterType) } - rule(:population) { (entityRef).as(:population) } - rule(:precisionSpec) { (numericExpression).as(:precisionSpec) } + rule(:population) { entityRef.as(:population) } + rule(:precisionSpec) { numericExpression.as(:precisionSpec) } rule(:primary) { (literal | qualifiableFactor >> qualifier.repeat.as(:qualifier)).as(:primary) } rule(:procedureCallStmt) { ((builtInProcedure | procedureRef) >> actualParameterList.maybe >> op_delim).as(:procedureCallStmt) } rule(:procedureDecl) { (procedureHead >> algorithmHead >> stmt.repeat.as(:stmt) >> tEND_PROCEDURE >> op_delim).as(:procedureDecl) } rule(:procedureHeadParameter) { (tVAR.maybe >> formalParameter).as(:procedureHeadParameter) } - rule(:procedureHead) { (tPROCEDURE >> procedureId >> (op_leftparen >> (procedureHeadParameter >> (op_delim >> procedureHeadParameter).repeat).as(:listOf_procedureHeadParameter) >> op_rightparen).maybe >> (op_delim.as(:op_delim2))).as(:procedureHead) } - rule(:procedureId) { (simpleId).as(:procedureId) } - rule(:procedureRef) { (procedureId).as(:procedureRef) } + rule(:procedureHead) do + ( + tPROCEDURE >> procedureId >> + ( + op_leftparen >> ( + procedureHeadParameter >> + (op_delim >> procedureHeadParameter).repeat + ).as(:listOf_procedureHeadParameter) >> op_rightparen + ).maybe >> (op_delim.as(:op_delim2))).as(:procedureHead) + end + rule(:procedureId) { simpleId.as(:procedureId) } + rule(:procedureRef) { procedureId.as(:procedureRef) } rule(:qualifiableFactor) { (functionCall | attributeRef | constantFactor | generalRef | population).as(:qualifiableFactor) } rule(:qualifiedAttribute) { (tSELF >> groupQualifier >> attributeQualifier).as(:qualifiedAttribute) } rule(:qualifier) { (attributeQualifier | groupQualifier | indexQualifier).as(:qualifier) } - rule(:queryExpression) { (tQUERY >> op_leftparen >> variableId >> op_query_begin >> aggregateSource >> op_pipe >> logicalExpression >> op_rightparen).as(:queryExpression) } + rule(:queryExpression) do + (tQUERY >> op_leftparen >> variableId >> op_query_begin >> aggregateSource >> op_pipe >> logicalExpression >> op_rightparen).as(:queryExpression) + end rule(:realLiteral) { cts((digits >> str(".") >> digits.maybe >> (match["eE"] >> sign.maybe >> digits).maybe).as(:str)).as(:realLiteral) } rule(:realType) { (tREAL >> (op_leftparen >> precisionSpec >> op_rightparen).maybe).as(:realType) } rule(:redeclaredAttribute) { (qualifiedAttribute >> (tRENAMED >> attributeId).maybe).as(:redeclaredAttribute) } - rule(:referenceClause) { (tREFERENCE >> tFROM >> schemaRef >> (op_leftparen >> (resourceOrRename >> (op_comma >> resourceOrRename).repeat).as(:listOf_resourceOrRename) >> op_rightparen).maybe >> op_delim).as(:referenceClause) } + rule(:referenceClause) do + ( + tREFERENCE >> tFROM >> schemaRef >> + (op_leftparen >> (resourceOrRename >> ( + op_comma >> resourceOrRename + ).repeat).as(:listOf_resourceOrRename) >> op_rightparen).maybe >> op_delim + ).as(:referenceClause) + end rule(:referencedAttribute) { (attributeRef | qualifiedAttribute).as(:referencedAttribute) } rule(:relOpExtended) { (relOp | tIN | tLIKE).as(:relOpExtended) } - rule(:relOp) { (op_less_equal | op_greater_equal | op_less_greater | op_less_than | op_greater_than | op_equals | op_colon_less_greater_colon | op_colon_equals_colon).as(:relOp) } + rule(:relOp) do + ( + op_less_equal | op_greater_equal | op_less_greater | op_less_than | op_greater_than | op_equals | + op_colon_less_greater_colon | op_colon_equals_colon + ).as(:relOp) + end rule(:renameId) { (constantId | entityId | functionId | procedureId | typeId).as(:renameId) } rule(:repeatControl) { (incrementControl.maybe >> whileControl.maybe >> untilControl.maybe).as(:repeatControl) } rule(:repeatStmt) { (tREPEAT >> repeatControl >> op_delim >> stmt.repeat(1).as(:stmt) >> tEND_REPEAT >> (op_delim.as(:op_delim2))).as(:repeatStmt) } - rule(:repetition) { (numericExpression).as(:repetition) } + rule(:repetition) { numericExpression.as(:repetition) } rule(:resourceOrRename) { (resourceRef >> (tAS >> renameId).maybe).as(:resourceOrRename) } rule(:resourceRef) { (constantRef | entityRef | functionRef | procedureRef | typeRef).as(:resourceRef) } rule(:returnStmt) { (tRETURN >> (op_leftparen >> expression >> op_rightparen).maybe >> op_delim).as(:returnStmt) } rule(:ruleDecl) { (ruleHead >> algorithmHead >> stmt.repeat.as(:stmt) >> whereClause >> tEND_RULE >> op_delim).as(:ruleDecl) } - rule(:ruleHead) { (tRULE >> ruleId >> tFOR >> op_leftparen >> (entityRef >> (op_comma >> entityRef).repeat).as(:listOf_entityRef) >> op_rightparen >> op_delim).as(:ruleHead) } - rule(:ruleId) { (simpleId).as(:ruleId) } - rule(:ruleLabelId) { (simpleId).as(:ruleLabelId) } - rule(:ruleLabelRef) { (ruleLabelId).as(:ruleLabelRef) } - rule(:ruleRef) { (ruleId).as(:ruleRef) } + rule(:ruleHead) do + ( + tRULE >> ruleId >> tFOR >> op_leftparen >> + (entityRef >> (op_comma >> entityRef).repeat).as(:listOf_entityRef) >> op_rightparen >> op_delim + ).as(:ruleHead) + end + rule(:ruleId) { simpleId.as(:ruleId) } + rule(:ruleLabelId) { simpleId.as(:ruleLabelId) } + rule(:ruleLabelRef) { ruleLabelId.as(:ruleLabelRef) } + rule(:ruleRef) { ruleId.as(:ruleRef) } rule(:schemaBodyDeclaration) { (declaration | ruleDecl).as(:schemaBodyDeclaration) } - rule(:schemaBody) { (interfaceSpecification.repeat.as(:interfaceSpecification) >> constantDecl.maybe >> schemaBodyDeclaration.repeat.as(:schemaBodyDeclaration)).as(:schemaBody) } - rule(:schemaDecl) { (tSCHEMA >> schemaId >> schemaVersionId.maybe >> op_delim >> schemaBody >> tEND_SCHEMA >> (op_delim.as(:op_delim2))).as(:schemaDecl) } - rule(:schemaId) { (simpleId).as(:schemaId) } - rule(:schemaRef) { (schemaId).as(:schemaRef) } - rule(:schemaVersionId) { (stringLiteral).as(:schemaVersionId) } + rule(:schemaBody) do + ( + interfaceSpecification.repeat.as(:interfaceSpecification) >> constantDecl.maybe >> + schemaBodyDeclaration.repeat.as(:schemaBodyDeclaration) + ).as(:schemaBody) + end + rule(:schemaDecl) do + (tSCHEMA >> schemaId >> schemaVersionId.maybe >> op_delim >> schemaBody >> tEND_SCHEMA >> (op_delim.as(:op_delim2))).as(:schemaDecl) + end + rule(:schemaId) { simpleId.as(:schemaId) } + rule(:schemaRef) { schemaId.as(:schemaRef) } + rule(:schemaVersionId) { stringLiteral.as(:schemaVersionId) } rule(:selectExtension) { (tBASED_ON >> typeRef >> (tWITH >> selectList).maybe).as(:selectExtension) } rule(:selectList) { (op_leftparen >> (namedTypes >> (op_comma >> namedTypes).repeat).as(:listOf_namedTypes) >> op_rightparen).as(:selectList) } - rule(:selector) { (expression).as(:selector) } + rule(:selector) { expression.as(:selector) } rule(:selectType) { ((tEXTENSIBLE >> tGENERIC_ENTITY.maybe).maybe >> tSELECT >> (selectList | selectExtension).maybe).as(:selectType) } rule(:setType) { (tSET >> boundSpec.maybe >> tOF >> instantiableType).as(:setType) } rule(:sign) { match["+-"] } rule(:simpleExpression) { (term >> (addLikeOp.as(:operator) >> term).as(:item).repeat.as(:rhs)).as(:simpleExpression) } - rule(:simpleFactor) { (aggregateInitializer | entityConstructor | interval | queryExpression | simpleFactorExpression | simpleFactorUnaryExpression | enumerationReference).as(:simpleFactor) } + rule(:simpleFactor) do + ( + aggregateInitializer | entityConstructor | interval | queryExpression | simpleFactorExpression | + simpleFactorUnaryExpression | enumerationReference + ).as(:simpleFactor) + end rule(:simpleFactorExpression) { (op_leftparen >> expression >> op_rightparen | primary).as(:simpleFactorExpression) } rule(:simpleFactorUnaryExpression) { (unaryOp >> simpleFactorExpression).as(:simpleFactorUnaryExpression) } rule(:simpleId) { anyKeyword.absent? >> cts((match["a-zA-Z_"] >> match["a-zA-Z0-9_"].repeat).as(:str)).as(:simpleId) } @@ -255,17 +352,24 @@ def keyword_rule(str) rule(:skipStmt) { (tSKIP >> op_delim).as(:skipStmt) } rule(:space) { match[" \r\n\t\f"] | embeddedRemark | tailRemark } rule(:spaces) { space.repeat.as(:spaces) } - rule(:stmt) { (aliasStmt | assignmentStmt | caseStmt | compoundStmt | escapeStmt | ifStmt | nullStmt | procedureCallStmt | repeatStmt | returnStmt | skipStmt).as(:stmt) } + rule(:stmt) do + ( + aliasStmt | assignmentStmt | caseStmt | compoundStmt | escapeStmt | ifStmt | + nullStmt | procedureCallStmt | repeatStmt | returnStmt | skipStmt + ).as(:stmt) + end rule(:stringLiteral) { (simpleStringLiteral | encodedStringLiteral).as(:stringLiteral) } rule(:stringType) { (tSTRING >> widthSpec.maybe).as(:stringType) } rule(:subsuper) { (supertypeConstraint.maybe >> subtypeDeclaration.maybe).as(:subsuper) } rule(:subtypeConstraintBody) { (abstractSupertype.maybe >> totalOver.maybe >> (supertypeExpression >> op_delim).maybe).as(:subtypeConstraintBody) } rule(:subtypeConstraintDecl) { (subtypeConstraintHead >> subtypeConstraintBody >> tEND_SUBTYPE_CONSTRAINT >> op_delim).as(:subtypeConstraintDecl) } rule(:subtypeConstraintHead) { (tSUBTYPE_CONSTRAINT >> subtypeConstraintId >> tFOR >> entityRef >> op_delim).as(:subtypeConstraintHead) } - rule(:subtypeConstraintId) { (simpleId).as(:subtypeConstraintId) } - rule(:subtypeConstraintRef) { (subtypeConstraintId).as(:subtypeConstraintRef) } + rule(:subtypeConstraintId) { simpleId.as(:subtypeConstraintId) } + rule(:subtypeConstraintRef) { subtypeConstraintId.as(:subtypeConstraintRef) } rule(:subtypeConstraint) { (tOF >> op_leftparen >> supertypeExpression >> op_rightparen).as(:subtypeConstraint) } - rule(:subtypeDeclaration) { (tSUBTYPE >> tOF >> op_leftparen >> entityRef >> (op_comma >> entityRef).repeat >> op_rightparen).as(:listOf_entityRef).as(:subtypeDeclaration) } + rule(:subtypeDeclaration) do + (tSUBTYPE >> tOF >> op_leftparen >> entityRef >> (op_comma >> entityRef).repeat >> op_rightparen).as(:listOf_entityRef).as(:subtypeDeclaration) + end rule(:supertypeConstraint) { (abstractSupertypeDeclaration | abstractEntityDeclaration | supertypeRule).as(:supertypeConstraint) } rule(:supertypeExpression) { (supertypeFactor >> (tANDOR.as(:operator) >> supertypeFactor).as(:item).repeat.as(:rhs)).as(:supertypeExpression) } rule(:supertypeFactor) { (supertypeTerm >> (tAND.as(:operator) >> supertypeTerm).as(:item).repeat.as(:rhs)).as(:supertypeFactor) } @@ -274,24 +378,44 @@ def keyword_rule(str) rule(:syntax) { (spaces.as(:spaces) >> schemaDecl.repeat(1).as(:schemaDecl) >> spaces.as(:trailer)).as(:syntax) } rule(:tailRemark) { (str("--") >> (str("\n").absent? >> any).repeat >> str("\n")).as(:tailRemark) } rule(:term) { (factor >> (multiplicationLikeOp >> factor).as(:item).repeat.as(:rhs)).as(:term) } - rule(:totalOver) { (tTOTAL_OVER >> op_leftparen >> (entityRef >> (op_comma >> entityRef).repeat).as(:listOf_entityRef) >> op_rightparen >> op_delim).as(:totalOver) } - rule(:typeDecl) { (tTYPE >> typeId >> op_equals >> underlyingType >> op_delim >> whereClause.maybe >> tEND_TYPE >> (op_delim.as(:op_delim2))).as(:typeDecl) } - rule(:typeId) { (simpleId).as(:typeId) } - rule(:typeLabelId) { (simpleId).as(:typeLabelId) } - rule(:typeLabelRef) { (typeLabelId).as(:typeLabelRef) } + rule(:totalOver) do + (tTOTAL_OVER >> op_leftparen >> (entityRef >> (op_comma >> entityRef).repeat).as(:listOf_entityRef) >> op_rightparen >> op_delim).as(:totalOver) + end + rule(:typeDecl) do + (tTYPE >> typeId >> op_equals >> underlyingType >> op_delim >> whereClause.maybe >> tEND_TYPE >> (op_delim.as(:op_delim2))).as(:typeDecl) + end + rule(:typeId) { simpleId.as(:typeId) } + rule(:typeLabelId) { simpleId.as(:typeLabelId) } + rule(:typeLabelRef) { typeLabelId.as(:typeLabelRef) } rule(:typeLabel) { (typeLabelId | typeLabelRef).as(:typeLabel) } - rule(:typeRef) { (typeId).as(:typeRef) } + rule(:typeRef) { typeId.as(:typeRef) } rule(:unaryOp) { (op_plus | op_minus | tNOT).as(:unaryOp) } rule(:underlyingType) { (concreteTypes | constructedTypes).as(:underlyingType) } - rule(:uniqueClause) { (tUNIQUE >> (uniqueRule >> op_delim >> (uniqueRule >> (op_delim.as(:op_delim2))).repeat).as(:listOf_uniqueRule)).as(:uniqueClause) } - rule(:uniqueRule) { ((ruleLabelId >> op_colon).maybe >> (referencedAttribute >> (op_comma >> referencedAttribute).repeat).as(:listOf_referencedAttribute)).as(:uniqueRule) } + rule(:uniqueClause) do + (tUNIQUE >> (uniqueRule >> op_delim >> (uniqueRule >> (op_delim.as(:op_delim2))).repeat).as(:listOf_uniqueRule)).as(:uniqueClause) + end + rule(:uniqueRule) do + ((ruleLabelId >> op_colon).maybe >> (referencedAttribute >> (op_comma >> referencedAttribute).repeat).as(:listOf_referencedAttribute)).as(:uniqueRule) + end rule(:untilControl) { (tUNTIL >> logicalExpression).as(:untilControl) } - rule(:useClause) { (tUSE >> tFROM >> schemaRef >> (op_leftparen >> (namedTypeOrRename >> (op_comma >> namedTypeOrRename).repeat).as(:listOf_namedTypeOrRename) >> op_rightparen).maybe >> op_delim).as(:useClause) } - rule(:variableId) { (simpleId).as(:variableId) } - rule(:variableRef) { (variableId).as(:variableRef) } + rule(:useClause) do + ( + tUSE >> tFROM >> schemaRef >> + ( + op_leftparen >> ( + namedTypeOrRename >> ( + op_comma >> + namedTypeOrRename + ).repeat + ).as(:listOf_namedTypeOrRename) >> op_rightparen + ).maybe >> op_delim + ).as(:useClause) + end + rule(:variableId) { simpleId.as(:variableId) } + rule(:variableRef) { variableId.as(:variableRef) } rule(:whereClause) { (tWHERE >> (domainRule >> op_delim).repeat.as(:listOf_domainRule)).as(:whereClause) } rule(:whileControl) { (tWHILE >> logicalExpression).as(:whileControl) } - rule(:width) { (numericExpression).as(:width) } + rule(:width) { numericExpression.as(:width) } rule(:widthSpec) { (op_leftparen >> width >> op_rightparen >> tFIXED.maybe).as(:widthSpec) } end @@ -326,9 +450,9 @@ def self.from_file(file, skip_references: nil, include_source: nil) # @param [Boolean] include_source attach original source code to model elements # @return [Model::Repository] def self.from_files(files, skip_references: nil, include_source: nil) - schemas = files.each_with_index.map do |file, i| + schemas = files.each_with_index.map do |file, _i| # start = Time.now - repository = self.from_file(file, skip_references: true) + repository = from_file(file, skip_references: true) # STDERR.puts "#{i+1}/#{files.length} #{file} #{Time.now - start}" repository.schemas end.flatten diff --git a/lib/expressir/express/resolve_references_model_visitor.rb b/lib/expressir/express/resolve_references_model_visitor.rb index bbdf2c21..870bd7aa 100644 --- a/lib/expressir/express/resolve_references_model_visitor.rb +++ b/lib/expressir/express/resolve_references_model_visitor.rb @@ -17,15 +17,15 @@ def visit(node) def visit_references_simple_reference(node) return if node.parent.is_a? Model::References::AttributeReference - if node.parent.is_a? Model::Declarations::InterfaceItem - base_item = node.find("#{node.parent.parent.schema.id}.#{node.parent.ref.id}") - else - base_item = node.find(node.id) - end + base_item = if node.parent.is_a? Model::Declarations::InterfaceItem + node.find("#{node.parent.parent.schema.id}.#{node.parent.ref.id}") + else + node.find(node.id) + end return unless base_item node.base_path = base_item.path end end end -end \ No newline at end of file +end diff --git a/lib/expressir/express/schema_head_formatter.rb b/lib/expressir/express/schema_head_formatter.rb index fea63d8f..0db37f56 100644 --- a/lib/expressir/express/schema_head_formatter.rb +++ b/lib/expressir/express/schema_head_formatter.rb @@ -8,8 +8,8 @@ module Express module SchemaHeadFormatter # @!visibility private def self.included(mod) - if !mod.superclass.private_method_defined? :format_declarations_schema or !mod.superclass.private_method_defined? :format_declarations_schema_head - raise 'Missing method' + if !mod.superclass.private_method_defined?(:format_declarations_schema) || !mod.superclass.private_method_defined?(:format_declarations_schema_head) + raise "Missing method" end end @@ -20,4 +20,4 @@ def format_declarations_schema(node) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/express/visitor.rb b/lib/expressir/express/visitor.rb index ff9520d1..a709e85f 100644 --- a/lib/expressir/express/visitor.rb +++ b/lib/expressir/express/visitor.rb @@ -25,16 +25,16 @@ # - prevents segfault in ANTLR4 C++ runtime, not sure why they are caused # - e.g. see visit_schema_decl -require 'objspace' +require "objspace" module Expressir module Express class Visitor class Ctx - attr_reader :name - attr_reader :data + attr_reader :name, :data attr_accessor :source_pos - def initialize(data,name) + + def initialize(data, name) @data = data @name = name end @@ -43,10 +43,10 @@ def text str.data.to_s end - def method_missing(name,*args) - rulename = name.to_s.sub(/^visit_/,"").gsub(/_([a-z])/) { |m| m[1].upcase }.to_sym + def method_missing(name, *args) + rulename = name.to_s.sub(/^visit_/, "").gsub(/_([a-z])/) { |m| m[1].upcase }.to_sym self.class.define_method(name) { @data[rulename] } - self.send name, *args + send name, *args end def keys @@ -63,9 +63,9 @@ def each(&block) end class SimpleCtx - attr_reader :name - attr_reader :data - def initialize(data,name) + attr_reader :name, :data + + def initialize(data, name) @data = data @name = name end @@ -88,68 +88,69 @@ def initialize(source, include_source: nil) @attached_remark_tokens = Set.new @visit_methods = Hash[ - private_methods.grep(/^visit_/).map { |name| - rulename = name.to_s.sub(/^visit_/,"").gsub(/_([a-z])/) { $1.upcase } - [rulename.to_sym,name.to_sym] - } + private_methods.grep(/^visit_/).map do |name| + rulename = name.to_s.sub(/^visit_/, "").gsub(/_([a-z])/) { $1.upcase } + [rulename.to_sym, name.to_sym] + end ] end - def to_ctx(ast,name=:unnamed) + def to_ctx(ast, name = :unnamed) case ast when Hash nodes = Hash[ - ast.map { |k,v| - if k.match(/^listOf_(.*)$/) + ast.map do |k, v| + if k =~ /^listOf_(.*)$/ itemkey = $1.to_sym - ary = (Array === v) ? v : [v] - [ itemkey, to_ctx(ary.select { |v| v[itemkey] }.map { |v| v.slice(itemkey) }) ] + ary = Array === v ? v : [v] + [itemkey, to_ctx(ary.select { |v| v[itemkey] }.map { |v| v.slice(itemkey) })] else - [ k, to_ctx(v,k) ] + [k, to_ctx(v, k)] end - } + end ] - Ctx.new nodes,name + Ctx.new nodes, name when Array - ast.map { |v| + ast.map do |v| v.length == 1 or raise "element of array invalid (#{v.keys})" - to_ctx(v.values[0],v.keys[0]) - } + to_ctx(v.values[0], v.keys[0]) + end when nil nil else - SimpleCtx.new ast,name + SimpleCtx.new ast, name end end def get_source_pos(ctx) - ranges = nil + nil ranges = case ctx - when Ctx - ctx.source_pos and return ctx.source_pos # cache - ctx.values.map { |item| get_source_pos(item) } - when SimpleCtx - return nil unless ctx.data.respond_to? :offset - [ [ctx.data.offset, ctx.data.offset + ctx.data.length] ] - when Array - ctx.map { |item| get_source_pos(item) } - else - raise "unknown type in Ctx tree: #{ctx}" + when Ctx + ctx.source_pos and return ctx.source_pos # cache + ctx.values.map { |item| get_source_pos(item) } + when SimpleCtx + return nil unless ctx.data.respond_to? :offset + + [[ctx.data.offset, ctx.data.offset + ctx.data.length]] + when Array + ctx.map { |item| get_source_pos(item) } + else + raise "unknown type in Ctx tree: #{ctx}" + end + source_pos = ranges.compact.reduce do |item, acc| + [[item[0], acc[0]].min, [item[1], acc[1]].max] end - source_pos = ranges.compact.reduce { |item,acc| - [ [item[0],acc[0]].min, [item[1],acc[1]].max ] - } Ctx === ctx and ctx.source_pos = source_pos source_pos end def get_source(ctx) - a,b = get_source_pos ctx - @source[a..b-1].strip + a, b = get_source_pos ctx + @source[a..b - 1].strip end - def visit_ast(ast,name) - ctx = to_ctx(ast,name) + def visit_ast(ast, name) + ctx = to_ctx(ast, name) visit ctx end @@ -161,7 +162,7 @@ def visit(ctx) node = ctx if @visit_methods[ctx.name] - node = send(@visit_methods[ctx.name],ctx) + node = send(@visit_methods[ctx.name], ctx) if @include_source && node.respond_to?(:source) node.source = get_source ctx end @@ -171,7 +172,7 @@ def visit(ctx) node end - ############################################3 + # ###########################################3 private def visit_top(ctx) @@ -188,7 +189,7 @@ def visit_if(ctx, default = nil) def visit_if_map(ctx) if ctx - ctx.map{|ctx2| visit(ctx2)} + ctx.map { |ctx2| visit(ctx2) } else [] end @@ -196,7 +197,7 @@ def visit_if_map(ctx) def visit_if_map_flatten(ctx) if ctx - ctx.map{|ctx2| visit(ctx2)}.flatten + ctx.map { |ctx2| visit(ctx2) }.flatten else [] end @@ -204,11 +205,10 @@ def visit_if_map_flatten(ctx) def node_find(node, path) if node.is_a?(Enumerable) - target_node = node.find { |item| item.find(path) } + node.find { |item| item.find(path) } else - target_node = node.find(path) + node.find(path) end - target_node end def find_remark_target(node, path) @@ -221,15 +221,15 @@ def find_remark_target(node, path) rest, _, current_path = path.rpartition(".") # get last path part _, _, current_path = current_path.rpartition(":") # ignore prefix parent_node = node_find(node, rest) - if parent_node and parent_node.class.method_defined? :remark_items + if parent_node&.class&.method_defined?(:remark_items) remark_item = Model::Declarations::RemarkItem.new( - id: current_path + id: current_path, ) remark_item.parent = parent_node # check if path can create implicit informal proposition # see https://github.com/lutaml/expressir/issues/50 - if parent_node.class.method_defined? :informal_propositions and current_path.match(/^IP\d+$/) + if parent_node.class.method_defined?(:informal_propositions) && current_path.match(/^IP\d+$/) parent_node.informal_propositions << remark_item else parent_node.remark_items << remark_item @@ -240,16 +240,16 @@ def find_remark_target(node, path) end end - def get_remarks(ctx,indent="") + def get_remarks(ctx, indent = "") case ctx when Ctx - ctx.values.map { |item| get_remarks(item,indent+" ") }.inject([],:+) + ctx.values.map { |item| get_remarks(item, "#{indent} ") }.inject([], :+) when Array - x = ctx.map { |item| get_remarks(item,indent+" ") }.inject([],:+) - x + ctx.map { |item| get_remarks(item, "#{indent} ") }.inject([], :+) + else - if [:tailRemark, :embeddedRemark].include?(ctx.name) - [ get_source_pos(ctx) ] + if %i[tailRemark embeddedRemark].include?(ctx.name) + [get_source_pos(ctx)] else [] end @@ -257,30 +257,29 @@ def get_remarks(ctx,indent="") end def attach_remarks(ctx, node) - remark_tokens = get_remarks ctx # skip already attached remarks - remark_tokens = remark_tokens.select{|x| !@attached_remark_tokens.include?(x)} + remark_tokens = remark_tokens.reject { |x| @attached_remark_tokens.include?(x) } # parse remarks, find remark targets tagged_remark_tokens = remark_tokens.map do |span| - text = @source[span[0]..span[1]-1] - _, remark_tag, remark_text = if text.start_with?('--') - text.match(/^--"([^"]*)"(.*)$/).to_a - else - text.match(/^\(\*"([^"]*)"(.*)\*\)$/m).to_a - end + text = @source[span[0]..span[1] - 1] + _, remark_tag, remark_text = if text.start_with?("--") + text.match(/^--"([^"]*)"(.*)$/).to_a + else + text.match(/^\(\*"([^"]*)"(.*)\*\)$/m).to_a + end if remark_tag remark_target = find_remark_target(node, remark_tag) end if remark_text - remark_text = remark_text.strip.force_encoding('UTF-8') + remark_text = remark_text.strip.force_encoding("UTF-8") end [span, remark_target, remark_text] - end.select{|x| x[1]} + end.select { |x| x[1] } tagged_remark_tokens.each do |span, remark_target, remark_text| # attach remark @@ -298,7 +297,7 @@ def visit_attribute_ref(ctx) id = visit_if(ctx__attribute_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -308,7 +307,7 @@ def visit_constant_ref(ctx) id = visit_if(ctx__constant_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -318,7 +317,7 @@ def visit_entity_ref(ctx) id = visit_if(ctx__entity_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -328,7 +327,7 @@ def visit_enumeration_ref(ctx) id = visit_if(ctx__enumeration_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -338,7 +337,7 @@ def visit_function_ref(ctx) id = visit_if(ctx__function_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -348,7 +347,7 @@ def visit_parameter_ref(ctx) id = visit_if(ctx__parameter_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -358,7 +357,7 @@ def visit_procedure_ref(ctx) id = visit_if(ctx__procedure_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -368,7 +367,7 @@ def visit_rule_label_ref(ctx) id = visit_if(ctx__rule_label_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -378,7 +377,7 @@ def visit_rule_ref(ctx) id = visit_if(ctx__rule_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -388,7 +387,7 @@ def visit_schema_ref(ctx) id = visit_if(ctx__schema_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -398,7 +397,7 @@ def visit_subtype_constraint_ref(ctx) id = visit_if(ctx__subtype_constraint_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -408,7 +407,7 @@ def visit_type_label_ref(ctx) id = visit_if(ctx__type_label_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -418,7 +417,7 @@ def visit_type_ref(ctx) id = visit_if(ctx__type_id) Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -428,16 +427,16 @@ def visit_variable_ref(ctx) id = visit_if(ctx__variable_id) Model::References::SimpleReference.new( - id: id + id: id, ) end - def visit_abstract_entity_declaration(ctx) - raise 'Invalid state' + def visit_abstract_entity_declaration(_ctx) + raise "Invalid state" end - def visit_abstract_supertype(ctx) - raise 'Invalid state' + def visit_abstract_supertype(_ctx) + raise "Invalid state" end def visit_abstract_supertype_declaration(ctx) @@ -454,8 +453,8 @@ def visit_actual_parameter_list(ctx) def visit_add_like_op(ctx) ctx__text = ctx.values[0].text - ctx__ADDITION = ctx__text == '+' - ctx__SUBTRACTION = ctx__text == '-' + ctx__ADDITION = ctx__text == "+" + ctx__SUBTRACTION = ctx__text == "-" ctx__OR = ctx.tOR ctx__XOR = ctx.tXOR @@ -468,7 +467,7 @@ def visit_add_like_op(ctx) elsif ctx__XOR Model::Expressions::BinaryExpression::XOR else - raise 'Invalid state' + raise "Invalid state" end end @@ -478,7 +477,7 @@ def visit_aggregate_initializer(ctx) items = visit_if_map(ctx__element) Model::Expressions::AggregateInitializer.new( - items: items + items: items, ) end @@ -497,7 +496,7 @@ def visit_aggregate_type(ctx) Model::DataTypes::Aggregate.new( id: id, - base_type: base_type + base_type: base_type, ) end @@ -510,8 +509,8 @@ def visit_aggregation_types(ctx) visit_if(ctx__array_type || ctx__bag_type || ctx__list_type || ctx__set_type) end - def visit_algorithm_head(ctx) - raise 'Invalid state' + def visit_algorithm_head(_ctx) + raise "Invalid state" end def visit_alias_stmt(ctx) @@ -527,7 +526,7 @@ def visit_alias_stmt(ctx) Model::Statements::Alias.new( id: id, expression: expression, - statements: statements + statements: statements, ) end @@ -550,7 +549,7 @@ def visit_array_type(ctx) bound2: bound2, optional: optional, unique: unique, - base_type: base_type + base_type: base_type, ) end @@ -564,7 +563,7 @@ def visit_assignment_stmt(ctx) Model::Statements::Assignment.new( ref: ref, - expression: expression + expression: expression, ) end @@ -579,7 +578,7 @@ def visit_attribute_decl(ctx) Model::Declarations::Attribute.new( id: id, - supertype_attribute: supertype_attribute + supertype_attribute: supertype_attribute, ) end @@ -595,12 +594,12 @@ def visit_attribute_qualifier(ctx) attribute = visit_if(ctx__attribute_ref) Model::References::AttributeReference.new( - attribute: attribute + attribute: attribute, ) end - def visit_attribute_reference(ctx) - raise 'Invalid state' + def visit_attribute_reference(_ctx) + raise "Invalid state" end def visit_bag_type(ctx) @@ -616,7 +615,7 @@ def visit_bag_type(ctx) Model::DataTypes::Bag.new( bound1: bound1, bound2: bound2, - base_type: base_type + base_type: base_type, ) end @@ -630,11 +629,11 @@ def visit_binary_type(ctx) Model::DataTypes::Binary.new( width: width, - fixed: fixed + fixed: fixed, ) end - def visit_boolean_type(ctx) + def visit_boolean_type(_ctx) Model::DataTypes::Boolean.new end @@ -650,8 +649,8 @@ def visit_bound2(ctx) visit_if(ctx__numeric_expression) end - def visit_bound_spec(ctx) - raise 'Invalid state' + def visit_bound_spec(_ctx) + raise "Invalid state" end def visit_built_in_constant(ctx) @@ -660,7 +659,7 @@ def visit_built_in_constant(ctx) id = ctx__text Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -670,7 +669,7 @@ def visit_built_in_function(ctx) id = ctx__text Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -680,7 +679,7 @@ def visit_built_in_procedure(ctx) id = ctx__text Model::References::SimpleReference.new( - id: id + id: id, ) end @@ -693,7 +692,7 @@ def visit_case_action(ctx) Model::Statements::CaseAction.new( labels: labels, - statement: statement + statement: statement, ) end @@ -716,7 +715,7 @@ def visit_case_stmt(ctx) Model::Statements::Case.new( expression: expression, actions: actions, - otherwise_statement: otherwise_statement + otherwise_statement: otherwise_statement, ) end @@ -726,7 +725,7 @@ def visit_compound_stmt(ctx) statements = visit_if_map(ctx__stmt) Model::Statements::Compound.new( - statements: statements + statements: statements, ) end @@ -750,7 +749,7 @@ def visit_constant_body(ctx) Model::Declarations::Constant.new( id: id, type: type, - expression: expression + expression: expression, ) end @@ -804,7 +803,7 @@ def visit_derived_attr(ctx) kind: Model::Declarations::Attribute::DERIVED, supertype_attribute: attribute.supertype_attribute, # reuse type: type, - expression: expression + expression: expression, ) end @@ -823,7 +822,7 @@ def visit_domain_rule(ctx) Model::Declarations::WhereRule.new( id: id, - expression: expression + expression: expression, ) end @@ -837,15 +836,15 @@ def visit_element(ctx) Model::Expressions::AggregateInitializerItem.new( expression: expression, - repetition: repetition + repetition: repetition, ) else visit_if(ctx__expression) end end - def visit_entity_body(ctx) - raise 'Invalid state' + def visit_entity_body(_ctx) + raise "Invalid state" end def visit_entity_constructor(ctx) @@ -861,7 +860,7 @@ def visit_entity_constructor(ctx) # ) Model::Expressions::FunctionCall.new( function: entity, - parameters: parameters + parameters: parameters, ) end @@ -871,8 +870,10 @@ def visit_entity_decl(ctx) ctx__entity_head__entity_id = ctx__entity_head&.entity_id ctx__entity_head__subsuper = visit_if ctx__entity_head&.subsuper ctx__entity_head__subsuper__supertype_constraint = ctx__entity_head__subsuper&.supertype_constraint - ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration = ctx__entity_head__subsuper__supertype_constraint&.abstract_entity_declaration - ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration = ctx__entity_head__subsuper__supertype_constraint&.abstract_supertype_declaration + ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration = + ctx__entity_head__subsuper__supertype_constraint&.abstract_entity_declaration + ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration = + ctx__entity_head__subsuper__supertype_constraint&.abstract_supertype_declaration ctx__entity_head__subsuper__supertype_constraint__supertype_rule = ctx__entity_head__subsuper__supertype_constraint&.supertype_rule ctx__entity_head__subsuper__subtype_declaration = ctx__entity_head__subsuper&.subtype_declaration ctx__entity_body__explicit_attr = ctx__entity_body&.explicit_attr @@ -882,13 +883,15 @@ def visit_entity_decl(ctx) ctx__entity_body__where_clause = ctx__entity_body&.where_clause id = visit_if(ctx__entity_head__entity_id) - abstract = (ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration || ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration) && true - supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration || ctx__entity_head__subsuper__supertype_constraint__supertype_rule) + abstract = (ctx__entity_head__subsuper__supertype_constraint__abstract_entity_declaration || + ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration) && true + supertype_expression = visit_if(ctx__entity_head__subsuper__supertype_constraint__abstract_supertype_declaration || + ctx__entity_head__subsuper__supertype_constraint__supertype_rule) subtype_of = visit_if(ctx__entity_head__subsuper__subtype_declaration, []) attributes = [ *visit_if_map_flatten(ctx__entity_body__explicit_attr), *visit_if(ctx__entity_body__derive_clause), - *visit_if(ctx__entity_body__inverse_clause) + *visit_if(ctx__entity_body__inverse_clause), ] unique_rules = visit_if(ctx__entity_body__unique_clause, []) where_rules = visit_if(ctx__entity_body__where_clause, []) @@ -900,12 +903,12 @@ def visit_entity_decl(ctx) subtype_of: subtype_of, attributes: attributes, unique_rules: unique_rules, - where_rules: where_rules + where_rules: where_rules, ) end - def visit_entity_head(ctx) - raise 'Invalid state' + def visit_entity_head(_ctx) + raise "Invalid state" end def visit_entity_id(ctx) @@ -914,8 +917,8 @@ def visit_entity_id(ctx) handle_simple_id(ctx__SimpleId) end - def visit_enumeration_extension(ctx) - raise 'Invalid state' + def visit_enumeration_extension(_ctx) + raise "Invalid state" end def visit_enumeration_id(ctx) @@ -936,7 +939,7 @@ def visit_enumeration_item(ctx) id = visit_if(ctx__enumeration_id) Model::DataTypes::EnumerationItem.new( - id: id + id: id, ) end @@ -950,7 +953,7 @@ def visit_enumeration_reference(ctx) Model::References::AttributeReference.new( ref: ref, - attribute: attribute + attribute: attribute, ) else visit_if(ctx__enumeration_ref) @@ -971,11 +974,11 @@ def visit_enumeration_type(ctx) Model::DataTypes::Enumeration.new( extensible: extensible, based_on: based_on, - items: items + items: items, ) end - def visit_escape_stmt(ctx) + def visit_escape_stmt(_ctx) Model::Statements::Escape.new end @@ -994,7 +997,7 @@ def visit_explicit_attr(ctx) kind: Model::Declarations::Attribute::EXPLICIT, supertype_attribute: attribute.supertype_attribute, # reuse optional: optional, - type: type + type: type, ) end end @@ -1012,7 +1015,7 @@ def visit_expression(ctx) Model::Expressions::BinaryExpression.new( operator: operator, operand1: operand1, - operand2: operand2 + operand2: operand2, ) else visit_if(ctx__simple_expression) @@ -1031,7 +1034,7 @@ def visit_factor(ctx) Model::Expressions::BinaryExpression.new( operator: operator, operand1: operand1, - operand2: operand2 + operand2: operand2, ) else visit_if(ctx__simple_factor) @@ -1048,7 +1051,7 @@ def visit_formal_parameter(ctx) ids.map do |id| Model::Declarations::Parameter.new( id: id, - type: type + type: type, ) end end @@ -1063,7 +1066,7 @@ def visit_function_call(ctx) Model::Expressions::FunctionCall.new( function: function, - parameters: parameters + parameters: parameters, ) end @@ -1082,11 +1085,11 @@ def visit_function_decl(ctx) parameters = visit_if_map_flatten(ctx__function_head__formal_parameter) return_type = visit_if(ctx__function_head__parameter_type) declarations = visit_if_map(ctx__algorithm_head__declaration) - types = declarations.select{|x| x.is_a? Model::Declarations::Type} - entities = declarations.select{|x| x.is_a? Model::Declarations::Entity} - subtype_constraints = declarations.select{|x| x.is_a? Model::Declarations::SubtypeConstraint} - functions = declarations.select{|x| x.is_a? Model::Declarations::Function} - procedures = declarations.select{|x| x.is_a? Model::Declarations::Procedure} + types = declarations.select { |x| x.is_a? Model::Declarations::Type } + entities = declarations.select { |x| x.is_a? Model::Declarations::Entity } + subtype_constraints = declarations.select { |x| x.is_a? Model::Declarations::SubtypeConstraint } + functions = declarations.select { |x| x.is_a? Model::Declarations::Function } + procedures = declarations.select { |x| x.is_a? Model::Declarations::Procedure } constants = visit_if(ctx__algorithm_head__constant_decl, []) variables = visit_if(ctx__algorithm_head__local_decl, []) statements = visit_if_map(ctx__stmt) @@ -1102,12 +1105,12 @@ def visit_function_decl(ctx) procedures: procedures, constants: constants, variables: variables, - statements: statements + statements: statements, ) end - def visit_function_head(ctx) - raise 'Invalid state' + def visit_function_head(_ctx) + raise "Invalid state" end def visit_function_id(ctx) @@ -1153,7 +1156,7 @@ def visit_general_array_type(ctx) bound2: bound2, optional: optional, unique: unique, - base_type: base_type + base_type: base_type, ) end @@ -1170,7 +1173,7 @@ def visit_general_bag_type(ctx) Model::DataTypes::Bag.new( bound1: bound1, bound2: bound2, - base_type: base_type + base_type: base_type, ) end @@ -1190,7 +1193,7 @@ def visit_general_list_type(ctx) bound1: bound1, bound2: bound2, unique: unique, - base_type: base_type + base_type: base_type, ) end @@ -1214,7 +1217,7 @@ def visit_general_set_type(ctx) Model::DataTypes::Set.new( bound1: bound1, bound2: bound2, - base_type: base_type + base_type: base_type, ) end @@ -1224,7 +1227,7 @@ def visit_generic_entity_type(ctx) id = visit_if(ctx__type_label) Model::DataTypes::GenericEntity.new( - id: id + id: id, ) end @@ -1234,7 +1237,7 @@ def visit_generic_type(ctx) id = visit_if(ctx__type_label) Model::DataTypes::Generic.new( - id: id + id: id, ) end @@ -1244,12 +1247,12 @@ def visit_group_qualifier(ctx) entity = visit_if(ctx__entity_ref) Model::References::GroupReference.new( - entity: entity + entity: entity, ) end - def visit_group_reference(ctx) - raise 'Invalid state' + def visit_group_reference(_ctx) + raise "Invalid state" end def visit_if_stmt(ctx) @@ -1264,7 +1267,7 @@ def visit_if_stmt(ctx) Model::Statements::If.new( expression: expression, statements: statements, - else_statements: else_statements + else_statements: else_statements, ) end @@ -1286,8 +1289,8 @@ def visit_increment(ctx) visit_if(ctx__numeric_expression) end - def visit_increment_control(ctx) - raise 'Invalid state' + def visit_increment_control(_ctx) + raise "Invalid state" end def visit_index(ctx) @@ -1317,12 +1320,12 @@ def visit_index_qualifier(ctx) Model::References::IndexReference.new( index1: index1, - index2: index2 + index2: index2, ) end - def visit_index_reference(ctx) - raise 'Invalid state' + def visit_index_reference(_ctx) + raise "Invalid state" end def visit_instantiable_type(ctx) @@ -1332,7 +1335,7 @@ def visit_instantiable_type(ctx) visit_if(ctx__concrete_types || ctx__entity_ref) end - def visit_integer_type(ctx) + def visit_integer_type(_ctx) Model::DataTypes::Integer.new end @@ -1361,7 +1364,7 @@ def visit_interval(ctx) operator1: operator1, item: item, operator2: operator2, - high: high + high: high, ) end @@ -1385,15 +1388,15 @@ def visit_interval_low(ctx) def visit_interval_op(ctx) ctx__text = ctx.values[0].text - ctx__LESS_THAN = ctx__text == '<' - ctx__LESS_THAN_OR_EQUAL = ctx__text == '<=' + ctx__LESS_THAN = ctx__text == "<" + ctx__LESS_THAN_OR_EQUAL = ctx__text == "<=" if ctx__LESS_THAN Model::Expressions::Interval::LESS_THAN elsif ctx__LESS_THAN_OR_EQUAL Model::Expressions::Interval::LESS_THAN_OR_EQUAL else - raise 'Invalid state' + raise "Invalid state" end end @@ -1406,23 +1409,23 @@ def visit_inverse_attr(ctx) attribute = visit_if(ctx__attribute_decl) type = visit_if(ctx__inverse_attr_type) expression = if ctx__entity_ref - ref = visit(ctx__entity_ref) - attribute_ref = visit(ctx__attribute_ref) + ref = visit(ctx__entity_ref) + attribute_ref = visit(ctx__attribute_ref) - Model::References::AttributeReference.new( - ref: ref, - attribute: attribute_ref - ) - else - visit(ctx__attribute_ref) - end + Model::References::AttributeReference.new( + ref: ref, + attribute: attribute_ref, + ) + else + visit(ctx__attribute_ref) + end Model::Declarations::Attribute.new( id: attribute.id, # reuse kind: Model::Declarations::Attribute::INVERSE, supertype_attribute: attribute.supertype_attribute, # reuse type: type, - expression: expression + expression: expression, ) end @@ -1442,7 +1445,7 @@ def visit_inverse_attr_type(ctx) Model::DataTypes::Set.new( bound1: bound1, bound2: bound2, - base_type: base_type + base_type: base_type, ) elsif ctx__BAG bound1 = visit_if(ctx__bound_spec__bound1) @@ -1452,7 +1455,7 @@ def visit_inverse_attr_type(ctx) Model::DataTypes::Bag.new( bound1: bound1, bound2: bound2, - base_type: base_type + base_type: base_type, ) else visit_if(ctx__entity_ref) @@ -1481,7 +1484,7 @@ def visit_list_type(ctx) bound1: bound1, bound2: bound2, unique: unique, - base_type: base_type + base_type: base_type, ) end @@ -1503,7 +1506,7 @@ def visit_literal(ctx) elsif ctx__string_literal visit(ctx__string_literal) else - raise 'Invalid state' + raise "Invalid state" end end @@ -1526,7 +1529,7 @@ def visit_local_variable(ctx) Model::Declarations::Variable.new( id: id, type: type, - expression: expression + expression: expression, ) end end @@ -1543,32 +1546,32 @@ def visit_logical_literal(ctx) ctx__UNKNOWN = ctx.tUNKNOWN value = if ctx__TRUE - Model::Literals::Logical::TRUE - elsif ctx__FALSE - Model::Literals::Logical::FALSE - elsif ctx__UNKNOWN - Model::Literals::Logical::UNKNOWN - else - raise 'Invalid state' - end + Model::Literals::Logical::TRUE + elsif ctx__FALSE + Model::Literals::Logical::FALSE + elsif ctx__UNKNOWN + Model::Literals::Logical::UNKNOWN + else + raise "Invalid state" + end Model::Literals::Logical.new( - value: value + value: value, ) end - def visit_logical_type(ctx) + def visit_logical_type(_ctx) Model::DataTypes::Logical.new end def visit_multiplication_like_op(ctx) ctx__text = ctx.values[0].text - ctx__MULTIPLICATION = ctx__text == '*' - ctx__REAL_DIVISION = ctx__text == '/' + ctx__MULTIPLICATION = ctx__text == "*" + ctx__REAL_DIVISION = ctx__text == "/" ctx__INTEGER_DIVISION = ctx.tDIV ctx__MODULO = ctx.tMOD ctx__AND = ctx.tAND - ctx__COMBINE = ctx__text == '||' + ctx__COMBINE = ctx__text == "||" if ctx__MULTIPLICATION Model::Expressions::BinaryExpression::MULTIPLICATION @@ -1583,7 +1586,7 @@ def visit_multiplication_like_op(ctx) elsif ctx__COMBINE Model::Expressions::BinaryExpression::COMBINE else - raise 'Invalid state' + raise "Invalid state" end end @@ -1604,15 +1607,15 @@ def visit_named_type_or_rename(ctx) Model::Declarations::InterfaceItem.new( ref: ref, - id: id + id: id, ) end - def visit_null_stmt(ctx) + def visit_null_stmt(_ctx) Model::Statements::Null.new end - def visit_number_type(ctx) + def visit_number_type(_ctx) Model::DataTypes::Number.new end @@ -1628,7 +1631,7 @@ def visit_one_of(ctx) operands = visit_if_map(ctx__supertype_expression) Model::SupertypeExpressions::OneofSupertypeExpression.new( - operands: operands + operands: operands, ) end @@ -1674,7 +1677,7 @@ def visit_primary(ctx) elsif ctx__qualifiable_factor handle_qualified_ref(visit(ctx__qualifiable_factor), ctx__qualifier) else - raise 'Invalid state' + raise "Invalid state" end end @@ -1688,7 +1691,7 @@ def visit_procedure_call_stmt(ctx) Model::Statements::ProcedureCall.new( procedure: procedure, - parameters: parameters + parameters: parameters, ) end @@ -1705,11 +1708,11 @@ def visit_procedure_decl(ctx) id = visit_if(ctx__procedure_head__procedure_id) parameters = visit_if_map_flatten(ctx__procedure_head__procedure_head_parameter) declarations = visit_if_map(ctx__algorithm_head__declaration) - types = declarations.select{|x| x.is_a? Model::Declarations::Type} - entities = declarations.select{|x| x.is_a? Model::Declarations::Entity} - subtype_constraints = declarations.select{|x| x.is_a? Model::Declarations::SubtypeConstraint} - functions = declarations.select{|x| x.is_a? Model::Declarations::Function} - procedures = declarations.select{|x| x.is_a? Model::Declarations::Procedure} + types = declarations.select { |x| x.is_a? Model::Declarations::Type } + entities = declarations.select { |x| x.is_a? Model::Declarations::Entity } + subtype_constraints = declarations.select { |x| x.is_a? Model::Declarations::SubtypeConstraint } + functions = declarations.select { |x| x.is_a? Model::Declarations::Function } + procedures = declarations.select { |x| x.is_a? Model::Declarations::Procedure } constants = visit_if(ctx__algorithm_head__constant_decl, []) variables = visit_if(ctx__algorithm_head__local_decl, []) statements = visit_if_map(ctx__stmt) @@ -1724,17 +1727,17 @@ def visit_procedure_decl(ctx) procedures: procedures, constants: constants, variables: variables, - statements: statements + statements: statements, ) end - def visit_procedure_head(ctx) - raise 'Invalid state' + def visit_procedure_head(_ctx) + raise "Invalid state" end def visit_procedure_head_parameter(ctx) ctx__formal_parameter = ctx.formal_parameter - ctx__VAR = ctx.tVAR + ctx.tVAR parameters = visit(ctx__formal_parameter) @@ -1743,7 +1746,7 @@ def visit_procedure_head_parameter(ctx) Model::Declarations::Parameter.new( id: parameter.id, var: true, - type: parameter.type + type: parameter.type, ) end else @@ -1771,18 +1774,18 @@ def visit_qualified_attribute(ctx) ctx__group_qualifier = ctx.group_qualifier ctx__attribute_qualifier = ctx.attribute_qualifier - id = 'SELF' + id = "SELF" group_reference = visit_if(ctx__group_qualifier) attribute_reference = visit_if(ctx__attribute_qualifier) Model::References::AttributeReference.new( ref: Model::References::GroupReference.new( ref: Model::References::SimpleReference.new( - id: id + id: id, ), - entity: group_reference.entity # reuse + entity: group_reference.entity, # reuse ), - attribute: attribute_reference.attribute # reuse + attribute: attribute_reference.attribute, # reuse ) end @@ -1806,7 +1809,7 @@ def visit_query_expression(ctx) Model::Expressions::QueryExpression.new( id: id, aggregate_source: aggregate_source, - expression: expression + expression: expression, ) end @@ -1816,12 +1819,12 @@ def visit_real_type(ctx) precision = visit_if(ctx__precision_spec) Model::DataTypes::Real.new( - precision: precision + precision: precision, ) end - def visit_redeclared_attribute(ctx) - raise 'Invalid state' + def visit_redeclared_attribute(_ctx) + raise "Invalid state" end def visit_referenced_attribute(ctx) @@ -1841,20 +1844,20 @@ def visit_reference_clause(ctx) Model::Declarations::Interface.new( kind: Model::Declarations::Interface::REFERENCE, schema: schema, - items: items + items: items, ) end def visit_rel_op(ctx) ctx__text = ctx.values[0].text - ctx__LESS_THAN = ctx__text == '<' - ctx__GREATER_THAN = ctx__text == '>' - ctx__LESS_THAN_OR_EQUAL = ctx__text == '<=' - ctx__GREATER_THAN_OR_EQUAL = ctx__text == '>=' - ctx__NOT_EQUAL = ctx__text == '<>' - ctx__EQUAL = ctx__text == '=' - ctx__INSTANCE_NOT_EQUAL = ctx__text == ':<>:' - ctx__INSTANCE_EQUAL = ctx__text == ':=:' + ctx__LESS_THAN = ctx__text == "<" + ctx__GREATER_THAN = ctx__text == ">" + ctx__LESS_THAN_OR_EQUAL = ctx__text == "<=" + ctx__GREATER_THAN_OR_EQUAL = ctx__text == ">=" + ctx__NOT_EQUAL = ctx__text == "<>" + ctx__EQUAL = ctx__text == "=" + ctx__INSTANCE_NOT_EQUAL = ctx__text == ":<>:" + ctx__INSTANCE_EQUAL = ctx__text == ":=:" if ctx__LESS_THAN Model::Expressions::BinaryExpression::LESS_THAN @@ -1873,7 +1876,7 @@ def visit_rel_op(ctx) elsif ctx__INSTANCE_EQUAL Model::Expressions::BinaryExpression::INSTANCE_EQUAL else - raise 'Invalid state' + raise "Invalid state" end end @@ -1889,7 +1892,7 @@ def visit_rel_op_extended(ctx) elsif ctx__LIKE Model::Expressions::BinaryExpression::LIKE else - raise 'Invalid state' + raise "Invalid state" end end @@ -1904,7 +1907,7 @@ def visit_rename_id(ctx) end def visit_repeat_control(ctx) - (SimpleCtx === ctx) ? to_ctx({},:repeatControl) : ctx + SimpleCtx === ctx ? to_ctx({}, :repeatControl) : ctx end def visit_repeat_stmt(ctx) @@ -1933,7 +1936,7 @@ def visit_repeat_stmt(ctx) increment: increment, while_expression: while_expression, until_expression: until_expression, - statements: statements + statements: statements, ) end @@ -1952,7 +1955,7 @@ def visit_resource_or_rename(ctx) Model::Declarations::InterfaceItem.new( ref: ref, - id: id + id: id, ) end @@ -1972,7 +1975,7 @@ def visit_return_stmt(ctx) expression = visit_if(ctx__expression) Model::Statements::Return.new( - expression: expression + expression: expression, ) end @@ -1990,11 +1993,11 @@ def visit_rule_decl(ctx) id = visit_if(ctx__rule_head__rule_id) applies_to = visit_if_map(ctx__rule_head__entity_ref) declarations = visit_if_map(ctx__algorithm_head__declaration) - types = declarations.select{|x| x.is_a? Model::Declarations::Type} - entities = declarations.select{|x| x.is_a? Model::Declarations::Entity} - subtype_constraints = declarations.select{|x| x.is_a? Model::Declarations::SubtypeConstraint} - functions = declarations.select{|x| x.is_a? Model::Declarations::Function} - procedures = declarations.select{|x| x.is_a? Model::Declarations::Procedure} + types = declarations.select { |x| x.is_a? Model::Declarations::Type } + entities = declarations.select { |x| x.is_a? Model::Declarations::Entity } + subtype_constraints = declarations.select { |x| x.is_a? Model::Declarations::SubtypeConstraint } + functions = declarations.select { |x| x.is_a? Model::Declarations::Function } + procedures = declarations.select { |x| x.is_a? Model::Declarations::Procedure } constants = visit_if(ctx__algorithm_head__constant_decl, []) variables = visit_if(ctx__algorithm_head__local_decl, []) statements = visit_if_map(ctx__stmt) @@ -2011,12 +2014,12 @@ def visit_rule_decl(ctx) constants: constants, variables: variables, statements: statements, - where_rules: where_rules + where_rules: where_rules, ) end - def visit_rule_head(ctx) - raise 'Invalid state' + def visit_rule_head(_ctx) + raise "Invalid state" end def visit_rule_id(ctx) @@ -2031,8 +2034,8 @@ def visit_rule_label_id(ctx) handle_simple_id(ctx__SimpleId) end - def visit_schema_body(ctx) - raise 'Invalid state' + def visit_schema_body(_ctx) + raise "Invalid state" end def visit_schema_body_declaration(ctx) @@ -2055,12 +2058,12 @@ def visit_schema_decl(ctx) interfaces = visit_if_map(ctx__schema_body__interface_specification) constants = visit_if(ctx__schema_body__constant_decl, []) declarations = visit_if_map(ctx__schema_body__schema_body_declaration) - types = declarations.select{|x| x.is_a? Model::Declarations::Type} - entities = declarations.select{|x| x.is_a? Model::Declarations::Entity} - subtype_constraints = declarations.select{|x| x.is_a? Model::Declarations::SubtypeConstraint} - functions = declarations.select{|x| x.is_a? Model::Declarations::Function} - rules = declarations.select{|x| x.is_a? Model::Declarations::Rule} - procedures = declarations.select{|x| x.is_a? Model::Declarations::Procedure} + types = declarations.select { |x| x.is_a? Model::Declarations::Type } + entities = declarations.select { |x| x.is_a? Model::Declarations::Entity } + subtype_constraints = declarations.select { |x| x.is_a? Model::Declarations::SubtypeConstraint } + functions = declarations.select { |x| x.is_a? Model::Declarations::Function } + rules = declarations.select { |x| x.is_a? Model::Declarations::Rule } + procedures = declarations.select { |x| x.is_a? Model::Declarations::Procedure } Model::Declarations::Schema.new( id: id, @@ -2072,7 +2075,7 @@ def visit_schema_decl(ctx) subtype_constraints: subtype_constraints, functions: functions, rules: rules, - procedures: procedures + procedures: procedures, ) end @@ -2088,34 +2091,34 @@ def visit_schema_version_id(ctx) value = visit_if(ctx__string_literal) value = value.value - items = if value.start_with?('{') and value.end_with?('}') - parts = value.sub(/^\{/, '').sub(/\}$/, '').split(' ') - parts.map do |part| - if match = part.match(/^(.+)\((\d+)\)$/) - Model::Declarations::SchemaVersionItem.new( - name: match[1], - value: match[2] - ) - elsif part.match(/^\d+$/) - Model::Declarations::SchemaVersionItem.new( - value: part - ) - else - Model::Declarations::SchemaVersionItem.new( - name: part - ) - end - end - end + items = if value.start_with?("{") && value.end_with?("}") + parts = value.sub(/^\{/, "").sub(/\}$/, "").split(" ") + parts.map do |part| + if match = part.match(/^(.+)\((\d+)\)$/) + Model::Declarations::SchemaVersionItem.new( + name: match[1], + value: match[2], + ) + elsif /^\d+$/.match?(part) + Model::Declarations::SchemaVersionItem.new( + value: part, + ) + else + Model::Declarations::SchemaVersionItem.new( + name: part, + ) + end + end + end Model::Declarations::SchemaVersion.new( value: value, - items: items + items: items, ) end - def visit_selector(ctx) - raise 'Invalid state' + def visit_selector(_ctx) + raise "Invalid state" end def visit_select_extension(ctx) @@ -2147,7 +2150,7 @@ def visit_select_type(ctx) extensible: extensible, generic_entity: generic_entity, based_on: based_on, - items: items + items: items, ) end @@ -2164,28 +2167,28 @@ def visit_set_type(ctx) Model::DataTypes::Set.new( bound1: bound1, bound2: bound2, - base_type: base_type + base_type: base_type, ) end def visit_simple_expression(ctx) - ctx__term = [ctx.term] + ctx.rhs.map { |item| item.term } + ctx__term = [ctx.term] + ctx.rhs.map(&:term) ctx__add_like_op = ctx.rhs.map { |item| item.operator.values[0] } if ctx__term if ctx__term.length >= 2 - if ctx__add_like_op and ctx__add_like_op.length == ctx__term.length - 1 - operands = ctx__term.map(&self.method(:visit)) - operators = ctx__add_like_op.map(&self.method(:visit)) + if ctx__add_like_op && (ctx__add_like_op.length == ctx__term.length - 1) + operands = ctx__term.map(&method(:visit)) + operators = ctx__add_like_op.map(&method(:visit)) handle_binary_expression(operands, operators) else - raise 'Invalid state' + raise "Invalid state" end elsif ctx__term.length == 1 visit(ctx__term[0]) else - raise 'Invalid state' + raise "Invalid state" end end end @@ -2199,7 +2202,10 @@ def visit_simple_factor(ctx) ctx__simple_factor_expression = ctx.simple_factor_expression ctx__simple_factor_unary_expression = ctx.simple_factor_unary_expression - visit_if(ctx__aggregate_initializer || ctx__entity_constructor || ctx__enumeration_reference || ctx__interval || ctx__query_expression || ctx__simple_factor_expression || ctx__simple_factor_unary_expression) + visit_if(ctx__aggregate_initializer || ctx__entity_constructor || + ctx__enumeration_reference || ctx__interval || + ctx__query_expression || ctx__simple_factor_expression || + ctx__simple_factor_unary_expression) end def visit_simple_factor_expression(ctx) @@ -2218,7 +2224,7 @@ def visit_simple_factor_unary_expression(ctx) Model::Expressions::UnaryExpression.new( operator: operator, - operand: operand + operand: operand, ) end @@ -2231,10 +2237,12 @@ def visit_simple_types(ctx) ctx__real_type = ctx.real_type ctx__string_type = ctx.string_type - visit_if(ctx__binary_type || ctx__boolean_type || ctx__integer_type || ctx__logical_type || ctx__number_type || ctx__real_type || ctx__string_type) + visit_if(ctx__binary_type || ctx__boolean_type || ctx__integer_type || + ctx__logical_type || ctx__number_type || ctx__real_type || + ctx__string_type) end - def visit_skip_stmt(ctx) + def visit_skip_stmt(_ctx) Model::Statements::Skip.new end @@ -2251,7 +2259,10 @@ def visit_stmt(ctx) ctx__return_stmt = ctx.return_stmt ctx__skip_stmt = ctx.skip_stmt - visit_if(ctx__alias_stmt || ctx__assignment_stmt || ctx__case_stmt || ctx__compound_stmt || ctx__escape_stmt || ctx__if_stmt || ctx__null_stmt || ctx__procedure_call_stmt || ctx__repeat_stmt || ctx__return_stmt || ctx__skip_stmt) + visit_if(ctx__alias_stmt || ctx__assignment_stmt || ctx__case_stmt || + ctx__compound_stmt || ctx__escape_stmt || ctx__if_stmt || + ctx__null_stmt || ctx__procedure_call_stmt || + ctx__repeat_stmt || ctx__return_stmt || ctx__skip_stmt) end def visit_string_literal(ctx) @@ -2263,7 +2274,7 @@ def visit_string_literal(ctx) elsif ctx__EncodedStringLiteral handle_encoded_string_literal(ctx__EncodedStringLiteral) else - raise 'Invalid state' + raise "Invalid state" end end @@ -2277,12 +2288,12 @@ def visit_string_type(ctx) Model::DataTypes::String.new( width: width, - fixed: fixed + fixed: fixed, ) end def visit_subsuper(ctx) - (SimpleCtx === ctx) ? to_ctx({},:subsuper) : ctx + SimpleCtx === ctx ? to_ctx({}, :subsuper) : ctx end def visit_subtype_constraint(ctx) @@ -2292,7 +2303,7 @@ def visit_subtype_constraint(ctx) end def visit_subtype_constraint_body(ctx) - (SimpleCtx === ctx) ? to_ctx({},:subtypeConstraintBody) : ctx + SimpleCtx === ctx ? to_ctx({}, :subtypeConstraintBody) : ctx end def visit_subtype_constraint_decl(ctx) @@ -2315,12 +2326,12 @@ def visit_subtype_constraint_decl(ctx) applies_to: applies_to, abstract: abstract, total_over: total_over, - supertype_expression: supertype_expression + supertype_expression: supertype_expression, ) end - def visit_subtype_constraint_head(ctx) - raise 'Invalid state' + def visit_subtype_constraint_head(_ctx) + raise "Invalid state" end def visit_subtype_constraint_id(ctx) @@ -2335,50 +2346,50 @@ def visit_subtype_declaration(ctx) visit_if_map(ctx__entity_ref) end - def visit_supertype_constraint(ctx) - raise 'Invalid state' + def visit_supertype_constraint(_ctx) + raise "Invalid state" end def visit_supertype_expression(ctx) - ctx__supertype_factor = [ctx.supertype_factor]+ctx.rhs.map { |item| item.supertype_factor } + ctx__supertype_factor = [ctx.supertype_factor] + ctx.rhs.map(&:supertype_factor) ctx__ANDOR = ctx.rhs.map { |item| item.operator.values[0] } if ctx__supertype_factor if ctx__supertype_factor.length >= 2 - if ctx__ANDOR and ctx__ANDOR.length == ctx__supertype_factor.length - 1 - operands = ctx__supertype_factor.map(&self.method(:visit)) - operators = ctx__ANDOR.map{Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR} + if ctx__ANDOR && (ctx__ANDOR.length == ctx__supertype_factor.length - 1) + operands = ctx__supertype_factor.map(&method(:visit)) + operators = ctx__ANDOR.map { Model::SupertypeExpressions::BinarySupertypeExpression::ANDOR } handle_binary_supertype_expression(operands, operators) else - raise 'Invalid state' + raise "Invalid state" end elsif ctx__supertype_factor.length == 1 visit(ctx__supertype_factor[0]) else - raise 'Invalid state' + raise "Invalid state" end end end def visit_supertype_factor(ctx) - ctx__supertype_term = [ctx.supertype_term] + ctx.rhs.map { |item| item.supertype_term } + ctx__supertype_term = [ctx.supertype_term] + ctx.rhs.map(&:supertype_term) ctx__AND = ctx.rhs.map { |item| item.operator.values[0] } if ctx__supertype_term if ctx__supertype_term.length >= 2 - if ctx__AND and ctx__AND.length == ctx__supertype_term.length - 1 - operands = ctx__supertype_term.map(&self.method(:visit)) - operators = ctx__AND.map{Model::SupertypeExpressions::BinarySupertypeExpression::AND} + if ctx__AND && (ctx__AND.length == ctx__supertype_term.length - 1) + operands = ctx__supertype_term.map(&method(:visit)) + operators = ctx__AND.map { Model::SupertypeExpressions::BinarySupertypeExpression::AND } handle_binary_supertype_expression(operands, operators) else - raise 'Invalid state' + raise "Invalid state" end elsif ctx__supertype_term.length == 1 visit(ctx__supertype_term[0]) else - raise 'Invalid state' + raise "Invalid state" end end end @@ -2403,28 +2414,28 @@ def visit_syntax(ctx) schemas = visit_if_map(ctx__schema_decl) Model::Repository.new( - schemas: schemas + schemas: schemas, ) end def visit_term(ctx) - ctx__factor = [ctx.factor] + ctx.rhs.map { |item| item.factor } - ctx__multiplication_like_op = ctx.rhs.map { |item| item.multiplication_like_op } + ctx__factor = [ctx.factor] + ctx.rhs.map(&:factor) + ctx__multiplication_like_op = ctx.rhs.map(&:multiplication_like_op) if ctx__factor if ctx__factor.length >= 2 - if ctx__multiplication_like_op and ctx__multiplication_like_op.length == ctx__factor.length - 1 - operands = ctx__factor.map(&self.method(:visit)) - operators = ctx__multiplication_like_op.map(&self.method(:visit)) + if ctx__multiplication_like_op && (ctx__multiplication_like_op.length == ctx__factor.length - 1) + operands = ctx__factor.map(&method(:visit)) + operators = ctx__multiplication_like_op.map(&method(:visit)) handle_binary_expression(operands, operators) else - raise 'Invalid state' + raise "Invalid state" end elsif ctx__factor.length == 1 visit(ctx__factor[0]) else - raise 'Invalid state' + raise "Invalid state" end end end @@ -2447,7 +2458,7 @@ def visit_type_decl(ctx) Model::Declarations::Type.new( id: id, underlying_type: underlying_type, - where_rules: where_rules + where_rules: where_rules, ) end @@ -2472,8 +2483,8 @@ def visit_type_label_id(ctx) def visit_unary_op(ctx) ctx__text = ctx.values[0].text - ctx__PLUS = ctx__text == '+' - ctx__MINUS = ctx__text == '-' + ctx__PLUS = ctx__text == "+" + ctx__MINUS = ctx__text == "-" ctx__NOT = ctx.tNOT if ctx__PLUS @@ -2483,7 +2494,7 @@ def visit_unary_op(ctx) elsif ctx__NOT Model::Expressions::UnaryExpression::NOT else - raise 'Invalid state' + raise "Invalid state" end end @@ -2509,7 +2520,7 @@ def visit_unique_rule(ctx) Model::Declarations::UniqueRule.new( id: id, - attributes: attributes + attributes: attributes, ) end @@ -2529,7 +2540,7 @@ def visit_use_clause(ctx) Model::Declarations::Interface.new( kind: Model::Declarations::Interface::USE, schema: schema, - items: items + items: items, ) end @@ -2557,25 +2568,25 @@ def visit_width(ctx) visit_if(ctx__numeric_expression) end - def visit_width_spec(ctx) - raise 'Invalid state' + def visit_width_spec(_ctx) + raise "Invalid state" end def handle_binary_expression(operands, operators) if operands.length != operators.length + 1 - raise 'Invalid state' + raise "Invalid state" end expression = Model::Expressions::BinaryExpression.new( operator: operators[0], operand1: operands[0], - operand2: operands[1] + operand2: operands[1], ) operators[1..(operators.length - 1)].each_with_index do |operator, i| expression = Model::Expressions::BinaryExpression.new( operator: operator, operand1: expression, - operand2: operands[i + 2] + operand2: operands[i + 2], ) end expression @@ -2583,19 +2594,19 @@ def handle_binary_expression(operands, operators) def handle_binary_supertype_expression(operands, operators) if operands.length != operators.length + 1 - raise 'Invalid state' + raise "Invalid state" end expression = Model::SupertypeExpressions::BinarySupertypeExpression.new( operator: operators[0], operand1: operands[0], - operand2: operands[1] + operand2: operands[1], ) operators[1..(operators.length - 1)].each_with_index do |operator, i| expression = Model::SupertypeExpressions::BinarySupertypeExpression.new( operator: operator, operand1: expression, - operand2: operands[i + 2] + operand2: operands[i + 2], ) end expression @@ -2612,14 +2623,14 @@ def handle_qualified_ref(ref, qualifiers) Model::References::AttributeReference.new( ref: ref, - attribute: attribute_reference.attribute + attribute: attribute_reference.attribute, ) elsif ctx__group_qualifier group_reference = visit_if(ctx__group_qualifier) Model::References::GroupReference.new( ref: ref, - entity: group_reference.entity + entity: group_reference.entity, ) elsif ctx__index_qualifier index_reference = visit_if(ctx__index_qualifier) @@ -2627,10 +2638,10 @@ def handle_qualified_ref(ref, qualifiers) Model::References::IndexReference.new( ref: ref, index1: index_reference.index1, - index2: index_reference.index2 + index2: index_reference.index2, ) else - raise 'Invalid state' + raise "Invalid state" end end end @@ -2641,7 +2652,7 @@ def handle_binary_literal(ctx) value = ctx__text[1..(ctx__text.length - 1)] Model::Literals::Binary.new( - value: value + value: value, ) end @@ -2651,7 +2662,7 @@ def handle_integer_literal(ctx) value = ctx__text Model::Literals::Integer.new( - value: value + value: value, ) end @@ -2661,34 +2672,32 @@ def handle_real_literal(ctx) value = ctx__text Model::Literals::Real.new( - value: value + value: value, ) end def handle_simple_id(ctx) - ctx__text = ctx.text - - ctx__text + ctx.text end def handle_simple_string_literal(ctx) ctx__text = ctx.text - value = ctx__text[1..(ctx__text.length - 2)].force_encoding('UTF-8') + value = ctx__text[1..(ctx__text.length - 2)].force_encoding("UTF-8") Model::Literals::String.new( - value: value + value: value, ) end def handle_encoded_string_literal(ctx) ctx__text = ctx.text - value = ctx__text[1..(ctx__text.length - 2)].force_encoding('UTF-8') + value = ctx__text[1..(ctx__text.length - 2)].force_encoding("UTF-8") Model::Literals::String.new( value: value, - encoded: true + encoded: true, ) end end diff --git a/lib/expressir/model/cache.rb b/lib/expressir/model/cache.rb index 5b860e08..8f35f5e9 100644 --- a/lib/expressir/model/cache.rb +++ b/lib/expressir/model/cache.rb @@ -2,8 +2,8 @@ module Expressir module Model # Cache content object with Expressir version class Cache < ModelElement - model_attr_accessor :version, 'String' - model_attr_accessor :content, 'ModelElement' + model_attr_accessor :version, "String" + model_attr_accessor :content, "ModelElement" # @param [Hash] options # @option options [String] :version @@ -14,4 +14,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_type.rb b/lib/expressir/model/data_type.rb index 2812bd40..574c452c 100644 --- a/lib/expressir/model/data_type.rb +++ b/lib/expressir/model/data_type.rb @@ -6,4 +6,4 @@ module Model class DataType < ModelElement end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/aggregate.rb b/lib/expressir/model/data_types/aggregate.rb index 2490f3aa..26e4c210 100644 --- a/lib/expressir/model/data_types/aggregate.rb +++ b/lib/expressir/model/data_types/aggregate.rb @@ -6,7 +6,7 @@ module DataTypes class Aggregate < DataType include Identifier - model_attr_accessor :base_type, 'Type' + model_attr_accessor :base_type, "Type" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -22,10 +22,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/array.rb b/lib/expressir/model/data_types/array.rb index 6dabd20d..7149130c 100644 --- a/lib/expressir/model/data_types/array.rb +++ b/lib/expressir/model/data_types/array.rb @@ -4,11 +4,11 @@ module DataTypes # Specified in ISO 10303-11:2004 # - section 8.2.1 Array data type class Array < DataType - model_attr_accessor :bound1, 'Expression' - model_attr_accessor :bound2, 'Expression' - model_attr_accessor :optional, '::Boolean' - model_attr_accessor :unique, '::Boolean' - model_attr_accessor :base_type, 'DataType' + model_attr_accessor :bound1, "Expression" + model_attr_accessor :bound2, "Expression" + model_attr_accessor :optional, "::Boolean" + model_attr_accessor :unique, "::Boolean" + model_attr_accessor :base_type, "DataType" # @param [Hash] options # @option options [Expression] :bound1 @@ -28,4 +28,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/bag.rb b/lib/expressir/model/data_types/bag.rb index 67062bf1..622d8ea5 100644 --- a/lib/expressir/model/data_types/bag.rb +++ b/lib/expressir/model/data_types/bag.rb @@ -4,9 +4,9 @@ module DataTypes # Specified in ISO 10303-11:2004 # - section 8.2.3 Bag data type class Bag < DataType - model_attr_accessor :bound1, 'Expression' - model_attr_accessor :bound2, 'Expression' - model_attr_accessor :base_type, 'DataType' + model_attr_accessor :bound1, "Expression" + model_attr_accessor :bound2, "Expression" + model_attr_accessor :base_type, "DataType" # @param [Hash] options # @option options [Expression] :bound1 @@ -22,4 +22,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/binary.rb b/lib/expressir/model/data_types/binary.rb index 99b67e2a..3d9db3b3 100644 --- a/lib/expressir/model/data_types/binary.rb +++ b/lib/expressir/model/data_types/binary.rb @@ -4,8 +4,8 @@ module DataTypes # Specified in ISO 10303-11:2004 # - section 8.1.7 Binary data type class Binary < DataType - model_attr_accessor :width, 'Expression' - model_attr_accessor :fixed, '::Boolean' + model_attr_accessor :width, "Expression" + model_attr_accessor :fixed, "::Boolean" # @param [Hash] options # @option options [Expression] :width @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/boolean.rb b/lib/expressir/model/data_types/boolean.rb index dbda723c..b8f0f5db 100644 --- a/lib/expressir/model/data_types/boolean.rb +++ b/lib/expressir/model/data_types/boolean.rb @@ -7,4 +7,4 @@ class Boolean < DataType end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/enumeration.rb b/lib/expressir/model/data_types/enumeration.rb index 189cff0d..4e42ced6 100644 --- a/lib/expressir/model/data_types/enumeration.rb +++ b/lib/expressir/model/data_types/enumeration.rb @@ -4,9 +4,9 @@ module DataTypes # Specified in ISO 10303-11:2004 # - section 8.4.1 Enumeration data type class Enumeration < DataType - model_attr_accessor :extensible, '::Boolean' - model_attr_accessor :based_on, 'Reference' - model_attr_accessor :items, '::Array' + model_attr_accessor :extensible, "::Boolean" + model_attr_accessor :based_on, "Reference" + model_attr_accessor :items, "::Array" # @param [Hash] options # @option options [::Boolean] :extensible @@ -22,4 +22,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/enumeration_item.rb b/lib/expressir/model/data_types/enumeration_item.rb index c7121410..4aee6ada 100644 --- a/lib/expressir/model/data_types/enumeration_item.rb +++ b/lib/expressir/model/data_types/enumeration_item.rb @@ -17,10 +17,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/generic.rb b/lib/expressir/model/data_types/generic.rb index f0d6303a..0b40e518 100644 --- a/lib/expressir/model/data_types/generic.rb +++ b/lib/expressir/model/data_types/generic.rb @@ -17,10 +17,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/generic_entity.rb b/lib/expressir/model/data_types/generic_entity.rb index fadb2d0e..46c625c5 100644 --- a/lib/expressir/model/data_types/generic_entity.rb +++ b/lib/expressir/model/data_types/generic_entity.rb @@ -18,9 +18,9 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/integer.rb b/lib/expressir/model/data_types/integer.rb index 34575eb3..e1955564 100644 --- a/lib/expressir/model/data_types/integer.rb +++ b/lib/expressir/model/data_types/integer.rb @@ -7,4 +7,4 @@ class Integer < DataType end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/list.rb b/lib/expressir/model/data_types/list.rb index 6e625d25..26912061 100644 --- a/lib/expressir/model/data_types/list.rb +++ b/lib/expressir/model/data_types/list.rb @@ -4,10 +4,10 @@ module DataTypes # Specified in ISO 10303-11:2004 # - section 8.2.2 List data type class List < DataType - model_attr_accessor :bound1, 'Expression' - model_attr_accessor :bound2, 'Expression' - model_attr_accessor :unique, '::Boolean' - model_attr_accessor :base_type, 'DataType' + model_attr_accessor :bound1, "Expression" + model_attr_accessor :bound2, "Expression" + model_attr_accessor :unique, "::Boolean" + model_attr_accessor :base_type, "DataType" # @param [Hash] options # @option options [Expression] :bound1 @@ -25,4 +25,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/logical.rb b/lib/expressir/model/data_types/logical.rb index 2c270a01..76589548 100644 --- a/lib/expressir/model/data_types/logical.rb +++ b/lib/expressir/model/data_types/logical.rb @@ -7,4 +7,4 @@ class Logical < DataType end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/number.rb b/lib/expressir/model/data_types/number.rb index 3e94c448..7c091f27 100644 --- a/lib/expressir/model/data_types/number.rb +++ b/lib/expressir/model/data_types/number.rb @@ -7,4 +7,4 @@ class Number < DataType end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/real.rb b/lib/expressir/model/data_types/real.rb index f8dc72a2..9ee5e714 100644 --- a/lib/expressir/model/data_types/real.rb +++ b/lib/expressir/model/data_types/real.rb @@ -4,7 +4,7 @@ module DataTypes # Specified in ISO 10303-11:2004 # - section 8.1.2 Real data type class Real < DataType - model_attr_accessor :precision, 'Expression' + model_attr_accessor :precision, "Expression" # @param [Hash] options # @option options [Expression] :precision @@ -16,4 +16,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/select.rb b/lib/expressir/model/data_types/select.rb index 8dde12e5..f8b2cbd5 100644 --- a/lib/expressir/model/data_types/select.rb +++ b/lib/expressir/model/data_types/select.rb @@ -4,10 +4,10 @@ module DataTypes # Specified in ISO 10303-11:2004 # - section 8.4.2 Select data type class Select < DataType - model_attr_accessor :extensible, '::Boolean' - model_attr_accessor :generic_entity, '::Boolean' - model_attr_accessor :based_on, 'Reference' - model_attr_accessor :items, '::Array' + model_attr_accessor :extensible, "::Boolean" + model_attr_accessor :generic_entity, "::Boolean" + model_attr_accessor :based_on, "Reference" + model_attr_accessor :items, "::Array" # @param [Hash] options # @option options [::Boolean] :extensible @@ -25,4 +25,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/set.rb b/lib/expressir/model/data_types/set.rb index 151c3f4b..e5c42b7f 100644 --- a/lib/expressir/model/data_types/set.rb +++ b/lib/expressir/model/data_types/set.rb @@ -4,9 +4,9 @@ module DataTypes # Specified in ISO 10303-11:2004 # - section 8.2.4 Set data type class Set < DataType - model_attr_accessor :bound1, 'Expression' - model_attr_accessor :bound2, 'Expression' - model_attr_accessor :base_type, 'DataType' + model_attr_accessor :bound1, "Expression" + model_attr_accessor :bound2, "Expression" + model_attr_accessor :base_type, "DataType" # @param [Hash] options # @option options [Expression] :bound1 @@ -22,4 +22,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/data_types/string.rb b/lib/expressir/model/data_types/string.rb index 9322ed4c..d29ba21f 100644 --- a/lib/expressir/model/data_types/string.rb +++ b/lib/expressir/model/data_types/string.rb @@ -4,8 +4,8 @@ module DataTypes # Specified in ISO 10303-11:2004 # - section 8.1.6 String data type class String < DataType - model_attr_accessor :width, 'Expression' - model_attr_accessor :fixed, '::Boolean' + model_attr_accessor :width, "Expression" + model_attr_accessor :fixed, "::Boolean" # @param [Hash] options # @option options [Expression] :width @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declaration.rb b/lib/expressir/model/declaration.rb index bd0fd62c..2770a6f3 100644 --- a/lib/expressir/model/declaration.rb +++ b/lib/expressir/model/declaration.rb @@ -6,4 +6,4 @@ module Model class Declaration < ModelElement end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/attribute.rb b/lib/expressir/model/declarations/attribute.rb index 9e670d5c..68aeaebc 100644 --- a/lib/expressir/model/declarations/attribute.rb +++ b/lib/expressir/model/declarations/attribute.rb @@ -10,11 +10,11 @@ class Attribute < Declaration DERIVED = :DERIVED INVERSE = :INVERSE - model_attr_accessor :kind, ':EXPLICIT, :DERIVED, :INVERSE' - model_attr_accessor :supertype_attribute, 'Reference' - model_attr_accessor :optional, 'Boolean' - model_attr_accessor :type, 'DataType' - model_attr_accessor :expression, 'Expression' + model_attr_accessor :kind, ":EXPLICIT, :DERIVED, :INVERSE" + model_attr_accessor :supertype_attribute, "Reference" + model_attr_accessor :optional, "Boolean" + model_attr_accessor :type, "DataType" + model_attr_accessor :expression, "Expression" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -38,10 +38,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/constant.rb b/lib/expressir/model/declarations/constant.rb index fd8b08f1..9f38e377 100644 --- a/lib/expressir/model/declarations/constant.rb +++ b/lib/expressir/model/declarations/constant.rb @@ -6,8 +6,8 @@ module Declarations class Constant < Declaration include Identifier - model_attr_accessor :type, 'DataType' - model_attr_accessor :expression, 'Expression' + model_attr_accessor :type, "DataType" + model_attr_accessor :expression, "Expression" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -25,10 +25,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/entity.rb b/lib/expressir/model/declarations/entity.rb index 75f154c5..21e142a4 100644 --- a/lib/expressir/model/declarations/entity.rb +++ b/lib/expressir/model/declarations/entity.rb @@ -6,13 +6,13 @@ module Declarations class Entity < Declaration include Identifier - model_attr_accessor :abstract, 'Boolean' - model_attr_accessor :supertype_expression, 'SupertypeExpression' - model_attr_accessor :subtype_of, 'Array' - model_attr_accessor :attributes, 'Array' - model_attr_accessor :unique_rules, 'Array' - model_attr_accessor :where_rules, 'Array' - model_attr_accessor :informal_propositions, 'Array' + model_attr_accessor :abstract, "Boolean" + model_attr_accessor :supertype_expression, "SupertypeExpression" + model_attr_accessor :subtype_of, "Array" + model_attr_accessor :attributes, "Array" + model_attr_accessor :unique_rules, "Array" + model_attr_accessor :where_rules, "Array" + model_attr_accessor :informal_propositions, "Array" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -44,10 +44,10 @@ def children *unique_rules, *where_rules, *informal_propositions, - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/function.rb b/lib/expressir/model/declarations/function.rb index 2c1600a7..491ef62c 100644 --- a/lib/expressir/model/declarations/function.rb +++ b/lib/expressir/model/declarations/function.rb @@ -6,16 +6,16 @@ module Declarations class Function < Declaration include Identifier - model_attr_accessor :parameters, 'Array' - model_attr_accessor :return_type, 'DataType' - model_attr_accessor :types, 'Array' - model_attr_accessor :entities, 'Array' - model_attr_accessor :subtype_constraints, 'Array' - model_attr_accessor :functions, 'Array' - model_attr_accessor :procedures, 'Array' - model_attr_accessor :constants, 'Array' - model_attr_accessor :variables, 'Array' - model_attr_accessor :statements, 'Array' + model_attr_accessor :parameters, "Array" + model_attr_accessor :return_type, "DataType" + model_attr_accessor :types, "Array" + model_attr_accessor :entities, "Array" + model_attr_accessor :subtype_constraints, "Array" + model_attr_accessor :functions, "Array" + model_attr_accessor :procedures, "Array" + model_attr_accessor :constants, "Array" + model_attr_accessor :variables, "Array" + model_attr_accessor :statements, "Array" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -51,17 +51,17 @@ def children [ *parameters, *types, - *types.flat_map{|x| x.enumeration_items}, + *types.flat_map(&:enumeration_items), *entities, *subtype_constraints, *functions, *procedures, *constants, *variables, - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/interface.rb b/lib/expressir/model/declarations/interface.rb index a32e5cf1..58af6369 100644 --- a/lib/expressir/model/declarations/interface.rb +++ b/lib/expressir/model/declarations/interface.rb @@ -7,9 +7,9 @@ class Interface < Declaration USE = :USE REFERENCE = :REFERENCE - model_attr_accessor :kind, ':USE, :REFERENCE' - model_attr_accessor :schema, 'Reference' - model_attr_accessor :items, 'Array' + model_attr_accessor :kind, ":USE, :REFERENCE" + model_attr_accessor :schema, "Reference" + model_attr_accessor :items, "Array" # @param [Hash] options # @option options [:USE, :REFERENCE] :kind @@ -25,4 +25,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/interface_item.rb b/lib/expressir/model/declarations/interface_item.rb index 024355ab..a341193d 100644 --- a/lib/expressir/model/declarations/interface_item.rb +++ b/lib/expressir/model/declarations/interface_item.rb @@ -4,8 +4,8 @@ module Declarations # Specified in ISO 10303-11:2004 # - section 11 Interface specification class InterfaceItem < ModelElement - model_attr_accessor :ref, 'Reference' - model_attr_accessor :id, 'String' + model_attr_accessor :ref, "Reference" + model_attr_accessor :id, "String" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -20,4 +20,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/interfaced_item.rb b/lib/expressir/model/declarations/interfaced_item.rb index ec17bea2..0f560bb1 100644 --- a/lib/expressir/model/declarations/interfaced_item.rb +++ b/lib/expressir/model/declarations/interfaced_item.rb @@ -4,11 +4,11 @@ module Declarations # Specified in ISO 10303-11:2004 # - section 11 Interface specification class InterfacedItem < ModelElement - model_attr_accessor :id, 'String' - model_attr_accessor :remarks, 'Array' - model_attr_accessor :remark_items, 'Array' + model_attr_accessor :id, "String" + model_attr_accessor :remarks, "Array" + model_attr_accessor :remark_items, "Array" - model_attr_accessor :base_item, 'ModelElement' + model_attr_accessor :base_item, "ModelElement" # @param [Hash] options # @option options [String] :id @@ -28,10 +28,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/parameter.rb b/lib/expressir/model/declarations/parameter.rb index 92973113..7af8608a 100644 --- a/lib/expressir/model/declarations/parameter.rb +++ b/lib/expressir/model/declarations/parameter.rb @@ -6,8 +6,8 @@ module Declarations class Parameter < Declaration include Identifier - model_attr_accessor :var, 'Boolean' - model_attr_accessor :type, 'DataType' + model_attr_accessor :var, "Boolean" + model_attr_accessor :type, "DataType" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -25,10 +25,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/procedure.rb b/lib/expressir/model/declarations/procedure.rb index 6ea2bd87..b67f6d6c 100644 --- a/lib/expressir/model/declarations/procedure.rb +++ b/lib/expressir/model/declarations/procedure.rb @@ -6,15 +6,15 @@ module Declarations class Procedure < Declaration include Identifier - model_attr_accessor :parameters, 'Array' - model_attr_accessor :types, 'Array' - model_attr_accessor :entities, 'Array' - model_attr_accessor :subtype_constraints, 'Array' - model_attr_accessor :functions, 'Array' - model_attr_accessor :procedures, 'Array' - model_attr_accessor :constants, 'Array' - model_attr_accessor :variables, 'Array' - model_attr_accessor :statements, 'Array' + model_attr_accessor :parameters, "Array" + model_attr_accessor :types, "Array" + model_attr_accessor :entities, "Array" + model_attr_accessor :subtype_constraints, "Array" + model_attr_accessor :functions, "Array" + model_attr_accessor :procedures, "Array" + model_attr_accessor :constants, "Array" + model_attr_accessor :variables, "Array" + model_attr_accessor :statements, "Array" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -48,17 +48,17 @@ def children [ *parameters, *types, - *types.flat_map{|x| x.enumeration_items}, + *types.flat_map(&:enumeration_items), *entities, *subtype_constraints, *functions, *procedures, *constants, *variables, - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/remark_item.rb b/lib/expressir/model/declarations/remark_item.rb index a99fcf54..befaa302 100644 --- a/lib/expressir/model/declarations/remark_item.rb +++ b/lib/expressir/model/declarations/remark_item.rb @@ -3,8 +3,8 @@ module Model module Declarations # Implicit item with remarks class RemarkItem < Declaration - model_attr_accessor :id, 'String' - model_attr_accessor :remarks, 'Array' + model_attr_accessor :id, "String" + model_attr_accessor :remarks, "Array" # @param [Hash] options # @option options [String] :id @@ -18,4 +18,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/rule.rb b/lib/expressir/model/declarations/rule.rb index 8c16043a..f0257a36 100644 --- a/lib/expressir/model/declarations/rule.rb +++ b/lib/expressir/model/declarations/rule.rb @@ -6,17 +6,17 @@ module Declarations class Rule < Declaration include Identifier - model_attr_accessor :applies_to, 'Array' - model_attr_accessor :types, 'Array' - model_attr_accessor :entities, 'Array' - model_attr_accessor :subtype_constraints, 'Array' - model_attr_accessor :functions, 'Array' - model_attr_accessor :procedures, 'Array' - model_attr_accessor :constants, 'Array' - model_attr_accessor :variables, 'Array' - model_attr_accessor :statements, 'Array' - model_attr_accessor :where_rules, 'Array' - model_attr_accessor :informal_propositions, 'Array' + model_attr_accessor :applies_to, "Array" + model_attr_accessor :types, "Array" + model_attr_accessor :entities, "Array" + model_attr_accessor :subtype_constraints, "Array" + model_attr_accessor :functions, "Array" + model_attr_accessor :procedures, "Array" + model_attr_accessor :constants, "Array" + model_attr_accessor :variables, "Array" + model_attr_accessor :statements, "Array" + model_attr_accessor :where_rules, "Array" + model_attr_accessor :informal_propositions, "Array" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -53,7 +53,7 @@ def initialize(options = {}) def children [ *types, - *types.flat_map{|x| x.enumeration_items}, + *types.flat_map(&:enumeration_items), *entities, *subtype_constraints, *functions, @@ -62,10 +62,10 @@ def children *variables, *where_rules, *informal_propositions, - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/schema.rb b/lib/expressir/model/declarations/schema.rb index 002f90b1..4f1274cf 100644 --- a/lib/expressir/model/declarations/schema.rb +++ b/lib/expressir/model/declarations/schema.rb @@ -4,19 +4,19 @@ module Declarations # Specified in ISO 10303-11:2004 # - section 9.3 Schema class Schema < Declaration - model_attr_accessor :file, 'String' + model_attr_accessor :file, "String" include Identifier - model_attr_accessor :version, 'SchemaVersion' - model_attr_accessor :interfaces, 'Array' - model_attr_accessor :constants, 'Array' - model_attr_accessor :types, 'Array' - model_attr_accessor :entities, 'Array' - model_attr_accessor :subtype_constraints, 'Array' - model_attr_accessor :functions, 'Array' - model_attr_accessor :rules, 'Array' - model_attr_accessor :procedures, 'Array' + model_attr_accessor :version, "SchemaVersion" + model_attr_accessor :interfaces, "Array" + model_attr_accessor :constants, "Array" + model_attr_accessor :types, "Array" + model_attr_accessor :entities, "Array" + model_attr_accessor :subtype_constraints, "Array" + model_attr_accessor :functions, "Array" + model_attr_accessor :rules, "Array" + model_attr_accessor :procedures, "Array" # @param [Hash] options # @option options [String] :file @@ -53,13 +53,13 @@ def safe_children [ *constants, *types, - *types.flat_map{|x| x.enumeration_items}, + *types.flat_map(&:enumeration_items), *entities, *subtype_constraints, *functions, *rules, *procedures, - *remark_items + *remark_items, ] end @@ -67,7 +67,7 @@ def safe_children def children [ *interfaced_items, - *safe_children + *safe_children, ] end @@ -78,7 +78,7 @@ def children # @return [InterfacedItem] def create_interfaced_item(id, base_item) interfaced_item = InterfacedItem.new( - id: id + id: id, ) interfaced_item.base_item = base_item # skip overriding parent interfaced_item.parent = self @@ -93,8 +93,8 @@ def interfaced_items schema = parent.children_by_id[interface.schema.id.safe_downcase] if schema schema_safe_children = schema.safe_children - schema_safe_children_by_id = schema_safe_children.select{|x| x.id}.map{|x| [x.id.safe_downcase, x]}.to_h - if interface.items.length > 0 + schema_safe_children_by_id = schema_safe_children.select(&:id).map { |x| [x.id.safe_downcase, x] }.to_h + if interface.items.length.positive? interface.items.map do |interface_item| base_item = schema_safe_children_by_id[interface_item.ref.id.safe_downcase] if base_item @@ -109,9 +109,9 @@ def interfaced_items end end end - end.select{|x| x} + end.select { |x| x } end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/schema_version.rb b/lib/expressir/model/declarations/schema_version.rb index 740109e5..29d10d45 100644 --- a/lib/expressir/model/declarations/schema_version.rb +++ b/lib/expressir/model/declarations/schema_version.rb @@ -4,8 +4,8 @@ module Declarations # Specified in ISO 10303-11:2004 # - section 9.3 Schema class SchemaVersion < ModelElement - model_attr_accessor :value, 'String' - model_attr_accessor :items, 'Array' + model_attr_accessor :value, "String" + model_attr_accessor :items, "Array" # @param [Hash] options # @option options [String] :value @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/schema_version_item.rb b/lib/expressir/model/declarations/schema_version_item.rb index 6e248572..af3cbcb4 100644 --- a/lib/expressir/model/declarations/schema_version_item.rb +++ b/lib/expressir/model/declarations/schema_version_item.rb @@ -4,8 +4,8 @@ module Declarations # Specified in ISO 10303-11:2004 # - section 9.3 Schema class SchemaVersionItem < ModelElement - model_attr_accessor :name, 'String' - model_attr_accessor :value, 'String' + model_attr_accessor :name, "String" + model_attr_accessor :value, "String" # @param [Hash] options # @option options [String] :name @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/subtype_constraint.rb b/lib/expressir/model/declarations/subtype_constraint.rb index 08ab26e1..3d0fe5ec 100644 --- a/lib/expressir/model/declarations/subtype_constraint.rb +++ b/lib/expressir/model/declarations/subtype_constraint.rb @@ -6,10 +6,10 @@ module Declarations class SubtypeConstraint < Declaration include Identifier - model_attr_accessor :applies_to, 'Reference' - model_attr_accessor :abstract, 'Boolean' - model_attr_accessor :total_over, 'Array' - model_attr_accessor :supertype_expression, 'SupertypeExpression' + model_attr_accessor :applies_to, "Reference" + model_attr_accessor :abstract, "Boolean" + model_attr_accessor :total_over, "Array" + model_attr_accessor :supertype_expression, "SupertypeExpression" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -31,10 +31,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/type.rb b/lib/expressir/model/declarations/type.rb index 44e8e57e..46bbb0da 100644 --- a/lib/expressir/model/declarations/type.rb +++ b/lib/expressir/model/declarations/type.rb @@ -6,9 +6,9 @@ module Declarations class Type < Declaration include Identifier - model_attr_accessor :underlying_type, 'DataType' - model_attr_accessor :where_rules, 'Array' - model_attr_accessor :informal_propositions, 'Array' + model_attr_accessor :underlying_type, "DataType" + model_attr_accessor :where_rules, "Array" + model_attr_accessor :informal_propositions, "Array" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -36,10 +36,10 @@ def children *enumeration_items, *where_rules, *informal_propositions, - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/unique_rule.rb b/lib/expressir/model/declarations/unique_rule.rb index 0d03c19b..4a1b51db 100644 --- a/lib/expressir/model/declarations/unique_rule.rb +++ b/lib/expressir/model/declarations/unique_rule.rb @@ -6,7 +6,7 @@ module Declarations class UniqueRule < Declaration include Identifier - model_attr_accessor :attributes, 'Reference' + model_attr_accessor :attributes, "Reference" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -22,10 +22,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/variable.rb b/lib/expressir/model/declarations/variable.rb index cebd4350..db032a52 100644 --- a/lib/expressir/model/declarations/variable.rb +++ b/lib/expressir/model/declarations/variable.rb @@ -6,8 +6,8 @@ module Declarations class Variable < Declaration include Identifier - model_attr_accessor :type, 'DataType' - model_attr_accessor :expression, 'Expression' + model_attr_accessor :type, "DataType" + model_attr_accessor :expression, "Expression" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -25,10 +25,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/declarations/where_rule.rb b/lib/expressir/model/declarations/where_rule.rb index e92d2435..c04ba6b7 100644 --- a/lib/expressir/model/declarations/where_rule.rb +++ b/lib/expressir/model/declarations/where_rule.rb @@ -6,7 +6,7 @@ module Declarations class WhereRule < Declaration include Identifier - model_attr_accessor :expression, 'Expression' + model_attr_accessor :expression, "Expression" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -22,10 +22,10 @@ def initialize(options = {}) # @return [Array] def children [ - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/expression.rb b/lib/expressir/model/expression.rb index 988a2662..4b28fcd5 100644 --- a/lib/expressir/model/expression.rb +++ b/lib/expressir/model/expression.rb @@ -6,4 +6,4 @@ module Model class Expression < ModelElement end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/expressions/aggregate_initializer.rb b/lib/expressir/model/expressions/aggregate_initializer.rb index bf7cde54..63f851d9 100644 --- a/lib/expressir/model/expressions/aggregate_initializer.rb +++ b/lib/expressir/model/expressions/aggregate_initializer.rb @@ -4,7 +4,7 @@ module Expressions # Specified in ISO 10303-11:2004 # - section 12.9 Aggregate initializer class AggregateInitializer < Expression - model_attr_accessor :items, 'Array' + model_attr_accessor :items, "Array" # @param [Hash] options # @option options [Array] :items @@ -16,4 +16,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/expressions/aggregate_initializer_item.rb b/lib/expressir/model/expressions/aggregate_initializer_item.rb index 09ce9ebf..b2668ee7 100644 --- a/lib/expressir/model/expressions/aggregate_initializer_item.rb +++ b/lib/expressir/model/expressions/aggregate_initializer_item.rb @@ -4,8 +4,8 @@ module Expressions # Specified in ISO 10303-11:2004 # - section 12.9 Aggregate initializer class AggregateInitializerItem < Expression - model_attr_accessor :expression, 'Expression' - model_attr_accessor :repetition, 'Expression' + model_attr_accessor :expression, "Expression" + model_attr_accessor :repetition, "Expression" # @param [Hash] options # @option options [Expression] :expression @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/expressions/binary_expression.rb b/lib/expressir/model/expressions/binary_expression.rb index 2af96e4b..1ce482c7 100644 --- a/lib/expressir/model/expressions/binary_expression.rb +++ b/lib/expressir/model/expressions/binary_expression.rb @@ -32,12 +32,19 @@ class BinaryExpression < Expression SUBTRACTION = :SUBTRACTION XOR = :XOR - model_attr_accessor :operator, ':ADDITION, :AND, :COMBINE, :EQUAL, :EXPONENTIATION, :GREATER_THAN, :GREATER_THAN_OR_EQUAL, :IN, :INSTANCE_EQUAL, :INSTANCE_NOT_EQUAL, :INTEGER_DIVISION, :LESS_THAN, :LESS_THAN_OR_EQUAL, :LIKE, :MODULO, :MULTIPLICATION, :NOT_EQUAL, :OR, :REAL_DIVISION, :SUBTRACTION, :XOR' - model_attr_accessor :operand1, 'Expression' - model_attr_accessor :operand2, 'Expression' + model_attr_accessor :operator, + ":ADDITION, :AND, :COMBINE, :EQUAL, :EXPONENTIATION, :GREATER_THAN, \ + :GREATER_THAN_OR_EQUAL, :IN, :INSTANCE_EQUAL, :INSTANCE_NOT_EQUAL, \ + :INTEGER_DIVISION, :LESS_THAN, :LESS_THAN_OR_EQUAL, :LIKE, :MODULO,\ + :MULTIPLICATION, :NOT_EQUAL, :OR, :REAL_DIVISION, :SUBTRACTION, :XOR" + model_attr_accessor :operand1, "Expression" + model_attr_accessor :operand2, "Expression" # @param [Hash] options - # @option options [:ADDITION, :AND, :COMBINE, :EQUAL, :EXPONENTIATION, :GREATER_THAN, :GREATER_THAN_OR_EQUAL, :IN, :INSTANCE_EQUAL, :INSTANCE_NOT_EQUAL, :INTEGER_DIVISION, :LESS_THAN, :LESS_THAN_OR_EQUAL, :LIKE, :MODULO, :MULTIPLICATION, :NOT_EQUAL, :OR, :REAL_DIVISION, :SUBTRACTION, :XOR] :operator + # @option options [:ADDITION, :AND, :COMBINE, :EQUAL, :EXPONENTIATION, :GREATER_THAN, + # :GREATER_THAN_OR_EQUAL, :IN, :INSTANCE_EQUAL, :INSTANCE_NOT_EQUAL, + # :INTEGER_DIVISION, :LESS_THAN, :LESS_THAN_OR_EQUAL, :LIKE, :MODULO, + # :MULTIPLICATION, :NOT_EQUAL, :OR, :REAL_DIVISION, :SUBTRACTION, :XOR] :operator # @option options [Expression] :operand1 # @option options [Expression] :operand2 def initialize(options = {}) @@ -50,4 +57,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/expressions/entity_constructor.rb b/lib/expressir/model/expressions/entity_constructor.rb index e6922e92..1765f72a 100644 --- a/lib/expressir/model/expressions/entity_constructor.rb +++ b/lib/expressir/model/expressions/entity_constructor.rb @@ -4,8 +4,8 @@ module Expressions # Specified in ISO 10303-11:2004 # - section 9.2.6 Implicit declarations class EntityConstructor < Expression - model_attr_accessor :entity, 'Reference' - model_attr_accessor :parameters, 'Array' + model_attr_accessor :entity, "Reference" + model_attr_accessor :parameters, "Array" # @param [Hash] options # @option options [Reference] :entity @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/expressions/function_call.rb b/lib/expressir/model/expressions/function_call.rb index 37ff9e7e..0a88de23 100644 --- a/lib/expressir/model/expressions/function_call.rb +++ b/lib/expressir/model/expressions/function_call.rb @@ -4,8 +4,8 @@ module Expressions # Specified in ISO 10303-11:2004 # - section 12.8 Function call class FunctionCall < Expression - model_attr_accessor :function, 'Reference' - model_attr_accessor :parameters, 'Array' + model_attr_accessor :function, "Reference" + model_attr_accessor :parameters, "Array" # @param [Hash] options # @option options [Reference] :function @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/expressions/interval.rb b/lib/expressir/model/expressions/interval.rb index c6d0a59d..39b8432c 100644 --- a/lib/expressir/model/expressions/interval.rb +++ b/lib/expressir/model/expressions/interval.rb @@ -7,11 +7,11 @@ class Interval < Expression LESS_THAN = :LESS_THAN LESS_THAN_OR_EQUAL = :LESS_THAN_OR_EQUAL - model_attr_accessor :low, 'Expression' - model_attr_accessor :operator1, ':LESS_THAN, :LESS_THAN_OR_EQUAL' - model_attr_accessor :item, 'Reference' - model_attr_accessor :operator2, ':LESS_THAN, :LESS_THAN_OR_EQUAL' - model_attr_accessor :high, 'Expression' + model_attr_accessor :low, "Expression" + model_attr_accessor :operator1, ":LESS_THAN, :LESS_THAN_OR_EQUAL" + model_attr_accessor :item, "Reference" + model_attr_accessor :operator2, ":LESS_THAN, :LESS_THAN_OR_EQUAL" + model_attr_accessor :high, "Expression" # @param [Hash] options # @option options [Expression] :low @@ -31,4 +31,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/expressions/query_expression.rb b/lib/expressir/model/expressions/query_expression.rb index 99b158d0..84238440 100644 --- a/lib/expressir/model/expressions/query_expression.rb +++ b/lib/expressir/model/expressions/query_expression.rb @@ -6,8 +6,8 @@ module Expressions class QueryExpression < Expression include Identifier - model_attr_accessor :aggregate_source, 'Reference' - model_attr_accessor :expression, 'Expression' + model_attr_accessor :aggregate_source, "Reference" + model_attr_accessor :expression, "Expression" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -26,10 +26,10 @@ def initialize(options = {}) def children [ self, - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/expressions/unary_expression.rb b/lib/expressir/model/expressions/unary_expression.rb index 7fe1f754..1767267a 100644 --- a/lib/expressir/model/expressions/unary_expression.rb +++ b/lib/expressir/model/expressions/unary_expression.rb @@ -9,8 +9,8 @@ class UnaryExpression < Expression NOT = :NOT PLUS = :PLUS - model_attr_accessor :operator, ':MINUS, :NOT, :PLUS' - model_attr_accessor :operand, 'Expression' + model_attr_accessor :operator, ":MINUS, :NOT, :PLUS" + model_attr_accessor :operand, "Expression" # @param [Hash] options # @option options [:MINUS, :NOT, :PLUS] :operator @@ -24,4 +24,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/identifier.rb b/lib/expressir/model/identifier.rb index bd602fd0..5d28ac28 100644 --- a/lib/expressir/model/identifier.rb +++ b/lib/expressir/model/identifier.rb @@ -11,10 +11,10 @@ module Identifier # @return [::String] # @!visibility private def self.included(mod) - mod.model_attr_accessor :id, '::String' - mod.model_attr_accessor :remarks, '::Array<::String>' - mod.model_attr_accessor :remark_items, '::Array' - mod.model_attr_accessor :source, '::String' + mod.model_attr_accessor :id, "::String" + mod.model_attr_accessor :remarks, "::Array<::String>" + mod.model_attr_accessor :remark_items, "::Array" + mod.model_attr_accessor :source, "::String" end # @param [Hash] options @@ -31,4 +31,4 @@ def initialize_identifier(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/literal.rb b/lib/expressir/model/literal.rb index 49929a87..4b00b338 100644 --- a/lib/expressir/model/literal.rb +++ b/lib/expressir/model/literal.rb @@ -6,4 +6,4 @@ module Model class Literal < ModelElement end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/literals/binary.rb b/lib/expressir/model/literals/binary.rb index 7cd08da0..fb949e61 100644 --- a/lib/expressir/model/literals/binary.rb +++ b/lib/expressir/model/literals/binary.rb @@ -4,7 +4,7 @@ module Literals # Specified in ISO 10303-11:2004 # - section 7.5.1 Binary literal class Binary < Literal - model_attr_accessor :value, '::String' + model_attr_accessor :value, "::String" # @param [Hash] options # @option options [::String] :value @@ -16,4 +16,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/literals/integer.rb b/lib/expressir/model/literals/integer.rb index a767d026..0574024c 100644 --- a/lib/expressir/model/literals/integer.rb +++ b/lib/expressir/model/literals/integer.rb @@ -4,7 +4,7 @@ module Literals # Specified in ISO 10303-11:2004 # - section 7.5.2 Integer literal class Integer < Literal - model_attr_accessor :value, '::String' + model_attr_accessor :value, "::String" # @param [Hash] options # @option options [::String] :value @@ -16,4 +16,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/literals/logical.rb b/lib/expressir/model/literals/logical.rb index 3fc3879b..34950a11 100644 --- a/lib/expressir/model/literals/logical.rb +++ b/lib/expressir/model/literals/logical.rb @@ -8,7 +8,7 @@ class Logical < Literal FALSE = :FALSE UNKNOWN = :UNKNOWN - model_attr_accessor :value, ':TRUE, :FALSE, :UNKNOWN' + model_attr_accessor :value, ":TRUE, :FALSE, :UNKNOWN" # @param [Hash] options # @option options [:TRUE, :FALSE, :UNKNOWN] :value @@ -20,4 +20,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/literals/real.rb b/lib/expressir/model/literals/real.rb index 6a2e3fd1..f3679a4f 100644 --- a/lib/expressir/model/literals/real.rb +++ b/lib/expressir/model/literals/real.rb @@ -4,7 +4,7 @@ module Literals # Specified in ISO 10303-11:2004 # - section 7.5.3 Real literal class Real < Literal - model_attr_accessor :value, '::String' + model_attr_accessor :value, "::String" # @param [Hash] options # @option options [::String] :value @@ -16,4 +16,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/literals/string.rb b/lib/expressir/model/literals/string.rb index d7e08a78..68478b15 100644 --- a/lib/expressir/model/literals/string.rb +++ b/lib/expressir/model/literals/string.rb @@ -4,8 +4,8 @@ module Literals # Specified in ISO 10303-11:2004 # - section 7.5.4 String literal class String < Literal - model_attr_accessor :value, '::String' - model_attr_accessor :encoded, '::Boolean' + model_attr_accessor :value, "::String" + model_attr_accessor :encoded, "::Boolean" # @param [Hash] options # @option options [::String] :value @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/model_element.rb b/lib/expressir/model/model_element.rb index 593d5213..05e1dac9 100644 --- a/lib/expressir/model/model_element.rb +++ b/lib/expressir/model/model_element.rb @@ -1,12 +1,12 @@ -require 'pathname' +require "pathname" module Expressir module Model # Base model element class ModelElement - CLASS_KEY = '_class' - FILE_KEY = 'file' - SOURCE_KEY = 'source' + CLASS_KEY = "_class".freeze + FILE_KEY = "file".freeze + SOURCE_KEY = "source".freeze private_constant :CLASS_KEY private_constant :FILE_KEY @@ -16,19 +16,19 @@ class ModelElement attr_accessor :parent # @param [Hash] options - def initialize(options = {}) + def initialize(_options = {}) attach_parent_to_children end # @return [String] def path # this creates an implicit scope - return if is_a? Statements::Alias or is_a? Statements::Repeat or is_a? Expressions::QueryExpression + return if is_a?(Statements::Alias) || is_a?(Statements::Repeat) || is_a?(Expressions::QueryExpression) current_node = self path_parts = [] loop do - if current_node.class.method_defined? :id and !(current_node.is_a? References::SimpleReference) + if current_node.class.method_defined?(:id) && !(current_node.is_a? References::SimpleReference) path_parts << current_node.id end @@ -82,7 +82,7 @@ def children # @return [Hash] def children_by_id - @children_by_id ||= children.select{|x| x.id}.map{|x| [x.id.safe_downcase, x]}.to_h + @children_by_id ||= children.select(&:id).map { |x| [x.id.safe_downcase, x] }.to_h end # @return [nil] @@ -105,11 +105,11 @@ def to_hash(root_path: nil, formatter: nil, include_empty: nil, select_proc: nil hash[CLASS_KEY] = self.class.name self.class.model_attrs.each do |variable| - value = self.send(variable) - empty = value.nil? || (value.is_a?(Array) && value.count == 0) + value = send(variable) + empty = value.nil? || (value.is_a?(Array) && value.count.zero?) # skip empty values - next unless !empty or include_empty + next unless !empty || include_empty value_hash = case value when Array @@ -119,7 +119,7 @@ def to_hash(root_path: nil, formatter: nil, include_empty: nil, select_proc: nil root_path: root_path, formatter: formatter, include_empty: include_empty, - select_proc: select_proc + select_proc: select_proc, ) else v @@ -130,7 +130,7 @@ def to_hash(root_path: nil, formatter: nil, include_empty: nil, select_proc: nil root_path: root_path, formatter: formatter, include_empty: include_empty, - select_proc: select_proc + select_proc: select_proc, ) else value @@ -139,11 +139,11 @@ def to_hash(root_path: nil, formatter: nil, include_empty: nil, select_proc: nil hash[variable.to_s] = value_hash unless value_hash.nil? end - if self.is_a? Declarations::Schema and file + if is_a?(Declarations::Schema) && file hash[FILE_KEY] = root_path ? Pathname.new(file).relative_path_from(root_path).to_s : file end - if self.class.method_defined? :source and formatter + if self.class.method_defined?(:source) && formatter hash[SOURCE_KEY] = formatter.format(self) end @@ -152,19 +152,15 @@ def to_hash(root_path: nil, formatter: nil, include_empty: nil, select_proc: nil # @return [Liquid::Drop] def to_liquid - klass_name = self.class.name.gsub("::Model::", "::Liquid::") + "Drop" + klass_name = "#{self.class.name.gsub('::Model::', '::Liquid::')}Drop" klass = Object.const_get(klass_name) klass.new(self) end - def to_s - to_s(no_remarks: false, formatter: nil) - end - def to_s(no_remarks: false, formatter: nil) formatter ||= Class.new(Expressir::Express::Formatter) do if no_remarks - def format_remarks(node); []; end + def format_remarks(_node); []; end end end formatter.format(self) @@ -181,28 +177,26 @@ def self.from_hash(hash, root_path: nil) value = hash[variable.to_s] node_options[variable] = case value - when Array - value.map do |value| - if value.is_a? Hash - self.from_hash(value, root_path: root_path) - else - value - end - end - when Hash - self.from_hash(value, root_path: root_path) - else - value - end + when Array + value.map do |value| + if value.is_a? Hash + from_hash(value, root_path: root_path) + else + value + end + end + when Hash + from_hash(value, root_path: root_path) + else + value + end end - if node_class == Declarations::Schema and hash[FILE_KEY] + if (node_class == Declarations::Schema) && hash[FILE_KEY] node_options[FILE_KEY.to_sym] = root_path ? File.expand_path("#{root_path}/#{hash[FILE_KEY]}") : hash[FILE_KEY] end - node = node_class.new(node_options) - - node + node_class.new(node_options) end # @return [Array] @@ -216,7 +210,7 @@ def self.model_attrs # @!macro [attach] model_attr_accessor # @!attribute $1 # @return [$2] - def self.model_attr_accessor(attr_name, attr_type = nil) + def self.model_attr_accessor(attr_name, _attr_type = nil) @model_attrs ||= [] @model_attrs << attr_name @@ -228,7 +222,7 @@ def self.model_attr_accessor(attr_name, attr_type = nil) # @return [nil] def attach_parent_to_children self.class.model_attrs.each do |variable| - value = self.send(variable) + value = send(variable) case value when Array @@ -245,4 +239,4 @@ def attach_parent_to_children end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/reference.rb b/lib/expressir/model/reference.rb index f59785c4..4928df65 100644 --- a/lib/expressir/model/reference.rb +++ b/lib/expressir/model/reference.rb @@ -6,4 +6,4 @@ module Model class Reference < ModelElement end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/references/attribute_reference.rb b/lib/expressir/model/references/attribute_reference.rb index 0421226f..be778295 100644 --- a/lib/expressir/model/references/attribute_reference.rb +++ b/lib/expressir/model/references/attribute_reference.rb @@ -4,8 +4,8 @@ module References # Specified in ISO 10303-11:2004 # - section 12.7.3 Attribute references class AttributeReference < Reference - model_attr_accessor :ref, 'Reference' - model_attr_accessor :attribute, 'Reference' + model_attr_accessor :ref, "Reference" + model_attr_accessor :attribute, "Reference" # @param [Hash] options # @option options [Reference] :ref @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/references/group_reference.rb b/lib/expressir/model/references/group_reference.rb index 2fe22762..f14acff1 100644 --- a/lib/expressir/model/references/group_reference.rb +++ b/lib/expressir/model/references/group_reference.rb @@ -4,8 +4,8 @@ module References # Specified in ISO 10303-11:2004 # - section 12.7.4 Group references class GroupReference < Reference - model_attr_accessor :ref, 'Reference' - model_attr_accessor :entity, 'Reference' + model_attr_accessor :ref, "Reference" + model_attr_accessor :entity, "Reference" # @param [Hash] options # @option options [Reference] :ref @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/references/index_reference.rb b/lib/expressir/model/references/index_reference.rb index 558ccd5a..f6cf44c8 100644 --- a/lib/expressir/model/references/index_reference.rb +++ b/lib/expressir/model/references/index_reference.rb @@ -6,9 +6,9 @@ module References # - section 12.5.1 String indexing # - section 12.6.1 Aggregate indexing class IndexReference < Reference - model_attr_accessor :ref, 'Reference' - model_attr_accessor :index1, 'Expression' - model_attr_accessor :index2, 'Expression' + model_attr_accessor :ref, "Reference" + model_attr_accessor :index1, "Expression" + model_attr_accessor :index2, "Expression" # @param [Hash] options # @option options [Reference] :ref @@ -24,4 +24,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/references/simple_reference.rb b/lib/expressir/model/references/simple_reference.rb index 8c762f71..90467a3b 100644 --- a/lib/expressir/model/references/simple_reference.rb +++ b/lib/expressir/model/references/simple_reference.rb @@ -4,9 +4,9 @@ module References # Specified in ISO 10303-11:2004 # - section 12.7.1 Simple references class SimpleReference < Reference - model_attr_accessor :id, 'String' + model_attr_accessor :id, "String" - model_attr_accessor :base_path, 'String' + model_attr_accessor :base_path, "String" # @param [Hash] options # @option options [String] :id @@ -21,4 +21,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/repository.rb b/lib/expressir/model/repository.rb index 492e1b8a..4ad3a479 100644 --- a/lib/expressir/model/repository.rb +++ b/lib/expressir/model/repository.rb @@ -2,7 +2,7 @@ module Expressir module Model # Multi-schema global scope class Repository < ModelElement - model_attr_accessor :schemas, 'Array' + model_attr_accessor :schemas, "Array" # @param [Hash] options # @option options [Array] :schemas @@ -15,10 +15,9 @@ def initialize(options = {}) # @return [Array] def children [ - *schemas + *schemas, ] end - end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statement.rb b/lib/expressir/model/statement.rb index 63f6db7b..fdcf8325 100644 --- a/lib/expressir/model/statement.rb +++ b/lib/expressir/model/statement.rb @@ -6,4 +6,4 @@ module Model class Statement < ModelElement end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/alias.rb b/lib/expressir/model/statements/alias.rb index 884a28c2..82e1edf9 100644 --- a/lib/expressir/model/statements/alias.rb +++ b/lib/expressir/model/statements/alias.rb @@ -6,8 +6,8 @@ module Statements class Alias < Statement include Identifier - model_attr_accessor :expression, 'Expression' - model_attr_accessor :statements, 'Array' + model_attr_accessor :expression, "Expression" + model_attr_accessor :statements, "Array" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -26,10 +26,10 @@ def initialize(options = {}) def children [ self, - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/assignment.rb b/lib/expressir/model/statements/assignment.rb index a8adc9f2..dda0ef80 100644 --- a/lib/expressir/model/statements/assignment.rb +++ b/lib/expressir/model/statements/assignment.rb @@ -4,8 +4,8 @@ module Statements # Specified in ISO 10303-11:2004 # - section 13.3 Assignment class Assignment < Statement - model_attr_accessor :ref, 'Reference' - model_attr_accessor :expression, 'Expression' + model_attr_accessor :ref, "Reference" + model_attr_accessor :expression, "Expression" # @param [Hash] options # @option options [Reference] :ref @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/case.rb b/lib/expressir/model/statements/case.rb index c477e50b..62e33471 100644 --- a/lib/expressir/model/statements/case.rb +++ b/lib/expressir/model/statements/case.rb @@ -4,9 +4,9 @@ module Statements # Specified in ISO 10303-11:2004 # - section 13.4 Case statement class Case < Statement - model_attr_accessor :expression, 'Expression' - model_attr_accessor :actions, 'Array' - model_attr_accessor :otherwise_statement, 'Statement' + model_attr_accessor :expression, "Expression" + model_attr_accessor :actions, "Array" + model_attr_accessor :otherwise_statement, "Statement" # @param [Hash] options # @option options [Expression] :expression @@ -22,4 +22,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/case_action.rb b/lib/expressir/model/statements/case_action.rb index 61e2bc8d..5fbf23b2 100644 --- a/lib/expressir/model/statements/case_action.rb +++ b/lib/expressir/model/statements/case_action.rb @@ -4,8 +4,8 @@ module Statements # Specified in ISO 10303-11:2004 # - section 13.4 Case statement class CaseAction < ModelElement - model_attr_accessor :labels, 'Array' - model_attr_accessor :statement, 'Statement' + model_attr_accessor :labels, "Array" + model_attr_accessor :statement, "Statement" # @param [Hash] options # @option options [Array] :labels @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/compound.rb b/lib/expressir/model/statements/compound.rb index c2efb9b3..cda70bf6 100644 --- a/lib/expressir/model/statements/compound.rb +++ b/lib/expressir/model/statements/compound.rb @@ -4,7 +4,7 @@ module Statements # Specified in ISO 10303-11:2004 # - section 13.5 Compound statement class Compound < Statement - model_attr_accessor :statements, 'Array' + model_attr_accessor :statements, "Array" # @param [Hash] options # @option options [Array] :statements @@ -16,4 +16,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/escape.rb b/lib/expressir/model/statements/escape.rb index bd04a1b2..b1414646 100644 --- a/lib/expressir/model/statements/escape.rb +++ b/lib/expressir/model/statements/escape.rb @@ -7,4 +7,4 @@ class Escape < Statement end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/if.rb b/lib/expressir/model/statements/if.rb index 7ba0e537..d6720411 100644 --- a/lib/expressir/model/statements/if.rb +++ b/lib/expressir/model/statements/if.rb @@ -4,9 +4,9 @@ module Statements # Specified in ISO 10303-11:2004 # - section 13.7 If ... Then ... Else statement class If < Statement - model_attr_accessor :expression, 'Expression' - model_attr_accessor :statements, 'Array' - model_attr_accessor :else_statements, 'Array' + model_attr_accessor :expression, "Expression" + model_attr_accessor :statements, "Array" + model_attr_accessor :else_statements, "Array" # @param [Hash] options # @option options [Expression] :expression @@ -22,4 +22,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/null.rb b/lib/expressir/model/statements/null.rb index fcaa1290..34f138f3 100644 --- a/lib/expressir/model/statements/null.rb +++ b/lib/expressir/model/statements/null.rb @@ -7,4 +7,4 @@ class Null < Statement end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/procedure_call.rb b/lib/expressir/model/statements/procedure_call.rb index 74bc97a1..f482fa0e 100644 --- a/lib/expressir/model/statements/procedure_call.rb +++ b/lib/expressir/model/statements/procedure_call.rb @@ -4,8 +4,8 @@ module Statements # Specified in ISO 10303-11:2004 # - section 13.8 Procedure call statement class ProcedureCall < Statement - model_attr_accessor :procedure, 'Reference' - model_attr_accessor :parameters, 'Array' + model_attr_accessor :procedure, "Reference" + model_attr_accessor :parameters, "Array" # @param [Hash] options # @option options [Reference] :procedure @@ -19,4 +19,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/repeat.rb b/lib/expressir/model/statements/repeat.rb index 33edc4c4..e842f0cf 100644 --- a/lib/expressir/model/statements/repeat.rb +++ b/lib/expressir/model/statements/repeat.rb @@ -6,12 +6,12 @@ module Statements class Repeat < Statement include Identifier - model_attr_accessor :bound1, 'Expression' - model_attr_accessor :bound2, 'Expression' - model_attr_accessor :increment, 'Expression' - model_attr_accessor :while_expression, 'Expression' - model_attr_accessor :until_expression, 'Expression' - model_attr_accessor :statements, 'Array' + model_attr_accessor :bound1, "Expression" + model_attr_accessor :bound2, "Expression" + model_attr_accessor :increment, "Expression" + model_attr_accessor :while_expression, "Expression" + model_attr_accessor :until_expression, "Expression" + model_attr_accessor :statements, "Array" # @param [Hash] options # @option (see Identifier#initialize_identifier) @@ -38,10 +38,10 @@ def initialize(options = {}) def children [ self, - *remark_items + *remark_items, ] end end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/return.rb b/lib/expressir/model/statements/return.rb index a3f92f7a..51250c02 100644 --- a/lib/expressir/model/statements/return.rb +++ b/lib/expressir/model/statements/return.rb @@ -4,7 +4,7 @@ module Statements # Specified in ISO 10303-11:2004 # - section 13.10 Return statement class Return < Statement - model_attr_accessor :expression, 'Expression' + model_attr_accessor :expression, "Expression" # @param [Hash] options # @option options [Expression] :expression @@ -16,4 +16,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/statements/skip.rb b/lib/expressir/model/statements/skip.rb index f0c36270..e4b3f563 100644 --- a/lib/expressir/model/statements/skip.rb +++ b/lib/expressir/model/statements/skip.rb @@ -7,4 +7,4 @@ class Skip < Statement end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/supertype_expression.rb b/lib/expressir/model/supertype_expression.rb index 25183072..33258f94 100644 --- a/lib/expressir/model/supertype_expression.rb +++ b/lib/expressir/model/supertype_expression.rb @@ -6,4 +6,4 @@ module Model class SupertypeExpression < ModelElement end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb b/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb index 7b25b13d..4d114e8e 100644 --- a/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +++ b/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb @@ -8,9 +8,9 @@ class BinarySupertypeExpression < SupertypeExpression AND = :AND ANDOR = :ANDOR - model_attr_accessor :operator, ':AND, :ANDOR' - model_attr_accessor :operand1, 'SupertypeExpression' - model_attr_accessor :operand2, 'SupertypeExpression' + model_attr_accessor :operator, ":AND, :ANDOR" + model_attr_accessor :operand1, "SupertypeExpression" + model_attr_accessor :operand2, "SupertypeExpression" # @param [Hash] options # @option options [:AND, :ANDOR] :operator @@ -26,4 +26,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb b/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb index 28eccd70..dafc0328 100644 --- a/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +++ b/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb @@ -4,7 +4,7 @@ module SupertypeExpressions # Specified in ISO 10303-11:2004 # - section 9.2.5.2 ONEOF class OneofSupertypeExpression < SupertypeExpression - model_attr_accessor :operands, 'Array' + model_attr_accessor :operands, "Array" # @param [Hash] options # @option options [Array] :operands @@ -16,4 +16,4 @@ def initialize(options = {}) end end end -end \ No newline at end of file +end