expressir 0.2.7-x86-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. checksums.yaml +7 -0
  2. data/.cross_rubies +30 -0
  3. data/.github/workflows/rake.yml +45 -0
  4. data/.github/workflows/release.yml +84 -0
  5. data/.gitignore +17 -0
  6. data/.gitmodules +3 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +508 -0
  9. data/Gemfile +4 -0
  10. data/README.adoc +147 -0
  11. data/Rakefile +11 -0
  12. data/bin/console +12 -0
  13. data/bin/rspec +29 -0
  14. data/bin/setup +8 -0
  15. data/demo.rb +18 -0
  16. data/docs/development.md +90 -0
  17. data/exe/expressir +20 -0
  18. data/exe/generate-parser +48 -0
  19. data/expressir.gemspec +43 -0
  20. data/lib/expressir/cli/ui.rb +36 -0
  21. data/lib/expressir/cli.rb +27 -0
  22. data/lib/expressir/config.rb +23 -0
  23. data/lib/expressir/express/aggregate_dimension.rb +38 -0
  24. data/lib/expressir/express/attribute.rb +15 -0
  25. data/lib/expressir/express/comment.rb +7 -0
  26. data/lib/expressir/express/defined_type.rb +36 -0
  27. data/lib/expressir/express/derived.rb +65 -0
  28. data/lib/expressir/express/derived_aggregate.rb +43 -0
  29. data/lib/expressir/express/entity.rb +137 -0
  30. data/lib/expressir/express/explicit.rb +70 -0
  31. data/lib/expressir/express/explicit_aggregate.rb +46 -0
  32. data/lib/expressir/express/explicit_or_derived.rb +16 -0
  33. data/lib/expressir/express/global_rule.rb +44 -0
  34. data/lib/expressir/express/interface_specification.rb +51 -0
  35. data/lib/expressir/express/interfaced_item.rb +38 -0
  36. data/lib/expressir/express/inverse.rb +46 -0
  37. data/lib/expressir/express/inverse_aggregate.rb +37 -0
  38. data/lib/expressir/express/model_element.rb +7 -0
  39. data/lib/expressir/express/named_type.rb +19 -0
  40. data/lib/expressir/express/remark.rb +8 -0
  41. data/lib/expressir/express/repository.rb +306 -0
  42. data/lib/expressir/express/schema_definition.rb +96 -0
  43. data/lib/expressir/express/subtype_constraint.rb +14 -0
  44. data/lib/expressir/express/type.rb +26 -0
  45. data/lib/expressir/express/type_aggregate.rb +42 -0
  46. data/lib/expressir/express/type_enum.rb +29 -0
  47. data/lib/expressir/express/type_parser.rb +45 -0
  48. data/lib/expressir/express/type_select.rb +82 -0
  49. data/lib/expressir/express/unique_rule.rb +35 -0
  50. data/lib/expressir/express/where_rule.rb +32 -0
  51. data/lib/expressir/express.rb +11 -0
  52. data/lib/expressir/express_exp/2.4/express_parser.so +0 -0
  53. data/lib/expressir/express_exp/2.5/express_parser.so +0 -0
  54. data/lib/expressir/express_exp/2.6/express_parser.so +0 -0
  55. data/lib/expressir/express_exp/2.7/express_parser.so +0 -0
  56. data/lib/expressir/express_exp/3.0/express_parser.so +0 -0
  57. data/lib/expressir/express_exp/formatter.rb +1450 -0
  58. data/lib/expressir/express_exp/parser.rb +41 -0
  59. data/lib/expressir/express_exp/visitor.rb +2464 -0
  60. data/lib/expressir/express_parser.rb +30 -0
  61. data/lib/expressir/model/attribute.rb +27 -0
  62. data/lib/expressir/model/constant.rb +17 -0
  63. data/lib/expressir/model/entity.rb +46 -0
  64. data/lib/expressir/model/enumeration_item.rb +11 -0
  65. data/lib/expressir/model/expressions/aggregate_initializer.rb +13 -0
  66. data/lib/expressir/model/expressions/aggregate_item.rb +15 -0
  67. data/lib/expressir/model/expressions/attribute_reference.rb +15 -0
  68. data/lib/expressir/model/expressions/binary_expression.rb +40 -0
  69. data/lib/expressir/model/expressions/call.rb +15 -0
  70. data/lib/expressir/model/expressions/entity_constructor.rb +15 -0
  71. data/lib/expressir/model/expressions/group_reference.rb +15 -0
  72. data/lib/expressir/model/expressions/index_reference.rb +17 -0
  73. data/lib/expressir/model/expressions/interval.rb +21 -0
  74. data/lib/expressir/model/expressions/query_expression.rb +26 -0
  75. data/lib/expressir/model/expressions/simple_reference.rb +13 -0
  76. data/lib/expressir/model/expressions/unary_expression.rb +19 -0
  77. data/lib/expressir/model/function.rb +62 -0
  78. data/lib/expressir/model/identifier.rb +10 -0
  79. data/lib/expressir/model/interface.rb +18 -0
  80. data/lib/expressir/model/literals/binary.rb +13 -0
  81. data/lib/expressir/model/literals/integer.rb +13 -0
  82. data/lib/expressir/model/literals/logical.rb +17 -0
  83. data/lib/expressir/model/literals/real.rb +13 -0
  84. data/lib/expressir/model/literals/string.rb +15 -0
  85. data/lib/expressir/model/parameter.rb +17 -0
  86. data/lib/expressir/model/procedure.rb +60 -0
  87. data/lib/expressir/model/renamed_ref.rb +13 -0
  88. data/lib/expressir/model/repository.rb +19 -0
  89. data/lib/expressir/model/rule.rb +62 -0
  90. data/lib/expressir/model/schema.rb +67 -0
  91. data/lib/expressir/model/scope.rb +17 -0
  92. data/lib/expressir/model/statements/alias.rb +26 -0
  93. data/lib/expressir/model/statements/assignment.rb +15 -0
  94. data/lib/expressir/model/statements/call.rb +15 -0
  95. data/lib/expressir/model/statements/case.rb +17 -0
  96. data/lib/expressir/model/statements/case_action.rb +15 -0
  97. data/lib/expressir/model/statements/compound.rb +13 -0
  98. data/lib/expressir/model/statements/escape.rb +8 -0
  99. data/lib/expressir/model/statements/if.rb +17 -0
  100. data/lib/expressir/model/statements/null.rb +8 -0
  101. data/lib/expressir/model/statements/repeat.rb +34 -0
  102. data/lib/expressir/model/statements/return.rb +13 -0
  103. data/lib/expressir/model/statements/skip.rb +8 -0
  104. data/lib/expressir/model/subtype_constraint.rb +27 -0
  105. data/lib/expressir/model/type.rb +24 -0
  106. data/lib/expressir/model/types/aggregate.rb +17 -0
  107. data/lib/expressir/model/types/array.rb +21 -0
  108. data/lib/expressir/model/types/bag.rb +17 -0
  109. data/lib/expressir/model/types/binary.rb +15 -0
  110. data/lib/expressir/model/types/boolean.rb +8 -0
  111. data/lib/expressir/model/types/enumeration.rb +19 -0
  112. data/lib/expressir/model/types/generic.rb +13 -0
  113. data/lib/expressir/model/types/generic_entity.rb +13 -0
  114. data/lib/expressir/model/types/integer.rb +8 -0
  115. data/lib/expressir/model/types/list.rb +19 -0
  116. data/lib/expressir/model/types/logical.rb +8 -0
  117. data/lib/expressir/model/types/number.rb +8 -0
  118. data/lib/expressir/model/types/real.rb +13 -0
  119. data/lib/expressir/model/types/select.rb +21 -0
  120. data/lib/expressir/model/types/set.rb +17 -0
  121. data/lib/expressir/model/types/string.rb +15 -0
  122. data/lib/expressir/model/unique.rb +15 -0
  123. data/lib/expressir/model/variable.rb +17 -0
  124. data/lib/expressir/model/where.rb +15 -0
  125. data/lib/expressir/model.rb +65 -0
  126. data/lib/expressir/parser/owl_parser.rb +8 -0
  127. data/lib/expressir/parser.rb +6 -0
  128. data/lib/expressir/version.rb +3 -0
  129. data/lib/expressir.rb +21 -0
  130. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +9589 -0
  131. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +36619 -0
  132. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +13294 -0
  133. data/original/examples/employment/eclipse/.project +17 -0
  134. data/original/examples/employment/eclipse/Export/Employment.png +0 -0
  135. data/original/examples/employment/eclipse/Express/employment_schema.exp +33 -0
  136. data/original/examples/employment/eclipse/Express/employment_schema.xmi +77 -0
  137. data/original/examples/employment/eclipse/Express/employment_schema.xml +93 -0
  138. data/original/examples/employment/eclipse/Models/Employment.uml +4 -0
  139. data/original/examples/employment/eclipse/Models/Employment.umldi +240 -0
  140. data/original/examples/employment/eclipse/readme.txt +7 -0
  141. data/original/examples/employment/employment_schema.exp +33 -0
  142. data/original/examples/employment/employment_schema.rb +232 -0
  143. data/original/examples/employment/employment_schema.xml +93 -0
  144. data/original/examples/employment/employment_schema___module.rb +46 -0
  145. data/original/examples/employment/employment_schema___p28attr.rb +126 -0
  146. data/original/examples/employment/employment_schema___p28inst.rb +26 -0
  147. data/original/examples/employment/example_employment_data.xml +1 -0
  148. data/original/examples/employment/example_employment_data_copy.xml +1 -0
  149. data/original/examples/employment/example_employment_reader.rb +30 -0
  150. data/original/examples/employment/example_employment_writer.rb +51 -0
  151. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +3710 -0
  152. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +35880 -0
  153. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +15357 -0
  154. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +9468 -0
  155. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +8404 -0
  156. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +43147 -0
  157. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +18341 -0
  158. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +11632 -0
  159. data/original/examples/syntax/remark.exp +146 -0
  160. data/original/examples/syntax/remark_formatted.exp +175 -0
  161. data/original/examples/syntax/syntax.exp +311 -0
  162. data/original/examples/syntax/syntax_formatted.exp +1191 -0
  163. data/original/exp2ruby.rb +525 -0
  164. data/original/expsm.rb +34 -0
  165. data/original/mapping_owl.rb +1018 -0
  166. data/original/mapping_sysml.rb +2281 -0
  167. data/original/mapping_uml2.rb +599 -0
  168. data/original/mapping_uml2_eclipse.rb +433 -0
  169. data/original/reeper.rb +134 -0
  170. data/rakelib/cross-ruby.rake +308 -0
  171. data/spec/acceptance/express_to_owl_spec.rb +18 -0
  172. data/spec/acceptance/version_spec.rb +12 -0
  173. data/spec/expressir/express/repository_spec.rb +25 -0
  174. data/spec/expressir/express_exp/ap233_spec.rb +22 -0
  175. data/spec/expressir/express_exp/format_remark_spec.rb +28 -0
  176. data/spec/expressir/express_exp/format_syntax_spec.rb +28 -0
  177. data/spec/expressir/express_exp/parse_remark_spec.rb +346 -0
  178. data/spec/expressir/express_exp/parse_syntax_spec.rb +3003 -0
  179. data/spec/expressir/model/find_spec.rb +110 -0
  180. data/spec/expressr_spec.rb +5 -0
  181. data/spec/spec_helper.rb +17 -0
  182. data/spec/support/console_helper.rb +29 -0
  183. metadata +357 -0
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/demo.rb ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'expressir'
4
+ require 'expressir/express_exp/parser'
5
+
6
+ # This file is from:
7
+ # https://github.com/metanorma/annotated-express/blob/master/data/resources/action_schema/action_schema.exp
8
+ file = 'action_schema.exp'
9
+
10
+ # repo = Expressir::ExpressExp::Parser.from_exp(file)
11
+ # schema = repo.schemas.find{|schema| schema.id == "support_resource_schema"}
12
+
13
+ repo = Expressir::ExpressExp::Parser.from_exp(file)
14
+ schema = repo.schemas.find{|schema| schema.id == "action_schema"}
15
+ entity = schema.entities.find{|entity| entity.id == "action_directive_relationship"}
16
+ where = entity.where.find{|where| where.id == "WR1"}
17
+
18
+ puts where.inspect
@@ -0,0 +1,90 @@
1
+ ## Development Plan
2
+
3
+ This document is a draft to understand the basic of the original library, and
4
+ how the whole tool chain is working at the moment. Once, we've an understanding
5
+ then let's look at the potential area of improvement, and plan out a high level
6
+ plan to start the development.
7
+
8
+ ### What is it, expressir?
9
+
10
+ * Expressir is a ruby tool to harvest iso express data model
11
+ * Express is one of the language to represent data model
12
+ * Expressir tool is used to manipulate iso express data model
13
+ * The input for the expressir is a standard xml document
14
+ * XML Spec: http://stepmod.sourceforge.net/express_model_spec/
15
+ * Expressir does the job of representing express model as ruby class
16
+ * REXML-based parser that reads EXPRESS as XML and creates the dictionary (i.e.
17
+ instances of the EXPRESS Ruby Classes) and then calls a mapper, that may be
18
+ specified as an option at runtime
19
+ * Mappers that read the EXPRESS dictionary and perform the conversion to the
20
+ desired language or format
21
+ * Express to UML2 Mapper - Convert the express model to UML2
22
+ * Express to OWL Structure - Convert the express model to OWL Structure
23
+ * Ruby API generator for express language
24
+ * Current Ruby API is super slow, it takes 2 hours to generate 400 entity
25
+
26
+ ### How does the original version work?
27
+
28
+ At the core the `expressir.rb` is responsible for everything at moment, it takes
29
+ an Express XML file as an input and then it parses that XML file and build the
30
+ correct ruby interface for further processing.
31
+
32
+ This `expressir.rb` also expect one mapping file `deafult to mapping.rb`, and it
33
+ also expect the file to specify a custom method `map_from_express` to take the
34
+ `Ruby Express Representation` and convert this ruby representation to the
35
+ desire output format.
36
+
37
+ The library also provides couple mapping for UM2, OWL and SysML, so anyone can
38
+ export their data to any of those format if necessary, and the use cases for
39
+ those library are as following:
40
+
41
+ ```ruby
42
+ ruby expressir.rb expxml=<schema.xml> map=<mapping_owl.rb>
43
+ ```
44
+
45
+ ### What are potential improvement area?
46
+
47
+ * The interface is not well defined, someone needs to dig deeper to understand
48
+ just the basic of the library and how to use for their use cases. This is
49
+ something that could be improved as initial step.
50
+ * At the moment, these are some ruby files, so potentially we could group those
51
+ together as a CLI tool and group some of the common functionality, and provide
52
+ a straight forward interface for users.
53
+ * The good part about this library is author had the extensibility in mind from
54
+ the beginning, so we should keep that functionality as flexible as possible.
55
+ * There are lot of boilerplate code in the library, but it's understandable as
56
+ it was written quite long time ago, so maybe most of the tool was not even
57
+ available back then, so this is the another area we could improve.
58
+ * Another improvement we could do in terms of actual codebase, we should be able
59
+ to refactor this library and cleanup as much as possible.
60
+
61
+ ### What are the initial changes?
62
+
63
+ Initially, we can start by creating a ruby cli gem, group these functionality
64
+ together. This could be named as `expressir`, and this gem will be shipped with an
65
+ executable called `expressir`.
66
+
67
+ Second of all, let's add some dedicated interface for the default type, so user
68
+ does not need to know all the details but the name of the interface, for example
69
+ we could expose the transformation as follows:
70
+
71
+ ```sh
72
+ # Convert to owl
73
+ expressir express2owl file=[express_xml_file] [**options]
74
+
75
+ # Convert to UML
76
+ expressir express2uml file=[express_xml_file] [**options]
77
+
78
+ # Convert to SysML
79
+ expressir express2sysml file=[express_xml_file] [**options]
80
+
81
+ # Custom conversion
82
+ expressir express2custom file=[express_xml_file] mapping=[custom_mapping.rb]
83
+ ```
84
+
85
+ Third of all once this library is functional as the original version then we
86
+ will go through each of the existing types, and refactor those as necessary.
87
+
88
+ ### References
89
+
90
+ * https://martinfowler.com/bliki/MovingToNokogiri.html
data/exe/expressir ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # resolve bin path, ignoring symlinks
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # add self to libpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
12
+ require "rubygems/specification"
13
+
14
+ class Gem::Specification
15
+ def this; self; end
16
+ end
17
+
18
+ # start up the CLI
19
+ require "expressir"
20
+ Expressir::Cli.start(ARGV)
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ require 'antlr4-native'
5
+
6
+ grammar_file = ARGV.shift
7
+
8
+ # ANTLR does weird things if the grammar file isn't in the current working directory
9
+ temp_grammar_file = File.join(FileUtils.pwd(), File.basename(grammar_file))
10
+ FileUtils.cp(grammar_file, temp_grammar_file)
11
+
12
+ # generate parser
13
+ generator = Antlr4Native::Generator.new(
14
+ grammar_files: [File.basename(temp_grammar_file)],
15
+ output_dir: 'ext',
16
+ parser_root_method: 'syntax'
17
+ )
18
+ generator.generate
19
+
20
+ # fix issues with generated parser
21
+ parser_source_file = File.join(*%w(ext express-parser express_parser.cpp))
22
+ parser_source_lines = File.read(parser_source_file).split(/\n/)
23
+
24
+ # - add ParserProxy tokens method, simple compensation for missing exposed BufferedTokenStream
25
+ i = parser_source_lines.index{|x| x == ' Object syntax() {'}
26
+ parser_source_lines[i + 6] += "\n" + <<~CPP.split(/\n/).map{|x| x != "" ? " " + x : x}.join("\n") + "\n"
27
+ Array getTokens() {
28
+ Array a;
29
+
30
+ std::vector<Token*> tokens = this -> tokens -> getTokens();
31
+
32
+ for (auto &token : tokens) {
33
+ a.push(token);
34
+ }
35
+
36
+ return a;
37
+ }
38
+ CPP
39
+ i = parser_source_lines.index{|x| x == ' .define_method("syntax", &ParserProxy::syntax)'}
40
+ parser_source_lines[i] += "\n" + <<~CPP.split(/\n/).map{|x| x != "" ? " " + x : x}.join("\n")
41
+ .define_method("tokens", &ParserProxy::getTokens)
42
+ CPP
43
+
44
+ # write fixed parser file
45
+ File.write(parser_source_file, parser_source_lines.join("\n") + "\n")
46
+
47
+ # cleanup
48
+ FileUtils.rm(temp_grammar_file)
data/expressir.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "expressir/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "expressir"
7
+ spec.version = Expressir::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com'"]
10
+
11
+ spec.summary = "ISO EXPRESS parser in Ruby, tools for accessing EXPRESS data models."
12
+ spec.description = "ISO EXPRESS parser in Ruby, tools for accessing EXPRESS data models."
13
+ spec.homepage = "https://github.com/lutaml/expressir"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/lutaml/expressir/releases"
19
+
20
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
21
+
22
+ spec.files = `git ls-files`.split("\n")\
23
+ + Dir.glob('ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/**/*')
24
+
25
+ spec.test_files = `git ls-files -- {spec}/*`.split("\n")
26
+
27
+ spec.bindir = "exe"
28
+ spec.require_paths = ["lib"]
29
+ spec.executables = %w[expressir]
30
+
31
+ spec.extensions = File.join(*%w(ext express-parser extconf.rb))
32
+
33
+ spec.add_runtime_dependency "nokogiri", "~> 1.10"
34
+ spec.add_runtime_dependency "thor", "~> 1.0"
35
+ spec.add_runtime_dependency "rice", "~> 2.2.0"
36
+ spec.add_development_dependency "antlr4-native", "~> 1.1.0"
37
+ spec.add_development_dependency "bundler", "~> 2.0"
38
+ spec.add_development_dependency "pry", "~> 0.12.2"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rake-compiler", "~> 1.1"
41
+ spec.add_development_dependency "rake-compiler-dock", "~> 1.1"
42
+ spec.add_development_dependency "rspec", "~> 3.0"
43
+ end
@@ -0,0 +1,36 @@
1
+ require "thor"
2
+
3
+ module Expressir
4
+ module Cli
5
+ class UI < Thor
6
+ def self.ask(message)
7
+ new.ask(message)
8
+ end
9
+
10
+ def self.say(message)
11
+ new.say(message)
12
+ end
13
+
14
+ def self.error(message)
15
+ if log_types.include?("error")
16
+ new.error(message)
17
+ end
18
+ end
19
+
20
+ def self.info(message)
21
+ if log_types.include?("info")
22
+ new.say(message)
23
+ end
24
+ end
25
+
26
+ def self.run(command)
27
+ require "open3"
28
+ Open3.capture3(command)
29
+ end
30
+
31
+ def self.log_types
32
+ Expressir.configuration.logs.map(&:to_s) || []
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ require "thor"
2
+ require "expressir/cli/ui"
3
+ require "expressir/express_parser"
4
+
5
+ module Expressir
6
+ module Cli
7
+ def self.ui
8
+ Expressir::Cli::UI
9
+ end
10
+
11
+ def self.start(args)
12
+ Base.start(args)
13
+ end
14
+
15
+ class Base < Thor
16
+ desc "version", "The Expressir Version"
17
+ def version
18
+ Cli.ui.say("Version #{Expressir::VERSION}")
19
+ end
20
+
21
+ desc "express-to-owl FILE", "Express to OWL conversion"
22
+ def express_to_owl(file)
23
+ Cli.ui.say(ExpressParser.to_owl(file))
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ module Expressir
2
+ module Config
3
+ def configure
4
+ if block_given?
5
+ yield configuration
6
+ end
7
+ end
8
+
9
+ def configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :logs
16
+
17
+ def initialize
18
+ @logs ||= %i(error)
19
+ end
20
+ end
21
+
22
+ extend Config
23
+ end
@@ -0,0 +1,38 @@
1
+ module Expressir
2
+ module Express
3
+ class AggregateDimension
4
+ attr_accessor :aggrtype, :lower, :upper, :isUnique, :isOptionalArray
5
+
6
+ def initialize(options = {})
7
+ @aggrtype = "SET"
8
+ @lower = "0"
9
+ @upper = "?"
10
+ @isUnique = false
11
+ @isOptionalArray = false
12
+
13
+ @options = options
14
+ end
15
+
16
+ def parse
17
+ document = @options.fetch(:document, nil)
18
+ extract_attributes(document) if document
19
+
20
+ self
21
+ end
22
+
23
+ def self.parse(document)
24
+ new(document: document).parse
25
+ end
26
+
27
+ private
28
+
29
+ def extract_attributes(document)
30
+ @aggrtype = document.attributes["type"]
31
+ @lower = document.attributes["lower"]
32
+ @upper = document.attributes["upper"]
33
+ @isUnique = document.attributes["unique"] == "YES"
34
+ @isOptionalArray = document.attributes["optional"] == "YES"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ require "expressir/express/model_element"
2
+
3
+ module Expressir
4
+ module Express
5
+ class Attribute < ModelElement
6
+ attr_accessor :name, :entity, :domain, :redeclare_entity,
7
+ :redeclare_oldname
8
+
9
+ def initialize
10
+ @redeclare_entity = nil
11
+ @redeclare_oldname = nil
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Expressir
2
+ module Express
3
+ class Comment
4
+ attr_accessor :comment, :ModelElement
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ require "expressir/express/named_type"
2
+
3
+ module Expressir
4
+ module Express
5
+ class DefinedType < NamedType
6
+ def initialize(options = {})
7
+ @options = options
8
+ @schema = options.fetch(:schema)
9
+ end
10
+
11
+ def parse
12
+ document = @options.fetch(:document)
13
+ extract_type_attributes(document)
14
+
15
+ self
16
+ end
17
+
18
+ def self.parse(document, schema)
19
+ new(document: document, schema: schema).parse
20
+ end
21
+
22
+ private
23
+
24
+ def extract_type_attributes(document)
25
+ @name = document.attributes["name"].to_s
26
+ @wheres = extract_where_rules(document)
27
+ end
28
+
29
+ def extract_where_rules(document)
30
+ document.xpath("where").map do |where|
31
+ Express::WhereRule.parse(where)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,65 @@
1
+ module Expressir
2
+ module Express
3
+ class Derived < ExplicitOrDerived
4
+ attr_accessor :expression
5
+
6
+ def initialize(options = {})
7
+ @options = options
8
+ @entity = options.fetch(:entity, nil)
9
+ end
10
+
11
+ def parse
12
+ document = @options.fetch(:document, nil)
13
+ extract_common_attributes(document)
14
+ extract_type_specific_attributes(document)
15
+
16
+ self
17
+ end
18
+
19
+ def self.parse(document, entity)
20
+ new(document: document, entity: entity).parse
21
+ end
22
+
23
+ private
24
+
25
+ def extract_type_specific_attributes(document); end
26
+
27
+ def extract_common_attributes(document)
28
+ @name = document.attributes["name"].to_s
29
+ @expression = document.attributes["expression"].to_s
30
+ @domain = extract_domain_name(document.xpath("typename"))
31
+
32
+ extract_builtintype_attributes(document)
33
+ extract_redeclaration_attributes(document)
34
+ end
35
+
36
+ def extract_domain_name(typename)
37
+ unless typename.empty?
38
+ typename.first.attributes["name"].to_s
39
+ end
40
+ end
41
+
42
+ def extract_redeclaration_attributes(document)
43
+ redeclaration = document.xpath("redeclaration").first
44
+
45
+ if redeclaration
46
+ @redeclare_entity = redeclaration.attributes["entity-ref"].to_s
47
+ old_name = redeclaration.attributes["old_name"]
48
+ @redeclare_oldname = old_name.to_s if old_name
49
+ end
50
+ end
51
+
52
+ def extract_builtintype_attributes(document)
53
+ builtin_type = document.xpath("builtintype").first
54
+
55
+ if builtin_type
56
+ @isBuiltin = true
57
+ @domain = builtin_type.attributes["type"].to_s
58
+ @width = builtin_type.attributes["width"].to_s
59
+ @fixed = builtin_type.attributes["fixed"] == "YES"
60
+ @precision = builtin_type.attributes["precision"].to_s
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,43 @@
1
+ module Expressir
2
+ module Express
3
+ class DerivedAggregate < Derived
4
+ attr_accessor :rank, :dimensions
5
+
6
+ def initialize(options = {})
7
+ @rank = 0
8
+ @dimensions = []
9
+
10
+ super(options)
11
+ end
12
+
13
+ private
14
+
15
+ def extract_type_specific_attributes(document)
16
+ @dimensions = document.xpath("aggregate").map do |aggregate|
17
+ Express::AggregateDimension.parse(aggregate)
18
+ end
19
+
20
+ @rank = @dimensions.size
21
+ extract_inverse_aggregate(document)
22
+ end
23
+
24
+ # @todo: Non existance attributes
25
+ #
26
+ # In the codebase, they are trying to add couple of aggregate
27
+ # dimensions related attributes that was never a part of the
28
+ # Explict class, but for consistency we are keeping those as
29
+ # it is for now. let's revist those later and fix it.
30
+ #
31
+ def extract_inverse_aggregate(document)
32
+ aggregates = document.xpath("inverse.aggregate")
33
+
34
+ if !aggregates.empty?
35
+ dimension = Express::AggregateDimension.parse(aggregates.first)
36
+ @aggrtype = dimension.aggrtype
37
+ @lower = dimension.lower
38
+ @upper = dimension.upper
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end