plurimath 0.1.0 → 0.2.1

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.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +33 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +2 -0
  5. data/AsciiMath-Supported-Data.adoc +280 -0
  6. data/Gemfile +1 -0
  7. data/Latex-Supported-Data.adoc +1872 -0
  8. data/MathML-Supported-Data.adoc +270 -0
  9. data/README.adoc +94 -0
  10. data/lib/plurimath/asciimath/constants.rb +301 -0
  11. data/lib/plurimath/asciimath/parse.rb +121 -0
  12. data/lib/plurimath/asciimath/parser.rb +25 -0
  13. data/lib/plurimath/asciimath/transform.rb +395 -0
  14. data/lib/plurimath/asciimath.rb +16 -0
  15. data/lib/plurimath/html/constants.rb +50 -0
  16. data/lib/plurimath/html/parse.rb +149 -0
  17. data/lib/plurimath/html/parser.rb +26 -0
  18. data/lib/plurimath/html/transform.rb +363 -0
  19. data/lib/plurimath/html.rb +15 -0
  20. data/lib/plurimath/latex/constants.rb +1990 -0
  21. data/lib/plurimath/latex/parse.rb +198 -0
  22. data/lib/plurimath/latex/parser.rb +25 -0
  23. data/lib/plurimath/latex/transform.rb +458 -0
  24. data/lib/plurimath/latex.rb +15 -0
  25. data/lib/plurimath/math/formula.rb +51 -0
  26. data/lib/plurimath/math/function/abs.rb +12 -0
  27. data/lib/plurimath/math/function/arccos.rb +12 -0
  28. data/lib/plurimath/math/function/arcsin.rb +12 -0
  29. data/lib/plurimath/math/function/arctan.rb +12 -0
  30. data/lib/plurimath/math/function/bar.rb +16 -0
  31. data/lib/plurimath/math/function/base.rb +36 -0
  32. data/lib/plurimath/math/function/binary_function.rb +58 -0
  33. data/lib/plurimath/math/function/cancel.rb +12 -0
  34. data/lib/plurimath/math/function/ceil.rb +12 -0
  35. data/lib/plurimath/math/function/color.rb +23 -0
  36. data/lib/plurimath/math/function/cos.rb +12 -0
  37. data/lib/plurimath/math/function/cosh.rb +12 -0
  38. data/lib/plurimath/math/function/cot.rb +12 -0
  39. data/lib/plurimath/math/function/coth.rb +12 -0
  40. data/lib/plurimath/math/function/csc.rb +12 -0
  41. data/lib/plurimath/math/function/csch.rb +12 -0
  42. data/lib/plurimath/math/function/ddot.rb +12 -0
  43. data/lib/plurimath/math/function/deg.rb +12 -0
  44. data/lib/plurimath/math/function/det.rb +12 -0
  45. data/lib/plurimath/math/function/dim.rb +12 -0
  46. data/lib/plurimath/math/function/dot.rb +12 -0
  47. data/lib/plurimath/math/function/exp.rb +12 -0
  48. data/lib/plurimath/math/function/f.rb +12 -0
  49. data/lib/plurimath/math/function/fenced.rb +27 -0
  50. data/lib/plurimath/math/function/floor.rb +12 -0
  51. data/lib/plurimath/math/function/font_style/bold.rb +18 -0
  52. data/lib/plurimath/math/function/font_style/double_struck.rb +18 -0
  53. data/lib/plurimath/math/function/font_style/fraktur.rb +18 -0
  54. data/lib/plurimath/math/function/font_style/monospace.rb +18 -0
  55. data/lib/plurimath/math/function/font_style/sans-serif.rb +18 -0
  56. data/lib/plurimath/math/function/font_style/script.rb +18 -0
  57. data/lib/plurimath/math/function/font_style.rb +25 -0
  58. data/lib/plurimath/math/function/frac.rb +23 -0
  59. data/lib/plurimath/math/function/g.rb +12 -0
  60. data/lib/plurimath/math/function/gcd.rb +12 -0
  61. data/lib/plurimath/math/function/glb.rb +12 -0
  62. data/lib/plurimath/math/function/hat.rb +12 -0
  63. data/lib/plurimath/math/function/hom.rb +12 -0
  64. data/lib/plurimath/math/function/inf.rb +17 -0
  65. data/lib/plurimath/math/function/int.rb +17 -0
  66. data/lib/plurimath/math/function/ker.rb +12 -0
  67. data/lib/plurimath/math/function/lcm.rb +12 -0
  68. data/lib/plurimath/math/function/left.rb +20 -0
  69. data/lib/plurimath/math/function/lg.rb +12 -0
  70. data/lib/plurimath/math/function/lim.rb +23 -0
  71. data/lib/plurimath/math/function/liminf.rb +12 -0
  72. data/lib/plurimath/math/function/limits.rb +18 -0
  73. data/lib/plurimath/math/function/limsup.rb +12 -0
  74. data/lib/plurimath/math/function/ln.rb +12 -0
  75. data/lib/plurimath/math/function/log.rb +29 -0
  76. data/lib/plurimath/math/function/lub.rb +12 -0
  77. data/lib/plurimath/math/function/max.rb +12 -0
  78. data/lib/plurimath/math/function/min.rb +12 -0
  79. data/lib/plurimath/math/function/mod.rb +29 -0
  80. data/lib/plurimath/math/function/multiscript.rb +11 -0
  81. data/lib/plurimath/math/function/norm.rb +16 -0
  82. data/lib/plurimath/math/function/obrace.rb +12 -0
  83. data/lib/plurimath/math/function/oint.rb +17 -0
  84. data/lib/plurimath/math/function/over.rb +29 -0
  85. data/lib/plurimath/math/function/overset.rb +23 -0
  86. data/lib/plurimath/math/function/power.rb +36 -0
  87. data/lib/plurimath/math/function/power_base.rb +33 -0
  88. data/lib/plurimath/math/function/prod.rb +29 -0
  89. data/lib/plurimath/math/function/right.rb +24 -0
  90. data/lib/plurimath/math/function/root.rb +23 -0
  91. data/lib/plurimath/math/function/sec.rb +12 -0
  92. data/lib/plurimath/math/function/sech.rb +12 -0
  93. data/lib/plurimath/math/function/sin.rb +12 -0
  94. data/lib/plurimath/math/function/sinh.rb +12 -0
  95. data/lib/plurimath/math/function/sqrt.rb +16 -0
  96. data/lib/plurimath/math/function/stackrel.rb +12 -0
  97. data/lib/plurimath/math/function/substack.rb +17 -0
  98. data/lib/plurimath/math/function/sum.rb +29 -0
  99. data/lib/plurimath/math/function/sup.rb +12 -0
  100. data/lib/plurimath/math/function/table/align.rb +24 -0
  101. data/lib/plurimath/math/function/table/array.rb +25 -0
  102. data/lib/plurimath/math/function/table/bmatrix.rb +26 -0
  103. data/lib/plurimath/math/function/table/matrix.rb +24 -0
  104. data/lib/plurimath/math/function/table/multline.rb +24 -0
  105. data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
  106. data/lib/plurimath/math/function/table/split.rb +24 -0
  107. data/lib/plurimath/math/function/table/vmatrix.rb +25 -0
  108. data/lib/plurimath/math/function/table.rb +54 -0
  109. data/lib/plurimath/math/function/tan.rb +12 -0
  110. data/lib/plurimath/math/function/tanh.rb +12 -0
  111. data/lib/plurimath/math/function/td.rb +32 -0
  112. data/lib/plurimath/math/function/ternary_function.rb +52 -0
  113. data/lib/plurimath/math/function/text.rb +44 -0
  114. data/lib/plurimath/math/function/tilde.rb +12 -0
  115. data/lib/plurimath/math/function/tr.rb +30 -0
  116. data/lib/plurimath/math/function/ubrace.rb +12 -0
  117. data/lib/plurimath/math/function/ul.rb +12 -0
  118. data/lib/plurimath/math/function/unary_function.rb +46 -0
  119. data/lib/plurimath/math/function/underover.rb +12 -0
  120. data/lib/plurimath/math/function/underset.rb +12 -0
  121. data/lib/plurimath/math/function/vec.rb +16 -0
  122. data/lib/plurimath/math/function.rb +14 -0
  123. data/lib/plurimath/math/number.rb +37 -0
  124. data/lib/plurimath/math/symbol.rb +43 -0
  125. data/lib/plurimath/math.rb +56 -0
  126. data/lib/plurimath/mathml/constants.rb +295 -0
  127. data/lib/plurimath/mathml/parse.rb +68 -0
  128. data/lib/plurimath/mathml/parser.rb +26 -0
  129. data/lib/plurimath/mathml/transform.rb +200 -0
  130. data/lib/plurimath/mathml.rb +16 -0
  131. data/lib/plurimath/omml/constants.rb +154 -0
  132. data/lib/plurimath/omml/parser.rb +22 -0
  133. data/lib/plurimath/omml/transform.rb +216 -0
  134. data/lib/plurimath/omml.rb +15 -0
  135. data/lib/plurimath/unicode.rb +15 -0
  136. data/lib/plurimath/unitsml.rb +15 -0
  137. data/lib/plurimath/utility.rb +73 -0
  138. data/lib/plurimath/version.rb +3 -1
  139. data/lib/plurimath.rb +3 -5
  140. data/plurimath.gemspec +4 -3
  141. metadata +169 -9
  142. data/README.md +0 -40
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ module Math
5
+ class Number
6
+ attr_accessor :value
7
+
8
+ def initialize(value)
9
+ @value = value
10
+ end
11
+
12
+ def ==(object)
13
+ object.value == value
14
+ end
15
+
16
+ def to_asciimath
17
+ value
18
+ end
19
+
20
+ def to_mathml_without_math_tag
21
+ "<mn>#{value}</mn>"
22
+ end
23
+
24
+ def to_latex
25
+ value
26
+ end
27
+
28
+ def to_html
29
+ value
30
+ end
31
+
32
+ def class_name
33
+ self.class.name.split("::").last.downcase
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ module Math
5
+ class Symbol
6
+ attr_accessor :value
7
+
8
+ def initialize(sym)
9
+ @value = sym
10
+ end
11
+
12
+ def ==(object)
13
+ object.value == value
14
+ end
15
+
16
+ def to_asciimath
17
+ symbol = Asciimath::Constants::SYMBOLS.invert[value.to_sym].to_s
18
+ symbol.empty? ? value : symbol
19
+ end
20
+
21
+ def to_mathml_without_math_tag
22
+ "<mo>#{mathml_symbol_value}</mo>"
23
+ end
24
+
25
+ def mathml_symbol_value
26
+ Mathml::Constants::UNICODE_SYMBOLS.invert[value] || value
27
+ end
28
+
29
+ def to_latex
30
+ symbols = Latex::Constants::SYMBOLS.invert
31
+ symbols.key?(value) ? "\\#{symbols[value]}" : value
32
+ end
33
+
34
+ def to_html
35
+ value
36
+ end
37
+
38
+ def class_name
39
+ self.class.name.split("::").last.downcase
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ox"
4
+ require_relative "unicode"
5
+ require_relative "asciimath"
6
+ require_relative "omml"
7
+ require_relative "mathml"
8
+ require_relative "html"
9
+ require_relative "latex"
10
+ require_relative "unitsml"
11
+ require_relative "math/formula"
12
+ require_relative "math/function"
13
+ require_relative "math/number"
14
+ require_relative "math/symbol"
15
+ require_relative "asciimath/parser"
16
+ require_relative "mathml/parser"
17
+ require_relative "latex/parser"
18
+ require_relative "html/parser"
19
+ require_relative "omml/parser"
20
+ require_relative "utility"
21
+ module Plurimath
22
+ module Math
23
+ class Error < StandardError; end
24
+
25
+ VALID_TYPES = {
26
+ omml: Omml,
27
+ html: Html,
28
+ latex: Latex,
29
+ mathml: Mathml,
30
+ unitsml: Unitsml,
31
+ unicode: Unicode,
32
+ asciimath: Asciimath,
33
+ }.freeze
34
+
35
+ def parse(text, type)
36
+ raise_error! unless valid_type?(type)
37
+
38
+ klass = VALID_TYPES[type.to_sym]
39
+ klass.new(text).to_formula
40
+ end
41
+
42
+ private
43
+
44
+ def raise_error!
45
+ raise Plurimath::Math::Error, Error.new("Type is not valid, "\
46
+ "please enter string or symbol")
47
+ end
48
+
49
+ def valid_type?(type)
50
+ (type.is_a?(::Symbol) || type.is_a?(String)) &&
51
+ VALID_TYPES.key?(type.to_sym)
52
+ end
53
+
54
+ module_function :parse, :raise_error!, :valid_type?
55
+ end
56
+ end
@@ -0,0 +1,295 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Mathml
5
+ class Constants
6
+ UNICODE_SYMBOLS = {
7
+ "&#x3B1;": "alpha",
8
+ "&#x3B2;": "beta",
9
+ "&#x3B3;": "gamma",
10
+ "&#x393;": "Gamma",
11
+ "&#x3B4;": "delta",
12
+ "&#x394;": "Delta",
13
+ "&#x2206;": "Delta",
14
+ "&#x3B5;": "epsilon",
15
+ "&#x25b;": "varepsilon",
16
+ "&#x3B6;": "zeta",
17
+ "&#x3B7;": "eta",
18
+ "&#x3B8;": "theta",
19
+ "&#x398;": "Theta",
20
+ "&#x3D1;": "vartheta",
21
+ "&#x3B9;": "iota",
22
+ "&#x3BA;": "kappa",
23
+ "&#x3BB;": "lambda",
24
+ "&#x39B;": "Lambda",
25
+ "&#x3BC;": "mu",
26
+ "&#x3BD;": "nu",
27
+ "&#x3BE;": "xi",
28
+ "&#x39E;": "Xi",
29
+ "&#x3C0;": "pi",
30
+ "&#x3A0;": "Pi",
31
+ "&#x3C1;": "rho",
32
+ "&#x3C2;": "beta",
33
+ "&#x3C3;": "sigma",
34
+ "&#x3A3;": "Sigma",
35
+ "&#x3C4;": "tau",
36
+ "&#x3C5;": "upsilon",
37
+ "&#x3C6;": "phi",
38
+ "&#x3A6;": "Phi",
39
+ "&#x3D5;": "varphi",
40
+ "&#x3C7;": "chi",
41
+ "&#x3C8;": "psi",
42
+ "&#x3A8;": "Psi",
43
+ "&#x3C9;": "omega",
44
+ "&#x3A9;": "omega",
45
+ "&#x22C5;": "dot",
46
+ "&#x2219;": "*",
47
+ "&#xB7;": ".",
48
+ "&#x2217;": "**",
49
+ "&#x22C6;": "***",
50
+ "&#xD7;": "xx",
51
+ "&#x22C9;": "|><",
52
+ "&#x22CA;": "><|",
53
+ "&#x22C8;": "|><|",
54
+ "&#xF7;": "-:",
55
+ "&#x2218;": "@",
56
+ "&#x2295;": "o+",
57
+ "&#x2A01;": "o+",
58
+ "&#x2297;": "ox",
59
+ "&#x2299;": " ",
60
+ "&#x2211;": "sum",
61
+ "&#x220F;": "prod",
62
+ "&#x220f;": "prod",
63
+ "&#x2227;": "^^",
64
+ "&#x22C0;": "^^^",
65
+ "&#x2228;": "vv",
66
+ "&#x22c1;": "vvv",
67
+ "&#x2229;": "nn",
68
+ "&#x22C2;": "nnn",
69
+ "&#x222A;": "cup",
70
+ "&#x22C3;": "uuu",
71
+ "&#x2260;": "!=",
72
+ "&#x2264;": "<=",
73
+ "&#x2265;": ">=",
74
+ "&#x227A;": "-<",
75
+ "&#x227B;": ">-",
76
+ "&#x2AAF;": "-<=",
77
+ "&#x2AB0;": " >-=",
78
+ "&#x2208;": "in",
79
+ "&#x2209;": "!in",
80
+ "&#x2282;": "sub",
81
+ "&#x2283;": "sup",
82
+ "&#x2286;": "sube",
83
+ "&#x2287;": "supe",
84
+ "&#x2261;": "-=",
85
+ "&#x2245;": "~=",
86
+ "&#x2248;": "~~",
87
+ "&#x221D;": "prop",
88
+ "&#xAC;": "not",
89
+ "&#x2200;": "AA",
90
+ "&#x2203;": "EE",
91
+ "&#x22A5;": "_|_",
92
+ "&#x22A4;": "TT",
93
+ "&#x22A2;": "|--",
94
+ "&#x22A8;": "|==",
95
+ "&#x2329;": "(:",
96
+ "&#x232A;": ":)",
97
+ "&#x27E8;": "<<",
98
+ "&#x27E9;": ">>",
99
+ "&#x222B;": "int",
100
+ "&#x222E;": "oint",
101
+ "&#x2202;": "del",
102
+ "&#x2207;": "grad",
103
+ "&#xB1;": "+-",
104
+ "&#x2205;": "O/",
105
+ "&#x221E;": "oo",
106
+ "&#x2135;": "aleph",
107
+ "&#x2234;": ":.",
108
+ "&#x2235;": ":'",
109
+ "&#x2220;": "/_",
110
+ "&#x25B3;": "/_\\",
111
+ "&#x2032;": "'",
112
+ "&#xA0;&#xA0;": "quad",
113
+ "&#xA0;&#xA0;&#xA0;&#xA0;": "qquad",
114
+ "&#x2322;": "frown",
115
+ "&#x22EF;": "cdots",
116
+ "&#x22EE;": "vdots",
117
+ "&#x22F1;": "ddots",
118
+ "&#x22C4;": "diamond",
119
+ "&#x25A1;": "square",
120
+ "&#x230A;": "|__",
121
+ "&#x230B;": "__|",
122
+ "&#x2308;": "|~",
123
+ "&#x2309;": "~|",
124
+ "&#x2102;": "CC",
125
+ "&#x2115;": "NN",
126
+ "&#x211A;": "QQ",
127
+ "&#x211D;": "RR",
128
+ "&#x2124;": "ZZ",
129
+ "&#x2191;": "uarr",
130
+ "&#x2193;": "darr",
131
+ "&#x2190;": "larr",
132
+ "&#x2194;": "harr",
133
+ "&#x21D2;": "rArr",
134
+ "&#x21D0;": "lArr",
135
+ "&#x21D4;": "hArr",
136
+ "&#x2192;": "->",
137
+ "&#x21A3;": ">->",
138
+ "&#x21A0;": "->>",
139
+ "&#x2916;": ">->>",
140
+ "&#x21A6;": "|->",
141
+ "&#x2026;": "...",
142
+ "&#x2212;": "-",
143
+ "&#x2061;": "",
144
+ "&#x23DE;": "obrace",
145
+ "&#x23DF;": "ubrace",
146
+ }.freeze
147
+ SYMBOLS = {
148
+ "|": "|",
149
+ "/": "//",
150
+ "\\": "\\\\",
151
+ "~": "tilde",
152
+ "(": "(",
153
+ ")": ")",
154
+ "(:": "(:",
155
+ ":)": ":)",
156
+ "{": "{",
157
+ "}": "}",
158
+ "{:": "{:",
159
+ ":}": ":}",
160
+ "]": "]",
161
+ "[": "[",
162
+ "=": "=",
163
+ "+": "+",
164
+ "-": "-",
165
+ }.freeze
166
+ CLASSES = %w[
167
+ mathfrak
168
+ underset
169
+ stackrel
170
+ overset
171
+ mathcal
172
+ arccos
173
+ arcsin
174
+ arctan
175
+ mathsf
176
+ mathbb
177
+ mathbf
178
+ mathtt
179
+ ubrace
180
+ obrace
181
+ cancel
182
+ tilde
183
+ floor
184
+ color
185
+ frac
186
+ root
187
+ oint
188
+ ceil
189
+ ddot
190
+ coth
191
+ csch
192
+ sech
193
+ sinh
194
+ tanh
195
+ cosh
196
+ sqrt
197
+ norm
198
+ text
199
+ prod
200
+ sec
201
+ int
202
+ sin
203
+ tan
204
+ cos
205
+ sum
206
+ exp
207
+ gcd
208
+ glb
209
+ lcm
210
+ lub
211
+ cot
212
+ csc
213
+ det
214
+ dim
215
+ max
216
+ min
217
+ abs
218
+ bar
219
+ dot
220
+ hat
221
+ vec
222
+ mod
223
+ log
224
+ ul
225
+ ln
226
+ f
227
+ g
228
+ ].freeze
229
+ TAGS = %i[
230
+ annotation-xml
231
+ annotation_xml
232
+ mmultiscripts
233
+ maligngroup
234
+ malignmark
235
+ annotation
236
+ munderover
237
+ mscarries
238
+ semantics
239
+ mphantom
240
+ mlongdiv
241
+ menclose
242
+ mscarry
243
+ msubsup
244
+ mpadded
245
+ maction
246
+ msgroup
247
+ mfenced
248
+ merror
249
+ munder
250
+ mtable
251
+ mstyle
252
+ mstack
253
+ mspace
254
+ msline
255
+ mfrac
256
+ mover
257
+ msrow
258
+ mroot
259
+ msqrt
260
+ msup
261
+ msub
262
+ mrow
263
+ math
264
+ mtr
265
+ mtd
266
+ ms
267
+ mi
268
+ mo
269
+ mn
270
+ ].freeze
271
+ BINARY_CLASSES = %i[
272
+ underset
273
+ stackrel
274
+ overset
275
+ color
276
+ prod
277
+ frac
278
+ root
279
+ oint
280
+ int
281
+ sum
282
+ mod
283
+ log
284
+ ].freeze
285
+ FONT_CLASSES = %i[
286
+ double-struck
287
+ sans-serif
288
+ monospace
289
+ fraktur
290
+ script
291
+ bold
292
+ ].freeze
293
+ end
294
+ end
295
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+ module Plurimath
5
+ class Mathml
6
+ class Parse < Parslet::Parser
7
+ rule(:parse_record) do
8
+ array_to_expression(Constants::CLASSES).as(:class) |
9
+ array_to_expression(Constants::UNICODE_SYMBOLS.keys).as(:symbol) |
10
+ array_to_expression(Constants::SYMBOLS.keys).as(:symbol) |
11
+ match["a-zA-Z"].repeat(1).as(:text) |
12
+ match(/[0-9]/).repeat(1).as(:number) |
13
+ str("")
14
+ end
15
+
16
+ rule(:tag) do
17
+ (parse_tag(:open) >> iteration.as(:iteration) >> parse_tag(:close)).as(:tag) |
18
+ parse_text_tag.as(:tag)
19
+ end
20
+
21
+ rule(:sequence) { (tag >> sequence.as(:sequence)) | tag }
22
+
23
+ rule(:iteration) { (sequence >> iteration.as(:iteration)) | parse_record }
24
+
25
+ rule(:expression) do
26
+ parse_tag(:open) >> iteration.as(:iteration) >> parse_tag(:close)
27
+ end
28
+
29
+ root :expression
30
+
31
+ def array_to_expression(array, name = nil)
32
+ initial_type = array.first.class
33
+ array.reduce do |expr, tag|
34
+ expr = str_to_expression(expr, name) if expr.is_a?(initial_type)
35
+ expr | str_to_expression(tag, name)
36
+ end
37
+ end
38
+
39
+ def str_to_expression(string, name)
40
+ return str(string) if name.nil?
41
+
42
+ str(string).as(name)
43
+ end
44
+
45
+ def parse_tag(opts)
46
+ tag = str("<")
47
+ tag = tag >> str("/") if opts == :close
48
+ tag = tag >> array_to_expression(Constants::TAGS, opts)
49
+ tag = tag >> attributes.as(:attributes) if opts == :open
50
+ tag >> str(">")
51
+ end
52
+
53
+ def attributes
54
+ (match["a-zA-Z"].repeat.as(:name) >>
55
+ str("=") >> quoted_string).repeat
56
+ end
57
+
58
+ def quoted_string
59
+ (str('"') >> match("[^\"]").repeat.as(:value) >> str('"')) |
60
+ (str("'") >> match("[^\']").repeat.as(:value) >> str("'"))
61
+ end
62
+
63
+ def parse_text_tag
64
+ str("<mtext>") >> match("[^<]").repeat.as(:quoted_text) >> str("</mtext>")
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "parse"
4
+ require_relative "constants"
5
+ require_relative "transform"
6
+ module Plurimath
7
+ class Mathml
8
+ class Parser
9
+ attr_accessor :text
10
+
11
+ def initialize(text)
12
+ @text = text.gsub(/\s/, "")
13
+ end
14
+
15
+ def parse
16
+ tree_t = Plurimath::Mathml::Parse.new.parse(text)
17
+ tree_t = JSON.parse(tree_t.to_json, symbolize_names: true)
18
+ formula = Plurimath::Mathml::Transform.new.apply(tree_t)
19
+ formula = [formula] unless formula.is_a?(Array) || formula.nil?
20
+ return if formula.nil?
21
+
22
+ Plurimath::Math::Formula.new(formula)
23
+ end
24
+ end
25
+ end
26
+ end