plurimath 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +13 -0
- data/.github/workflows/release.yml +22 -0
- data/.hound.yml +5 -0
- data/.rubocop.yml +8 -0
- data/AsciiMath-Supported-Data.adoc +1994 -274
- data/Gemfile +2 -0
- data/Latex-Supported-Data.adoc +1875 -1868
- data/MathML-Supported-Data.adoc +280 -263
- data/README.adoc +22 -20
- data/lib/plurimath/asciimath/constants.rb +186 -141
- data/lib/plurimath/asciimath/parse.rb +104 -39
- data/lib/plurimath/asciimath/parser.rb +3 -1
- data/lib/plurimath/asciimath/transform.rb +1074 -238
- data/lib/plurimath/html/parse.rb +1 -1
- data/lib/plurimath/latex/constants.rb +3228 -1432
- data/lib/plurimath/latex/parse.rb +106 -83
- data/lib/plurimath/latex/parser.rb +11 -4
- data/lib/plurimath/latex/transform.rb +354 -99
- data/lib/plurimath/math/base.rb +15 -0
- data/lib/plurimath/math/formula.rb +90 -13
- data/lib/plurimath/math/function/bar.rb +35 -1
- data/lib/plurimath/math/function/base.rb +25 -4
- data/lib/plurimath/math/function/binary_function.rb +101 -19
- data/lib/plurimath/math/function/cancel.rb +8 -0
- data/lib/plurimath/math/function/ceil.rb +3 -0
- data/lib/plurimath/math/function/color.rb +15 -5
- data/lib/plurimath/math/function/f.rb +8 -0
- data/lib/plurimath/math/function/fenced.rb +95 -8
- data/lib/plurimath/math/function/floor.rb +15 -0
- data/lib/plurimath/math/function/font_style/bold.rb +19 -0
- data/lib/plurimath/math/function/font_style/double_struck.rb +19 -0
- data/lib/plurimath/math/function/font_style/fraktur.rb +19 -0
- data/lib/plurimath/math/function/font_style/italic.rb +37 -0
- data/lib/plurimath/math/function/font_style/monospace.rb +19 -0
- data/lib/plurimath/math/function/font_style/normal.rb +37 -0
- data/lib/plurimath/math/function/font_style/sans-serif.rb +19 -0
- data/lib/plurimath/math/function/font_style/script.rb +19 -0
- data/lib/plurimath/math/function/font_style.rb +18 -5
- data/lib/plurimath/math/function/frac.rb +33 -3
- data/lib/plurimath/math/function/g.rb +7 -0
- data/lib/plurimath/math/function/hat.rb +12 -0
- data/lib/plurimath/math/function/inf.rb +21 -0
- data/lib/plurimath/math/function/int.rb +23 -2
- data/lib/plurimath/math/function/left.rb +25 -1
- data/lib/plurimath/math/function/lim.rb +40 -2
- data/lib/plurimath/math/function/limits.rb +9 -0
- data/lib/plurimath/math/function/log.rb +55 -4
- data/lib/plurimath/math/function/longdiv.rb +12 -0
- data/lib/plurimath/math/function/mbox.rb +31 -0
- data/lib/plurimath/math/function/menclose.rb +46 -0
- data/lib/plurimath/math/function/merror.rb +12 -0
- data/lib/plurimath/math/function/mod.rb +19 -4
- data/lib/plurimath/math/function/msgroup.rb +37 -0
- data/lib/plurimath/math/function/msline.rb +12 -0
- data/lib/plurimath/math/function/multiscript.rb +19 -0
- data/lib/plurimath/math/function/norm.rb +17 -1
- data/lib/plurimath/math/function/obrace.rb +17 -0
- data/lib/plurimath/math/function/oint.rb +2 -2
- data/lib/plurimath/math/function/over.rb +12 -5
- data/lib/plurimath/math/function/overset.rb +34 -5
- data/lib/plurimath/math/function/phantom.rb +28 -0
- data/lib/plurimath/math/function/power.rb +27 -9
- data/lib/plurimath/math/function/power_base.rb +109 -11
- data/lib/plurimath/math/function/prod.rb +25 -4
- data/lib/plurimath/math/function/right.rb +22 -2
- data/lib/plurimath/math/function/root.rb +23 -1
- data/lib/plurimath/math/function/rule.rb +33 -0
- data/lib/plurimath/math/function/scarries.rb +12 -0
- data/lib/plurimath/math/function/scarry.rb +12 -0
- data/lib/plurimath/math/function/sqrt.rb +23 -1
- data/lib/plurimath/math/function/stackrel.rb +27 -0
- data/lib/plurimath/math/function/substack.rb +7 -0
- data/lib/plurimath/math/function/sum.rb +50 -2
- data/lib/plurimath/math/function/sup.rb +3 -0
- data/lib/plurimath/math/function/table/align.rb +5 -5
- data/lib/plurimath/math/function/table/array.rb +25 -6
- data/lib/plurimath/math/function/table/bmatrix.rb +18 -7
- data/lib/plurimath/math/function/table/matrix.rb +13 -5
- data/lib/plurimath/math/function/table/multline.rb +5 -5
- data/lib/plurimath/math/function/table/pmatrix.rb +5 -5
- data/lib/plurimath/math/function/table/split.rb +5 -5
- data/lib/plurimath/math/function/table/vmatrix.rb +5 -6
- data/lib/plurimath/math/function/table.rb +185 -27
- data/lib/plurimath/math/function/td.rb +22 -9
- data/lib/plurimath/math/function/ternary_function.rb +74 -9
- data/lib/plurimath/math/function/text.rb +36 -11
- data/lib/plurimath/math/function/tr.rb +23 -4
- data/lib/plurimath/math/function/ubrace.rb +17 -0
- data/lib/plurimath/math/function/ul.rb +29 -0
- data/lib/plurimath/math/function/unary_function.rb +81 -8
- data/lib/plurimath/math/function/underline.rb +12 -0
- data/lib/plurimath/math/function/underover.rb +107 -0
- data/lib/plurimath/math/function/underset.rb +39 -0
- data/lib/plurimath/math/function/vec.rb +7 -1
- data/lib/plurimath/math/number.rb +5 -5
- data/lib/plurimath/math/symbol.rb +51 -12
- data/lib/plurimath/math/unicode.rb +11 -0
- data/lib/plurimath/math.rb +7 -3
- data/lib/plurimath/mathml/constants.rb +224 -147
- data/lib/plurimath/mathml/parser.rb +24 -8
- data/lib/plurimath/mathml/transform.rb +249 -153
- data/lib/plurimath/omml/parser.rb +24 -4
- data/lib/plurimath/omml/transform.rb +219 -157
- data/lib/plurimath/utility.rb +342 -20
- data/lib/plurimath/version.rb +1 -1
- metadata +21 -6
- data/.github/workflows/test.yml +0 -33
- data/lib/plurimath/mathml/parse.rb +0 -68
- data/lib/plurimath/omml/constants.rb +0 -154
@@ -4,140 +4,146 @@ module Plurimath
|
|
4
4
|
class Asciimath
|
5
5
|
class Constants
|
6
6
|
TABLE_PARENTHESIS = {
|
7
|
+
"(:": ":)",
|
8
|
+
"ℒ": "ℛ",
|
7
9
|
"[": "]",
|
8
|
-
"{": "}",
|
9
10
|
"(": ")",
|
10
|
-
"|": "|",
|
11
11
|
}.freeze
|
12
12
|
PARENTHESIS = {
|
13
13
|
"(:": ":)",
|
14
|
-
"
|
14
|
+
"ℒ": "ℛ",
|
15
15
|
"(": ")",
|
16
16
|
"{": "}",
|
17
17
|
"[": "]",
|
18
18
|
}.freeze
|
19
19
|
SYMBOLS = {
|
20
20
|
twoheadrightarrowtail: :"⤖",
|
21
|
-
twoheadrightarrow: :"&#
|
22
|
-
rightarrowtail: :"&#
|
23
|
-
Leftrightarrow: :"&#
|
21
|
+
twoheadrightarrow: :"↠",
|
22
|
+
rightarrowtail: :"↣",
|
23
|
+
Leftrightarrow: :"⇔",
|
24
24
|
leftrightarrow: :"↔",
|
25
|
-
Rightarrow: :"&#
|
25
|
+
Rightarrow: :"⇒",
|
26
26
|
rightarrow: :"→",
|
27
|
-
varepsilon: :"&#
|
28
|
-
Leftarrow: :"&#
|
27
|
+
varepsilon: :"ɛ",
|
28
|
+
Leftarrow: :"⇐",
|
29
29
|
leftarrow: :"←",
|
30
30
|
downarrow: :"↓",
|
31
31
|
therefore: :"∴",
|
32
|
-
backslash: :"
|
33
|
-
setminus: :"
|
34
|
-
triangle: :"&#
|
35
|
-
bigwedge: :"&#
|
32
|
+
backslash: :"\",
|
33
|
+
setminus: :"⧵",
|
34
|
+
triangle: :"△",
|
35
|
+
bigwedge: :"⋀",
|
36
36
|
rceiling: :"⌉",
|
37
37
|
lceiling: :"⌈",
|
38
38
|
supseteq: :"⊇",
|
39
39
|
subseteq: :"⊆",
|
40
|
-
vartheta: :"&#
|
40
|
+
vartheta: :"ϑ",
|
41
41
|
emptyset: :"∅",
|
42
|
-
diamond: :"&#
|
42
|
+
diamond: :"⋄",
|
43
43
|
uparrow: :"↑",
|
44
|
-
implies: :"&#
|
44
|
+
implies: :"⇒",
|
45
45
|
partial: :"∂",
|
46
46
|
because: :"∵",
|
47
|
-
upsilon: :"&#
|
48
|
-
epsilon: :"&#
|
49
|
-
bigcap: :"&#
|
50
|
-
bigvee: :"&#
|
51
|
-
propto: :"&#
|
47
|
+
upsilon: :"υ",
|
48
|
+
epsilon: :"ε",
|
49
|
+
bigcap: :"⋂",
|
50
|
+
bigvee: :"⋁",
|
51
|
+
propto: :"∝",
|
52
52
|
approx: :"≈",
|
53
53
|
exists: :"∃",
|
54
54
|
forall: :"∀",
|
55
55
|
otimes: :"⊗",
|
56
|
-
ltimes: :"&#
|
57
|
-
bowtie: :"&#
|
58
|
-
rtimes: :"&#
|
59
|
-
models: :"&#
|
60
|
-
mapsto: :"&#
|
61
|
-
bigcup: :"&#
|
62
|
-
succeq: :"&#
|
63
|
-
preceq: :"&#
|
64
|
-
rfloor: :"&#
|
65
|
-
lfloor: :"&#
|
66
|
-
square: :"&#
|
56
|
+
ltimes: :"⋉",
|
57
|
+
bowtie: :"⋈",
|
58
|
+
rtimes: :"⋊",
|
59
|
+
models: :"⊨",
|
60
|
+
mapsto: :"↦",
|
61
|
+
bigcup: :"⋃",
|
62
|
+
succeq: :"⪰",
|
63
|
+
preceq: :"⪯",
|
64
|
+
rfloor: :"⌋",
|
65
|
+
lfloor: :"⌊",
|
66
|
+
square: :"□",
|
67
67
|
supset: :"⊃",
|
68
68
|
subset: :"⊂",
|
69
|
-
lambda: :"&#
|
70
|
-
Lambda: :"&#
|
71
|
-
varphi: :"&#
|
69
|
+
lambda: :"λ",
|
70
|
+
Lambda: :"Λ",
|
71
|
+
varphi: :"φ",
|
72
|
+
rangle: :"〉",
|
73
|
+
langle: :"〈",
|
72
74
|
">->>": :"⤖",
|
73
|
-
"/_\\": :"&#
|
74
|
-
"|><|": :"&#
|
75
|
-
kappa: :"&#
|
75
|
+
"/_\\": :"△",
|
76
|
+
"|><|": :"⋈",
|
77
|
+
kappa: :"κ",
|
76
78
|
Delta: :"Δ",
|
77
|
-
delta: :"&#
|
78
|
-
gamma: :"&#
|
79
|
+
delta: :"δ",
|
80
|
+
gamma: :"γ",
|
79
81
|
Gamma: :"Γ",
|
80
82
|
Theta: :"Θ",
|
81
|
-
theta: :"&#
|
82
|
-
alpha: :"&#
|
83
|
-
aleph: :"&#
|
84
|
-
infty: :"&#
|
85
|
-
equiv: :"&#
|
86
|
-
frown: :"&#
|
87
|
-
notin: :"&#
|
88
|
-
angle: :"&#
|
83
|
+
theta: :"θ",
|
84
|
+
alpha: :"α",
|
85
|
+
aleph: :"ℵ",
|
86
|
+
infty: :"∞",
|
87
|
+
equiv: :"≡",
|
88
|
+
frown: :"⌢",
|
89
|
+
notin: :"∉",
|
90
|
+
angle: :"∠",
|
91
|
+
prime: :"′",
|
89
92
|
"!in": :"∉",
|
90
|
-
cdots: :"&#
|
91
|
-
vdash: :"&#
|
93
|
+
cdots: :"⋯",
|
94
|
+
vdash: :"⊢",
|
92
95
|
wedge: :"∧",
|
93
96
|
oplus: :"⊕",
|
94
97
|
nabla: :"∇",
|
95
|
-
ddots: :"&#
|
96
|
-
vdots: :"&#
|
97
|
-
Sigma: :"&#
|
98
|
-
Omega: :"&#
|
99
|
-
omega: :"&#
|
100
|
-
sigma: :"&#
|
101
|
-
times: :"&#
|
102
|
-
ldots: :"
|
103
|
-
">-=": :"&#
|
104
|
-
"-<=": :"&#
|
105
|
-
"><|": :"&#
|
106
|
-
"|==": :"&#
|
107
|
-
"|--": :"&#
|
108
|
-
"^^^": :"&#
|
109
|
-
"|->": :"&#
|
110
|
-
">->": :"&#
|
111
|
-
"->>": :"&#
|
112
|
-
"__|": :"&#
|
113
|
-
"|__": :"&#
|
114
|
-
"|><": :"&#
|
115
|
-
"_|_": :"&#
|
116
|
-
"***": :"&#
|
117
|
-
"<=>": :"&#
|
118
|
-
|
119
|
-
|
98
|
+
ddots: :"⋱",
|
99
|
+
vdots: :"⋮",
|
100
|
+
Sigma: :"Σ",
|
101
|
+
Omega: :"Ω",
|
102
|
+
omega: :"ω",
|
103
|
+
sigma: :"σ",
|
104
|
+
times: :"×",
|
105
|
+
ldots: :"…",
|
106
|
+
">-=": :"⪰",
|
107
|
+
"-<=": :"⪯",
|
108
|
+
"><|": :"⋊",
|
109
|
+
"|==": :"⊨",
|
110
|
+
"|--": :"⊢",
|
111
|
+
"^^^": :"⋀",
|
112
|
+
"|->": :"↦",
|
113
|
+
">->": :"↣",
|
114
|
+
"->>": :"↠",
|
115
|
+
"__|": :"⌋",
|
116
|
+
"|__": :"⌊",
|
117
|
+
"|><": :"⋉",
|
118
|
+
"_|_": :"⊥",
|
119
|
+
"***": :"⋆",
|
120
|
+
"<=>": :"⇔",
|
121
|
+
"...": :"…",
|
122
|
+
"(:": :"〈",
|
123
|
+
":)": :"〉",
|
124
|
+
quad: :" ",
|
125
|
+
star: :"⋆",
|
120
126
|
odot: :"⊙",
|
121
|
-
cdot: :"&#
|
127
|
+
cdot: :"⋅",
|
122
128
|
rarr: :"→",
|
123
129
|
darr: :"↓",
|
124
|
-
prop: :"&#
|
125
|
-
lArr: :"&#
|
126
|
-
rArr: :"&#
|
130
|
+
prop: :"∝",
|
131
|
+
lArr: :"⇐",
|
132
|
+
rArr: :"⇒",
|
127
133
|
uarr: :"↑",
|
128
|
-
hArr: :"&#
|
134
|
+
hArr: :"⇔",
|
129
135
|
harr: :"↔",
|
130
136
|
larr: :"←",
|
131
137
|
grad: :"∇",
|
132
138
|
circ: :"∘",
|
133
139
|
sube: :"⊆",
|
134
140
|
supe: :"⊇",
|
135
|
-
succ: :"&#
|
136
|
-
prec: :"&#
|
137
|
-
cong: :"&#
|
138
|
-
beta: :"&#
|
139
|
-
zeta: :"&#
|
140
|
-
iota: :"&#
|
141
|
+
succ: :"≻",
|
142
|
+
prec: :"≺",
|
143
|
+
cong: :"≅",
|
144
|
+
beta: :"β",
|
145
|
+
zeta: :"ζ",
|
146
|
+
iota: :"ι",
|
141
147
|
":'": :"∵",
|
142
148
|
"^^": :"∧",
|
143
149
|
"o+": :"⊕",
|
@@ -146,13 +152,13 @@ module Plurimath
|
|
146
152
|
"~~": :"≈",
|
147
153
|
"O/": :"∅",
|
148
154
|
"->": :"→",
|
149
|
-
"=>": :"&#
|
150
|
-
">>": :"&#
|
155
|
+
"=>": :"⇒",
|
156
|
+
">>": :"〉",
|
151
157
|
"<<": :"〈",
|
152
158
|
"~|": :"⌉",
|
153
159
|
"!=": :"≠",
|
154
|
-
">-": :"&#
|
155
|
-
"-<": :"&#
|
160
|
+
">-": :"≻",
|
161
|
+
"-<": :"≺",
|
156
162
|
"~=": :"≅",
|
157
163
|
"-=": :"≡",
|
158
164
|
":.": :"∴",
|
@@ -160,70 +166,84 @@ module Plurimath
|
|
160
166
|
"<=": :"≤",
|
161
167
|
"|~": :"⌈",
|
162
168
|
"/_": :"∠",
|
163
|
-
"+-": :"&#
|
164
|
-
"-:": :"&#
|
169
|
+
"+-": :"±",
|
170
|
+
"-:": :"÷",
|
171
|
+
"\\ ": :" ",
|
172
|
+
"\\": :"\\",
|
173
|
+
"//": :/,
|
165
174
|
sup: :"⊃",
|
166
175
|
sub: :"⊂",
|
167
|
-
top: :"&#
|
168
|
-
vvv: :"&#
|
176
|
+
top: :"⊤",
|
177
|
+
vvv: :"⋁",
|
169
178
|
vee: :"∨",
|
170
|
-
nnn: :"&#
|
179
|
+
nnn: :"⋂",
|
171
180
|
cap: :"∩",
|
172
181
|
ast: :"∗",
|
173
|
-
bot: :"&#
|
182
|
+
bot: :"⊥",
|
174
183
|
del: :"∂",
|
175
|
-
uuu: :"&#
|
176
|
-
cup: :"&#
|
177
|
-
iff: :"&#
|
178
|
-
eta: :"&#
|
179
|
-
Phi: :"&#
|
180
|
-
Psi: :"&#
|
181
|
-
psi: :"&#
|
182
|
-
chi: :"&#
|
183
|
-
phi: :"&#
|
184
|
-
rho: :"&#
|
185
|
-
tau: :"&#
|
186
|
-
div: :"&#
|
187
|
-
neg: :"&#
|
188
|
-
not: :"&#
|
189
|
-
"
|
190
|
-
"
|
191
|
-
"<": :"
|
192
|
-
">": :"
|
193
|
-
"
|
184
|
+
uuu: :"⋃",
|
185
|
+
cup: :"∪",
|
186
|
+
iff: :"⇔",
|
187
|
+
eta: :"η",
|
188
|
+
Phi: :"Φ",
|
189
|
+
Psi: :"Ψ",
|
190
|
+
psi: :"ψ",
|
191
|
+
chi: :"χ",
|
192
|
+
phi: :"ϕ",
|
193
|
+
rho: :"ρ",
|
194
|
+
tau: :"τ",
|
195
|
+
div: :"÷",
|
196
|
+
neg: :"¬",
|
197
|
+
not: :"¬",
|
198
|
+
"*": :"⋅",
|
199
|
+
"@": :"@",
|
200
|
+
"<": :"<",
|
201
|
+
">": :">",
|
202
|
+
"/": :"/",
|
203
|
+
":": :":",
|
204
|
+
"!": :"!",
|
205
|
+
",": :",",
|
206
|
+
";": :";",
|
207
|
+
"?": :"?",
|
208
|
+
"$": :"$",
|
209
|
+
"~": :"~",
|
210
|
+
"|": :"|",
|
211
|
+
"%": :"%",
|
212
|
+
"'": :"'",
|
213
|
+
"&": :"&",
|
214
|
+
"#": :"#",
|
194
215
|
"=": :"=",
|
216
|
+
"-": :"-",
|
195
217
|
"+": :"+",
|
196
|
-
"/": :"/",
|
197
218
|
nn: :"∩",
|
198
219
|
vv: :"∨",
|
199
|
-
TT: :"&#
|
220
|
+
TT: :"⊤",
|
200
221
|
EE: :"∃",
|
201
222
|
ox: :"⊗",
|
202
223
|
to: :"→",
|
203
224
|
AA: :"∀",
|
204
|
-
uu: :"&#
|
225
|
+
uu: :"∪",
|
205
226
|
ne: :"≠",
|
206
|
-
|
207
|
-
RR: :"ℝ",
|
208
|
-
QQ: :"ℚ",
|
209
|
-
NN: :"ℕ",
|
210
|
-
CC: :"ℂ",
|
211
|
-
oo: :"∞",
|
227
|
+
oo: :"∞",
|
212
228
|
ge: :"≥",
|
213
229
|
le: :"≤",
|
214
230
|
in: :"∈",
|
215
|
-
nu: :"&#
|
216
|
-
mu: :"&#
|
217
|
-
pi: :"&#
|
218
|
-
Pi: :"&#
|
219
|
-
xi: :"&#
|
220
|
-
Xi: :"&#
|
221
|
-
xx: :"&#
|
222
|
-
pm: :"&#
|
223
|
-
gt: :"
|
224
|
-
lt: :"
|
231
|
+
nu: :"ν",
|
232
|
+
mu: :"μ",
|
233
|
+
pi: :"π",
|
234
|
+
Pi: :"Π",
|
235
|
+
xi: :"ξ",
|
236
|
+
Xi: :"Ξ",
|
237
|
+
xx: :"×",
|
238
|
+
pm: :"±",
|
239
|
+
gt: :">",
|
240
|
+
lt: :"<",
|
241
|
+
if: :if,
|
225
242
|
}.freeze
|
226
243
|
UNARY_CLASSES = %i[
|
244
|
+
underbrace
|
245
|
+
overbrace
|
246
|
+
underline
|
227
247
|
arccos
|
228
248
|
arcsin
|
229
249
|
arctan
|
@@ -272,15 +292,8 @@ module Plurimath
|
|
272
292
|
underset
|
273
293
|
stackrel
|
274
294
|
overset
|
275
|
-
color
|
276
|
-
prod
|
277
295
|
frac
|
278
296
|
root
|
279
|
-
oint
|
280
|
-
int
|
281
|
-
sum
|
282
|
-
mod
|
283
|
-
log
|
284
297
|
].freeze
|
285
298
|
FONT_STYLES = %i[
|
286
299
|
mathfrak
|
@@ -291,11 +304,43 @@ module Plurimath
|
|
291
304
|
mathbf
|
292
305
|
bbb
|
293
306
|
bb
|
307
|
+
rm
|
294
308
|
fr
|
295
309
|
cc
|
296
310
|
sf
|
297
311
|
tt
|
312
|
+
ii
|
298
313
|
].freeze
|
314
|
+
SUB_SUP_CLASSES = %w[
|
315
|
+
prod
|
316
|
+
oint
|
317
|
+
lim
|
318
|
+
sum
|
319
|
+
log
|
320
|
+
int
|
321
|
+
].freeze
|
322
|
+
SPECIAL_BOLD_ALPHABETS = %w[
|
323
|
+
ZZ
|
324
|
+
RR
|
325
|
+
QQ
|
326
|
+
NN
|
327
|
+
CC
|
328
|
+
].freeze
|
329
|
+
|
330
|
+
class << self
|
331
|
+
def precompile_constants
|
332
|
+
@values ||=
|
333
|
+
named_hash(UNARY_CLASSES, :unary_class)
|
334
|
+
.merge(named_hash(SYMBOLS.keys, :symbol))
|
335
|
+
.merge(named_hash(FONT_STYLES, :fonts))
|
336
|
+
.merge(named_hash(SPECIAL_BOLD_ALPHABETS, :special_fonts))
|
337
|
+
@values.sort_by { |v, _| -v.length }.to_h
|
338
|
+
end
|
339
|
+
|
340
|
+
def named_hash(hash_or_array, name_key)
|
341
|
+
hash_or_array.each_with_object({}) { |d, i| i[d] = name_key }
|
342
|
+
end
|
343
|
+
end
|
299
344
|
end
|
300
345
|
end
|
301
346
|
end
|
@@ -4,23 +4,29 @@ require "parslet"
|
|
4
4
|
module Plurimath
|
5
5
|
class Asciimath
|
6
6
|
class Parse < Parslet::Parser
|
7
|
-
rule(:
|
8
|
-
rule(:base)
|
9
|
-
rule(:power)
|
10
|
-
rule(:
|
11
|
-
|
12
|
-
rule(:
|
13
|
-
|
7
|
+
rule(:td) { expression.as(:td) }
|
8
|
+
rule(:base) { str("_") }
|
9
|
+
rule(:power) { str("^") }
|
10
|
+
rule(:space) { match(/\s+/) }
|
11
|
+
rule(:comma) { (str(",") >> space.maybe) }
|
12
|
+
rule(:number) do
|
13
|
+
(match("[0-9]").repeat(1) >> str(".") >> match("[0-9]").repeat(1)).as(:number) |
|
14
|
+
match("[0-9]").repeat(1).as(:number) |
|
15
|
+
str(".").as(:symbol)
|
16
|
+
end
|
14
17
|
|
15
|
-
rule(:
|
16
|
-
rule(:
|
18
|
+
rule(:controversial_symbols) { power_base | expression }
|
19
|
+
rule(:left_right_open_paren) { str("(") | str("[") }
|
20
|
+
rule(:left_right_close_paren) { str(")") | str("]") }
|
21
|
+
rule(:color_left_parenthesis) { str("(") | str("[") | str("{") }
|
22
|
+
rule(:color_right_parenthesis) { str(")") | str("]") | str("}") }
|
17
23
|
|
18
|
-
rule(:
|
19
|
-
|
24
|
+
rule(:binary_classes) do
|
25
|
+
arr_to_expression(Constants::BINARY_CLASSES, :binary_class)
|
26
|
+
end
|
20
27
|
|
21
|
-
rule(:
|
22
|
-
(
|
23
|
-
table
|
28
|
+
rule(:sub_sup_classes) do
|
29
|
+
arr_to_expression(Constants::SUB_SUP_CLASSES, :binary_class)
|
24
30
|
end
|
25
31
|
|
26
32
|
rule(:open_table) do
|
@@ -45,58 +51,100 @@ module Plurimath
|
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
54
|
+
rule(:left_right) do
|
55
|
+
(str("left") >> left_right_open_paren.as(:left) >> iteration.as(:left_right_value) >> str("right") >> left_right_close_paren.as(:right)) |
|
56
|
+
((table.as(:numerator) >> space.maybe >> match(/(?<!\/)\/(?!\/)/) >> space.maybe >> iteration.as(:denominator)).as(:frac) >> expression) |
|
57
|
+
(table.as(:table) >> expression.maybe)
|
58
|
+
end
|
59
|
+
|
48
60
|
rule(:quoted_text) do
|
49
61
|
str('"') >> match("[^\"]").repeat.as(:text) >> str('"')
|
50
62
|
end
|
51
63
|
|
52
64
|
rule(:symbol_text_or_integer) do
|
53
|
-
|
54
|
-
|
55
|
-
|
65
|
+
sub_sup_classes |
|
66
|
+
binary_classes |
|
67
|
+
hash_to_expression(Constants.precompile_constants) |
|
68
|
+
(match(/[0-9]/).as(:number) >> comma.as(:comma)).repeat(1).as(:comma_separated) |
|
56
69
|
quoted_text |
|
70
|
+
(str("d").as(:d) >> str("x").as(:x)).as(:intermediate_exp) |
|
57
71
|
match["a-zA-Z"].as(:symbol) |
|
58
|
-
match("
|
72
|
+
match(/[^\[{(\\\/@;:.,'"|\]})0-9a-zA-Z\-><$%^&*_=+!`~\s?]/).as(:symbol) |
|
73
|
+
number
|
74
|
+
end
|
75
|
+
|
76
|
+
rule(:power_base) do
|
77
|
+
(base >> space.maybe >> sequence.as(:base_value) >> power >> space.maybe >> sequence.as(:power_value)) |
|
78
|
+
(space.maybe >> base >> space.maybe >> sequence.as(:base_value)).as(:base) |
|
79
|
+
(space.maybe >> power >> space.maybe >> sequence.as(:power_value)).as(:power) |
|
80
|
+
(space.maybe >> base >> space.maybe >> power.as(:symbol).as(:base_value)).as(:base) |
|
81
|
+
(space.maybe >> power >> space.maybe >> base.as(:symbol).as(:power_value)).as(:power)
|
82
|
+
end
|
83
|
+
|
84
|
+
rule(:power_base_rules) do
|
85
|
+
(sub_sup_classes >> power_base).as(:power_base) |
|
86
|
+
(binary_classes >> space.maybe >> sequence.as(:base_value).maybe >> space.maybe >> sequence.as(:power_value).maybe).as(:power_base) |
|
87
|
+
(sequence.as(:power_base) >> power_base).as(:power_base)
|
59
88
|
end
|
60
89
|
|
61
90
|
rule(:table) do
|
62
91
|
(open_table.as(:table_left) >> tr >> close_table.as(:table_right)) |
|
92
|
+
(open_table.as(:table_left) >> tr >> str("}").as(:table_right)) |
|
93
|
+
(str("norm").as(:norm) >> open_table.as(:table_left) >> tr >> close_table.as(:table_right)) |
|
94
|
+
(str("{").as(:table_left) >> tr >> close_table.as(:table_right)) |
|
95
|
+
(str("|").as(:table_left) >> tr >> str("|").as(:table_right)) |
|
63
96
|
(str("left") >> left_right_open_paren.as(:left) >> tr >> str("right") >> left_right_close_paren.as(:right))
|
64
97
|
end
|
65
98
|
|
66
99
|
rule(:tr) do
|
67
|
-
((
|
68
|
-
(
|
100
|
+
((left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row) >> comma >> tr.as(:expr)) |
|
101
|
+
(left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row)
|
69
102
|
end
|
70
103
|
|
71
|
-
rule(:
|
72
|
-
(
|
73
|
-
|
104
|
+
rule(:color_value) do
|
105
|
+
(color_left_parenthesis.capture(:paren).as(:lparen) >> expression.as(:rgb_color) >> color_right_parenthesis.maybe.as(:rparen)).as(:intermediate_exp) |
|
106
|
+
iteration
|
74
107
|
end
|
75
108
|
|
76
109
|
rule(:sequence) do
|
77
|
-
(lparen >> expression >> rparen).as(:intermediate_exp) |
|
78
|
-
(
|
79
|
-
(str("text") >> lparen.capture(:paren) >> read_text >> rparen) |
|
80
|
-
(unary_functions >> sequence).as(:unary) |
|
81
|
-
(font_style >> sequence).as(:fonts) |
|
110
|
+
(lparen.as(:lparen) >> space.maybe >> expression.maybe.as(:expr) >> space.maybe >> rparen.maybe.as(:rparen)).as(:intermediate_exp) |
|
111
|
+
(str("text") >> lparen.capture(:paren).as(:lparen) >> read_text.as(:text) >> rparen.maybe.as(:rparen)).as(:intermediate_exp) |
|
82
112
|
symbol_text_or_integer
|
83
113
|
end
|
84
114
|
|
115
|
+
rule(:frac) do
|
116
|
+
(sequence.as(:numerator) >> space.maybe >> match(/(?<!\/)\/(?!\/)/) >> space.maybe >> iteration.as(:denominator)).as(:frac) |
|
117
|
+
((power_base_rules | power_base).as(:numerator) >> match(/(?<!\/)\/(?!\/)/) >> iteration.as(:denominator)).as(:frac)
|
118
|
+
end
|
119
|
+
|
120
|
+
rule(:mod) do
|
121
|
+
(sequence.as(:dividend) >> space.maybe >> str("mod").as(:mod) >> space.maybe >> iteration.as(:divisor)).as(:mod) |
|
122
|
+
((power_base_rules >> power_base).as(:dividend) >> space.maybe >> str("mod").as(:mod) >> space.maybe >> iteration.as(:divisor)).as(:mod) |
|
123
|
+
(power_base_rules.as(:dividend) >> space.maybe >> str("mod").as(:mod) >> space.maybe >> iteration.as(:divisor)).as(:mod)
|
124
|
+
end
|
125
|
+
|
85
126
|
rule(:iteration) do
|
86
127
|
table.as(:table) |
|
87
|
-
|
88
|
-
|
89
|
-
(sequence >>
|
90
|
-
(
|
128
|
+
comma.as(:comma) |
|
129
|
+
mod |
|
130
|
+
(sequence.as(:sequence) >> space.maybe >> str("//").as(:symbol)) |
|
131
|
+
(str("color") >> color_value.as(:color) >> sequence.as(:color_value)) |
|
132
|
+
frac |
|
133
|
+
(power_base_rules >> power_base) |
|
134
|
+
power_base_rules |
|
91
135
|
sequence.as(:sequence) |
|
92
136
|
space
|
93
137
|
end
|
94
138
|
|
95
139
|
rule(:expression) do
|
96
140
|
left_right.as(:left_right) |
|
97
|
-
(iteration >> expression).as(:expr) |
|
98
|
-
(
|
99
|
-
|
141
|
+
(iteration >> space.maybe >> expression).as(:expr) |
|
142
|
+
(base.as(:symbol) >> expression.maybe).as(:expr) |
|
143
|
+
(power.as(:symbol) >> expression.maybe).as(:expr) |
|
144
|
+
str("") |
|
145
|
+
(rparen.as(:rparen) >> space.maybe >> controversial_symbols >> comma.as(:comma).maybe >> expression).repeat(1).as(:expr) |
|
146
|
+
(power.as(:symbol) >> space.maybe >> expression).as(:expr) |
|
147
|
+
comma.as(:comma).maybe
|
100
148
|
end
|
101
149
|
|
102
150
|
root :expression
|
@@ -104,16 +152,33 @@ module Plurimath
|
|
104
152
|
def arr_to_expression(arr, name = nil)
|
105
153
|
type = arr.first.class
|
106
154
|
arr.reduce do |expression, expr_string|
|
107
|
-
|
108
|
-
expression
|
109
|
-
expression | str(expr_string).as(as_value)
|
155
|
+
expression = str(expression).as(name) if expression.is_a?(type)
|
156
|
+
expression | str(expr_string).as(name)
|
110
157
|
end
|
111
158
|
end
|
112
159
|
|
113
160
|
def read_text
|
114
161
|
dynamic do |_sour, context|
|
115
162
|
rparen = Constants::PARENTHESIS[context.captures[:paren].to_sym]
|
116
|
-
match("[^#{rparen}]").repeat
|
163
|
+
match("[^#{rparen}]").repeat
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def hash_to_expression(arr)
|
168
|
+
type = arr.first.class
|
169
|
+
@@expression ||= arr.reduce do |expression, expr_string|
|
170
|
+
expression = dynamic_parser_rules(expression) if expression.is_a?(type)
|
171
|
+
expression | dynamic_parser_rules(expr_string)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def dynamic_parser_rules(expr)
|
176
|
+
first_value = str(expr.first.to_s)
|
177
|
+
case expr.last
|
178
|
+
when :symbol then first_value.as(:symbol)
|
179
|
+
when :unary_class then (first_value.as(:unary_class) >> space.maybe >> sequence.maybe).as(:unary)
|
180
|
+
when :fonts then first_value.as(:fonts_class) >> space.maybe >> sequence.as(:fonts_value)
|
181
|
+
when :special_fonts then first_value.as(:bold_fonts)
|
117
182
|
end
|
118
183
|
end
|
119
184
|
end
|
@@ -10,11 +10,13 @@ module Plurimath
|
|
10
10
|
|
11
11
|
def initialize(text)
|
12
12
|
@text = text
|
13
|
+
&.gsub(/(\|:|:\|)/, "|")
|
14
|
+
&.gsub(/(\{:)/, "ℒ")
|
15
|
+
&.gsub(/(:\})/, "ℛ")
|
13
16
|
end
|
14
17
|
|
15
18
|
def parse
|
16
19
|
nodes = Parse.new.parse(text)
|
17
|
-
nodes = JSON.parse(nodes.to_json, symbolize_names: true)
|
18
20
|
transformed_tree = Transform.new.apply(nodes)
|
19
21
|
return transformed_tree if transformed_tree.is_a?(Math::Formula)
|
20
22
|
|