amath 0.1.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 +7 -0
- data/LICENSE.md +31 -0
- data/README.adoc +108 -0
- data/artifacts/asciimath.checksums.txt +10 -0
- data/artifacts/asciimath.json +1 -0
- data/corpora/uncertainty-shared-exponent.yml +119 -0
- data/docs/parser-contract.adoc +257 -0
- data/lib/amath/artifact.rb +52 -0
- data/lib/amath/configuration.rb +24 -0
- data/lib/amath/engine.rb +148 -0
- data/lib/amath/error_position.rb +68 -0
- data/lib/amath/errors.rb +39 -0
- data/lib/amath/native_recursion_guard.rb +44 -0
- data/lib/amath/parser.rb +44 -0
- data/lib/amath/renester.rb +133 -0
- data/lib/amath/version.rb +5 -0
- data/lib/amath.rb +73 -0
- metadata +79 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 30b2c9e57788d5b280dd5f5f2675bccbb388b4fa48b3d79e79a4b09768eceb07
|
|
4
|
+
data.tar.gz: b353722b5783b39e8ec920647f62f4701a466c247b6953190041d05ee16d81e7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 52db2fbc98d705ddb9469c56e6c5d9f860f543503c589d2d12aafb544bba5fac2341dae738dca13972d2eb5bd57a15f29c217b602ccca8b4e4e7c043ce81ea0f
|
|
7
|
+
data.tar.gz: e6f215511e89e94c5b1cec01cbd2990c1d2070262b2ba7ba44375f105fe9e9b704d7bb109cef99a4cae0bb5c764ea4f03131a6e8c93519ba07e34ebec83a0a20
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Licenses & Copyright
|
|
2
|
+
====================
|
|
3
|
+
|
|
4
|
+
This license file adheres to the formatting guidelines of
|
|
5
|
+
[readable-licenses](https://github.com/nevir/readable-licenses).
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Ribose's BSD 2-Clause License
|
|
9
|
+
-----------------------------
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026, [Ribose Inc](https://www.ribose.com).
|
|
12
|
+
All rights reserved.
|
|
13
|
+
|
|
14
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
15
|
+
are permitted provided that the following conditions are met:
|
|
16
|
+
|
|
17
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
18
|
+
this list of conditions and the following disclaimer.
|
|
19
|
+
|
|
20
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
21
|
+
this list of conditions and the following disclaimer in the documentation
|
|
22
|
+
and/or other materials provided with the distribution.
|
|
23
|
+
|
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
25
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
26
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
27
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
28
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
29
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
30
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
31
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
data/README.adoc
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
= Amath: AsciiMath parser for Ruby
|
|
2
|
+
|
|
3
|
+
== Purpose
|
|
4
|
+
|
|
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:
|
|
7
|
+
|
|
8
|
+
[source]
|
|
9
|
+
----
|
|
10
|
+
sum_(i=1)^n i^2 = (n(n+1)(2n+1))/6
|
|
11
|
+
----
|
|
12
|
+
|
|
13
|
+
The tree records the structure of the formula: which symbols, fractions,
|
|
14
|
+
roots, sub- and superscripts, matrices and brackets it contains, and how they
|
|
15
|
+
nest. Your code decides what to do with it, such as rendering, converting or
|
|
16
|
+
analysing it.
|
|
17
|
+
|
|
18
|
+
== Grammar
|
|
19
|
+
|
|
20
|
+
The AsciiMath grammar will be written in PARG, the grammar language of
|
|
21
|
+
https://github.com/parsanol/parsanol-ruby[Parsanol], and compiled into a
|
|
22
|
+
checksummed artifact that the gem loads at runtime. The repository will hold:
|
|
23
|
+
|
|
24
|
+
* `grammars/`: the grammar source.
|
|
25
|
+
* `artifacts/`: the compiled artifact.
|
|
26
|
+
* `corpora/`: conformance cases with the input and the tree it must produce.
|
|
27
|
+
|
|
28
|
+
== Installation
|
|
29
|
+
|
|
30
|
+
Amath has not been released to RubyGems yet. Until it is, use it from Git in
|
|
31
|
+
your `Gemfile`:
|
|
32
|
+
|
|
33
|
+
[source,ruby]
|
|
34
|
+
----
|
|
35
|
+
gem "amath", github: "plurimath/amath"
|
|
36
|
+
----
|
|
37
|
+
|
|
38
|
+
Amath needs Ruby 3.2 or later. Its only runtime dependency is
|
|
39
|
+
https://github.com/parsanol/parsanol-ruby[Parsanol].
|
|
40
|
+
|
|
41
|
+
== Usage
|
|
42
|
+
|
|
43
|
+
[source,ruby]
|
|
44
|
+
----
|
|
45
|
+
require "amath"
|
|
46
|
+
|
|
47
|
+
tree = Amath.parse("x_y")
|
|
48
|
+
# => {expr: {sequence: {symbol: "x"@0}, expr: {symbol: "_"@1, ...}}}
|
|
49
|
+
----
|
|
50
|
+
|
|
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.
|
|
54
|
+
|
|
55
|
+
Numbers use a dot as the decimal marker unless you say otherwise. A comma and
|
|
56
|
+
the Arabic decimal separator are also supported:
|
|
57
|
+
|
|
58
|
+
[source,ruby]
|
|
59
|
+
----
|
|
60
|
+
Amath.parse("1,5", decimal: ",")
|
|
61
|
+
Amath.parse("1\u066B5", decimal: "\u066B")
|
|
62
|
+
----
|
|
63
|
+
|
|
64
|
+
Input that is not valid AsciiMath raises `Amath::ParseError`, which tells you
|
|
65
|
+
where the parser gave up:
|
|
66
|
+
|
|
67
|
+
[source,ruby]
|
|
68
|
+
----
|
|
69
|
+
begin
|
|
70
|
+
Amath.parse("x 1.")
|
|
71
|
+
rescue Amath::ParseError => e
|
|
72
|
+
e.char_offset # => position in characters
|
|
73
|
+
e.byte_offset # => position in UTF-8 bytes
|
|
74
|
+
end
|
|
75
|
+
----
|
|
76
|
+
|
|
77
|
+
Amath uses Parsanol's fast native engine where it is available and its pure
|
|
78
|
+
Ruby engine elsewhere. You can choose one with `engine: :native` or
|
|
79
|
+
`engine: :ruby`; asking for the native engine where it cannot run raises
|
|
80
|
+
`Amath::EngineUnavailable` rather than quietly using Ruby.
|
|
81
|
+
The native engine has a recursion limit (roughly 100 levels of nested
|
|
82
|
+
brackets); by default amath parses deeper input with the Ruby engine, while
|
|
83
|
+
`engine: :native` raises `Amath::NestingTooDeep`, a kind of
|
|
84
|
+
`Amath::ParseError`.
|
|
85
|
+
Long sums and sequences (thousands of terms) are not nesting: both engines
|
|
86
|
+
parse them without going deeper as the expression gets longer.
|
|
87
|
+
`Amath.last_engine` tells you which engine handled the last call.
|
|
88
|
+
|
|
89
|
+
The exact rules for trees, positions, engines and errors are in
|
|
90
|
+
link:docs/parser-contract.adoc[the parser contract].
|
|
91
|
+
|
|
92
|
+
== Status
|
|
93
|
+
|
|
94
|
+
Amath parses all of Plurimath's AsciiMath: Plurimath uses it for AsciiMath
|
|
95
|
+
input
|
|
96
|
+
(https://github.com/plurimath/plurimath/issues/494[plurimath/plurimath#494]).
|
|
97
|
+
It also reads the measurement-uncertainty forms `ustd(...)`, `uexp(...)` and
|
|
98
|
+
`ucov(...)` that Plurimath turns into uncertainty nodes
|
|
99
|
+
(https://github.com/plurimath/plurimath/issues/493[plurimath/plurimath#493]).
|
|
100
|
+
Shared exponents can be written as `ustd((3.85, 0.23)e4)` or
|
|
101
|
+
`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.
|
|
103
|
+
|
|
104
|
+
It has not been released to RubyGems yet.
|
|
105
|
+
|
|
106
|
+
== License
|
|
107
|
+
|
|
108
|
+
Copyright Ribose Inc. Licensed under the BSD 2-Clause License; see link:LICENSE.md[].
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
|
9
|
+
entries dot comma arabic
|
|
10
|
+
order_warnings 496
|