plurimath 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +8 -11
  3. data/.gitignore +1 -0
  4. data/AsciiMath-Supported-Data.adoc +280 -0
  5. data/Gemfile +1 -0
  6. data/Latex-Supported-Data.adoc +1872 -0
  7. data/MathML-Supported-Data.adoc +270 -0
  8. data/README.adoc +94 -0
  9. data/lib/plurimath/asciimath/constants.rb +215 -222
  10. data/lib/plurimath/asciimath/parse.rb +45 -11
  11. data/lib/plurimath/asciimath/parser.rb +4 -3
  12. data/lib/plurimath/asciimath/transform.rb +222 -131
  13. data/lib/plurimath/asciimath.rb +1 -1
  14. data/lib/plurimath/html/constants.rb +50 -0
  15. data/lib/plurimath/html/parse.rb +149 -0
  16. data/lib/plurimath/html/parser.rb +26 -0
  17. data/lib/plurimath/html/transform.rb +363 -0
  18. data/lib/plurimath/html.rb +1 -1
  19. data/lib/plurimath/latex/constants.rb +1885 -1858
  20. data/lib/plurimath/latex/parse.rb +127 -34
  21. data/lib/plurimath/latex/parser.rb +5 -4
  22. data/lib/plurimath/latex/transform.rb +324 -164
  23. data/lib/plurimath/math/formula.rb +9 -1
  24. data/lib/plurimath/math/function/bar.rb +1 -1
  25. data/lib/plurimath/math/function/base.rb +7 -1
  26. data/lib/plurimath/math/function/binary_function.rb +10 -5
  27. data/lib/plurimath/math/function/color.rb +4 -4
  28. data/lib/plurimath/math/function/fenced.rb +7 -2
  29. data/lib/plurimath/math/function/font_style/bold.rb +18 -0
  30. data/lib/plurimath/math/function/font_style/double_struck.rb +18 -0
  31. data/lib/plurimath/math/function/font_style/fraktur.rb +18 -0
  32. data/lib/plurimath/math/function/font_style/monospace.rb +18 -0
  33. data/lib/plurimath/math/function/font_style/sans-serif.rb +18 -0
  34. data/lib/plurimath/math/function/font_style/script.rb +18 -0
  35. data/lib/plurimath/math/function/font_style.rb +2 -22
  36. data/lib/plurimath/math/function/frac.rb +4 -4
  37. data/lib/plurimath/math/function/inf.rb +0 -1
  38. data/lib/plurimath/math/function/left.rb +3 -6
  39. data/lib/plurimath/math/function/limits.rb +0 -1
  40. data/lib/plurimath/math/function/log.rb +6 -0
  41. data/lib/plurimath/math/function/mod.rb +6 -0
  42. data/lib/plurimath/math/function/multiscript.rb +11 -0
  43. data/lib/plurimath/math/function/norm.rb +2 -1
  44. data/lib/plurimath/math/function/over.rb +29 -0
  45. data/lib/plurimath/math/function/overset.rb +2 -2
  46. data/lib/plurimath/math/function/power.rb +7 -1
  47. data/lib/plurimath/math/function/power_base.rb +14 -7
  48. data/lib/plurimath/math/function/prod.rb +6 -0
  49. data/lib/plurimath/math/function/right.rb +24 -0
  50. data/lib/plurimath/math/function/root.rb +5 -4
  51. data/lib/plurimath/math/function/sqrt.rb +1 -1
  52. data/lib/plurimath/math/function/substack.rb +0 -1
  53. data/lib/plurimath/math/function/sum.rb +6 -0
  54. data/lib/plurimath/math/function/table/align.rb +24 -0
  55. data/lib/plurimath/math/function/table/array.rb +25 -0
  56. data/lib/plurimath/math/function/table/bmatrix.rb +26 -0
  57. data/lib/plurimath/math/function/table/matrix.rb +24 -0
  58. data/lib/plurimath/math/function/table/multline.rb +24 -0
  59. data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
  60. data/lib/plurimath/math/function/table/split.rb +24 -0
  61. data/lib/plurimath/math/function/table/vmatrix.rb +25 -0
  62. data/lib/plurimath/math/function/table.rb +17 -5
  63. data/lib/plurimath/math/function/td.rb +6 -1
  64. data/lib/plurimath/math/function/ternary_function.rb +16 -6
  65. data/lib/plurimath/math/function/text.rb +19 -7
  66. data/lib/plurimath/math/function/tr.rb +6 -1
  67. data/lib/plurimath/math/function/unary_function.rb +5 -0
  68. data/lib/plurimath/math/function/vec.rb +4 -0
  69. data/lib/plurimath/math/function.rb +13 -2
  70. data/lib/plurimath/math/number.rb +8 -0
  71. data/lib/plurimath/math/symbol.rb +12 -3
  72. data/lib/plurimath/math.rb +9 -4
  73. data/lib/plurimath/mathml/constants.rb +2 -34
  74. data/lib/plurimath/mathml/parse.rb +7 -2
  75. data/lib/plurimath/mathml/parser.rb +2 -1
  76. data/lib/plurimath/mathml/transform.rb +73 -68
  77. data/lib/plurimath/mathml.rb +1 -1
  78. data/lib/plurimath/omml/constants.rb +154 -0
  79. data/lib/plurimath/omml/parser.rb +22 -0
  80. data/lib/plurimath/omml/transform.rb +216 -0
  81. data/lib/plurimath/omml.rb +1 -1
  82. data/lib/plurimath/unitsml.rb +4 -0
  83. data/lib/plurimath/utility.rb +73 -0
  84. data/lib/plurimath/version.rb +1 -1
  85. data/plurimath.gemspec +1 -0
  86. metadata +49 -7
  87. data/README.md +0 -40
