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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30b2c9e57788d5b280dd5f5f2675bccbb388b4fa48b3d79e79a4b09768eceb07
4
- data.tar.gz: b353722b5783b39e8ec920647f62f4701a466c247b6953190041d05ee16d81e7
3
+ metadata.gz: cee421036ce983621c336b852622249a9443ffee540a19cfd30ec35db42df452
4
+ data.tar.gz: 344a9d8b27aeefb8ba8dd45e08b7eb2b39deb3b63bac8808970c10fa86bbc10c
5
5
  SHA512:
6
- metadata.gz: 52db2fbc98d705ddb9469c56e6c5d9f860f543503c589d2d12aafb544bba5fac2341dae738dca13972d2eb5bd57a15f29c217b602ccca8b4e4e7c043ce81ea0f
7
- data.tar.gz: e6f215511e89e94c5b1cec01cbd2990c1d2070262b2ba7ba44375f105fe9e9b704d7bb109cef99a4cae0bb5c764ea4f03131a6e8c93519ba07e34ebec83a0a20
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 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":"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 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: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 496
19
+ order_warnings 501