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
@@ -3,198 +3,294 @@
|
|
3
3
|
module Plurimath
|
4
4
|
class Mathml
|
5
5
|
class Transform < Parslet::Transform
|
6
|
-
rule(
|
7
|
-
rule(
|
8
|
-
rule(
|
9
|
-
rule(
|
10
|
-
rule(
|
6
|
+
rule(mi: simple(:mi)) { mi }
|
7
|
+
rule(mo: simple(:mo)) { mo }
|
8
|
+
rule(mo: sequence(:mo)) { Utility.mathml_unary_classes(mo) }
|
9
|
+
rule(xref: simple(:xref)) { nil }
|
10
|
+
rule(mtd: sequence(:mtd)) { Math::Function::Td.new(mtd) }
|
11
|
+
rule(mtr: sequence(:mtr)) { Math::Function::Tr.new(mtr) }
|
12
|
+
rule(accent: simple(:acc)) { nil }
|
13
|
+
rule(none: sequence(:none)) { nil }
|
14
|
+
rule(maxsize: simple(:att)) { nil }
|
15
|
+
rule(minsize: simple(:att)) { nil }
|
16
|
+
rule(notation: simple(:att)) { Math::Function::Menclose.new(att) }
|
17
|
+
rule(mtable: simple(:table)) { table }
|
18
|
+
rule(msqrt: sequence(:sqrt)) { Math::Function::Sqrt.new(sqrt.first) }
|
19
|
+
rule(mstyle: simple(:mstyle)) { mstyle }
|
20
|
+
rule(msline: sequence(:line)) { Math::Function::Msline.new }
|
21
|
+
rule(value: sequence(:value)) { Utility.filter_values(value) }
|
11
22
|
|
12
|
-
rule(
|
13
|
-
|
23
|
+
rule(mspace: sequence(:space)) { nil }
|
24
|
+
rule(mstyle: sequence(:mstyle)) { Utility.filter_values(mstyle) }
|
25
|
+
rule(mfenced: simple(:mfenced)) { mfenced }
|
26
|
+
rule(mtable: sequence(:mtable)) { Math::Function::Table.new(mtable) }
|
27
|
+
rule(mscarry: sequence(:scarry)) { nil }
|
28
|
+
rule(displaystyle: simple(:att)) { nil }
|
29
|
+
rule(menclose: simple(:enclose)) { enclose }
|
30
|
+
rule(mlabeledtr: sequence(:mtr)) { Math::Function::Tr.new(mtr) }
|
31
|
+
rule(mpadded: sequence(:padded)) { Utility.filter_values(padded) }
|
32
|
+
rule(malignmark: sequence(:mark)) { nil }
|
33
|
+
rule(maligngroup: sequence(:att)) { nil }
|
34
|
+
rule(mprescripts: sequence(:att)) { "mprescripts" }
|
35
|
+
rule(columnlines: simple(:lines)) { lines }
|
36
|
+
|
37
|
+
rule(math: subtree(:math)) do
|
38
|
+
Utility.filter_values(
|
39
|
+
math.flatten.compact,
|
40
|
+
)
|
14
41
|
end
|
15
42
|
|
16
|
-
rule(
|
17
|
-
|
43
|
+
rule(mphantom: sequence(:phantom)) do
|
44
|
+
Math::Function::Phantom.new(phantom)
|
18
45
|
end
|
19
46
|
|
20
|
-
rule(
|
21
|
-
|
47
|
+
rule(mn: sequence(:mn)) do
|
48
|
+
Math::Number.new(
|
49
|
+
Utility.string_to_html_entity(
|
50
|
+
mn.join,
|
51
|
+
),
|
52
|
+
)
|
22
53
|
end
|
23
54
|
|
24
|
-
rule(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
55
|
+
rule(mathvariant: simple(:variant)) do
|
56
|
+
Utility::FONT_STYLES[variant.to_sym]&.new(nil, variant)
|
57
|
+
end
|
58
|
+
|
59
|
+
rule(mi: sequence(:mi)) do
|
60
|
+
mi.any?(String) ? Utility.mathml_unary_classes(mi) : mi
|
61
|
+
end
|
62
|
+
|
63
|
+
rule(open: simple(:lparen)) do
|
64
|
+
Math::Function::Fenced.new(Math::Symbol.new(lparen))
|
65
|
+
end
|
66
|
+
|
67
|
+
rule(msgroup: sequence(:group)) do
|
68
|
+
if group.any?(String)
|
69
|
+
group.each_with_index do |object, ind|
|
70
|
+
group[ind] = Utility.text_classes(object) if object.is_a?(String)
|
71
|
+
end
|
29
72
|
end
|
30
|
-
Math::Function::
|
73
|
+
Math::Function::Msgroup.new(group.flatten.compact)
|
74
|
+
end
|
75
|
+
|
76
|
+
rule(mlongdiv: sequence(:long)) do
|
77
|
+
Math::Function::Longdiv.new(long.flatten.compact)
|
78
|
+
end
|
79
|
+
|
80
|
+
rule(menclose: sequence(:close)) do
|
81
|
+
Math::Function::Menclose.new(
|
82
|
+
nil,
|
83
|
+
Utility.filter_values(close),
|
84
|
+
)
|
31
85
|
end
|
32
86
|
|
33
|
-
rule(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
new_arr = []
|
39
|
-
new_arr = new_arr + tag unless tag.compact.empty?
|
40
|
-
new_arr = new_arr + sequence unless sequence.compact.empty?
|
41
|
-
new_arr << iteration unless iteration.to_s.empty?
|
42
|
-
new_arr
|
87
|
+
rule(mroot: sequence(:mroot)) do
|
88
|
+
Math::Function::Root.new(
|
89
|
+
mroot[1],
|
90
|
+
mroot[0],
|
91
|
+
)
|
43
92
|
end
|
44
93
|
|
45
|
-
rule(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
Math::Formula.new(tag + [sequence, iteration])
|
94
|
+
rule(merror: sequence(:merror)) do
|
95
|
+
Math::Function::Merror.new(
|
96
|
+
merror[0],
|
97
|
+
merror[1],
|
98
|
+
)
|
51
99
|
end
|
52
100
|
|
53
|
-
rule(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
iteration.size.zero? ? [tag, sequence] : [tag, sequence, iteration]
|
101
|
+
rule(mfrac: sequence(:mfrac)) do
|
102
|
+
Math::Function::Frac.new(
|
103
|
+
mfrac[0],
|
104
|
+
mfrac[1],
|
105
|
+
)
|
59
106
|
end
|
60
107
|
|
61
|
-
rule(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
108
|
+
rule(mfraction: sequence(:mfrac)) do
|
109
|
+
Math::Function::Frac.new(
|
110
|
+
mfrac[0],
|
111
|
+
mfrac[1],
|
112
|
+
)
|
66
113
|
end
|
67
114
|
|
68
|
-
rule(
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
115
|
+
rule(msub: sequence(:msub)) do
|
116
|
+
Math::Function::Base.new(
|
117
|
+
msub[0],
|
118
|
+
msub[1],
|
119
|
+
)
|
73
120
|
end
|
74
121
|
|
75
|
-
rule(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
122
|
+
rule(msup: sequence(:msup)) do
|
123
|
+
Math::Function::Power.new(
|
124
|
+
msup[0],
|
125
|
+
msup[1],
|
126
|
+
)
|
80
127
|
end
|
81
128
|
|
82
|
-
rule(
|
83
|
-
|
84
|
-
|
85
|
-
[
|
86
|
-
|
87
|
-
|
129
|
+
rule(msubsup: sequence(:msubsup)) do
|
130
|
+
Math::Function::PowerBase.new(
|
131
|
+
msubsup[0],
|
132
|
+
msubsup[1],
|
133
|
+
msubsup[2],
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
rule(munderover: sequence(:function)) do
|
138
|
+
binary_function = Plurimath::Math::Function::BinaryFunction
|
139
|
+
base_class = function[0]&.value&.first if function[0].is_a?(Math::Formula)
|
140
|
+
if base_class&.class&.ancestors&.include?(binary_function)
|
141
|
+
base_class.parameter_one = function[1]
|
142
|
+
base_class.parameter_two = function[2]
|
143
|
+
base_class
|
88
144
|
else
|
89
|
-
Math::
|
145
|
+
Math::Function::Underover.new(
|
146
|
+
function[0],
|
147
|
+
function[1],
|
148
|
+
function[2],
|
149
|
+
)
|
90
150
|
end
|
91
151
|
end
|
92
152
|
|
93
|
-
rule(
|
94
|
-
if
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
elsif name == "mathvariant"
|
99
|
-
value
|
153
|
+
rule(mrow: subtree(:mrow)) do
|
154
|
+
if mrow.any?(String)
|
155
|
+
mrow.each_with_index do |object, ind|
|
156
|
+
mrow[ind] = Utility.mathml_unary_classes([object]) if object.is_a?(String)
|
157
|
+
end
|
100
158
|
end
|
159
|
+
Math::Formula.new(mrow.flatten.compact)
|
101
160
|
end
|
102
161
|
|
103
|
-
rule(
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
) do
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
if open_tag == "mrow"
|
123
|
-
Math::Formula.new(iteration)
|
124
|
-
elsif open_tag == "munder"
|
125
|
-
if iteration.last.class_name == "obrace"
|
126
|
-
iteration.last.parameter_one = iteration.first
|
127
|
-
iteration.last
|
128
|
-
else
|
129
|
-
Math::Function::Underset.new(iteration[1], iteration[0])
|
130
|
-
end
|
131
|
-
elsif open_tag == "munderover"
|
132
|
-
Utility.get_class(open_tag.delete_prefix("m")).new(
|
133
|
-
iteration[0],
|
134
|
-
iteration[1],
|
135
|
-
iteration[2],
|
136
|
-
)
|
137
|
-
elsif open_tag == "mover"
|
138
|
-
if iteration.last.class_name == "ubrace"
|
139
|
-
iteration.last.parameter_one = iteration.first
|
140
|
-
iteration.last
|
141
|
-
else
|
142
|
-
Math::Function::Overset.new(iteration[1], iteration[0])
|
143
|
-
end
|
144
|
-
elsif ["msub", "msup"].include?(open_tag)
|
145
|
-
tag = (open_tag == "msup" ? "power" : "base")
|
146
|
-
Utility.get_class(tag).new(iteration[0], iteration[1])
|
147
|
-
elsif open_tag == "msubsup"
|
148
|
-
Math::Function::PowerBase.new(iteration[0],
|
149
|
-
iteration[1],
|
150
|
-
iteration[2])
|
151
|
-
elsif open_tag == "mfrac"
|
152
|
-
Math::Function::Frac.new(iteration.first, iteration.last)
|
153
|
-
elsif open_tag == "msqrt"
|
154
|
-
Math::Function::Sqrt.new(iteration.first)
|
155
|
-
elsif open_tag == "mroot"
|
156
|
-
Math::Function::Root.new(iteration[0], iteration[1])
|
157
|
-
elsif open_tag == "mfenced"
|
158
|
-
Math::Function::Fenced.new(
|
159
|
-
attributes[0],
|
160
|
-
iteration,
|
161
|
-
attributes[1],
|
162
|
+
rule(msrow: sequence(:msrow)) do
|
163
|
+
Math::Formula.new(msrow.flatten.compact)
|
164
|
+
end
|
165
|
+
|
166
|
+
rule(mstack: sequence(:stack)) do
|
167
|
+
Math::Function::Stackrel.new(
|
168
|
+
Utility.filter_values(stack),
|
169
|
+
)
|
170
|
+
end
|
171
|
+
|
172
|
+
rule(mover: sequence(:mover)) do
|
173
|
+
if ["ubrace", "obrace"].any?(mover.last.class_name)
|
174
|
+
mover.last.parameter_one = mover.shift if mover.length > 1
|
175
|
+
mover.last
|
176
|
+
else
|
177
|
+
Math::Function::Overset.new(
|
178
|
+
mover[1],
|
179
|
+
mover[0],
|
162
180
|
)
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
font_type = attributes.compact.last
|
171
|
-
if Utility::FONT_STYLES.key?(font_type.to_sym)
|
172
|
-
Utility::FONT_STYLES[font_type.to_sym].new(
|
173
|
-
iteration.last,
|
174
|
-
font_type,
|
175
|
-
)
|
176
|
-
else
|
177
|
-
Math::Function::FontStyle.new(iteration.last, font_type)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
rule(munder: sequence(:munder)) do
|
185
|
+
if munder.any?(String)
|
186
|
+
munder.each_with_index do |object, ind|
|
187
|
+
munder[ind] = Utility.mathml_unary_classes([object]) if object.is_a?(String)
|
178
188
|
end
|
189
|
+
end
|
190
|
+
if ["ubrace", "obrace"].any?(munder.last.class_name)
|
191
|
+
munder.last.parameter_one = munder.shift if munder.length > 1
|
192
|
+
munder.last
|
179
193
|
else
|
180
|
-
|
194
|
+
Math::Function::Underset.new(
|
195
|
+
munder[1],
|
196
|
+
munder[0],
|
197
|
+
)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
rule(mscarries: sequence(:scarries)) do
|
202
|
+
Math::Function::Scarries.new(
|
203
|
+
Utility.filter_values(scarries),
|
204
|
+
)
|
205
|
+
end
|
206
|
+
|
207
|
+
rule(mtext: sequence(:mtext)) do
|
208
|
+
entities = HTMLEntities.new
|
209
|
+
symbols = Constants::UNICODE_SYMBOLS.transform_keys(&:to_s)
|
210
|
+
text = entities.encode(mtext.first, :hexadecimal)
|
211
|
+
symbols.each do |code, string|
|
212
|
+
text.gsub!(code.downcase, "unicode[:#{string}]")
|
213
|
+
end
|
214
|
+
Math::Function::Text.new(text)
|
215
|
+
end
|
216
|
+
|
217
|
+
rule(ms: sequence(:ms)) do
|
218
|
+
entities = HTMLEntities.new
|
219
|
+
symbols = Constants::UNICODE_SYMBOLS.transform_keys(&:to_s)
|
220
|
+
text = entities.encode(ms.first, :hexadecimal)
|
221
|
+
symbols.each do |code, string|
|
222
|
+
text.gsub!(code.downcase, "unicode[:#{string}]")
|
181
223
|
end
|
224
|
+
Math::Function::Text.new(text)
|
225
|
+
end
|
226
|
+
|
227
|
+
rule(mfenced: sequence(:fenced)) do
|
228
|
+
Math::Function::Fenced.new(
|
229
|
+
Math::Symbol.new("("),
|
230
|
+
fenced,
|
231
|
+
Math::Symbol.new(")"),
|
232
|
+
)
|
233
|
+
end
|
234
|
+
|
235
|
+
rule(mmultiscripts: subtree(:script)) do
|
236
|
+
multi = Utility.multiscript(script.compact)
|
237
|
+
prescripts = multi[1]
|
238
|
+
Math::Function::Multiscript.new(
|
239
|
+
multi[0],
|
240
|
+
(prescripts[0] if prescripts),
|
241
|
+
(prescripts[1] if prescripts),
|
242
|
+
)
|
243
|
+
end
|
244
|
+
|
245
|
+
rule(mathcolor: simple(:color)) do
|
246
|
+
Math::Function::Color.new(
|
247
|
+
Math::Function::Text.new(color),
|
248
|
+
)
|
182
249
|
end
|
183
250
|
|
184
|
-
rule(
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
251
|
+
rule(open: simple(:lparen),
|
252
|
+
close: simple(:rparen)) do
|
253
|
+
Math::Function::Fenced.new(
|
254
|
+
Math::Symbol.new(lparen),
|
255
|
+
nil,
|
256
|
+
Math::Symbol.new(rparen),
|
257
|
+
)
|
258
|
+
end
|
191
259
|
|
192
|
-
|
193
|
-
|
260
|
+
rule(mathcolor: simple(:color),
|
261
|
+
mathvariant: simple(:variant)) do
|
262
|
+
variant_class = Utility::FONT_STYLES[variant.to_sym]
|
263
|
+
if variant_class
|
264
|
+
Math::Function::Color.new(
|
265
|
+
Math::Function::Text.new(
|
266
|
+
color,
|
267
|
+
),
|
268
|
+
variant_class.new(
|
269
|
+
nil,
|
270
|
+
variant,
|
271
|
+
),
|
272
|
+
)
|
194
273
|
else
|
195
|
-
|
274
|
+
Math::Function::Color.new(
|
275
|
+
Math::Function::Text.new(
|
276
|
+
color,
|
277
|
+
),
|
278
|
+
)
|
196
279
|
end
|
197
280
|
end
|
281
|
+
|
282
|
+
rule(attributes: simple(:attrs),
|
283
|
+
value: subtree(:value)) do
|
284
|
+
Utility.join_attr_value(attrs, value.flatten)
|
285
|
+
end
|
286
|
+
|
287
|
+
rule(attributes: subtree(:attrs),
|
288
|
+
value: sequence(:value)) do
|
289
|
+
Utility.join_attr_value(
|
290
|
+
attrs.is_a?(Hash) ? nil : attrs,
|
291
|
+
value.flatten,
|
292
|
+
)
|
293
|
+
end
|
198
294
|
end
|
199
295
|
end
|
200
296
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "constants"
|
4
3
|
require_relative "transform"
|
5
4
|
module Plurimath
|
6
5
|
class Omml
|
@@ -8,15 +7,36 @@ module Plurimath
|
|
8
7
|
attr_accessor :text
|
9
8
|
|
10
9
|
def initialize(text)
|
11
|
-
@text =
|
10
|
+
@text = text
|
12
11
|
end
|
13
12
|
|
14
13
|
def parse
|
15
|
-
nodes = Ox.load(text,
|
14
|
+
nodes = Ox.load(text, strip_namespace: true)
|
15
|
+
@hash = { sequence: parse_nodes(nodes.nodes) }
|
16
|
+
nodes = JSON.parse(@hash.to_json, symbolize_names: true)
|
16
17
|
Math::Formula.new(
|
17
|
-
Transform.new.apply(
|
18
|
+
Transform.new.apply(
|
19
|
+
nodes,
|
20
|
+
),
|
18
21
|
)
|
19
22
|
end
|
23
|
+
|
24
|
+
def parse_nodes(nodes)
|
25
|
+
nodes.map do |node|
|
26
|
+
if node.is_a?(String)
|
27
|
+
node
|
28
|
+
elsif !node.attributes.empty?
|
29
|
+
{
|
30
|
+
node.name => {
|
31
|
+
attributes: node.attributes,
|
32
|
+
value: parse_nodes(node.nodes),
|
33
|
+
},
|
34
|
+
}
|
35
|
+
else
|
36
|
+
{ node.name => parse_nodes(node.nodes) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
20
40
|
end
|
21
41
|
end
|
22
42
|
end
|