@@ -5,19 +5,29 @@ module Plurimath
5
5
  class Transform < Parslet::Transform
6
6
  rule(tag: simple(:tag)) { tag }
7
7
  rule(tag: sequence(:tag)) { tag }
8
- rule(text: simple(:text)) { Plurimath::Math::Symbol.new(text.to_s) }
9
- rule(class: simple(:string)) { Transform.get_class(string).new }
10
- rule(number: simple(:number)) { Plurimath::Math::Number.new(number.to_s) }
11
- rule(tag: sequence(:tag), sequence: simple(:sequence)) { tag + [sequence] }
12
- rule(tag: simple(:tag), sequence: sequence(:sequence)) { [tag] + sequence }
13
- rule(tag: sequence(:tag), sequence: sequence(:sequence)) { tag + sequence }
8
+ rule(text: simple(:text)) { Math::Symbol.new(text) }
9
+ rule(class: simple(:string)) { Utility.get_class(string).new }
10
+ rule(number: simple(:number)) { Math::Number.new(number) }
11
+
12
+ rule(tag: sequence(:tag), sequence: simple(:sequence)) do
13
+ tag + [sequence]
14
+ end
15
+
16
+ rule(tag: simple(:tag), sequence: sequence(:sequence)) do
17
+ [tag] + sequence
18
+ end
19
+
20
+ rule(tag: sequence(:tag), sequence: sequence(:sequence)) do
21
+ tag + sequence
22
+ end
14
23
 
15
24
  rule(quoted_text: simple(:quoted_text)) do
16
- text = quoted_text.to_s
17
- Constants::UNICODE_SYMBOLS.each do |code, string|
18
- text.gsub!(code.to_s, "unicode[:#{string}]")
25
+ text = quoted_text
26
+ symbols = Constants::UNICODE_SYMBOLS.transform_keys(&:to_s)
27
+ symbols.each do |code, string|
28
+ text.gsub!(code, "unicode[:#{string}]")
19
29
  end
20
- Plurimath::Math::Function::Text.new(text)
30
+ Math::Function::Text.new(text)
21
31
  end
22
32
 
23
33
  rule(
@@ -37,7 +47,7 @@ module Plurimath
37
47
  sequence: simple(:sequence),
38
48
  iteration: simple(:iteration),
39
49
  ) do
40
- Plurimath::Math::Formula.new(tag + [sequence])
50
+ Math::Formula.new(tag + [sequence, iteration])
41
51
  end
42
52
 
43
53
  rule(
@@ -45,7 +55,7 @@ module Plurimath
45
55
  sequence: simple(:sequence),
46
56
  iteration: simple(:iteration),
47
57
  ) do
