amath 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30b2c9e57788d5b280dd5f5f2675bccbb388b4fa48b3d79e79a4b09768eceb07
4
- data.tar.gz: b353722b5783b39e8ec920647f62f4701a466c247b6953190041d05ee16d81e7
3
+ metadata.gz: 303ea133bc685aa991f0555c577d1db2f4607aaf7608e0bbcd970284e76a3f12
4
+ data.tar.gz: f1ecf191f88b665a49b694d20c16e95eda282e2b07f53f7ef996fcc1087531ce
5
5
  SHA512:
6
- metadata.gz: 52db2fbc98d705ddb9469c56e6c5d9f860f543503c589d2d12aafb544bba5fac2341dae738dca13972d2eb5bd57a15f29c217b602ccca8b4e4e7c043ce81ea0f
7
- data.tar.gz: e6f215511e89e94c5b1cec01cbd2990c1d2070262b2ba7ba44375f105fe9e9b704d7bb109cef99a4cae0bb5c764ea4f03131a6e8c93519ba07e34ebec83a0a20
6
+ metadata.gz: 8cd58c0e8be2938bd63473ca9519a999328902cee39bcbc6a18c6dc4f8ee3c1d085bc8921b87096a5af3278c924f751daff23cc0ce61f3e60c28c23597032110
7
+ data.tar.gz: dd0ee10430d320a18cdd8a72173116fd2bfbcaed1c9f2fad83eea767efa8a53efe18d6345041153e57af04f59c338213cca5357fea6e3208ad8d6962efa4daa9
data/LICENSE.md CHANGED
@@ -29,3 +29,5 @@ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
29
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
30
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
31
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.adoc CHANGED
@@ -3,14 +3,15 @@
3
3
  == Purpose
4
4
 
5
5
  Amath is a parser for https://asciimath.org[AsciiMath], the plain-text
6
- notation for mathematics. It turns input like this into a parse tree:
6
+ notation for mathematics. It turns input like this into a typed model of the
7
+ formula:
7
8
 
8
9
  [source]
9
10
  ----
10
11
  sum_(i=1)^n i^2 = (n(n+1)(2n+1))/6
11
12
  ----
12
13
 
13
- The tree records the structure of the formula: which symbols, fractions,
14
+ The model records the structure of the formula: which symbols, fractions,
14
15
  roots, sub- and superscripts, matrices and brackets it contains, and how they
15
16
  nest. Your code decides what to do with it, such as rendering, converting or
16
17
  analysing it.
@@ -22,8 +23,9 @@ https://github.com/parsanol/parsanol-ruby[Parsanol], and compiled into a
22
23
  checksummed artifact that the gem loads at runtime. The repository will hold:
23
24
 
24
25
  * `grammars/`: the grammar source.
25
- * `artifacts/`: the compiled artifact.
26
+ * `artifacts/`: the compiled artifact and its declared binding artifacts.
26
27
  * `corpora/`: conformance cases with the input and the tree it must produce.
28
+ * `model/`: the exported LML declarations of the model classes.
27
29
 
28
30
  == Installation
29
31
 
@@ -35,8 +37,9 @@ your `Gemfile`:
35
37
  gem "amath", github: "plurimath/amath"
36
38
  ----
37
39
 
38
- Amath needs Ruby 3.2 or later. Its only runtime dependency is
39
- https://github.com/parsanol/parsanol-ruby[Parsanol].
40
+ Amath needs Ruby 3.2 or later. Its runtime dependencies are
41
+ https://github.com/parsanol/parsanol-ruby[Parsanol] and
42
+ https://github.com/lutaml/lutaml-model[LutaML Model].
40
43
 
41
44
  == Usage
42
45
 
@@ -44,21 +47,30 @@ https://github.com/parsanol/parsanol-ruby[Parsanol].
44
47
  ----
45
48
  require "amath"
46
49
 
47
- tree = Amath.parse("x_y")
48
- # => {expr: {sequence: {symbol: "x"@0}, expr: {symbol: "_"@1, ...}}}
50
+ doc = Amath.parse_model("x+1")
51
+ doc.expression.expr.amath_chain.first.amath_step.sequence.symbol.spelling
52
+ # => "x"
49
53
  ----
50
54
 
