scjson 0.3.3 → 0.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5458d979377d6bb8afc2d6ba6290f228d0b85602ab0c00885fd5f3a0c8f7055
4
- data.tar.gz: 0a5889b05002e6944b82ae94814aaefa33d008519164486d7d4db5a03f4a8ed3
3
+ metadata.gz: a958225a6d29fbafd51d046f9c38d7c65ff98aa80c7727e321c6c68ac952c00a
4
+ data.tar.gz: 13acb52ec061e0ab3c0c09c76a9ea172370938e6770efa7ee69a162183365fe9
5
5
  SHA512:
6
- metadata.gz: 762b5feb6ce8d91f42b99fe7358528a02e1c8a462bc41cfcdf6721e17cb8a12be73f1d0ad60185005a312da607fbf49699ec5f272cf3b94cd9a631930609f945
7
- data.tar.gz: 7e936f6fb3bf500d10e4618d2e19f62af93d124eec40642d162e6c2c939793718f561d6e329bae5c18bc363cf2d1db8f9c9f8bdc2d36e01668a16bf635eedd17
6
+ metadata.gz: b958161b70d561ccfdc324b1855a5f1a710edb0506798764c83e9dc8d26ef2989e2d8c1953a4a05834a01872b2b832adfde4d3a000e8e05f71b13f5c02a6e8a2
7
+ data.tar.gz: 5991fbfe49a89974bedf45a8030cdf5fead46e001fd3851ca14ac5f1131a8519ba3f16d487499a839d7a97c208e0652de82b6ffb7a48c439ab2cdb753f5e9188
data/LEGAL.md ADDED
@@ -0,0 +1,5 @@
1
+ # Legal Information
2
+
3
+ This package is part of the **scjson** project. All original Ruby source code is licensed under the BSD\u00A01-Clause license.
4
+
5
+ Examples derived from the W3C SCXML specification and the Alex Zhornyak tutorial remain under their respective licenses, described in the repository root `LEGAL.md` file.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ BSD 1-Clause License
2
+
3
+ Copyright (c) 2025, Softoboros Technology Inc.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ <p align="center"><img src="https://raw.githubusercontent.com/SoftOboros/scjson/main/scjson.png" alt="scjson logo" width="200"/></p>
2
+
3
+ # scjson Ruby Gem
4
+
5
+ This directory contains the Ruby implementation of **scjson**. The gem provides a command line tool and library functions to convert between `.scxml` and `.scjson` files.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ gem install scjson
11
+ ```
12
+
13
+ You can also install from a local checkout:
14
+
15
+ ```bash
16
+ cd ruby && gem build scjson.gemspec && gem install scjson-*.gem
17
+ ```
18
+
19
+ ## Command Line Usage
20
+
21
+ ```bash
22
+ scjson json path/to/machine.scxml
23
+ scjson xml path/to/machine.scjson
24
+ scjson validate path/to/dir -r
25
+ ```
26
+
27
+ ## Library Usage
28
+
29
+ ```ruby
30
+ require 'scjson'
31
+
32
+ document = Scjson::Types::ScxmlProps.new
33
+ json = document.to_json
34
+ round_trip = Scjson::Types::ScxmlProps.from_json(json)
35
+ ```
36
+
37
+ All source code in this directory is released under the BSD 1-Clause license. See [LICENSE](./LICENSE) and [LEGAL.md](./LEGAL.md) for details.
data/lib/scjson/cli.rb CHANGED
@@ -10,6 +10,7 @@ require 'pathname'
10
10
  require 'optparse'
11
11
  require 'fileutils'
12
12
  require_relative '../scjson'
13
+ require_relative 'engine'
13
14
 
14
15
  module Scjson
15
16
  ##
@@ -17,7 +18,7 @@ module Scjson
17
18
  #
18
19
  # @return [void]
19
20
  def self.splash
20
- puts "scjson #{VERSION} - SCXML <-> scjson converter"
21
+ puts "scjson #{VERSION} - SCXML/SCML execution, SCXML <-> scjson converter & validator"
21
22
  end
22
23
 
23
24
  ##
@@ -32,6 +33,9 @@ module Scjson
32
33
  puts(help_text)
33
34
  return
34
35
  end
36
+ if cmd == 'engine-trace'
37
+ return engine_trace(argv)
38
+ end
35
39
  parser = OptionParser.new do |opts|
36
40
  opts.banner = ''
37
41
  opts.on('-o', '--output PATH', 'output file or directory') { |v| options[:output] = v }
@@ -63,7 +67,7 @@ module Scjson
63
67
  #
64
68
  # @return [String] A one-line summary of the CLI purpose.
65
69
  def self.help_text
66
- 'scjson - SCXML <-> scjson converter and validator'
70
+ 'scjson - SCXML <-> scjson converter, validator, and engine trace'
67
71
  end
68
72
 
69
73
  ##
@@ -216,4 +220,84 @@ module Scjson
216
220
  false
217
221
  end
218
222
  end
223
+
224
+ ##
225
+ # Emit a standardized JSONL execution trace for a document.
226
+ #
227
+ # Mirrors the Python CLI flags where appropriate, using Ruby idioms.
228
+ #
229
+ # @param [Array<String>] argv Command line arguments following 'engine-trace'.
230
+ # @return [void]
231
+ def self.engine_trace(argv)
232
+ input = nil
233
+ events = nil
234
+ out = nil
235
+ is_xml = false
236
+ leaf_only = false
237
+ omit_actions = false
238
+ omit_delta = false
239
+ omit_transitions = false
240
+ advance_time = 0.0
241
+ ordering = 'tolerant'
242
+ max_steps = nil
243
+ strip_step0_noise = false
244
+ strip_step0_states = false
245
+ keep_cond = false
246
+ defer_done = true
247
+
248
+ parser = OptionParser.new do |opts|
249
+ opts.banner = 'scjson engine-trace [options]'
250
+ opts.on('-I', '--input PATH', 'SCJSON/SCXML document') { |v| input = v }
251
+ opts.on('-e', '--events PATH', 'JSONL stream of events') { |v| events = v }
252
+ opts.on('-o', '--out PATH', 'Destination trace file (stdout by default)') { |v| out = v }
253
+ opts.on('--xml', 'Treat input as SCXML') { is_xml = true }
254
+ opts.on('--leaf-only', 'Restrict configuration/entered/exited to leaf states') { leaf_only = true }
255
+ opts.on('--omit-actions', 'Omit actionLog entries from the trace') { omit_actions = true }
256
+ opts.on('--omit-delta', 'Omit datamodelDelta entries from the trace') { omit_delta = true }
257
+ opts.on('--omit-transitions', 'Omit firedTransitions entries from the trace') { omit_transitions = true }
258
+ opts.on('--advance-time N', Float, 'Advance time by N seconds before processing events') { |v| advance_time = v }
259
+ opts.on('--ordering MODE', ['tolerant', 'strict', 'scion'], 'Ordering policy (tolerant|strict|scion)') { |v| ordering = v }
260
+ opts.on('--defer-done', 'Defer done.invoke processing to next step (default)') { defer_done = true }
261
+ opts.on('--no-defer-done', 'Process done.invoke within the same step') { defer_done = false }
262
+ opts.on('--max-steps N', Integer, 'Maximum steps to process') { |v| max_steps = v }
263
+ opts.on('--strip-step0-noise', 'Clear datamodelDelta and firedTransitions at step 0') { strip_step0_noise = true }
264
+ opts.on('--strip-step0-states', 'Clear enteredStates and exitedStates at step 0') { strip_step0_states = true }
265
+ opts.on('--keep-cond', 'Keep transition cond fields (default scrubs cond)') { keep_cond = true }
266
+ opts.on('-h', '--help', 'Show help') do
267
+ puts opts
268
+ return
269
+ end
270
+ end
271
+
272
+ begin
273
+ parser.parse!(argv)
274
+ rescue OptionParser::ParseError => e
275
+ warn e.message
276
+ puts parser
277
+ return
278
+ end
279
+ unless input
280
+ warn 'Missing required --input'
281
+ puts parser
282
+ return
283
+ end
284
+
285
+ Scjson::Engine.trace(
286
+ input_path: input,
287
+ events_path: events,
288
+ out_path: out,
289
+ xml: is_xml,
290
+ leaf_only: leaf_only,
291
+ omit_actions: omit_actions,
292
+ omit_delta: omit_delta,
293
+ omit_transitions: omit_transitions,
294
+ advance_time: advance_time,
295
+ ordering: ordering,
296
+ max_steps: max_steps,
297
+ strip_step0_noise: strip_step0_noise,
298
+ strip_step0_states: strip_step0_states,
299
+ keep_cond: keep_cond,
300
+ defer_done: defer_done
301
+ )
302
+ end
219
303
  end