-
Notifications
You must be signed in to change notification settings - Fork 4
/
expressir_wrapped.txt
23068 lines (20725 loc) · 752 KB
/
expressir_wrapped.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--- START FILE: .github/workflows/codeql.yml ---
name: "CodeQL"
on:
push:
branches: [ main ]
schedule:
- cron: '0 23 * * 3'
workflow_dispatch:
concurrency:
group: '${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.ref_name }}'
cancel-in-progress: true
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@master
with:
ruby-version: 3.2
bundler-cache: true
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: "ruby, cpp"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
--- END FILE: .github/workflows/codeql.yml ---
--- START FILE: .github/workflows/rake.yml ---
name: rake
on:
push:
branches: [ main ]
paths-ignore:
- 'docs/**'
- '**.adoc'
- '**.md'
- .github/workflows/release.yml
- .github/workflows/codeql.yml
pull_request:
workflow_dispatch:
concurrency:
group: '${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.ref_name }}'
cancel-in-progress: true
env:
RUBYGEM_VER: 3.4.22
jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true
- name: Rubocop
run: bundle exec rake rubocop
rake:
name: test on ruby-${{ matrix.ruby }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ruby: [ '3.3', '3.2', '3.1', '3.0', '2.7' ]
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: |
bundle exec rake
cat .rspec_status
rake-alpine:
name: test on ruby-${{ matrix.ruby }} alpine container
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby: [ '3.3', '3.2', '3.1', '3.0', '2.7' ]
container: ruby:${{ matrix.ruby }}-alpine
steps:
- name: Install packages
run: |
apk --no-cache --upgrade add build-base git bash tar
- name: Checkout
uses: actions/checkout@v4
- name: Upgrade RubyGems
if: matrix.ruby == '3.0' || matrix.ruby == '2.7'
run: gem update --system ${{ env.RUBYGEM_VER }} --no-document
- name: Bundle
run: |
git config --global --add safe.directory $PWD
bundle install --jobs 4 --retry 3
- name: Run tests
run: |
bundle exec rake
cat .rspec_status
# test release workflow
pack-ruby:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Build gem without native extension
run: gem build expressir.gemspec
- name: Package gem without native extension
uses: actions/upload-artifact@v4
with:
name: pkg-ruby
path: expressir-*.gem
pack:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform: [ linux-gnu, linux-musl, windows, darwin ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Package gem with native extension
uses: actions/upload-artifact@v4
with:
name: pkg-${{ matrix.platform }}
path: pkg/*.gem
verify-ruby:
name: verify ruby gem on ruby-${{ matrix.ruby }} ${{ matrix.os }}
needs: pack-ruby
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ruby: [ '3.3', '3.2', '3.1', '3.0', '2.7' ]
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Download packaged gem
uses: actions/download-artifact@v4
with:
name: pkg-ruby
path: pkg
- name: Install gem
run: gem install -l pkg/expressir-*.gem
- name: Verify
run: |
cd $(ruby -e "puts Gem::Specification.find_by_name('expressir').gem_dir")
ruby bin/rspec
cat .rspec_status || echo ".rspec_status was not found"
--- END FILE: .github/workflows/rake.yml ---
--- START FILE: .github/workflows/release.yml ---
name: release
on:
workflow_dispatch:
inputs:
next_version:
description: |
Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
required: true
default: 'patch'
push:
tags: [ v* ]
concurrency:
group: '${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.ref_name }}'
cancel-in-progress: true
jobs:
bump:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@master
with:
ruby-version: '3.2'
- if: ${{ github.event_name == 'workflow_dispatch' }} # unfortunatelly cannot keep this condition on job level
run: |
git config --global user.name github-actions
git config --global user.email github-actions@github.com
gem install gem-release
gem bump --version ${{ github.event.inputs.next_version }} --tag --push
pack:
runs-on: ubuntu-latest
needs: bump
strategy:
fail-fast: false
matrix:
platform: [ linux-gnu, linux-musl, windows, darwin ]
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@master
with:
ruby-version: '3.2'
bundler-cache: true
- name: Build gem and save version
if: matrix.platform == 'linux-gnu'
run: |
gem build expressir.gemspec | grep -o 'Version: .*' | awk '{print $2}' > version
- if: matrix.platform == 'linux-gnu'
uses: actions/upload-artifact@v4
with:
name: pkg-ruby
path: expressir-*.gem
- if: matrix.platform == 'linux-gnu'
uses: actions/upload-artifact@v4
with:
name: version
path: version
# build gem WITH pre-built native extension
- run: bundle exec rake gem:${{ matrix.platform }}
- uses: actions/upload-artifact@v4
with:
name: pkg-${{ matrix.platform }}
path: pkg/*.gem
publish:
runs-on: ubuntu-latest
needs: pack
steps:
- uses: actions/download-artifact@v4
with:
name: pkg-ruby
path: pkg
- uses: actions/download-artifact@v4
with:
name: pkg-linux-gnu
path: pkg
- uses: actions/download-artifact@v4
with:
name: pkg-linux-musl
path: pkg
- uses: actions/download-artifact@v4
with:
name: pkg-windows
path: pkg
- uses: actions/download-artifact@v4
with:
name: pkg-darwin
path: pkg
- uses: ruby/setup-ruby@master
with:
ruby-version: '3.1'
- name: Publish to rubygems.org
env:
RUBYGEMS_API_KEY: ${{ secrets.LUTAML_CI_RUBYGEMS_API_KEY }}
run: |
ls -l pkg/
mkdir -p ~/.gem
cat > ~/.gem/credentials << EOF
---
:rubygems_api_key: ${RUBYGEMS_API_KEY}
EOF
chmod 0600 ~/.gem/credentials
gem signin
for gem in pkg/*.gem; do gem push $gem -V; done
sleep 15
verify:
name: Verify published gem on ${{ matrix.os }}
needs: publish
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- name: Install Ruby
uses: ruby/setup-ruby@master
with:
ruby-version: 3.2
bundler-cache: true
- name: Download version
uses: actions/download-artifact@v4
with:
name: version
- name: Install gem
run: gem install expressir -v $(cat version)
- name: Verify
run: expressir version
verify-alpine:
name: Verify published gem on alpine
needs: publish
runs-on: ubuntu-latest
container:
image: alpine:3.17
steps:
- name: Install packages
run: apk --no-cache add bash build-base git ruby-dev gcc g++ automake
- name: Download version
uses: actions/download-artifact@v4
with:
name: version
- name: Install gem
run: gem install expressir -v $(cat version)
- name: Verify
run: expressir version
--- END FILE: .github/workflows/release.yml ---
--- START FILE: .github/workflows/stress.yml ---
name: stress
on:
workflow_dispatch:
concurrency:
group: '${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.ref_name }}'
cancel-in-progress: true
env:
GC_STRESS: true
jobs:
rake:
name: test on ruby-${{ matrix.ruby }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ruby: [ '3.2', '3.1', '3.0', '2.7' ]
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@master
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: |
bundle exec rake
cat .rspec_status
--- END FILE: .github/workflows/stress.yml ---
--- START FILE: Gemfile ---
# frozen_string_literal: true
source "https://rubygems.org"
# Specify your gem's dependencies in reeper.gemspec
gemspec
# gem "asciidoctor", "~> 2.0.13"
gem "pry"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
gem "rubocop", "~> 1.21"
gem "rubocop-performance", require: false
gem "rubocop-rake", require: false
gem "rubocop-rspec", require: false
gem "webrick", "~> 1.7"
gem "yard", "~> 0.9"
--- END FILE: Gemfile ---
--- START FILE: README.adoc ---
= Expressir: EXPRESS in Ruby
image:https://img.shields.io/gem/v/expressir.svg["Gem Version", link="https://rubygems.org/gems/expressir"]
// image:https://codeclimate.com/github/lutaml/expressir/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/lutaml/expressir"]
image:https://github.com/lutaml/expressir/workflows/rake/badge.svg["Build Status", link="https://github.com/lutaml/expressir/actions?workflow=rake"]
== Purpose
Expressir ("`EXPRESS in Ruby`") is a Ruby parser for EXPRESS and
a set of Ruby tools for accessing ISO EXPRESS data models.
== Architecture
Expressir consists of 3 parts:
. Parsers. A parser allows Expressir to read EXPRESS files, including:
** EXPRESS data modelling language (ISO 10303-11:2007)
** EXPRESS data modelling language in XML (STEPmod)
** EXPRESS XML (ISO 10303-28:2007)
"`Industrial automation systems and integration — Product data representation and exchange — Part 28: Implementation methods: XML representations of EXPRESS schemas and data, using XML schemas`"
. Data model. The data model (`lib/expressir/express`) is the Ruby data model that fully represents an EXPRESS data model.
. Converters. A converter transforms the EXPRESS Ruby data model into an interoperable export format, including:
** EXPRESS data modelling language (ISO 10303-11:2007)
// ** W3C OWL
// ** OMG SysML (XMI 2.1, XMI 2.5)
// ** OMG UML 2 (XMI 2.1)
// ** OMG UML 2 for Eclipse (XMI 2.1)
== Usage
This gem ships with a CLI tool. To check what's available you can simply run
`expressir`, by default it will display some usage instructions.
[source, sh]
----
$ expressir
Commands:
expressir format PATH # pretty print EXPRESS schema located at PATH
expressir help [COMMAND] # Describe available commands or one specific command
expressir version # The Expressir Version
----
=== Pretty print
[source, sh]
----
expressir format schemas/resources/action_schema/action_schema.exp
----
== Development
We are following Sandi Metz's Rules for this gem, you can read
the http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers[description of the rules here] All new code should follow these rules.
If you make changes in a pre-existing file that violates these rules you should
fix the violations as part of your contribution.
=== Setup
Clone the repository.
[source, sh]
----
git clone https://github.com/metanorma/expressir
----
Setup your environment.
[source, sh]
----
bin/setup
git submodule update --init
bundle exec rake generate
bundle exec rake compile
----
Run the test suite
[source, sh]
----
bundle exec rake
----
== Installation
Add this line to your application's `Gemfile`:
[source, sh]
----
gem "expressir"
----
And then execute:
[source, sh]
----
$ bundle install
----
Or install it yourself as:
[source, sh]
----
$ gem install expressir
----
== Usage
=== Filtering out schemas
Use the `select_proc` argument of `to_hash`.
Example:
[source,ruby]
----
schema_yaml = YAML.load_file('documents/iso-10303-41/schemas.yaml')
schema_paths = schema_yaml['schemas'].map {|x,y| y['path'].gsub("../../", "")}
repo = Expressir::Express::Parser.from_files(schema_paths)
filtered_schemas = ["action_schema", "date_time_schema"]
select_proc = Proc.new do |value|
if value.is_a?(Expressir::Model::Declarations::Schema)
filtered_schemas.include?(value.id)
else
true
end
end
repo_hash = repo.to_hash(select_proc: select_proc)
schemas = repo_hash['schemas']
schemas.map {|s| s["id"] }
----
== Contributing
First, thank you for contributing! We love pull requests from everyone. By
participating in this project, you hereby grant
https://www.ribose.com[Ribose Inc.] the right to grant or transfer an unlimited
number of non exclusive licenses or sub-licenses to third parties, under the
copyright covering the contribution to use the contribution by all means.
Here are a few technical guidelines to follow:
* Open an https://github.com/lutaml/expressir/issues[issues] to discuss a new
feature.
* Write tests to support your new feature.
* Make sure the entire test suite passes locally and on CI.
* Open a Pull Request.
* https://github.com/thoughtbot/guides/tree/master/protocol/git#write-a-feature[Squash your commits] after receiving feedback.
* Party!
== License
Expressir is distributed under the BSD 2-clause license.
Expressir originally contained some code from the NIST Reeper project but
has been completely rewritten.
The https://www.nist.gov/services-resources/software/reeper[NIST Reeper license]
is reproduced below:
[quote]
____
This software was funded by NIST and developed by EuroSTEP.
Pursuant to title 17 Section 105 of the United States Code this
software is not subject to copyright protection and is in the public
domain.
We would appreciate acknowledgment if the software is used. Links to
non-Federal Government Web sites do not imply NIST endorsement of any
particular product, service, organization, company, information
provider, or content.
____
== Credits
Copyright Ribose Inc.
--- END FILE: README.adoc ---
--- START FILE: Rakefile ---
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
require "rubocop/rake_task"
RuboCop::RakeTask.new
task default: %i[spec rubocop]
require "yard"
YARD::Rake::YardocTask.new
--- END FILE: Rakefile ---
--- START FILE: docs/development.md ---
## Development Plan
This document is a draft to understand the basic of the original library, and
how the whole tool chain is working at the moment. Once, we've an understanding
then let's look at the potential area of improvement, and plan out a high level
plan to start the development.
### What is it, expressir?
* Expressir is a ruby tool to harvest iso express data model
* Express is one of the language to represent data model
* Expressir tool is used to manipulate iso express data model
* The input for the expressir is a standard xml document
* XML Spec: http://stepmod.sourceforge.net/express_model_spec/
* Expressir does the job of representing express model as ruby class
* REXML-based parser that reads EXPRESS as XML and creates the dictionary (i.e.
instances of the EXPRESS Ruby Classes) and then calls a mapper, that may be
specified as an option at runtime
* Mappers that read the EXPRESS dictionary and perform the conversion to the
desired language or format
* Express to UML2 Mapper - Convert the express model to UML2
* Express to OWL Structure - Convert the express model to OWL Structure
* Ruby API generator for express language
* Current Ruby API is super slow, it takes 2 hours to generate 400 entity
### How does the original version work?
At the core the `expressir.rb` is responsible for everything at moment, it takes
an Express XML file as an input and then it parses that XML file and build the
correct ruby interface for further processing.
This `expressir.rb` also expect one mapping file `deafult to mapping.rb`, and it
also expect the file to specify a custom method `map_from_express` to take the
`Ruby Express Representation` and convert this ruby representation to the
desire output format.
The library also provides couple mapping for UM2, OWL and SysML, so anyone can
export their data to any of those format if necessary, and the use cases for
those library are as following:
```ruby
ruby expressir.rb expxml=<schema.xml> map=<mapping_owl.rb>
```
### What are potential improvement area?
* The interface is not well defined, someone needs to dig deeper to understand
just the basic of the library and how to use for their use cases. This is
something that could be improved as initial step.
* At the moment, these are some ruby files, so potentially we could group those
together as a CLI tool and group some of the common functionality, and provide
a straight forward interface for users.
* The good part about this library is author had the extensibility in mind from
the beginning, so we should keep that functionality as flexible as possible.
* There are lot of boilerplate code in the library, but it's understandable as
it was written quite long time ago, so maybe most of the tool was not even
available back then, so this is the another area we could improve.
* Another improvement we could do in terms of actual codebase, we should be able
to refactor this library and cleanup as much as possible.
### What are the initial changes?
Initially, we can start by creating a ruby cli gem, group these functionality
together. This could be named as `expressir`, and this gem will be shipped with an
executable called `expressir`.
Second of all, let's add some dedicated interface for the default type, so user
does not need to know all the details but the name of the interface, for example
we could expose the transformation as follows:
```sh
# Convert to owl
expressir express2owl file=[express_xml_file] [**options]
# Convert to UML
expressir express2uml file=[express_xml_file] [**options]
# Convert to SysML
expressir express2sysml file=[express_xml_file] [**options]
# Custom conversion
expressir express2custom file=[express_xml_file] mapping=[custom_mapping.rb]
```
Third of all once this library is functional as the original version then we
will go through each of the existing types, and refactor those as necessary.
### References
* https://martinfowler.com/bliki/MovingToNokogiri.html
--- END FILE: docs/development.md ---
--- START FILE: expressir.gemspec ---
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "expressir/version"
Gem::Specification.new do |spec|
spec.name = "expressir"
spec.version = Expressir::VERSION
spec.authors = ["Ribose Inc."]
spec.email = ["open.source@ribose.com"]
spec.summary = "EXPRESS parser and toolkit for Ruby"
spec.description = "Expressir (“EXPRESS in Ruby”) is a Ruby parser for EXPRESS and a set of tools for accessing EXPRESS data models."
spec.homepage = "https://github.com/lutaml/expressir"
spec.license = "BSD-2-Clause"
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
spec.metadata["changelog_uri"] = "https://github.com/lutaml/expressir/releases"
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|features)/})
end
end
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
spec.add_dependency "thor", "~> 1.0"
spec.add_dependency "parslet", "~> 2.0"
spec.metadata["rubygems_mfa_required"] = "true"
end
--- END FILE: expressir.gemspec ---
--- START FILE: lib/expressir.rb ---
require "expressir/version"
require "expressir/cli"
require "expressir/config"
# ..........................................................
# https://bugs.ruby-lang.org/issues/19319
# The issue is that this bug is fixed for 3.1 and above,
# but not for 3.0 or 2.7, so we need a "safe" function
# ..........................................................
if RUBY_VERSION < "3.1"
class String
def safe_downcase
each_char.map(&:downcase).join
end
end
else
class String
def safe_downcase
downcase
end
end
end
module Expressir
class Error < StandardError; end
def self.root
File.dirname(__dir__)
end
def self.root_path
@root_path ||= Pathname.new(Expressir.root)
end
end
Dir[File.join(__dir__, "expressir", "express", "*.rb")].sort.each do |fea|
require fea
end
--- END FILE: lib/expressir.rb ---
--- START FILE: lib/expressir/cli.rb ---
require "thor"
module Expressir
class Cli < Thor
desc "format PATH", "pretty print EXPRESS schema located at PATH"
def format(path)
repository = Expressir::Express::Parser.from_file(path)
repository.schemas.each do |schema|
puts "\n(* Expressir formatted schema: #{schema.id} *)\n"
puts schema.to_s(no_remarks: true)
end
end
no_commands do
def _validate_schema(path)
repository = Expressir::Express::Parser.from_file(path)
repository.schemas.inject([]) do |acc, schema|
acc << schema.id unless schema.version&.value
acc
end
rescue StandardError
nil
end
def _print_validation_errors(type, array)
return if array.empty?
puts "#{'*' * 20} RESULTS: #{type.to_s.upcase.tr('_', ' ')} #{'*' * 20}"
array.each do |msg|
puts msg
end
end
end
desc "validate *PATH", "validate EXPRESS schema located at PATH"
def validate(*paths) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
no_version = []
no_valid = []
paths.each do |path|
x = Pathname.new(path).realpath.relative_path_from(Dir.pwd)
puts "Validating #{x}"
ret = _validate_schema(path)
if ret.nil?
no_valid << "Failed to parse: #{x}"
next
end
ret.each do |schema_id|
no_version << "Missing version string: schema `#{schema_id}` | #{x}"
end
end
_print_validation_errors(:failed_to_parse, no_valid)
_print_validation_errors(:missing_version_string, no_version)
exit 1 unless [no_valid, no_version].all?(&:empty?)
puts "Validation passed for all EXPRESS schemas."
end
desc "version", "Expressir Version"
def version
say(Expressir::VERSION)
end
end
end
--- END FILE: lib/expressir/cli.rb ---
--- START FILE: lib/expressir/config.rb ---
module Expressir
module Config
def configure
if block_given?
yield configuration
end
end
def configuration
@configuration ||= Configuration.new
end
end
class Configuration
attr_accessor :logs
def initialize
@logs = %i(error)
end
end
extend Config
end
--- END FILE: lib/expressir/config.rb ---
--- START FILE: lib/expressir/express/cache.rb ---
require 'yaml'
require 'zlib'
require 'expressir/model'
module Expressir
module Express
class Cache
# Save Express model into a cache file
# @param file [String] cache file path
# @param content [Model::ModelElement] Express model
# @param root_path [String] Express repository root path, to be stripped from Express file paths to create a portable cache file
# @param test_overwrite_version [String] don't use, only for tests
# @return [nil]
def self.to_file(file, content, root_path: nil, test_overwrite_version: nil)
version = test_overwrite_version || VERSION
cache = Model::Cache.new(
version: version,
content: content
)
hash = cache.to_hash(root_path: root_path)
yaml = YAML.dump(hash)
yaml_compressed = Zlib::Deflate.deflate(yaml)
File.binwrite(file, yaml_compressed)
nil
end
# Load Express model from a cache file
# @param file [String] cache file path
# @param root_path [String] Express repository root path, to be prepended to Express file paths if loading a portable cache file
# @param test_overwrite_version [String] don't use, only for tests
# @return [Model::ModelElement] Express model
def self.from_file(file, root_path: nil, test_overwrite_version: nil)
version = test_overwrite_version || VERSION
yaml_compressed = File.binread(file)
yaml = Zlib::Inflate.inflate(yaml_compressed)
hash = YAML.load(yaml)
cache = Model::ModelElement.from_hash(hash, root_path: root_path)
if cache.version != version
raise Error.new("Cache version mismatch, cache version is #{cache.version}, Expressir version is #{version}")
end
cache.content
end
end
end
end
--- END FILE: lib/expressir/express/cache.rb ---
--- START FILE: lib/expressir/express/formatter.rb ---
require 'expressir/model'
module Expressir
module Express
class Formatter
INDENT_CHAR = ' '
INDENT_WIDTH = 2
INDENT = INDENT_CHAR * INDENT_WIDTH
OPERATOR_PRECEDENCE = {
Model::Expressions::BinaryExpression::EXPONENTIATION => 1,
Model::Expressions::BinaryExpression::MULTIPLICATION => 2,
Model::Expressions::BinaryExpression::REAL_DIVISION => 2,
Model::Expressions::BinaryExpression::INTEGER_DIVISION => 2,
Model::Expressions::BinaryExpression::MODULO => 2,
Model::Expressions::BinaryExpression::AND => 2,
Model::Expressions::BinaryExpression::COMBINE => 2,
Model::Expressions::BinaryExpression::SUBTRACTION => 3,
Model::Expressions::BinaryExpression::ADDITION => 3,
Model::Expressions::BinaryExpression::OR => 3,
Model::Expressions::BinaryExpression::XOR => 3,
Model::Expressions::BinaryExpression::EQUAL => 4,
Model::Expressions::BinaryExpression::NOT_EQUAL => 4,
Model::Expressions::BinaryExpression::LESS_THAN_OR_EQUAL => 4,
Model::Expressions::BinaryExpression::GREATER_THAN_OR_EQUAL => 4,
Model::Expressions::BinaryExpression::LESS_THAN => 4,
Model::Expressions::BinaryExpression::GREATER_THAN => 4,
Model::Expressions::BinaryExpression::INSTANCE_EQUAL => 4,
Model::Expressions::BinaryExpression::INSTANCE_NOT_EQUAL => 4,
Model::Expressions::BinaryExpression::IN => 4,
Model::Expressions::BinaryExpression::LIKE => 4,
}
SUPERTYPE_OPERATOR_PRECEDENCE = {