51
- The result is a Parsanol tree: hashes and arrays whose leaves are
52
- `Parsanol::Slice` objects. Each leaf knows its text and where it starts in
53
- the input. Empty input gives back an empty string.
55
+ `Amath.parse_model` returns an `Amath::Model::Document`, built with LutaML Model. Its
56
+ `expression` holds the formula; a run of terms such as `x + 1` is one flat
57
+ list of items, however long it is. Symbols such as `alpha` or `->` are
58
+ `Amath::Model::MathSymbol` objects that carry the text as written, its
59
+ Unicode value and its kind. Numbers keep the text you wrote. Empty input
60
+ gives a document whose `expression` is nil.
61
+
62
+ `Amath.parse` keeps the amath 0.1 contract: it returns the raw Parsanol tree
63
+ (a Hash/Array tree with `Parsanol::Slice` leaves, or `""` for empty input)
64
+ and takes only `decimal:` and `engine:`. Plurimath 0.11 uses it; new code
65
+ should call `Amath.parse_model`.
54
66
 
55
67
  Numbers use a dot as the decimal marker unless you say otherwise. A comma and
56
68
  the Arabic decimal separator are also supported:
57
69
 
58
70
  [source,ruby]
59
71
  ----
60
- Amath.parse("1,5", decimal: ",")
61
- Amath.parse("1\u066B5", decimal: "\u066B")
72
+ Amath.parse_model("1,5", decimal: ",")
73
+ Amath.parse_model("1\u066B5", decimal: "\u066B")
62
74
  ----
63
75
 
64
76
  Input that is not valid AsciiMath raises `Amath::ParseError`, which tells you
@@ -67,7 +79,7 @@ where the parser gave up:
67
79
  [source,ruby]
68
80
  ----
69
81
  begin
70
- Amath.parse("x 1.")
82
+ Amath.parse_model("x 1.")
71
83
  rescue Amath::ParseError => e
72
84
  e.char_offset # => position in characters
73
85
  e.byte_offset # => position in UTF-8 bytes
@@ -86,7 +98,7 @@ Long sums and sequences (thousands of terms) are not nesting: both engines
86
98
  parse them without going deeper as the expression gets longer.
87
99
  `Amath.last_engine` tells you which engine handled the last call.
88
100
 
89
- The exact rules for trees, positions, engines and errors are in
101
+ The exact rules for the model, positions, engines and errors are in
90
102
  link:docs/parser-contract.adoc[the parser contract].
91
103
 
92
104
  == Status