48
- [tag, sequence]
58
+ iteration.size.zero? ? [tag, sequence] : [tag, sequence, iteration]
49
59
  end
50
60
 
51
61
  rule(tag: sequence(:tag), iteration: simple(:iteration)) do
@@ -72,21 +82,21 @@ module Plurimath
72
82
  rule(symbol: simple(:symbol)) do
73
83
  decoded_symbol = Constants::UNICODE_SYMBOLS[symbol.to_sym]
74
84
  if Constants::CLASSES.include?(decoded_symbol)
75
- [Transform.get_class(decoded_symbol).new]
85
+ [Utility.get_class(decoded_symbol).new]
76
86
  elsif decoded_symbol.nil? && Constants::SYMBOLS[symbol.to_sym]
77
- Plurimath::Math::Symbol.new(Constants::SYMBOLS[symbol.to_sym])
87
+ Math::Symbol.new(Constants::SYMBOLS[symbol.to_sym])
78
88
  else
79
- Plurimath::Math::Symbol.new(decoded_symbol)
89
+ Math::Symbol.new(decoded_symbol)
80
90
  end
81
91
  end
82
92
 
83
93
  rule(name: simple(:name), value: simple(:value)) do
84
- if ["open", "close"].include?(name.to_s)
85
- Plurimath::Math::Symbol.new(value.to_s)
86
- elsif name.to_s == "mathcolor"
87
- Plurimath::Math::Function::Color.new(value.to_s)
88
- elsif name.to_s == "mathvariant"
89
- value.to_s
94
+ if ["open", "close"].include?(name)
95
+ Math::Symbol.new(value)
96
+ elsif name == "mathcolor"
97
+ Math::Function::Color.new(value)
98
+ elsif name == "mathvariant"
99
+ value
90
100
  end
91
101
  end
92
102
 
@@ -95,15 +105,10 @@ module Plurimath
95
105
  sequence: sequence(:sequence),
96
106
  iteration: simple(:iteration),
97
107
  ) do
98
- tag_str = tag.to_s.split("::").last.downcase.to_sym
99
- if Constants::BINARY_CLASSES.include?(tag_str)
100
- tag.new(sequence.first, sequence.last)
101
- else
102
- new_arr = sequence.compact
103
- new_arr = [tag] + new_arr unless tag.nil?
104
- new_arr << iteration unless iteration.to_s.empty?
105
- new_arr
106
- end
108
+ new_arr = sequence.compact
109
+ new_arr = [tag] + new_arr unless tag.nil?
110
+ new_arr << iteration unless iteration.to_s.empty?
111
+ new_arr
107
112
  end
108
113
 
109
114
  rule(
@@ -112,53 +117,64 @@ module Plurimath
112
117
  iteration: sequence(:iteration),
113
118
  close: simple(:close_tag),
114
119
  ) do
115
- Transform.raise_error!(open_tag, close_tag) unless open_tag == close_tag
120
+ Utility.raise_error!(open_tag, close_tag) unless open_tag == close_tag
116
121
 
117
122
  if open_tag == "mrow"
118
- Plurimath::Math::Formula.new(iteration)
123
+ Math::Formula.new(iteration)
119
124
  elsif open_tag == "munder"
120
- if Transform.get_class("obrace") == iteration.last.class
125
+ if iteration.last.class_name == "obrace"
121
126
  iteration.last.parameter_one = iteration.first
122
127
  iteration.last
123
128
  else
124
- Plurimath::Math::Function::Underset.new(iteration[1], iteration[0])
129
+ Math::Function::Underset.new(iteration[1], iteration[0])
125
130
  end
126
131
  elsif open_tag == "munderover"
127
- Plurimath::Math::Function::Underover.new(iteration[0], iteration[1], iteration[2])
132
+ Utility.get_class(open_tag.delete_prefix("m")).new(
133
+ iteration[0],
134
+ iteration[1],
135
+ iteration[2],
136
+ )
128
137
  elsif open_tag == "mover"
129
- if Transform.get_class("ubrace") == iteration.last.class
138
+ if iteration.last.class_name == "ubrace"
130
139
  iteration.last.parameter_one = iteration.first
