sbuilder-ial 0.0.1

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.
data/lib/model/sexp.rb ADDED
@@ -0,0 +1,58 @@
1
+ module Sbuilder
2
+ module Ial
3
+ module Model
4
+ class Sexp < Array
5
+
6
+ def initialize(*args)
7
+ super(args)
8
+ end
9
+
10
+ ##
11
+ # Returns the node type of the Sexp.
12
+
13
+ def sexp_type
14
+ first
15
+ end
16
+
17
+ ##
18
+ # Returns the Sexp body, ie the values without the node type.
19
+
20
+ def sexp_body
21
+ self[1..-1]
22
+ end
23
+
24
+ # @return [Sexp|Nil] sexp_body.first for corresponding 'prop'
25
+ def sexp_property( prop )
26
+ sexp_element = sexp_body && sexp_body.select{ |e| e.is_a?(Sexp) && e.sexp_type == prop }.first
27
+ sexp_element.sexp_body.first unless sexp_element.nil?
28
+ end
29
+
30
+ # @return [Sexp:Array] sexp_body for corresponding 'prop'
31
+ def sexp_properties( prop )
32
+ sexp_element = sexp_body && sexp_body.select{ |e| e.is_a?(Sexp) && e.sexp_type == prop }
33
+ # [[:sexp, [:sexp1, ...], [:sexp1, ...]]] --> [:sexp, [:sexp1, ...], [:sexp1, ...]]
34
+ sexp_element.flatten(1)[1..-1]
35
+ end
36
+
37
+
38
+ # alias :head :sexp_type
39
+ # alias :rest :sexp_body
40
+
41
+
42
+ end
43
+
44
+ end
45
+
46
+ # Important shortcut
47
+ def s(*args)
48
+ Model::Sexp.new(*args )
49
+ end
50
+ module_function :s
51
+
52
+ end
53
+ end
54
+
55
+
56
+ def s(*args)
57
+ Sbuilder::Ial::Model::Sexp.new(*args )
58
+ end
@@ -0,0 +1,273 @@
1
+ # coding: utf-8
2
+ require 'sbuilder'
3
+
4
+ module Sbuilder
5
+ module Ial
6
+
7
+ class Plugin < Sbuilder::LoaderPluginRoot
8
+
9
+ TRANSLATE_SNIPPETS =
10
+ [
11
+ :base_snippets,
12
+ :library_snippets,
13
+ :variables_snippets,
14
+ :macros_snippets,
15
+ :operators_snippets,
16
+ :transaction_entry_snippets,
17
+ :transaction_function_snippets,
18
+ :transaction_exit_snippets,
19
+ ]
20
+
21
+ # mix api loader plugin services
22
+ include ApiLoaderPluginMixer
23
+
24
+ # mix snippet loader plugin services
25
+ include SnippetLoaderPluginMixer
26
+
27
+ # @attr [Hash] options set in constructor
28
+ attr_reader :options
29
+
30
+
31
+ # @attr [String|String:Array] rubypaths configuration setting
32
+ attr_accessor :rubypaths
33
+
34
+ # @attr [String] metatypes set in configuration
35
+ attr_accessor :metatypes
36
+
37
+ # @attr [object] applicationConfiguration to pass to Ruby IAL application modules
38
+ attr_accessor :applicationConfiguration
39
+
40
+ # # @əttr [Sbuilder::Ial::App::App] loaded appstate after loading
41
+ attr_accessor :app
42
+
43
+ # @əttr [Sbuilder::Ial::Model::Model] app holding the state
44
+ attr_accessor :model
45
+
46
+
47
+ # ------------------------------------------------------------------
48
+ # Validation
49
+ PLUGIN_CONFIGURATION_REQUIRED= [ 'rubypaths', 'metatypes', ]
50
+ PLUGIN_CONFIGURATION_ALLOWED=[ 'application' ]
51
+
52
+ # ------------------------------------------------------------------
53
+ # @!group Construct && configure
54
+
55
+ def initialize( options={} )
56
+ super( options )
57
+ @options = options
58
+ logger.info "#{__method__}: sbuilder-ial plugin created @options=#{@options}"
59
+
60
+ end
61
+
62
+
63
+ # Class level configuration
64
+ #
65
+ # @param [Hash] configuration given in 'extend.loaders'
66
+ #
67
+ # @option configuration [String] solc_command path to solc
68
+ # executable
69
+ #
70
+ def self.configure( configuration )
71
+ # validateProperties( configuration, Constants::VALIDATION[:class_configure][:required], Constants::VALIDATION[:class_configure][:allowed] )
72
+ # @@solc_command = configuration['solc_command'] if configuration.is_a?(Hash ) && configuration.key?( 'solc_command' )
73
+ end
74
+
75
+ # Instance level configuration
76
+ #
77
+ # @param [Hash] configuration for object instance
78
+ def configure( configuration )
79
+
80
+ logger.info "#{__method__}: sbuilder-ial plugin configuration=#{configuration}"
81
+ validateProperties( configuration, PLUGIN_CONFIGURATION_REQUIRED, PLUGIN_CONFIGURATION_ALLOWED )
82
+
83
+ # array of filepath from which to load IAL model
84
+ self.rubypaths = configuration['rubypaths']
85
+
86
+ self.metatypes = configuration['metatypes'] if configuration['metatypes']
87
+
88
+ # configuration passed to Ruby ial modules
89
+ self.applicationConfiguration = configuration['application']
90
+
91
+ # Init application state (model) from 'rubypaths'
92
+ initModel( rubypaths )
93
+ end
94
+
95
+
96
+ # @!endgroup
97
+
98
+ # ------------------------------------------------------------------
99
+ # @!group sbuilder extension poinsts
100
+
101
+ # API loader extension point
102
+
103
+ def load( sbuilderConfig )
104
+
105
+ logger.info "#{__method__} API loader extension point: sbuilderConfig=#{sbuilderConfig}"
106
+
107
+ apiLoader
108
+
109
+ end
110
+
111
+ # Snippet loader extension point
112
+ #
113
+ # Implemtnation assumes that +process+ method has been called
114
+ # earlier, and uses +snippets+ getter to retrive TLA generate
115
+ # element to load into sbuilder.
116
+ #
117
+ # Overrides abstract method in parent class.
118
+ #
119
+ # @param [Hash:Array] snippetDefitions given in sbuilder.yaml
120
+ #
121
+ # @return [Boolean] true after success
122
+ #
123
+ def doRegisterSnippets( snippetDefitions )
124
+
125
+ logger.info "#{__method__} snippet extension point snippetDefitions=#{snippetDefitions}"
126
+
127
+ loadSnippets
128
+
129
+ end
130
+ # @!endgroup
131
+
132
+ # ------------------------------------------------------------------
133
+ # @!group plugin load ial
134
+
135
+ ##
136
+ # Init application state (model) from 'rbFiles'
137
+
138
+ def initModel( rbFiles )
139
+
140
+ # Init app
141
+ logger.info "#{__method__}: start app with option=#{options}"
142
+ self.app = Sbuilder::Ial::App::App.start( options, metatypes: metatypes, applicationConfiguration: applicationConfiguration )
143
+
144
+ # Load [files] -> Model|Error
145
+ loadInput( rbFiles )
146
+ end
147
+
148
+ # Load Intermediate Api Language input from 'files'
149
+ #
150
+ # @param [String:Array] files path to IAL language input files
151
+ def loadInput( files )
152
+
153
+ app.loadIalImplementation( files ).pipe() do |v|
154
+ logger.debug "#{__method__}: loadIalImplementation=#{v}" if logger.debug?
155
+ end.and_then do |ialImplementation|
156
+ # process array of dsl objects - build model
157
+ app.buildModel(ialImplementation)
158
+ end.pipe do |v|
159
+ logger.debug "#{__method__}: buildModel=#{v}" if logger.debug?
160
+ end.and_then do
161
+ # Extract model from app
162
+ self.model = app.getModel
163
+ end.pipe do |v|
164
+ logger.debug "#{__method__}: getModel=#{v}"
165
+ end.or_else do |err|
166
+ # Collect Errors in self.model
167
+
168
+ self.model = Error(
169
+ err.select do |e|
170
+ e.is_a? Exception || e.respond_to?( :isError ) && e.isError
171
+ end.map do |e|
172
+ Error( e )
173
+ end
174
+ )
175
+ end
176
+
177
+ end
178
+
179
+ def apiLoader
180
+ # puts "app, =#{app}, model=#{model}"
181
+ return ( Error( "nil" ) ) if model.nil?
182
+
183
+ #
184
+ model.and_then do
185
+ app.translateModel( model, [ :domains_defines ] ).flatten.each do |domain|
186
+ logger.info( "#{__method__} defineDomain=#{domain}")
187
+ facade.defineDomain( domain[:name], domain[:values] )
188
+ end
189
+ Result( "domains" )
190
+ end.and_then do
191
+
192
+ app.translateModel( model, [ :api_definitions ] ).flatten.each do |definition|
193
+
194
+ # definition is a Hash with ':name' and ':properties' -keys
195
+ logger.info( "#{__method__} add definition=#{definition}")
196
+ currentDefinition = facade.newDefinition( definition[:name] )
197
+ Sequence( definition[:properties] ).and_then do |property|
198
+ # Property is a struct with 'name' and 'domain' methods, validation should
199
+ raise "Application error - validation should prevent property.domain.nil?" if property.domain.nil?
200
+ logger.info( "#{__method__} definitino '#{definition[:name] }' property =#{property}")
201
+ newParameter = facade.newParameter( property.name )
202
+ facade.addParameter( currentDefinition, newParameter, property.domain.name )
203
+ end
204
+
205
+ facade.modelDefinition( currentDefinition )
206
+ end
207
+ Result( "definitions" )
208
+ end.and_then do
209
+
210
+ app.translateModel( model, [ :transaction_interfaces ] ).flatten.each do |interface|
211
+ logger.info( "#{__method__} define interface=#{interface}")
212
+ currentInterface = facade.newInterface( interface[:path], interface[:operation] )
213
+ Sequence( interface[:request].properties ).and_then do |property|
214
+ logger.debug( "#{__method__} property.name=#{property.name}, property.domain=#{property && property.domain ? property.domain.name : "-" } property.definition=#{property && property.definition ? property.definition.name : "-" } ") if logger.debug?
215
+ if property.domain
216
+ newParameter = facade.newParameter( property.name )
217
+ facade.addParameter( currentInterface, newParameter, property.domain.name )
218
+ elsif property.definition
219
+ isArray = false
220
+ newParameterReference = facade.newParameterReference( property.name, property.definition.name, isArray )
221
+ facade.addParameter( currentInterface, newParameterReference )
222
+ else
223
+ raise "Must define 'domain' or 'definition' for parameter '#{property.name}'"
224
+ end
225
+ end
226
+ facade.modelInterface( currentInterface )
227
+ end
228
+ Result( "interfaces" )
229
+ end.or_else do |err|
230
+ logger.error "{__method__}: #{err}"
231
+ warn err
232
+ end
233
+
234
+ # domains = )
235
+ # puts "domains=#{domains}"
236
+ # return Result( "success" )
237
+ end
238
+
239
+ def loadSnippets
240
+ # puts "app, =#{app}, model=#{model}"
241
+ return ( Error( "nil" ) ) if model.nil?
242
+
243
+ model.and_then do
244
+ appMetatypes = app.appMetatypes
245
+ logger.info "#{__method__}, appMetatypes=#{appMetatypes}"
246
+ appMetatypes.keys.each { |metatype| snippetFacade.registerMetatype( metatype, app.appMetatypes[metatype][:name], app.appMetatypes[metatype][:prefix] ) }
247
+ end.and_then do
248
+ ret = true
249
+ app.translateModel( model, TRANSLATE_SNIPPETS ).flatten.each do |snippet|
250
+ logger.info "#{__method__}: render & hand over snippet #{snippet}"
251
+ if snippet.is_a?( Hash ) then
252
+ snippetBody = app.renderSnippet( snippet ) || snippet[:body]
253
+ logger.debug "#{__method__}: snippetBody=#{snippetBody}" if logger.debug?
254
+ snippetFacade.handOver( snippet[:metatype].to_s, snippet[:appName], snippetBody, snippet[:specName] )
255
+ else
256
+ logger.error "#{__method__}: snippet=#{snippet}"
257
+ ret = snippet
258
+ end
259
+ end
260
+ ret
261
+ end.
262
+ or_else do |err|
263
+ logger.error "{__method__}: #{err}"
264
+ warn err
265
+ end
266
+ end
267
+
268
+
269
+ # @!endgroup
270
+ end # class
271
+
272
+ end
273
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'utils/logger'
2
+
3
+ require_relative 'fp/exception'
4
+ require_relative 'fp/compositable'
5
+ require_relative 'fp/sequence'
6
+ require_relative 'fp/error'
7
+ require_relative 'fp/result'
8
+ def Result(x)
9
+ Sbuilder::Fp.Result(x)
10
+ end
11
+
12
+ def Error(x)
13
+ Sbuilder::Fp.Error(x)
14
+ end
15
+ def Sequence(x)
16
+ Sbuilder::Fp.Sequence(x)
17
+ end
18
+
19
+ require_relative 'model/constants'
20
+ require_relative 'model/sexp'
21
+ require_relative 'model/model_dsl'
22
+ require_relative 'model/model'
23
+ # require_relative 'model/ctx'
24
+
25
+ require_relative 'ial/exception'
26
+
27
+ require_relative 'action/exception'
28
+ require_relative 'action/render/exception'
29
+ # require_relative 'action/validator'
30
+ require_relative 'action/render/tla_element_generator'
31
+ require_relative 'action/render/producer'
32
+ require_relative 'action/render/producer_ethereum'
33
+ require_relative 'action/render/renderer'
34
+ require_relative 'action/file_path'
35
+ require_relative 'action/text'
36
+ # require_relative 'action/schema'
37
+ require_relative 'action/model_builder'
38
+ require_relative 'action/tla_rules'
39
+ require_relative 'action/translator'
40
+ require_relative 'action/extender'
41
+ require_relative 'action/script_eval'
42
+
43
+ require_relative 'app/app'
44
+ require_relative 'plugin/plugin'
@@ -0,0 +1,82 @@
1
+ module Sbuilder
2
+ module Ial
3
+ require 'logger'
4
+
5
+ # see http://hawkins.io/2013/08/using-the-ruby-logger/
6
+
7
+ module MyLogger
8
+
9
+ # no logging done
10
+
11
+ class NullLoger < Logger
12
+ def initialize(*args)
13
+ end
14
+
15
+ def add(*args, &block)
16
+ end
17
+
18
+ def debug?
19
+ false
20
+ end
21
+ end
22
+
23
+ @@logfile = nil # absolute path to log file
24
+ LOGFILE="sbuilder.log"
25
+
26
+ def logfile( options )
27
+ return @@logfile if @@logfile
28
+ @@logfile = options[:logfile] || File.join( Dir.getwd, LOGFILE )
29
+ @@logfile
30
+ end
31
+
32
+ def getLogger( progname=nil, options={} )
33
+
34
+
35
+ progname = self.class.name.split('::').last if progname.nil?
36
+ level = get_level( options )
37
+
38
+ if level.nil?
39
+
40
+ return NullLoger.new
41
+
42
+ else
43
+
44
+
45
+ logger = Logger.new( logfile(options) )
46
+ logger.level=level
47
+ logger.progname = progname
48
+ return logger
49
+
50
+ end
51
+
52
+ end # getLogger
53
+
54
+
55
+ # ------------------------------------------------------------------
56
+ private
57
+
58
+ def get_level( options )
59
+
60
+ level_name = options && options[:log] ? options[:log] : ENV['LOG_LEVEL']
61
+
62
+ level = case level_name
63
+ when 'warn', 'WARN'
64
+ Logger::WARN
65
+ when 'info', 'INFO'
66
+ Logger::INFO
67
+ when 'debug', 'DEBUG'
68
+ Logger::DEBUG
69
+ when 'error', 'ERROR'
70
+ Logger::ERROR
71
+ else
72
+ nil
73
+ end
74
+
75
+ return level
76
+ end
77
+
78
+ end
79
+
80
+
81
+ end
82
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8; mode: ruby -*-
2
+
3
+ lib = File.expand_path('../lib/', __FILE__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+
6
+ GEM_NAME='sbuilder-ial'
7
+ Gem::Specification.new do |s|
8
+
9
+ # version = "0.0.1.pre"
10
+ version = File.open( "VERSION", "r" ) { |f| f.read }.strip.gsub( "-SNAPSHOT", ".pre" )
11
+
12
+ s.name = GEM_NAME
13
+ s.version = version
14
+ s.date = Time.now.strftime( "%Y-%m-%d" ) #'2014-09-10'
15
+ s.summary = "Intermediate API Language (IAL) for to build tla-sbuilder snippets"
16
+ s.description = <<EOF
17
+
18
+ Intermediate API Language (IAL) for to build tla-sbuilder snippets.
19
+
20
+
21
+ EOF
22
+ s.authors = ["jarjuk"]
23
+ s.files = [ "VERSION", "#{s.name}.gemspec" ] | Dir.glob("lib/**/*")
24
+ s.require_paths = [ "lib" ]
25
+ s.executables = [ ]
26
+ s.license = 'MIT'
27
+
28
+ s.homepage = "https://github.com/jarjuk/#{GEM_NAME}"
29
+
30
+ s.required_ruby_version = '~> 2.3', ">=2.3.1"
31
+
32
+ s.add_runtime_dependency "mustache", '~>1.0', ">=1.0.3"
33
+ s.add_runtime_dependency "docile", '~>1.1', ">=1.1.5"
34
+ s.add_runtime_dependency "tla-sbuilder", ">=0.3.4"
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sbuilder-ial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - jarjuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mustache
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: docile
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.1.5
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.1.5
53
+ - !ruby/object:Gem::Dependency
54
+ name: tla-sbuilder
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.3.4
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.3.4
67
+ description: |2+
68
+
69
+ Intermediate API Language (IAL) for to build tla-sbuilder snippets.
70
+
71
+
72
+ email:
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - VERSION
78
+ - lib/action/exception.rb
79
+ - lib/action/extender.rb
80
+ - lib/action/file_path.rb
81
+ - lib/action/model_builder.rb
82
+ - lib/action/render/exception.rb
83
+ - lib/action/render/producer.rb
84
+ - lib/action/render/producer_ethereum.rb
85
+ - lib/action/render/producer_ethereum_const.rb
86
+ - lib/action/render/renderer.rb
87
+ - lib/action/render/tla_element_generator.rb
88
+ - lib/action/script_eval.rb
89
+ - lib/action/text.rb
90
+ - lib/action/tla_rules.rb
91
+ - lib/action/translator.rb
92
+ - lib/app/app.rb
93
+ - lib/ethereum.rb
94
+ - lib/ethereum/api.rb
95
+ - lib/fp/compositable.rb
96
+ - lib/fp/error.rb
97
+ - lib/fp/exception.rb
98
+ - lib/fp/result.rb
99
+ - lib/fp/sequence.rb
100
+ - lib/ial/build.rb
101
+ - lib/ial/exception.rb
102
+ - lib/model/constants.rb
103
+ - lib/model/model.rb
104
+ - lib/model/model_dsl.rb
105
+ - lib/model/sexp.rb
106
+ - lib/plugin/plugin.rb
107
+ - lib/sbuilder-ial.rb
108
+ - lib/utils/logger.rb
109
+ - sbuilder-ial.gemspec
110
+ homepage: https://github.com/jarjuk/sbuilder-ial
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '2.3'
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: 2.3.1
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.5.1
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Intermediate API Language (IAL) for to build tla-sbuilder snippets
137
+ test_files: []