amath 0.1.0 → 0.2.0
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/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 +62 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cee421036ce983621c336b852622249a9443ffee540a19cfd30ec35db42df452
|
|
4
|
+
data.tar.gz: 344a9d8b27aeefb8ba8dd45e08b7eb2b39deb3b63bac8808970c10fa86bbc10c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a8dfc25c83ae1fb43f6ff6fed8610ed602fe9d0bdb3c6a6d579243f83a3f2cff3e59011cae4be29caef5d845c47120c316b557c0881c99045cc4460c362a5b2
|
|
7
|
+
data.tar.gz: 38fb7ff39fe200548935654d68a303b6d6f2427a718aba947235738f7b5ee0bef092226764158d00597cbd4aa2d7754713ba4f9aebf56e7b91614aaae20ae795
|
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":"8fc391577745dec67f31913a54de1060c6856f5514ed3c11300724a462ae8cfb","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:ba5cf036f8485fc9680e690c3b6382afd30816a18956a35a3fa9b8ab6638803c"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"artifact_kind":"parg-bindings","target":"rs","binding_version":1,"grammar":"Asciimath","grammar_version":"0.1.0","grammar_source_hash":"8fc391577745dec67f31913a54de1060c6856f5514ed3c11300724a462ae8cfb","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:d896d4ae537ccad8eacb83f2dd0ab6e0334aaba17f04f8c16c98f9e2df4b9f06"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"artifact_kind":"parg-bindings","target":"ruby","binding_version":1,"grammar":"Asciimath","grammar_version":"0.1.0","grammar_source_hash":"8fc391577745dec67f31913a54de1060c6856f5514ed3c11300724a462ae8cfb","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:8b2057f9dde92d141b81d0c44152df61cacabb13ad4eafa8b266999d87deea8a"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"artifact_kind":"parg-bindings","target":"ts","binding_version":1,"grammar":"Asciimath","grammar_version":"0.1.0","grammar_source_hash":"8fc391577745dec67f31913a54de1060c6856f5514ed3c11300724a462ae8cfb","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:ff12e02d535183a017e8c9acd60ddf80477008e8ac2a6889302f266038ec242a"}
|
|
@@ -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.3.
|
|
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:38d3d04d938de7a1989dd7779e725c1c19d6f6fb38a3a65feb4bcc5c8395f369
|
|
4
|
+
compiler_version 1.3.134
|
|
5
|
+
source_hash sha256:8fc391577745dec67f31913a54de1060c6856f5514ed3c11300724a462ae8cfb
|
|
6
|
+
artifacts/asciimath.json sha256:f7e812476e125729e4f69c00d08083d69e83b4666d3c33b911e3ab88d30988da
|
|
7
|
+
bindings_ruby_checksum sha256:8b2057f9dde92d141b81d0c44152df61cacabb13ad4eafa8b266999d87deea8a binding_version 1
|
|
8
|
+
artifacts/asciimath.bindings.ruby.json sha256:79cda5caa352a1a9a7ea16155be8db95c3bd1ec735a788c4afe6fab26d971ab7
|
|
9
|
+
bindings_rs_checksum sha256:d896d4ae537ccad8eacb83f2dd0ab6e0334aaba17f04f8c16c98f9e2df4b9f06 binding_version 1
|
|
10
|
+
artifacts/asciimath.bindings.rs.json sha256:ab8a3fbb9e62098a44e9919730eb28bf6f7951f273f9e13c7f7f2530ef5bc07d
|
|
11
|
+
bindings_ts_checksum sha256:ff12e02d535183a017e8c9acd60ddf80477008e8ac2a6889302f266038ec242a binding_version 1
|
|
12
|
+
artifacts/asciimath.bindings.ts.json sha256:1865cd1507bc519987b65eaba4b54b934fcfea3856555a3c6a646b0f07ceb62f
|
|
13
|
+
bindings_python_checksum sha256:ba5cf036f8485fc9680e690c3b6382afd30816a18956a35a3fa9b8ab6638803c binding_version 1
|
|
14
|
+
artifacts/asciimath.bindings.python.json sha256:2bf9e6723f1c1d66aa8853fd8095e1c908f60f17b034347fe12d858e3b0bf129
|
|
15
|
+
grammars/asciimath.parg sha256:8fc391577745dec67f31913a54de1060c6856f5514ed3c11300724a462ae8cfb
|
|
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
|