131
140
  iteration.last
132
141
  else
133
- Plurimath::Math::Function::Overset.new(iteration[1], iteration[0])
142
+ Math::Function::Overset.new(iteration[1], iteration[0])
134
143
  end
135
- elsif open_tag == "msup"
136
- Plurimath::Math::Function::Power.new(iteration[0], iteration[1])
137
- elsif open_tag == "msub"
138
- Plurimath::Math::Function::Base.new(iteration[0], iteration[1])
144
+ elsif ["msub", "msup"].include?(open_tag)
145
+ tag = (open_tag == "msup" ? "power" : "base")
146
+ Utility.get_class(tag).new(iteration[0], iteration[1])
139
147
  elsif open_tag == "msubsup"
140
- Plurimath::Math::Function::PowerBase.new(iteration[0], iteration[1], iteration[2])
148
+ Math::Function::PowerBase.new(iteration[0],
149
+ iteration[1],
150
+ iteration[2])
141
151
  elsif open_tag == "mfrac"
142
- Plurimath::Math::Function::Frac.new(iteration.first, iteration.last)
152
+ Math::Function::Frac.new(iteration.first, iteration.last)
143
153
  elsif open_tag == "msqrt"
144
- Plurimath::Math::Function::Sqrt.new(iteration.first)
154
+ Math::Function::Sqrt.new(iteration.first)
145
155
  elsif open_tag == "mroot"
146
- Plurimath::Math::Function::Root.new(iteration[0], iteration[1])
156
+ Math::Function::Root.new(iteration[0], iteration[1])
147
157
  elsif open_tag == "mfenced"
148
- Plurimath::Math::Function::Fenced.new(attributes[0], iteration, attributes[1])
149
- elsif open_tag == "mtable"
150
- Plurimath::Math::Function::Table.new(iteration)
151
- elsif open_tag == "mtr"
152
- Plurimath::Math::Function::Tr.new(iteration)
153
- elsif open_tag == "mtd"
154
- Plurimath::Math::Function::Td.new(iteration)
155
- elsif attributes.first.is_a?(Plurimath::Math::Function::Color)
158
+ Math::Function::Fenced.new(
159
+ attributes[0],
160
+ iteration,
161
+ attributes[1],
162
+ )
163
+ elsif ["mtr", "mtd", "mtable"].include?(open_tag)
164
+ tag = open_tag.delete_prefix("m")
165
+ Utility.get_class(tag).new(iteration)
166
+ elsif attributes.first.is_a?(Math::Function::Color)
156
167
  attributes.first.parameter_two = iteration.first
157
168
  attributes.first
158
169
  elsif open_tag == "mstyle" && !attributes.compact.empty?
159
- font_type = attributes.compact.last.to_sym
160
- if Constants::FONT_CLASSES.include?(font_type)
161
- Math::Function::FontStyle.new(iteration.last, font_type.to_s)
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)
162
178
  end
163
179
  else
164
180
  iteration
@@ -171,7 +187,7 @@ module Plurimath
171
187
  iteration: simple(:iteration),
172
188
  close: simple(:close_tag),
173
189
  ) do
174
- Transform.raise_error!(open_tag, close_tag) unless open_tag == close_tag
190
+ Utility.raise_error!(open_tag, close_tag) unless open_tag == close_tag
175
191
 
176
192
  if iteration.to_s.include?("Function")
177
193
  iteration
@@ -179,17 +195,6 @@ module Plurimath
179
195
  [iteration.to_s.empty? ? nil : iteration]
180
196
  end
181
197
  end
182
-
183
- def self.get_class(text)
184
- Object.const_get("Plurimath::Math::Function::#{text.to_s.capitalize}")
185
- end
186
-
187
- def self.raise_error!(open_tag, close_tag)
188
- message = "Please check your input."\
189
- " Opening tag is \"#{open_tag}\""\
190
- " and closing tag is \"#{close_tag}\""
191
- raise Plurimath::Math::Error.new(message)
192
- end
193
198
  end
194
199
  end
195
200
  end
@@ -10,7 +10,7 @@ module Plurimath
10
10
  end
11
11
 
12
12
  def to_formula
