asciichem 0.28.0 → 0.28.2
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 +4 -4
- data/.github/workflows/ci.yml +4 -0
- data/CHANGELOG.md +16 -0
- data/benchmarks/README.md +31 -0
- data/benchmarks/parsanol_recheck.rb +79 -0
- data/lib/asciichem/transform.rb +10 -3
- data/lib/asciichem/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e4646420eb8fdde22a218b2f65d6b4dce4661264124f98d1fd4716eb82a7faf
|
|
4
|
+
data.tar.gz: 1dd763180c8466a8c0245e0147b4f79201f8e40957586a8392827d8bf21fea11
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9783079bd787334d96149f8f7826bb80c0314aec5b9a4d45ba7be96b6b4a52ff43bce3f962c273c6bdbf2f6d78a4721a011f32a5ef2897a4fbcd99af5f074ef9
|
|
7
|
+
data.tar.gz: 2edf62206b51e7fa1cf97181976a19b8903f00bb4d5cd9cfbffc1c1a5750dfa0bb60d3f356f8b4031ce17cca1f142f147268f2aaa3ddb65ee8459c4c4130f2f8
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -16,6 +16,10 @@ jobs:
|
|
|
16
16
|
- uses: actions/checkout@v4
|
|
17
17
|
- name: Clone conformance corpus (asciichem-tests)
|
|
18
18
|
run: git clone --depth 1 https://github.com/asciichem/asciichem-tests.git ../asciichem-tests
|
|
19
|
+
- name: Record corpus version for the conformance report
|
|
20
|
+
run: |
|
|
21
|
+
git -C ../asciichem-tests fetch --depth 1 --tags --quiet
|
|
22
|
+
echo "ASCIICHEM_CORPUS_VERSION=$(git -C ../asciichem-tests describe --tags --abbrev=0 2>/dev/null || echo main)" >> "$GITHUB_ENV"
|
|
19
23
|
- uses: ruby/setup-ruby@v1
|
|
20
24
|
with:
|
|
21
25
|
ruby-version: ${{ matrix.ruby }}
|
data/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to AsciiChem are documented here.
|
|
4
4
|
This project follows [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## [0.28.2] - 2026-09-14
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- Conformance reports now name the corpus version CI actually ran
|
|
10
|
+
(derived from the cloned asciichem-tests tag) instead of a stale
|
|
11
|
+
default. Pairs with asciichem-tests v0.4.0 (MathML golden suite).
|
|
12
|
+
|
|
13
|
+
## [0.28.1] - 2026-09-14
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Cascade transform is engine-agnostic: CascadeBuilder#canonicalise_hash
|
|
17
|
+
wraps scalar arrow/products values instead of Array(hash), which
|
|
18
|
+
enumerates a Hash. The parsanol 1.3.13 re-check (221/221 corpus-green
|
|
19
|
+
through the unmodified grammar) surfaced the shape; parslet is
|
|
20
|
+
unaffected. Spec'd for all three engine shapes.
|
|
21
|
+
|
|
6
22
|
## [0.28.0] - 2026-09-14
|
|
7
23
|
|
|
8
24
|
### Changed
|
data/benchmarks/README.md
CHANGED
|
@@ -15,6 +15,7 @@ WORKLOAD = ["H_2O", "Ca^2+", "SO_4^2-", "(R)-CH_3CH(OH)COOH",
|
|
|
15
15
|
|---|---|---|---|
|
|
16
16
|
| Ruby (parslet), 3.4.8 arm64 | 29.1 ms | ~2.9 ms | `bundle exec ruby benchmarks/engines.rb` |
|
|
17
17
|
| Ruby + parse+text | 35.3 ms | ~3.5 ms | round-trip adds the formatter |
|
|
18
|
+
| Ruby (parsanol compat, :ruby), 1.3.13 | 19.9 ms | ~2.0 ms | `benchmarks/parsanol_recheck.rb`, same session as the 11.8 ms parslet baseline below |
|
|
18
19
|
| TypeScript (peggy), Node 24 | 0.19 ms | ~19 µs | `npm run bench` (asciichem-ts) |
|
|
19
20
|
| Python (RD), 3.10 | 3.94 ms | ~394 µs | `python benchmarks/engines.py` (asciichem-py) |
|
|
20
21
|
|
|
@@ -54,3 +55,33 @@ upstream in parsanol-ruby#25):
|
|
|
54
55
|
Revisit trigger unchanged: engage the native backend for full
|
|
55
56
|
grammars, fix the repetition-termination bug, and beat parslet on
|
|
56
57
|
this workload — then re-run the corpus against the port.
|
|
58
|
+
|
|
59
|
+
### Re-check (2026-09-14, parsanol 1.3.13)
|
|
60
|
+
|
|
61
|
+
The upstream "native by default" + RepetitionTag work landed, so the
|
|
62
|
+
revisit trigger was tested (`benchmarks/parsanol_recheck.rb`):
|
|
63
|
+
|
|
64
|
+
1. **The repetition-termination bug is fixed.** `SO_4^2-` parses and
|
|
65
|
+
round-trips, and the unmodified grammar passes the entire shared
|
|
66
|
+
corpus through the `Parsanol::Parslet` compat layer —
|
|
67
|
+
**221/221** parse/reject/round-trip cases identical to parslet.
|
|
68
|
+
One divergence surfaced on our side and is fixed in the gem:
|
|
69
|
+
parsanol's transform delivers cascade tail segments as scalar
|
|
70
|
+
hashes, and `CascadeBuilder#canonicalise_hash` used `Array(hash)`
|
|
71
|
+
(which enumerates a Hash instead of wrapping it) — now wraps
|
|
72
|
+
explicitly, engine-agnostic.
|
|
73
|
+
2. **Perf (compat, :ruby forced):** 19.9 ms vs 11.8 ms per 10-input
|
|
74
|
+
pass in the same session — **~1.7x slower than parslet** (down
|
|
75
|
+
from ~6x in the first investigation). Correct but not a win.
|
|
76
|
+
3. **Native still cannot serialize full parslet grammars** — two
|
|
77
|
+
upstream bugs (reported in parsanol-ruby#25):
|
|
78
|
+
`native.rb` never loads `native/dynamic` (NameError silently
|
|
79
|
+
falls back to :ruby), and `Dynamic.register` never increments
|
|
80
|
+
`@next_id`, so the second lazily-bound rule panics the Rust core
|
|
81
|
+
with "callback ID 1000000 is already registered".
|
|
82
|
+
|
|
83
|
+
**Verdict: still not adopted — but one small upstream fix away from
|
|
84
|
+
a meaningful re-measure.** Corpus correctness is already there; the
|
|
85
|
+
native path is the whole point and remains unmeasurable until
|
|
86
|
+
serialization survives a multi-rule grammar.
|
|
87
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Parsanol re-check (parsanol-ruby 1.3.13, post-issue-25): runs the
|
|
4
|
+
# UNMODIFIED AsciiChem grammar over the Parsanol engine via the
|
|
5
|
+
# Parslet compat shim, then (1) gates on the shared corpus, (2) gates
|
|
6
|
+
# on the issue-25 EOF repro, (3) measures against the parslet path.
|
|
7
|
+
#
|
|
8
|
+
# Native mode cannot serialize this grammar today (two upstream bugs:
|
|
9
|
+
# native.rb never loads native/dynamic; Dynamic.register never
|
|
10
|
+
# increments @next_id so the second callback panics the Rust core —
|
|
11
|
+
# parsanol-ruby#25). The measurement therefore forces :ruby, the
|
|
12
|
+
# only working mode for full parslet grammars via the shim.
|
|
13
|
+
#
|
|
14
|
+
# Run from asciichem-ruby/:
|
|
15
|
+
# ruby -I /tmp/parsanol_spike -I ../parsanol/parsanol-ruby/lib benchmarks/parsanol_recheck.rb
|
|
16
|
+
require "benchmark/ips"
|
|
17
|
+
require "asciichem"
|
|
18
|
+
require "json"
|
|
19
|
+
|
|
20
|
+
Parsanol::Native.singleton_class.define_method(:available?) { false } # spike: force :ruby
|
|
21
|
+
|
|
22
|
+
puts "parsanol #{Parsanol::VERSION} | parslet-compat Parser=#{Parsanol::Parslet::Parser}"
|
|
23
|
+
puts "AsciiChem::Grammar superclass: #{AsciiChem::Grammar.superclass}"
|
|
24
|
+
|
|
25
|
+
# -- 1. Issue-25 repro: repeat-of-maybe at end of input --------------
|
|
26
|
+
begin
|
|
27
|
+
formula = AsciiChem.parse("SO_4^2-")
|
|
28
|
+
puts "issue-25 repro SO_4^2-: PARSES -> #{formula.to_text.inspect}"
|
|
29
|
+
rescue AsciiChem::ParseError => e
|
|
30
|
+
puts "issue-25 repro SO_4^2-: FAILS -> #{e.message[0, 100]}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# -- 2. Shared-corpus gate --------------------------------------------
|
|
34
|
+
corpus_dir = File.expand_path("../../asciichem-tests/corpus/fixtures", __dir__)
|
|
35
|
+
cases = Dir[File.join(corpus_dir, "*.json")].sort.flat_map { |p| JSON.parse(File.read(p)) }
|
|
36
|
+
parser_cases = cases.select { |c| c.key?("input") && !c.key?("lint") && !c.key?("convention") }
|
|
37
|
+
|
|
38
|
+
pass = fail_parse = fail_reject = fail_roundtrip = 0
|
|
39
|
+
parser_cases.each do |fixture|
|
|
40
|
+
input = fixture.fetch("input")
|
|
41
|
+
if fixture.fetch("parses")
|
|
42
|
+
begin
|
|
43
|
+
formula = AsciiChem.parse(input)
|
|
44
|
+
if fixture["roundTrip"] && formula.to_text != input
|
|
45
|
+
fail_roundtrip += 1
|
|
46
|
+
puts " ROUNDTRIP DIFF: #{input.inspect} -> #{formula.to_text.inspect}" if fail_roundtrip <= 5
|
|
47
|
+
end
|
|
48
|
+
pass += 1
|
|
49
|
+
rescue AsciiChem::ParseError, Parslet::ParseFailed => e
|
|
50
|
+
fail_parse += 1
|
|
51
|
+
puts " PARSE FAIL: #{input.inspect} -> #{e.message[0, 90]}" if fail_parse <= 8
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
begin
|
|
55
|
+
AsciiChem.parse(input)
|
|
56
|
+
fail_reject += 1
|
|
57
|
+
puts " SHOULD REJECT: #{input.inspect}" if fail_reject <= 8
|
|
58
|
+
rescue AsciiChem::ParseError, Parslet::ParseFailed
|
|
59
|
+
pass += 1
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
total = parser_cases.length
|
|
64
|
+
puts format("corpus gate: %d/%d ok (parse-fails %d, should-reject %d, roundtrip-diffs %d)",
|
|
65
|
+
pass, total, fail_parse, fail_reject, fail_roundtrip)
|
|
66
|
+
|
|
67
|
+
# -- 3. Performance ----------------------------------------------------
|
|
68
|
+
WORKLOAD = [
|
|
69
|
+
"H_2O", "Ca^2+", "SO_4^2-", "(R)-CH_3CH(OH)COOH",
|
|
70
|
+
"2H_2 + O_2 -> 2H_2O", "N_2 + 3H_2 <=>[Fe][400C] 2NH_3",
|
|
71
|
+
"C1-C-C-C-C-C1", "CH_3-CH_2-OH",
|
|
72
|
+
'^14C @name("carbon-14") @cas("14104-86-4")',
|
|
73
|
+
"A ->[heat] B ->[cool] C",
|
|
74
|
+
].freeze
|
|
75
|
+
|
|
76
|
+
Benchmark.ips do |x|
|
|
77
|
+
x.report("parsanol parse x10") { WORKLOAD.each { |s| AsciiChem.parse(s) } }
|
|
78
|
+
x.compare!
|
|
79
|
+
end
|
data/lib/asciichem/transform.rb
CHANGED
|
@@ -830,11 +830,18 @@ module AsciiChem
|
|
|
830
830
|
|
|
831
831
|
def canonicalise_hash(hash)
|
|
832
832
|
first = hash[:first]
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
833
|
+
# Wrap, never Array(): Array(hash) on a scalar Hash value
|
|
834
|
+
# (the shape parsanol's transform delivers) would enumerate
|
|
835
|
+
# key/value pairs instead of wrapping it.
|
|
836
|
+
tail = wrap(hash[:arrow]).zip(wrap(hash[:products]))
|
|
836
837
|
[first, tail]
|
|
837
838
|
end
|
|
839
|
+
|
|
840
|
+
def wrap(value)
|
|
841
|
+
return [] if value.nil?
|
|
842
|
+
|
|
843
|
+
value.is_a?(Array) ? value : [value]
|
|
844
|
+
end
|
|
838
845
|
end
|
|
839
846
|
|
|
840
847
|
# Maps the captured stereo letter to the model's stereo symbol.
|
data/lib/asciichem/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: asciichem
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.28.
|
|
4
|
+
version: 0.28.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -190,6 +190,7 @@ files:
|
|
|
190
190
|
- benchmarks/RESULTS.md
|
|
191
191
|
- benchmarks/benchmark.rb
|
|
192
192
|
- benchmarks/engines.rb
|
|
193
|
+
- benchmarks/parsanol_recheck.rb
|
|
193
194
|
- exe/asciichem
|
|
194
195
|
- lib/asciichem.rb
|
|
195
196
|
- lib/asciichem/citation.rb
|