expressir 1.3.0-aarch64-linux-gnu
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.
- checksums.yaml +7 -0
- data/.cross_rubies +20 -0
- data/.github/workflows/rake.yml +313 -0
- data/.github/workflows/release.yml +181 -0
- data/.gitignore +23 -0
- data/.gitmodules +6 -0
- data/.hound.yml +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +18 -0
- data/.yardopts +11 -0
- data/Gemfile +4 -0
- data/README.adoc +155 -0
- data/Rakefile +17 -0
- data/bin/console +11 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/docs/development.md +90 -0
- data/exe/expressir +22 -0
- data/exe/format +18 -0
- data/exe/format-test +81 -0
- data/exe/generate-parser +51 -0
- data/expressir.gemspec +48 -0
- data/lib/expressir/cli/ui.rb +36 -0
- data/lib/expressir/cli.rb +21 -0
- data/lib/expressir/config.rb +23 -0
- data/lib/expressir/express/2.7/express_parser.so +0 -0
- data/lib/expressir/express/3.0/express_parser.so +0 -0
- data/lib/expressir/express/3.1/express_parser.so +0 -0
- data/lib/expressir/express/3.2/express_parser.so +0 -0
- data/lib/expressir/express/cache.rb +51 -0
- data/lib/expressir/express/formatter.rb +1608 -0
- data/lib/expressir/express/hyperlink_formatter.rb +36 -0
- data/lib/expressir/express/model_visitor.rb +24 -0
- data/lib/expressir/express/parser.rb +84 -0
- data/lib/expressir/express/resolve_references_model_visitor.rb +31 -0
- data/lib/expressir/express/schema_head_formatter.rb +23 -0
- data/lib/expressir/express/visitor.rb +2588 -0
- data/lib/expressir/model/cache.rb +17 -0
- data/lib/expressir/model/data_type.rb +9 -0
- data/lib/expressir/model/data_types/aggregate.rb +31 -0
- data/lib/expressir/model/data_types/array.rb +31 -0
- data/lib/expressir/model/data_types/bag.rb +25 -0
- data/lib/expressir/model/data_types/binary.rb +22 -0
- data/lib/expressir/model/data_types/boolean.rb +10 -0
- data/lib/expressir/model/data_types/enumeration.rb +25 -0
- data/lib/expressir/model/data_types/enumeration_item.rb +26 -0
- data/lib/expressir/model/data_types/generic.rb +26 -0
- data/lib/expressir/model/data_types/generic_entity.rb +26 -0
- data/lib/expressir/model/data_types/integer.rb +10 -0
- data/lib/expressir/model/data_types/list.rb +28 -0
- data/lib/expressir/model/data_types/logical.rb +10 -0
- data/lib/expressir/model/data_types/number.rb +10 -0
- data/lib/expressir/model/data_types/real.rb +19 -0
- data/lib/expressir/model/data_types/select.rb +28 -0
- data/lib/expressir/model/data_types/set.rb +25 -0
- data/lib/expressir/model/data_types/string.rb +22 -0
- data/lib/expressir/model/declaration.rb +9 -0
- data/lib/expressir/model/declarations/attribute.rb +47 -0
- data/lib/expressir/model/declarations/constant.rb +34 -0
- data/lib/expressir/model/declarations/entity.rb +53 -0
- data/lib/expressir/model/declarations/function.rb +67 -0
- data/lib/expressir/model/declarations/interface.rb +28 -0
- data/lib/expressir/model/declarations/interface_item.rb +23 -0
- data/lib/expressir/model/declarations/interfaced_item.rb +37 -0
- data/lib/expressir/model/declarations/parameter.rb +34 -0
- data/lib/expressir/model/declarations/procedure.rb +64 -0
- data/lib/expressir/model/declarations/remark_item.rb +21 -0
- data/lib/expressir/model/declarations/rule.rb +71 -0
- data/lib/expressir/model/declarations/schema.rb +117 -0
- data/lib/expressir/model/declarations/schema_version.rb +22 -0
- data/lib/expressir/model/declarations/schema_version_item.rb +22 -0
- data/lib/expressir/model/declarations/subtype_constraint.rb +40 -0
- data/lib/expressir/model/declarations/type.rb +45 -0
- data/lib/expressir/model/declarations/unique_rule.rb +31 -0
- data/lib/expressir/model/declarations/variable.rb +34 -0
- data/lib/expressir/model/declarations/where_rule.rb +31 -0
- data/lib/expressir/model/expression.rb +9 -0
- data/lib/expressir/model/expressions/aggregate_initializer.rb +19 -0
- data/lib/expressir/model/expressions/aggregate_initializer_item.rb +22 -0
- data/lib/expressir/model/expressions/binary_expression.rb +53 -0
- data/lib/expressir/model/expressions/entity_constructor.rb +22 -0
- data/lib/expressir/model/expressions/function_call.rb +22 -0
- data/lib/expressir/model/expressions/interval.rb +34 -0
- data/lib/expressir/model/expressions/query_expression.rb +35 -0
- data/lib/expressir/model/expressions/unary_expression.rb +27 -0
- data/lib/expressir/model/identifier.rb +34 -0
- data/lib/expressir/model/literal.rb +9 -0
- data/lib/expressir/model/literals/binary.rb +19 -0
- data/lib/expressir/model/literals/integer.rb +19 -0
- data/lib/expressir/model/literals/logical.rb +23 -0
- data/lib/expressir/model/literals/real.rb +19 -0
- data/lib/expressir/model/literals/string.rb +22 -0
- data/lib/expressir/model/model_element.rb +208 -0
- data/lib/expressir/model/reference.rb +9 -0
- data/lib/expressir/model/references/attribute_reference.rb +22 -0
- data/lib/expressir/model/references/group_reference.rb +22 -0
- data/lib/expressir/model/references/index_reference.rb +27 -0
- data/lib/expressir/model/references/simple_reference.rb +24 -0
- data/lib/expressir/model/repository.rb +23 -0
- data/lib/expressir/model/statement.rb +9 -0
- data/lib/expressir/model/statements/alias.rb +35 -0
- data/lib/expressir/model/statements/assignment.rb +22 -0
- data/lib/expressir/model/statements/case.rb +25 -0
- data/lib/expressir/model/statements/case_action.rb +22 -0
- data/lib/expressir/model/statements/compound.rb +19 -0
- data/lib/expressir/model/statements/escape.rb +10 -0
- data/lib/expressir/model/statements/if.rb +25 -0
- data/lib/expressir/model/statements/null.rb +10 -0
- data/lib/expressir/model/statements/procedure_call.rb +22 -0
- data/lib/expressir/model/statements/repeat.rb +47 -0
- data/lib/expressir/model/statements/return.rb +19 -0
- data/lib/expressir/model/statements/skip.rb +10 -0
- data/lib/expressir/model/supertype_expression.rb +9 -0
- data/lib/expressir/model/supertype_expressions/binary_supertype_expression.rb +29 -0
- data/lib/expressir/model/supertype_expressions/oneof_supertype_expression.rb +19 -0
- data/lib/expressir/model.rb +79 -0
- data/lib/expressir/version.rb +3 -0
- data/lib/expressir.rb +24 -0
- data/rakelib/antlr4-native.rake +161 -0
- data/rakelib/cross-ruby.rake +384 -0
- data/spec/acceptance/version_spec.rb +27 -0
- data/spec/expressir/express/cache_spec.rb +89 -0
- data/spec/expressir/express/formatter_spec.rb +173 -0
- data/spec/expressir/express/parser_spec.rb +141 -0
- data/spec/expressir/model/model_element_spec.rb +318 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/console_helper.rb +29 -0
- data/spec/syntax/multiple.exp +23 -0
- data/spec/syntax/multiple.yaml +198 -0
- data/spec/syntax/multiple_formatted.exp +71 -0
- data/spec/syntax/multiple_hyperlink_formatted.exp +71 -0
- data/spec/syntax/multiple_schema_head_hyperlink_formatted.exp +13 -0
- data/spec/syntax/remark.exp +193 -0
- data/spec/syntax/remark.yaml +471 -0
- data/spec/syntax/remark_formatted.exp +228 -0
- data/spec/syntax/single.exp +4 -0
- data/spec/syntax/single.yaml +18 -0
- data/spec/syntax/single_formatted.exp +10 -0
- data/spec/syntax/single_formatted.yaml +36 -0
- data/spec/syntax/syntax.exp +333 -0
- data/spec/syntax/syntax.yaml +3509 -0
- data/spec/syntax/syntax_formatted.exp +902 -0
- data/spec/syntax/syntax_hyperlink_formatted.exp +902 -0
- data/spec/syntax/syntax_schema_head_formatted.exp +18 -0
- metadata +390 -0
data/README.adoc
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
= Expressir: EXPRESS in Ruby
|
2
|
+
|
3
|
+
image:https://img.shields.io/gem/v/expressir.svg["Gem Version", link="https://rubygems.org/gems/expressir"]
|
4
|
+
// image:https://codeclimate.com/github/lutaml/expressir/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/lutaml/expressir"]
|
5
|
+
image:https://github.com/lutaml/expressir/workflows/rake/badge.svg["Build Status", link="https://github.com/lutaml/expressir/actions?workflow=rake"]
|
6
|
+
|
7
|
+
== Purpose
|
8
|
+
|
9
|
+
Expressir ("`EXPRESS in Ruby`") is a Ruby parser for EXPRESS and
|
10
|
+
a set of Ruby tools for accessing ISO EXPRESS data models.
|
11
|
+
|
12
|
+
== Architecture
|
13
|
+
|
14
|
+
Expressir consists of 3 parts:
|
15
|
+
|
16
|
+
. Parsers. A parser allows Expressir to read EXPRESS files, including:
|
17
|
+
|
18
|
+
** EXPRESS data modelling language (ISO 10303-11:2007)
|
19
|
+
** EXPRESS data modelling language in XML (STEPmod)
|
20
|
+
** EXPRESS XML (ISO 10303-28:2007)
|
21
|
+
"`Industrial automation systems and integration — Product data representation and exchange — Part 28: Implementation methods: XML representations of EXPRESS schemas and data, using XML schemas`")
|
22
|
+
|
23
|
+
. Data model. The data model (`lib/expressir/express`) is the Ruby data model that fully represents an EXPRESS data model.
|
24
|
+
|
25
|
+
. Converters. A converter transforms the EXPRESS Ruby data model into an interoperable export format, including:
|
26
|
+
** EXPRESS data modelling language (ISO 10303-11:2007)
|
27
|
+
** W3C OWL
|
28
|
+
** OMG SysML (XMI 2.1, XMI 2.5)
|
29
|
+
** OMG UML 2 (XMI 2.1)
|
30
|
+
** OMG UML 2 for Eclipse (XMI 2.1)
|
31
|
+
|
32
|
+
|
33
|
+
== Usage
|
34
|
+
|
35
|
+
This gem ships with a CLI tool. To check what's available you can simply run
|
36
|
+
the script directly from `exe/expressir`, by default it will display some usage
|
37
|
+
instructions.
|
38
|
+
|
39
|
+
[source, sh]
|
40
|
+
----
|
41
|
+
./exe/expressir
|
42
|
+
|
43
|
+
Commands:
|
44
|
+
expressir help [COMMAND] # Describe available commands or one specific command
|
45
|
+
expressir version # The Expressir Version
|
46
|
+
----
|
47
|
+
|
48
|
+
== Development
|
49
|
+
|
50
|
+
We are following Sandi Metz's Rules for this gem, you can read
|
51
|
+
the http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers[description of the rules here] All new code should follow these rules.
|
52
|
+
If you make changes in a pre-existing file that violates these rules you should
|
53
|
+
fix the violations as part of your contribution.
|
54
|
+
|
55
|
+
=== Setup
|
56
|
+
|
57
|
+
Clone the repository.
|
58
|
+
|
59
|
+
[source, sh]
|
60
|
+
----
|
61
|
+
git clone https://github.com/metanorma/expressir
|
62
|
+
----
|
63
|
+
|
64
|
+
Setup your environment.
|
65
|
+
|
66
|
+
[source, sh]
|
67
|
+
----
|
68
|
+
bin/setup
|
69
|
+
----
|
70
|
+
|
71
|
+
Run the test suite
|
72
|
+
|
73
|
+
[source, sh]
|
74
|
+
----
|
75
|
+
bin/rspec
|
76
|
+
----
|
77
|
+
|
78
|
+
=== Grammar updates
|
79
|
+
EXPRESS grammar is lined as git submodule to ext/express-grammar
|
80
|
+
Shoudl you update it, run ```rake generate```. This command will generate source code for updated native extension using antlr4-native gem.
|
81
|
+
Please note that we create several classes on top of antlr4-native output so using embedded rake task is a real requirement.
|
82
|
+
|
83
|
+
When new extension is gnerated and tested plase check in updated C++ files to git (```rake generate``` is NOT a CI step,
|
84
|
+
extension source files are pulled from the repo).
|
85
|
+
|
86
|
+
== Installation
|
87
|
+
|
88
|
+
Add this line to your application's `Gemfile`:
|
89
|
+
|
90
|
+
[source, sh]
|
91
|
+
----
|
92
|
+
gem "expressir"
|
93
|
+
----
|
94
|
+
|
95
|
+
And then execute:
|
96
|
+
|
97
|
+
[source, sh]
|
98
|
+
----
|
99
|
+
$ bundle install
|
100
|
+
----
|
101
|
+
|
102
|
+
Or install it yourself as:
|
103
|
+
|
104
|
+
[source, sh]
|
105
|
+
----
|
106
|
+
$ gem install expressir
|
107
|
+
----
|
108
|
+
|
109
|
+
|
110
|
+
== Contributing
|
111
|
+
|
112
|
+
First, thank you for contributing! We love pull requests from everyone. By
|
113
|
+
participating in this project, you hereby grant
|
114
|
+
https://www.ribose.com[Ribose Inc.] the right to grant or transfer an unlimited
|
115
|
+
number of non exclusive licenses or sub-licenses to third parties, under the
|
116
|
+
copyright covering the contribution to use the contribution by all means.
|
117
|
+
|
118
|
+
Here are a few technical guidelines to follow:
|
119
|
+
|
120
|
+
* Open an https://github.com/lutaml/expressir/issues[issues] to discuss a new
|
121
|
+
feature.
|
122
|
+
* Write tests to support your new feature.
|
123
|
+
* Make sure the entire test suite passes locally and on CI.
|
124
|
+
* Open a Pull Request.
|
125
|
+
* https://github.com/thoughtbot/guides/tree/master/protocol/git#write-a-feature[Squash your commits] after receiving feedback.
|
126
|
+
* Party!
|
127
|
+
|
128
|
+
|
129
|
+
== License
|
130
|
+
|
131
|
+
Expressir is distributed under the BSD 2-clause license.
|
132
|
+
|
133
|
+
Expressir is built on code originally from the NIST Reeper project.
|
134
|
+
|
135
|
+
The https://www.nist.gov/services-resources/software/reeper[NIST Reeper license]
|
136
|
+
is reproduced below:
|
137
|
+
|
138
|
+
[quote]
|
139
|
+
____
|
140
|
+
This software was funded by NIST and developed by EuroSTEP.
|
141
|
+
Pursuant to title 17 Section 105 of the United States Code this
|
142
|
+
software is not subject to copyright protection and is in the public
|
143
|
+
domain.
|
144
|
+
|
145
|
+
We would appreciate acknowledgment if the software is used. Links to
|
146
|
+
non-Federal Government Web sites do not imply NIST endorsement of any
|
147
|
+
particular product, service, organization, company, information
|
148
|
+
provider, or content.
|
149
|
+
____
|
150
|
+
|
151
|
+
|
152
|
+
== Credits
|
153
|
+
|
154
|
+
Expressir is created using the structure and examples provided by
|
155
|
+
the NIST Reeper software on https://sourceforge.net/p/reeper/[Sourceforge].
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
require "rake/extensiontask"
|
4
|
+
require "rubocop/rake_task"
|
5
|
+
require "yard"
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task default: :spec
|
10
|
+
|
11
|
+
GEMSPEC = Gem::Specification.load("expressir.gemspec")
|
12
|
+
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
Gem::PackageTask.new(GEMSPEC).define
|
16
|
+
|
17
|
+
YARD::Rake::YardocTask.new
|
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "reeper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
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", __dir__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300).include?("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
data/docs/development.md
ADDED
@@ -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,22 @@
|
|
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
|
+
module Gem
|
15
|
+
class Specification
|
16
|
+
def this; self; end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# start up the CLI
|
21
|
+
require "expressir"
|
22
|
+
Expressir::Cli.start(ARGV)
|
data/exe/format
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
require "expressir/express/parser"
|
5
|
+
require "expressir/express/formatter"
|
6
|
+
require "expressir/express/schema_head_formatter"
|
7
|
+
require "expressir/express/hyperlink_formatter"
|
8
|
+
|
9
|
+
exp_files = ARGV
|
10
|
+
|
11
|
+
repository = Expressir::Express::Parser.from_files(exp_files)
|
12
|
+
formatter = Class.new(Expressir::Express::Formatter) do
|
13
|
+
include Expressir::Express::SchemaHeadFormatter
|
14
|
+
include Expressir::Express::HyperlinkFormatter
|
15
|
+
end
|
16
|
+
result = repository.to_hash(formatter: formatter, skip_empty: true)
|
17
|
+
|
18
|
+
puts YAML.dump(result)
|
data/exe/format-test
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
require "tempfile"
|
5
|
+
require "expressir/express/parser"
|
6
|
+
require "expressir/express/formatter"
|
7
|
+
require "expressir/express/schema_head_formatter"
|
8
|
+
require "expressir/express/hyperlink_formatter"
|
9
|
+
require "expressir/express/cache"
|
10
|
+
|
11
|
+
exp_files = [
|
12
|
+
# basic test
|
13
|
+
# '../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp',
|
14
|
+
# '../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp',
|
15
|
+
# '../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp',
|
16
|
+
# cyclic reference test
|
17
|
+
# '../iso-10303-stepmod/data/modules/analysis/mim_annotated.exp',
|
18
|
+
# '../iso-10303-stepmod/data/modules/analysis_product_relationships/mim_annotated.exp',
|
19
|
+
# cyclic reference test 2
|
20
|
+
# '../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp',
|
21
|
+
# '../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp',
|
22
|
+
# renamed reference test (36s)
|
23
|
+
# '../iso-10303-stepmod/ballots/ballots/ap210_wg12/express/resources/mathematical_functions_schema.exp',
|
24
|
+
# '../iso-10303-stepmod/data/resources/iso13584_expressions_schema/iso13584_expressions_schema.exp',
|
25
|
+
# annotated-express test (12s)
|
26
|
+
# see https://github.com/metanorma/annotated-express/blob/master/data/documents/resources/fundamentals_of_product_description_and_support/sections/04-schemas.adoc
|
27
|
+
"../iso-10303-stepmod/data/resources/action_schema/action_schema_annotated.exp",
|
28
|
+
"../iso-10303-stepmod/data/resources/application_context_schema/application_context_schema_annotated.exp",
|
29
|
+
"../iso-10303-stepmod/data/resources/approval_schema/approval_schema_annotated.exp",
|
30
|
+
"../iso-10303-stepmod/data/resources/basic_attribute_schema/basic_attribute_schema_annotated.exp",
|
31
|
+
"../iso-10303-stepmod/data/resources/certification_schema/certification_schema_annotated.exp",
|
32
|
+
"../iso-10303-stepmod/data/resources/contract_schema/contract_schema_annotated.exp",
|
33
|
+
"../iso-10303-stepmod/data/resources/date_time_schema/date_time_schema_annotated.exp",
|
34
|
+
"../iso-10303-stepmod/data/resources/document_schema/document_schema.exp",
|
35
|
+
"../iso-10303-stepmod/data/resources/effectivity_schema/effectivity_schema_annotated.exp",
|
36
|
+
"../iso-10303-stepmod/data/resources/experience_schema/experience_schema_annotated.exp",
|
37
|
+
"../iso-10303-stepmod/data/resources/external_reference_schema/external_reference_schema_annotated.exp",
|
38
|
+
"../iso-10303-stepmod/data/resources/group_schema/group_schema_annotated.exp",
|
39
|
+
"../iso-10303-stepmod/data/resources/language_schema/language_schema_annotated.exp",
|
40
|
+
"../iso-10303-stepmod/data/resources/location_schema/location_schema_annotated.exp",
|
41
|
+
"../iso-10303-stepmod/data/resources/management_resources_schema/management_resources_schema_annotated.exp",
|
42
|
+
"../iso-10303-stepmod/data/resources/measure_schema/measure_schema_annotated.exp",
|
43
|
+
"../iso-10303-stepmod/data/resources/person_organization_schema/person_organization_schema_annotated.exp",
|
44
|
+
"../iso-10303-stepmod/data/resources/process_property_schema/process_property_schema_annotated.exp",
|
45
|
+
"../iso-10303-stepmod/data/resources/product_definition_schema/product_definition_schema_annotated.exp",
|
46
|
+
"../iso-10303-stepmod/data/resources/product_property_definition_schema/product_property_definition_schema_annotated.exp",
|
47
|
+
"../iso-10303-stepmod/data/resources/product_property_representation_schema/product_property_representation_schema_annotated.exp",
|
48
|
+
"../iso-10303-stepmod/data/resources/qualifications_schema/qualifications_schema_annotated.exp",
|
49
|
+
"../iso-10303-stepmod/data/resources/security_classification_schema/security_classification_schema_annotated.exp",
|
50
|
+
"../iso-10303-stepmod/data/resources/support_resource_schema/support_resource_schema_annotated.exp",
|
51
|
+
# full test (6m18s + 8s = 6m26s)
|
52
|
+
# *`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}
|
53
|
+
]
|
54
|
+
|
55
|
+
start = Time.now
|
56
|
+
repository = Expressir::Express::Parser.from_files(exp_files)
|
57
|
+
puts "Parser.from_files time: #{(Time.now - start).round(2)}s"
|
58
|
+
|
59
|
+
temp_file = Tempfile.new
|
60
|
+
begin
|
61
|
+
start = Time.now
|
62
|
+
Expressir::Express::Cache.to_file(temp_file, repository)
|
63
|
+
puts "Cache.to_file time: #{(Time.now - start).round(2)}s"
|
64
|
+
|
65
|
+
start = Time.now
|
66
|
+
repository = Expressir::Express::Cache.from_file(temp_file)
|
67
|
+
puts "Cache.from_file time: #{(Time.now - start).round(2)}s"
|
68
|
+
ensure
|
69
|
+
temp_file.close
|
70
|
+
temp_file.unlink
|
71
|
+
end
|
72
|
+
|
73
|
+
start = Time.now
|
74
|
+
formatter = Class.new(Expressir::Express::Formatter) do
|
75
|
+
include Expressir::Express::SchemaHeadFormatter
|
76
|
+
include Expressir::Express::HyperlinkFormatter
|
77
|
+
end
|
78
|
+
result = repository.to_hash(formatter: formatter, skip_empty: true)
|
79
|
+
puts "Repository.to_hash time: #{(Time.now - start).round(2)}s"
|
80
|
+
|
81
|
+
# puts YAML.dump(result)
|
data/exe/generate-parser
ADDED
@@ -0,0 +1,51 @@
|
|
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("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] += <<~CPP.split("\n").map { |x| x == "" ? x : " #{x}" }.join("\n")
|
27
|
+
|
28
|
+
Array getTokens() {
|
29
|
+
Array a;
|
30
|
+
|
31
|
+
std::vector<Token*> tokens = this -> tokens -> getTokens();
|
32
|
+
|
33
|
+
for (auto &token : tokens) {
|
34
|
+
a.push(token);
|
35
|
+
}
|
36
|
+
|
37
|
+
return a;
|
38
|
+
}
|
39
|
+
|
40
|
+
CPP
|
41
|
+
i = parser_source_lines.index { |x| x == ' .define_method("syntax", &ParserProxy::syntax, Return().keepAlive())' }
|
42
|
+
parser_source_lines[i] += <<~CPP.split("\n").map { |x| x == "" ? x : " #{x}" }.join("\n")
|
43
|
+
|
44
|
+
.define_method("tokens", &ParserProxy::getTokens)
|
45
|
+
CPP
|
46
|
+
|
47
|
+
# write fixed parser file
|
48
|
+
File.write(parser_source_file, "#{parser_source_lines.join("\n")}\n")
|
49
|
+
|
50
|
+
# cleanup
|
51
|
+
FileUtils.rm(temp_grammar_file)
|
data/expressir.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
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 and tools in Ruby."
|
12
|
+
spec.description = "Expressir (“EXPRESS in Ruby”) is a Ruby parser for EXPRESS and a set of Ruby tools for accessing ISO 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.7.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 "rice", "~> 4.1"
|
34
|
+
spec.add_runtime_dependency "thor", "~> 1.0"
|
35
|
+
spec.add_development_dependency "antlr4-native", "~> 2.1.0"
|
36
|
+
spec.add_development_dependency "asciidoctor", "~> 2.0.13"
|
37
|
+
spec.add_development_dependency "bundler", "~> 2.3"
|
38
|
+
spec.add_development_dependency "byebug", "~> 11.1"
|
39
|
+
spec.add_development_dependency "pry", "~> 0.12.2"
|
40
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
41
|
+
spec.add_development_dependency "rake-compiler", "~> 1.2"
|
42
|
+
spec.add_development_dependency "rake-compiler-dock", "~> 1.3"
|
43
|
+
spec.add_development_dependency "rspec", "~> 3.11"
|
44
|
+
spec.add_development_dependency "rubocop", "1.58"
|
45
|
+
spec.add_development_dependency "rubocop-performance", "~> 1.19"
|
46
|
+
spec.add_development_dependency "webrick", "~> 1.7.0"
|
47
|
+
spec.add_development_dependency "yard", "~> 0.9.26"
|
48
|
+
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,21 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "expressir/cli/ui"
|
3
|
+
|
4
|
+
module Expressir
|
5
|
+
module Cli
|
6
|
+
def self.ui
|
7
|
+
Expressir::Cli::UI
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.start(args)
|
11
|
+
Base.start(args)
|
12
|
+
end
|
13
|
+
|
14
|
+
class Base < Thor
|
15
|
+
desc "version", "The Expressir Version"
|
16
|
+
def version
|
17
|
+
Cli.ui.say("Version #{Expressir::VERSION}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
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
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|