13
- Plurimath::Mathml::Parser.new(text).parse
13
+ Parser.new(text).parse
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,154 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Omml
5
+ class Constants
6
+ TAGS = %w[
7
+ lastRenderedPageBreak
8
+ oMathParaPr
9
+ borderBoxPr
10
+ wrapIndent
11
+ strikeTLBR
12
+ strikeBLTR
13
+ groupChrPr
14
+ wrapRight
15
+ smallFrac
16
+ oMathPara
17
+ hideRight
18
+ brkBinSub
19
+ borderBox
20
+ sSubSupPr
21
+ zeroDesc
22
+ mathFont
23
+ limUppPr
24
+ limLowPr
25
+ hideLeft
26
+ groupChr
27
+ zeroWid
28
+ zeroAsc
29
+ strikeV
30
+ strikeH
31
+ rSpRule
32
+ rMargin
33
+ plcHide
34
+ phantPr
35
+ objDist
36
+ noBreak
37
+ naryLim
38
+ maxDist
39
+ lMargin
40
+ intraSp
41
+ interSp
42
+ hideTop
43
+ hideBot
44
+ eqArrPr
45
+ dispDef
46
+ degHide
47
+ cGpRule
48
+ supHide
49
+ subHide
50
+ vertJc
51
+ transp
52
+ sSupPr
53
+ sSubPr
54
+ sepChr
55
+ postSp
56
+ naryPr
57
+ mathPr
58
+ limUpp
59
+ limLow
60
+ rFonts
61
+ limLoc
62
+ intLim
63
+ funcPr
64
+ endChr
65
+ ctrlPr
66
+ brkBin
67
+ begChr
68
+ baseJc
69
+ alnScr
70
+ sPrePr
71
+ radPr
72
+ preSp
73
+ phant
74
+ opEmu
75
+ oMath
76
+ fName
77
+ eqArr
78
+ defJc
79
+ count
80
+ boxPr
81
+ barPr
82
+ argSz
83
+ argPr
84
+ accPr
85
+ type
86
+ show
87
+ mcPr
88
+ mcJc
89
+ grow
90
+ diff
91
+ sty
92
+ shp
93
+ scr
94
+ rSp
95
+ rPr
96
+ sup
97
+ sub
98
+ pos
99
+ num
100
+ nor
101
+ mPr
102
+ mcs
103
+ lit
104
+ lim
105
+ fPr
106
+ dPr
107
+ den
108
+ deg
109
+ cSp
110
+ chr
111
+ cGp
112
+ brk
113
+ box
114
+ bar
115
+ aln
116
+ mr
117
+ mc
118
+ jc
119
+ t
120
+ r
121
+ i
122
+ m
123
+ e
124
+ ].freeze
125
+ SUB_SUP_TAG = %w[
126
+ sSubSup
127
+ func
128
+ sPre
129
+ sSup
130
+ sSub
131
+ nary
132
+ acc
133
+ rad
134
+ f
135
+ d
136
+ ].freeze
137
+ UNARY_FUNCTIONS = %w[
138
+ arcsin
139
+ arctan
140
+ arccos
141
+ coth
142
+ tanh
143
+ sinh
144
+ cosh
145
+ tan
146
+ cos
147
+ cot
148
+ csc
149
+ sin
150
+ sec
151
+ ].freeze
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "constants"
4
+ require_relative "transform"
5
+ module Plurimath
6
+ class Omml
7
+ class Parser
8
+ attr_accessor :text
9
+
10
+ def initialize(text)
11
+ @text = CGI.unescape(text)
12
+ end
13
+
14
+ def parse
15
+ nodes = Ox.load(text, mode: :hash, strip_namespace: true)
16
+ Math::Formula.new(
17
+ Transform.new.apply(nodes),
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+ module Plurimath
5
+ class Omml
6
+ class Transform < Parslet::Transform
7
+ rule(r: simple(:r)) { r }
8
+ rule(f: simple(:f)) { f }
9
+ rule(d: simple(:d)) { Math::Function::Fenced.new(nil, [d], nil) }
10
+ rule(val: simple(:val)) { val }
11
+ rule(box: simple(:box)) { box }
12
+ rule(rPr: simple(:rpr)) { nil }
13
+ rule(rad: simple(:rad)) { rad }
14
+ rule(sSub: simple(:sub)) { sub }
15
+ rule(eqArr: simple(:arr)) { arr }
16
+ rule(nary: simple(:nary)) { nary }
17
+ rule(sSup: simple(:sSup)) { sSup }
18
+ rule(sPre: simple(:sPre)) { sPre }
19
+ rule(ctrlPr: simple(:ctrlPr)) { nil }
20
+ rule(argSz: sequence(:argsz)) { nil }
21
+ rule(rFonts: sequence(:fonts)) { nil }
22
+ rule(sSubSup: simple(:sSubSup)) { sSubSup }
23
+ rule(oMathPara: subtree(:omath)) { omath.drop(1) }
24
+ rule(rPr: simple(:rpr), i: simple(:i)) { nil }
25
+ rule(dPr: simple(:dpr), e: simple(:e)) { e }
26
+ rule(dPr: simple(:dpr), e: sequence(:e)) { e }
27
+ rule(boxPr: simple(:boxpr), e: simple(:e)) { e }
28
+ rule(argPr: simple(:argPr), f: simple(:f)) { f }
29
+ rule(rFonts: sequence(:fonts), i: simple(:i)) { nil }
30
+ rule(type: sequence(:type), ctrlPr: simple(:ctrl)) { nil }
31
+ rule(ascii: simple(:ascii), hAnsi: simple(:hansi)) { nil }
32
+ rule(diff: sequence(:diff), ctrlPr: simple(:ctrl)) { nil }
33
+ rule(limLoc: sequence(:limloc), ctrlPr: simple(:ctrl)) { limloc }
34
+ rule(degHide: sequence(:degHide), ctrlPr: simple(:ctrl)) { nil }
35
+
36
+ rule(oMath: subtree(:omath)) do
37
+ omath.is_a?(Array) ? omath.drop(1) : omath
38
+ end
39
+
40
+ rule(d: sequence(:d)) do
41
+ open_paren = d.shift if d.first.class_name == "symbol"
42
+ close_paren = d.pop if d.last.class_name == "symbol"
43
+ Math::Function::Fenced.new(
44
+ open_paren,
45
+ d,
46
+ close_paren,
47
+ )
48
+ end
49
+
50
+ rule(dPr: sequence(:dpr),
51
+ e: simple(:e)) do
52
+ [
53
+ dpr[0],
54
+ e,
55
+ dpr[1],
56
+ ]
57
+ end
58
+
59
+ rule(sSub: sequence(:sub), r: simple(:r)) do
60
+ [
61
+ Math::Formula.new(
62
+ sub.insert(1, r),
63
+ ),
64
+ ]
65
+ end
66
+
67
+ rule(rPr: simple(:rpr), t: subtree(:t)) do
68
+ Math::Function::Text.new(t.last)
69
+ end
70
+
71
+ rule(r: simple(:r), d: simple(:d)) do
72
+ Math::Formula.new(
73
+ [
74
+ r,
75
+ d,
76
+ ],
77
+ )
78
+ end
79
+
80
+ rule(eqArrPr: simple(:aqArrPr), e: sequence(:e)) do
81
+ table_value = []
82
+ e.each do |value|
83
+ table_value << Math::Function::Tr.new(
84
+ [
85
+ Math::Function::Td.new(
86
+ [
87
+ value,
88
+ ],
89
+ ),
90
+ ],
91
+ )
92
+ end
93
+ Math::Function::Table.new(table_value)
94
+ end
95
+
96
+ rule(rPr: simple(:rpr),
97
+ t: simple(:text)) do
98
+ if text.scan(/[[:digit:]]/).length == text.length
99
+ Math::Number.new(text)
100
+ elsif text.match?(/[[:alpha:]]/)
101
+ Math::Function::Text.new(text)
102
+ else
103
+ Math::Symbol.new(text)
104
+ end
105
+ end
106
+
107
+ rule(radPr: simple(:rad),
108
+ deg: simple(:deg),
109
+ e: simple(:e)) do
110
+ if deg.nil?
111
+ Math::Function::Sqrt.new(e)
112
+ else
113
+ Math::Function::Root.new(deg, e)
114
+ end
115
+ end
116
+
117
+ rule(fPr: simple(:fpr), num: simple(:num), den: simple(:den)) do
118
+ Math::Function::Frac.new(num, den)
119
+ end
120
+
121
+ rule(sSupPr: simple(:sSuppr), e: simple(:e), sup: simple(:power)) do
122
+ Math::Function::Power.new(e, power)
123
+ end
124
+
125
+ rule(sSubPr: simple(:sSubpr), e: simple(:e), sub: simple(:base)) do
126
+ Math::Function::Base.new(e, base)
127
+ end
128
+
129
+ rule(chr: sequence(:chr),
130
+ ctrlPr: simple(:ctrl)) do
131
+ [nil] + chr
132
+ end
133
+
134
+ rule(chr: sequence(:chr),
135
+ limLoc: sequence(:limloc),
136
+ ctrlPr: simple(:ctrl)) do
137
+ limloc + chr
138
+ end
139
+
140
+ rule(begChr: sequence(:begChr),
141
+ endChr: sequence(:endChr),
142
+ ctrlPr: simple(:ctrl)) do
143
+ [
144
+ Math::Symbol.new(begChr.first),
145
+ Math::Symbol.new(endChr.first),
146
+ ]
147
+ end
148
+
149
+ rule(chr: sequence(:chr),
150
+ supHide: sequence(:supHide),
151
+ ctrlPr: simple(:ctrl)) do
152
+ [nil] + chr
153
+ end
154
+
155
+ rule(chr: sequence(:chr),
156
+ limLoc: sequence(:limloc),
157
+ supHide: sequence(:sup),
158
+ ctrlPr: simple(:ctrl)) do
159
+ limloc + chr
160
+ end
161
+
162
+ rule(limLoc: sequence(:limloc),
163
+ subHide: sequence(:sub),
164
+ supHide: sequence(:sup),
165
+ ctrlPr: simple(:ctrl)) do
166
+ limloc
167
+ end
168
+
169
+ rule(chr: sequence(:chr),
170
+ limLoc: sequence(:limloc),
171
+ subHide: sequence(:sub),
172
+ supHide: sequence(:sup),
173
+ ctrlPr: simple(:ctrl)) do
174
+ limloc + chr
175
+ end
176
+
177
+ rule(naryPr: sequence(:naryPr),
178
+ sub: simple(:base),
179
+ sup: simple(:power),
180
+ e: simple(:e)) do
181
+ fonts = Plurimath::Math::Symbol.new(naryPr[1] || "∫")
182
+ first_value = if base.nil? && power.nil?
183
+ fonts
184
+ elsif naryPr.first == "undOvr"
185
+ Math::Function::Underover.new(fonts, base, power)
186
+ else
187
+ Math::Function::PowerBase.new(fonts, base, power)
188
+ end
189
+ Math::Formula.new(
190
+ [
191
+ first_value,
192
+ Math::Formula.new(
193
+ [
194
+ e,
195
+ ],
196
+ ),
197
+ ],
198
+ )
199
+ end
200
+
201
+ rule(sSubSupPr: simple(:sSubSuppr),
202
+ e: simple(:e),
203
+ sub: simple(:base),
204
+ sup: simple(:power)) do
205
+ Math::Function::PowerBase.new(e, base, power)
206
+ end
207
+
208
+ rule(sPrePr: simple(:sPrePr),
209
+ e: simple(:e),
210
+ sub: simple(:base),
211
+ sup: simple(:power)) do
212
+ Math::Function::Multiscript.new(e, base, power)
213
+ end
214
+ end
215
+ end
216
+ end
@@ -9,7 +9,7 @@ module Plurimath
9
9
  end
10
10
 
11
11
  def to_formula
12
- # TODO: Will be implemented soon
12
+ Parser.new(text).parse
13
13
  end
14
14
  end
15
15
  end
@@ -7,5 +7,9 @@ module Plurimath
7
7
  def initialize(text)
8
8
  @text = text
9
9
  end
10
+
11
+ def to_formula
12
+ # TODO: Will be implemented soon
13
+ end
10
14
  end
11
15
  end