@@ -99,7 +111,16 @@ It also reads the measurement-uncertainty forms `ustd(...)`, `uexp(...)` and
99
111
  (https://github.com/plurimath/plurimath/issues/493[plurimath/plurimath#493]).
100
112
  Shared exponents can be written as `ustd((3.85, 0.23)e4)` or
101
113
  `ustd(680(41)e-3)`; see the link:docs/parser-contract.adoc[parser contract]
102
- for the parse-tree fields and the corresponding expanded/interval call forms.
114
+ for the model fields and the corresponding expanded/interval call forms.
115
+
116
+ `Amath.parse_model(input, dialect: :pma)` reads pma (dialect P, the strict ASCII
117
+ dialect of
118
+ https://github.com/plurimath/amath/issues/16[plurimath/amath#16], specified
119
+ in Plurimath's `docs/pma.adoc`): measured literals such as
120
+ `(10.3 +/- 0.2 ~rect) unit(cm)`, the `ustd`, `uexp` and `ucov` constructors,
121
+ `unit(...)` and `diff(...)`. It refuses everything else with an
122
+ `Amath::ParseError` that names a category. See the
123
+ link:docs/parser-contract.adoc#pma[parser contract].
103
124
 
104
125
  It has not been released to RubyGems yet.
105
126
 
@@ -0,0 +1 @@
1
+ {"artifact_kind":"parg-bindings","target":"python","binding_version":1,"grammar":"Asciimath","grammar_version":"0.1.0","grammar_source_hash":"08cea18f49353c14f349ea67c91d748dd449538549654ab1be060f33269769ed","shape":"parsanol-tree/v2","entries":{"dot":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]},"comma":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]},"arabic":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]}},"checksum":"sha256:75526ee2563351094057f4e2e6e0d3075695724e19d2fc8faf0bdb9941070f73"}
@@ -0,0 +1 @@
1
+ {"artifact_kind":"parg-bindings","target":"rs","binding_version":1,"grammar":"Asciimath","grammar_version":"0.1.0","grammar_source_hash":"08cea18f49353c14f349ea67c91d748dd449538549654ab1be060f33269769ed","shape":"parsanol-tree/v2","entries":{"dot":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]},"comma":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]},"arabic":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]}},"checksum":"sha256:ee07612c5c23c4c921b57e3233169f25cfae20781b80059878c4f0929142d6c4"}
@@ -0,0 +1 @@
1
+ {"artifact_kind":"parg-bindings","target":"ruby","binding_version":1,"grammar":"Asciimath","grammar_version":"0.1.0","grammar_source_hash":"08cea18f49353c14f349ea67c91d748dd449538549654ab1be060f33269769ed","shape":"parsanol-tree/v2","entries":{"dot":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]},"comma":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]},"arabic":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]}},"checksum":"sha256:72c7e29ea500a5b583e5c852a5bbe8423ac974bd48a3cda1a7b0c28cebd182c9"}
@@ -0,0 +1 @@
1
+ {"artifact_kind":"parg-bindings","target":"ts","binding_version":1,"grammar":"Asciimath","grammar_version":"0.1.0","grammar_source_hash":"08cea18f49353c14f349ea67c91d748dd449538549654ab1be060f33269769ed","shape":"parsanol-tree/v2","entries":{"dot":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]},"comma":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]},"arabic":{"bindings":[{"capture":"root","path":"expression","type":"any","card":null,"preprocess":null}]}},"checksum":"sha256:f3963bc032ed3786891e23b55be7f0ca465847511e04db7a4900c856bba16535"}
@@ -1,10 +1,19 @@
1
- # Written by scripts/compile.rb. Envelope checksum is Parsanol's own (PN 2);
2
- # the sha256 lines are of the files' bytes.
3
- artifact_checksum sha256:e90f836c851504dfcbd5b3d97c9224f2f1c8cb4d2167c10fc6f1d02a62646d43
4
- compiler_version 1.3.109
5
- source_hash sha256:566f8ba866e921308b3b947b2443a1278ffc1125e2b20a4afb5c14132f91f975
6
- artifacts/asciimath.json sha256:4b8392c6c92d201dde0aee5a87a7f24337a5b6367362c9bd21881b855e4609d2
7
- grammars/asciimath.parg sha256:566f8ba866e921308b3b947b2443a1278ffc1125e2b20a4afb5c14132f91f975
8
- data/vocabulary.json sha256:965b1f5c4e2d14ba7d045ba79c09097b42c311b737175c2199faca0cc87cf2a6
1
+ # Written by scripts/compile.rb. Envelope and binding checksums are Parsanol's
2
+ # own (PN 2); the sha256 lines are of the files' bytes.
3
+ artifact_checksum sha256:ecfc0c6e99ab262d7290d9098550e60cb5c568a3dfb6bc8c0da20a13904fda62
4
+ compiler_version 1.5.1.0
5
+ source_hash sha256:08cea18f49353c14f349ea67c91d748dd449538549654ab1be060f33269769ed
6
+ artifacts/asciimath.json sha256:dcb76184896f81760293483f7d2e7096ac9a6d7243de67c6f33aeb8efdee296e
7
+ bindings_ruby_checksum sha256:72c7e29ea500a5b583e5c852a5bbe8423ac974bd48a3cda1a7b0c28cebd182c9 binding_version 1
8
+ artifacts/asciimath.bindings.ruby.json sha256:ff997c3e8799f8be745907fad531a71af7b60391670475c8cc01bba4f165d932
9
+ bindings_rs_checksum sha256:ee07612c5c23c4c921b57e3233169f25cfae20781b80059878c4f0929142d6c4 binding_version 1
10
+ artifacts/asciimath.bindings.rs.json sha256:2933709dae4afc1c5ef5c78121b72a69e49cfc663b838684a7242d8ffa933862
11
+ bindings_ts_checksum sha256:f3963bc032ed3786891e23b55be7f0ca465847511e04db7a4900c856bba16535 binding_version 1
12
+ artifacts/asciimath.bindings.ts.json sha256:bc27896a59a9a9dc4df02ab7cd1af35f9dbc24649141098f6da82eb7a0401586
13
+ bindings_python_checksum sha256:75526ee2563351094057f4e2e6e0d3075695724e19d2fc8faf0bdb9941070f73 binding_version 1
14
+ artifacts/asciimath.bindings.python.json sha256:b8e27ff352dc3b70ab1a25ef4cd5d303f07b378f2c8687568e1c3251bdd64308
15
+ grammars/asciimath.parg sha256:08cea18f49353c14f349ea67c91d748dd449538549654ab1be060f33269769ed
16
+ data/vocabulary.json amath-vocabulary/v2 sha256:768016984baee3ea142b69f0f31f4b9e9255ddedea078d6c7fb1728dc718695c
17
+ registry legacy_edition 1 sha256:965b1f5c4e2d14ba7d045ba79c09097b42c311b737175c2199faca0cc87cf2a6
9
18
  entries dot comma arabic
10
- order_warnings 496
19
+ order_warnings 501