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 +4 -4
- data/LICENSE.md +2 -0
- data/README.adoc +36 -15
- data/artifacts/asciimath.bindings.python.json +1 -0
- data/artifacts/asciimath.bindings.rs.json +1 -0
- data/artifacts/asciimath.bindings.ruby.json +1 -0
- data/artifacts/asciimath.bindings.ts.json +1 -0
- data/artifacts/asciimath.checksums.txt +18 -9
- data/artifacts/asciimath.json +1 -1
- data/artifacts/pma.bindings.python.json +1 -0
- data/artifacts/pma.bindings.rs.json +1 -0
- data/artifacts/pma.bindings.ruby.json +1 -0
- data/artifacts/pma.bindings.ts.json +1 -0
- data/artifacts/pma.checksums.txt +20 -0
- data/artifacts/pma.json +1 -0
- data/corpora/pma/accepted.yml +125 -0
- data/corpora/pma/refused.yml +67 -0
- data/corpora/uncertainty-shared-exponent.yml +20 -20
- data/data/asciimath-symbols.json +3302 -0
- data/data/quantities.json +234 -0
- data/docs/parser-contract.adoc +288 -42
- data/docs/stage-contract.adoc +293 -0
- data/grammars/asciimath.wrappers.json +20 -0
- data/lib/amath/artifact.rb +31 -6
- data/lib/amath/configuration.rb +5 -0
- data/lib/amath/engine.rb +3 -0
- data/lib/amath/errors.rb +5 -2
- data/lib/amath/model/nodes.rb +653 -0
- data/lib/amath/model.rb +79 -0
- data/lib/amath/parser.rb +39 -3
- data/lib/amath/pma.rb +285 -0
- data/lib/amath/raw_tree.rb +96 -0
- data/lib/amath/symbols.rb +49 -0
- data/lib/amath/version.rb +1 -1
- data/lib/amath.rb +37 -6
- data/model/asciimath.lml.json +2274 -0
- metadata +63 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 303ea133bc685aa991f0555c577d1db2f4607aaf7608e0bbcd970284e76a3f12
|
|
4
|
+
data.tar.gz: f1ecf191f88b665a49b694d20c16e95eda282e2b07f53f7ef996fcc1087531ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
48
|
-
|
|
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
|
-
|
|
52
|
-
`
|
|
53
|
-
|
|
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.
|
|
61
|
-
Amath.
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
2
|
-
# the sha256 lines are of the files' bytes.
|
|
3
|
-
artifact_checksum sha256:
|
|
4
|
-
compiler_version 1.
|
|
5
|
-
source_hash sha256:
|
|
6
|
-
artifacts/asciimath.json sha256:
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
19
|
+
order_warnings 501
|