plurimath 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +13 -0
  3. data/.github/workflows/release.yml +22 -0
  4. data/.gitignore +1 -0
  5. data/.hound.yml +5 -0
  6. data/.rubocop.yml +8 -0
  7. data/AsciiMath-Supported-Data.adoc +2000 -0
  8. data/Gemfile +3 -0
  9. data/Latex-Supported-Data.adoc +1879 -0
  10. data/MathML-Supported-Data.adoc +287 -0
  11. data/README.adoc +96 -0
  12. data/lib/plurimath/asciimath/constants.rb +267 -229
  13. data/lib/plurimath/asciimath/parse.rb +125 -26
  14. data/lib/plurimath/asciimath/parser.rb +6 -3
  15. data/lib/plurimath/asciimath/transform.rb +1135 -208
  16. data/lib/plurimath/asciimath.rb +1 -1
  17. data/lib/plurimath/html/constants.rb +50 -0
  18. data/lib/plurimath/html/parse.rb +149 -0
  19. data/lib/plurimath/html/parser.rb +26 -0
  20. data/lib/plurimath/html/transform.rb +363 -0
  21. data/lib/plurimath/html.rb +1 -1
  22. data/lib/plurimath/latex/constants.rb +3729 -1906
  23. data/lib/plurimath/latex/parse.rb +167 -51
  24. data/lib/plurimath/latex/parser.rb +12 -4
  25. data/lib/plurimath/latex/transform.rb +598 -183
  26. data/lib/plurimath/math/base.rb +15 -0
  27. data/lib/plurimath/math/formula.rb +96 -11
  28. data/lib/plurimath/math/function/bar.rb +34 -0
  29. data/lib/plurimath/math/function/base.rb +32 -5
  30. data/lib/plurimath/math/function/binary_function.rb +104 -17
  31. data/lib/plurimath/math/function/cancel.rb +8 -0
  32. data/lib/plurimath/math/function/ceil.rb +3 -0
  33. data/lib/plurimath/math/function/color.rb +16 -6
  34. data/lib/plurimath/math/function/f.rb +8 -0
  35. data/lib/plurimath/math/function/fenced.rb +95 -3
  36. data/lib/plurimath/math/function/floor.rb +15 -0
  37. data/lib/plurimath/math/function/font_style/bold.rb +37 -0
  38. data/lib/plurimath/math/function/font_style/double_struck.rb +37 -0
  39. data/lib/plurimath/math/function/font_style/fraktur.rb +37 -0
  40. data/lib/plurimath/math/function/font_style/italic.rb +37 -0
  41. data/lib/plurimath/math/function/font_style/monospace.rb +37 -0
  42. data/lib/plurimath/math/function/font_style/normal.rb +37 -0
  43. data/lib/plurimath/math/function/font_style/sans-serif.rb +37 -0
  44. data/lib/plurimath/math/function/font_style/script.rb +37 -0
  45. data/lib/plurimath/math/function/font_style.rb +18 -25
  46. data/lib/plurimath/math/function/frac.rb +35 -5
  47. data/lib/plurimath/math/function/g.rb +7 -0
  48. data/lib/plurimath/math/function/hat.rb +12 -0
  49. data/lib/plurimath/math/function/inf.rb +21 -1
  50. data/lib/plurimath/math/function/int.rb +23 -2
  51. data/lib/plurimath/math/function/left.rb +25 -4
  52. data/lib/plurimath/math/function/lim.rb +40 -2
  53. data/lib/plurimath/math/function/limits.rb +8 -0
  54. data/lib/plurimath/math/function/log.rb +61 -4
  55. data/lib/plurimath/math/function/longdiv.rb +12 -0
  56. data/lib/plurimath/math/function/mbox.rb +31 -0
  57. data/lib/plurimath/math/function/menclose.rb +46 -0
  58. data/lib/plurimath/math/function/merror.rb +12 -0
  59. data/lib/plurimath/math/function/mod.rb +25 -4
  60. data/lib/plurimath/math/function/msgroup.rb +37 -0
  61. data/lib/plurimath/math/function/msline.rb +12 -0
  62. data/lib/plurimath/math/function/multiscript.rb +30 -0
  63. data/lib/plurimath/math/function/norm.rb +18 -1
  64. data/lib/plurimath/math/function/obrace.rb +17 -0
  65. data/lib/plurimath/math/function/oint.rb +2 -2
  66. data/lib/plurimath/math/function/over.rb +36 -0
  67. data/lib/plurimath/math/function/overset.rb +36 -7
  68. data/lib/plurimath/math/function/phantom.rb +28 -0
  69. data/lib/plurimath/math/function/power.rb +33 -9
  70. data/lib/plurimath/math/function/power_base.rb +110 -5
  71. data/lib/plurimath/math/function/prod.rb +29 -2
  72. data/lib/plurimath/math/function/right.rb +44 -0
  73. data/lib/plurimath/math/function/root.rb +27 -4
  74. data/lib/plurimath/math/function/rule.rb +33 -0
  75. data/lib/plurimath/math/function/scarries.rb +12 -0
  76. data/lib/plurimath/math/function/scarry.rb +12 -0
  77. data/lib/plurimath/math/function/sqrt.rb +24 -2
  78. data/lib/plurimath/math/function/stackrel.rb +27 -0
  79. data/lib/plurimath/math/function/substack.rb +7 -1
  80. data/lib/plurimath/math/function/sum.rb +56 -2
  81. data/lib/plurimath/math/function/sup.rb +3 -0
  82. data/lib/plurimath/math/function/table/align.rb +24 -0
  83. data/lib/plurimath/math/function/table/array.rb +44 -0
  84. data/lib/plurimath/math/function/table/bmatrix.rb +37 -0
  85. data/lib/plurimath/math/function/table/matrix.rb +32 -0
  86. data/lib/plurimath/math/function/table/multline.rb +24 -0
  87. data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
  88. data/lib/plurimath/math/function/table/split.rb +24 -0
  89. data/lib/plurimath/math/function/table/vmatrix.rb +24 -0
  90. data/lib/plurimath/math/function/table.rb +190 -20
  91. data/lib/plurimath/math/function/td.rb +27 -9
  92. data/lib/plurimath/math/function/ternary_function.rb +83 -8
  93. data/lib/plurimath/math/function/text.rb +45 -8
  94. data/lib/plurimath/math/function/tr.rb +28 -4
  95. data/lib/plurimath/math/function/ubrace.rb +17 -0
  96. data/lib/plurimath/math/function/ul.rb +29 -0
  97. data/lib/plurimath/math/function/unary_function.rb +85 -7
  98. data/lib/plurimath/math/function/underline.rb +12 -0
  99. data/lib/plurimath/math/function/underover.rb +107 -0
  100. data/lib/plurimath/math/function/underset.rb +39 -0
  101. data/lib/plurimath/math/function/vec.rb +10 -0
  102. data/lib/plurimath/math/function.rb +13 -2
  103. data/lib/plurimath/math/number.rb +11 -3
  104. data/lib/plurimath/math/symbol.rb +57 -9
  105. data/lib/plurimath/math/unicode.rb +11 -0
  106. data/lib/plurimath/math.rb +15 -6
  107. data/lib/plurimath/mathml/constants.rb +224 -179
  108. data/lib/plurimath/mathml/parser.rb +24 -7
  109. data/lib/plurimath/mathml/transform.rb +249 -148
  110. data/lib/plurimath/mathml.rb +1 -1
  111. data/lib/plurimath/omml/parser.rb +42 -0
  112. data/lib/plurimath/omml/transform.rb +278 -0
  113. data/lib/plurimath/omml.rb +1 -1
  114. data/lib/plurimath/unitsml.rb +4 -0
  115. data/lib/plurimath/utility.rb +395 -0
  116. data/lib/plurimath/version.rb +1 -1
  117. data/plurimath.gemspec +1 -0
  118. metadata +66 -9
  119. data/.github/workflows/test.yml +0 -36
  120. data/README.md +0 -40
  121. data/lib/plurimath/mathml/parse.rb +0 -63
@@ -10,7 +10,7 @@ module Plurimath
10
10
  end
11
11
 
12
12
  def to_formula
13
- @text = Plurimath::Asciimath::Parser.new(text).parse
13
+ Parser.new(text).parse
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Html
5
+ class Constants
6
+ PARENTHESIS = {
7
+ "(": :")",
8
+ "{": :"}",
9
+ "[": :"]",
10
+ }.freeze
11
+ UNARY_CLASSES = %w[
12
+ arcsin
13
+ arccos
14
+ arctan
15
+ coth
16
+ tanh
17
+ sech
18
+ csch
19
+ sqrt
20
+ ceil
21
+ sinh
22
+ cosh
23
+ sin
24
+ cos
25
+ gcd
26
+ csc
27
+ abs
28
+ vec
29
+ exp
30
+ sec
31
+ tan
32
+ cot
33
+ lcm
34
+ det
35
+ ln
36
+ lg
37
+ g
38
+ f
39
+ ].freeze
40
+ SUB_SUP_CLASSES = {
41
+ "∏": :prod,
42
+ "∑": :sum,
43
+ log: :log,
44
+ lim: :lim,
45
+ "∏": :prod,
46
+ "∑": :sum,
47
+ }.freeze
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parslet"
4
+ module Plurimath
5
+ class Html
6
+ class Parse < Parslet::Parser
7
+ rule(:unary) { array_to_expression(Constants::UNARY_CLASSES, :unary) }
8
+ rule(:binary) { str("lim").as(:binary) }
9
+ rule(:sub_tag) { parse_sub_sup_tags("sub") }
10
+ rule(:sup_tag) { parse_sub_sup_tags("sup") }
11
+
12
+ rule(:mod) do
13
+ (parse_tag(:open) >> str("mod").as(:binary) >> parse_tag(:close)) |
14
+ str("mod").as(:binary)
15
+ end
16
+
17
+ rule(:lparen) do
18
+ array_to_expression(Constants::PARENTHESIS.keys, :lparen)
19
+ end
20
+
21
+ rule(:rparen) do
22
+ array_to_expression(Constants::PARENTHESIS.values, :rparen)
23
+ end
24
+
25
+ rule(:sub_sup) do
26
+ array_to_expression(Constants::SUB_SUP_CLASSES.keys, :sum_prod)
27
+ end
28
+
29
+ rule(:open_paren) do
30
+ (parse_tag(:open) >> lparen >> parse_tag(:close)) |
31
+ lparen
32
+ end
33
+
34
+ rule(:close_paren) do
35
+ (parse_tag(:open) >> rparen >> parse_tag(:close)) |
36
+ rparen
37
+ end
38
+
39
+ rule(:sub_sup_tags) do
40
+ (sub_tag >> sup_tag) |
41
+ (sup_tag >> sub_tag) |
42
+ sup_tag |
43
+ sub_tag
44
+ end
45
+
46
+ rule(:unary_args) do
47
+ (unary_functions >> parse_parenthesis.as(:first_value)).as(:unary_function) |
48
+ (unary_functions >> intermediate_exp.as(:first_value)).as(:unary_function) |
49
+ (unary_functions >> sequence.as(:first_value)).as(:unary_function)
50
+ end
51
+
52
+ rule(:binary_args) do
53
+ (binary_functions >> parse_parenthesis.as(:first_value) >> parse_parenthesis.as(:second_value)) |
54
+ (binary_functions >> parse_parenthesis.as(:first_value)) |
55
+ (binary_functions >> intermediate_exp.as(:first_value) >> intermediate_exp.as(:second_value)) |
56
+ (binary_functions >> intermediate_exp.as(:first_value))
57
+ end
58
+
59
+ rule(:unary_functions) do
60
+ (parse_tag(:open) >> unary >> parse_tag(:close)) |
61
+ unary
62
+ end
63
+
64
+ rule(:binary_functions) do
65
+ (parse_tag(:open) >> binary >> parse_tag(:close)) |
66
+ binary
67
+ end
68
+
69
+ rule(:parse_classes) do
70
+ unary_functions |
71
+ binary_functions
72
+ end
73
+
74
+ rule(:symbol_text_or_tag) do
75
+ tag_parse |
76
+ (str("&") >> match["a-zA-Z0-9"].repeat(2) >> str(";")).as(:symbol) |
77
+ match["0-9"].as(:number) |
78
+ match["a-zA-Z"].as(:text) |
79
+ match["^0-9a-zA-Z<>/(){}\\[\\]"].as(:symbol)
80
+ end
81
+
82
+ rule(:intermediate_exp) do
83
+ (sub_sup.as(:sub_sup) >> sub_sup_tags) |
84
+ (symbol_text_or_tag.as(:sub_sup) >> sub_sup_tags) |
85
+ sub_sup |
86
+ parse_classes |
87
+ symbol_text_or_tag
88
+ end
89
+
90
+ rule(:parse_parenthesis) do
91
+ (open_paren >> symbol_text_or_tag >> close_paren) |
92
+ (open_paren >> intermediate_exp >> close_paren) |
93
+ (open_paren >> expression >> close_paren)
94
+ end
95
+
96
+ rule(:sequence) do
97
+ parse_parenthesis.as(:parse_parenthesis) |
98
+ (unary_args >> sequence.as(:sequence)) |
99
+ (binary_args >> sequence.as(:sequence)) |
100
+ unary_args |
101
+ binary_args |
102
+ (symbol_text_or_tag >> parse_parenthesis.as(:parse_parenthesis)) |
103
+ (intermediate_exp >> expression.as(:expression)) |
104
+ intermediate_exp
105
+ end
106
+
107
+ rule(:tag_parse) do
108
+ parse_sub_sup_tags("table") |
109
+ parse_sub_sup_tags("tr") |
110
+ parse_sub_sup_tags("td") |
111
+ (parse_tag(:open) >> sequence.as(:sequence) >> parse_tag(:close))
112
+ end
113
+
114
+ rule(:expression) do
115
+ (intermediate_exp.as(:first_value) >> mod >> intermediate_exp.as(:second_value)) |
116
+ (parse_classes.as(:sub_sup) >> sub_sup_tags) |
117
+ (sequence.as(:sequence) >> sequence.as(:expression)) |
118
+ sequence
119
+ end
120
+
121
+ root :expression
122
+
123
+ def array_to_expression(array, name = nil)
124
+ initial_type = array.first.class
125
+ array.reduce do |expr, tag|
126
+ expr = str_to_expression(expr, name) if expr.is_a?(initial_type)
127
+ expr | str_to_expression(tag, name)
128
+ end
129
+ end
130
+
131
+ def str_to_expression(string, name)
132
+ return str(string) if name.nil?
133
+
134
+ str(string).as(name)
135
+ end
136
+
137
+ def parse_tag(opts)
138
+ tag = str("<")
139
+ tag = tag >> str("/") if opts == :close
140
+ tag = tag >> match(/\w+/).repeat
141
+ tag >> str(">")
142
+ end
143
+
144
+ def parse_sub_sup_tags(tag)
145
+ str("<#{tag}>") >> sequence.as(:"#{tag}_value") >> str("</#{tag}>")
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require_relative "parse"
5
+ require_relative "constants"
6
+ require_relative "transform"
7
+ module Plurimath
8
+ class Html
9
+ class Parser
10
+ attr_accessor :text
11
+
12
+ def initialize(text)
13
+ @text = CGI.unescapeHTML(text)
14
+ end
15
+
16
+ def parse
17
+ nodes = Parse.new.parse(text)
18
+ nodes = JSON.parse(nodes.to_json, symbolize_names: true)
19
+ transformed_tree = Transform.new.apply(nodes)
20
+ return transformed_tree if transformed_tree.is_a?(Math::Formula)
21
+
22
+ Math::Formula.new(transformed_tree)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,363 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plurimath
4
+ class Html
5
+ class Transform < Parslet::Transform
6
+ rule(text: simple(:text)) { Math::Function::Text.new(text) }
7
+ rule(unary: simple(:unary)) { Utility.get_class(unary).new }
8
+ rule(symbol: simple(:symbol)) { Math::Symbol.new(symbol) }
9
+ rule(number: simple(:number)) { Math::Number.new(number) }
10
+
11
+ rule(sequence: simple(:sequence)) { sequence }
12
+ rule(tr_value: simple(:tr_value)) { Math::Function::Tr.new([tr_value]) }
13
+ rule(td_value: simple(:td_value)) { Math::Function::Td.new([td_value]) }
14
+ rule(sequence: sequence(:sequence)) { Math::Formula.new(sequence) }
15
+ rule(td_value: sequence(:td_value)) { Math::Function::Td.new(td_value) }
16
+
17
+ rule(parse_parenthesis: simple(:parse_paren)) { parse_paren }
18
+ rule(unary_function: simple(:unary_function)) { unary_function }
19
+
20
+ rule(table_value: simple(:table_value)) do
21
+ Math::Function::Table.new([table_value])
22
+ end
23
+
24
+ rule(table_value: sequence(:table_value)) do
25
+ Math::Function::Table.new(table_value)
26
+ end
27
+
28
+ rule(sum_prod: simple(:sum_prod)) do
29
+ Utility.get_class(
30
+ Constants::SUB_SUP_CLASSES[sum_prod.to_sym],
31
+ ).new
32
+ end
33
+
34
+ rule(sequence: simple(:sequence),
35
+ expression: simple(:expr)) do
36
+ [sequence, expr]
37
+ end
38
+
39
+ rule(sequence: simple(:sequence),
40
+ expression: sequence(:expr)) do
41
+ expr.insert(0, sequence)
42
+ end
43
+
44
+ rule(sequence: sequence(:sequence),
45
+ expression: simple(:expr)) do
46
+ sequence << expr
47
+ end
48
+
49
+ rule(tr_value: simple(:tr_value),
50
+ expression: simple(:expr)) do
51
+ [
52
+ Math::Function::Tr.new([tr_value]),
53
+ expr,
54
+ ]
55
+ end
56
+
57
+ rule(tr_value: simple(:tr_value),
58
+ expression: sequence(:expr)) do
59
+ expr.insert(
60
+ 0,
61
+ Math::Function::Tr.new([tr_value]),
62
+ )
63
+ end
64
+
65
+ rule(unary_function: simple(:unary_function),
66
+ sequence: simple(:sequence)) do
67
+ Math::Formula.new(
68
+ [
69
+ unary_function,
70
+ sequence,
71
+ ],
72
+ )
73
+ end
74
+
75
+ rule(text: simple(:text),
76
+ expression: simple(:expr)) do
77
+ [
78
+ Math::Function::Text.new(text),
79
+ expr,
80
+ ]
81
+ end
82
+
83
+ rule(text: simple(:text),
84
+ expression: sequence(:expr)) do
85
+ [Math::Function::Text.new(text)] + expr
86
+ end
87
+
88
+ rule(symbol: simple(:symbol),
89
+ expression: simple(:expr)) do
90
+ [
91
+ Math::Symbol.new(symbol),
92
+ expr,
93
+ ]
94
+ end
95
+
96
+ rule(symbol: simple(:symbol),
97
+ expression: sequence(:expr)) do
98
+ [Math::Symbol.new(symbol)] + expr
99
+ end
100
+
101
+ rule(number: simple(:number),
102
+ expression: sequence(:expr)) do
103
+ [Math::Number.new(number)] + expr
104
+ end
105
+
106
+ rule(number: simple(:number),
107
+ expression: simple(:expr)) do
108
+ [
109
+ Math::Number.new(number),
110
+ expr,
111
+ ]
112
+ end
113
+
114
+ rule(text: simple(:text),
115
+ parse_parenthesis: simple(:parse_paren)) do
116
+ Math::Formula.new(
117
+ [
118
+ Math::Function::Text.new(text),
119
+ parse_paren,
120
+ ],
121
+ )
122
+ end
123
+
124
+ rule(unary: simple(:unary),
125
+ first_value: simple(:first_value)) do
126
+ Utility.get_class(unary).new(first_value)
127
+ end
128
+
129
+ rule(symbol: simple(:symbol),
130
+ parse_parenthesis: simple(:parse_paren)) do
131
+ [
132
+ Math::Symbol.new(symbol),
133
+ parse_paren,
134
+ ]
135
+ end
136
+
137
+ rule(sub_sup: simple(:sub_sup),
138
+ sub_value: simple(:sub_value)) do
139
+ if Utility.sub_sup_method?(sub_sup)
140
+ sub_sup.parameter_one = sub_value
141
+ sub_sup
142
+ else
143
+ Math::Function::Base.new(
144
+ sub_sup,
145
+ sub_value,
146
+ )
147
+ end
148
+ end
149
+
150
+ rule(sub_sup: simple(:sub_sup),
151
+ sub_value: sequence(:sub_value)) do
152
+ if Utility.sub_sup_method?(sub_sup)
153
+ sub_sup.parameter_one = Math::Formula.new(sub_value)
154
+ sub_sup
155
+ else
156
+ Math::Function::Base.new(
157
+ sub_sup,
158
+ Math::Formula.new(sub_value),
159
+ )
160
+ end
161
+ end
162
+
163
+ rule(sub_sup: simple(:sub_sup),
164
+ sup_value: simple(:sup_value)) do
165
+ if Utility.sub_sup_method?(sub_sup)
166
+ sub_sup.parameter_two = sup_value
167
+ sub_sup
168
+ else
169
+ Math::Function::Power.new(
170
+ sub_sup,
171
+ sup_value,
172
+ )
173
+ end
174
+ end
175
+
176
+ rule(sub_sup: simple(:sub_sup),
177
+ sup_value: sequence(:sup_value)) do
178
+ if Utility.sub_sup_method?(sub_sup)
179
+ sub_sup.parameter_two = Math::Formula.new(sup_value)
180
+ sub_sup
181
+ else
182
+ Math::Function::Power.new(
183
+ sub_sup,
184
+ Math::Formula.new(sup_value),
185
+ )
186
+ end
187
+ end
188
+
189
+ rule(sub_sup: simple(:sub_sup),
190
+ sub_value: simple(:sub_value),
191
+ sup_value: simple(:sup_value)) do
192
+ if Utility.sub_sup_method?(sub_sup)
193
+ sub_sup.parameter_one = sub_value
194
+ sub_sup.parameter_two = sup_value
195
+ sub_sup
196
+ else
197
+ Math::Function::PowerBase.new(
198
+ sub_sup,
199
+ sub_value,
200
+ sup_value,
201
+ )
202
+ end
203
+ end
204
+
205
+ rule(sub_sup: simple(:sub_sup),
206
+ sub_value: simple(:sub_value),
207
+ sup_value: sequence(:sup_value)) do
208
+ if Utility.sub_sup_method?(sub_sup)
209
+ sub_sup.parameter_one = sub_value
210
+ sub_sup.parameter_two = Math::Formula.new(sup_value)
211
+ sub_sup
212
+ else
213
+ Math::Function::PowerBase.new(
214
+ sub_sup,
215
+ sub_value,
216
+ Math::Formula.new(sup_value),
217
+ )
218
+ end
219
+ end
220
+
221
+ rule(sub_sup: simple(:sub_sup),
222
+ sub_value: sequence(:sub_value),
223
+ sup_value: simple(:sup_value)) do
224
+ if Utility.sub_sup_method?(sub_sup)
225
+ sub_sup.parameter_one = Math::Formula.new(sub_value)
226
+ sub_sup.parameter_two = sup_value
227
+ sub_sup
228
+ else
229
+ Math::Function::PowerBase.new(
230
+ sub_sup,
231
+ Math::Formula.new(sub_value),
232
+ sup_value,
233
+ )
234
+ end
235
+ end
236
+
237
+ rule(sub_sup: simple(:sub_sup),
238
+ sub_value: sequence(:sub_value),
239
+ sup_value: sequence(:sup_value)) do
240
+ if Utility.sub_sup_method?(sub_sup)
241
+ sub_sup.parameter_one = Math::Formula.new(sub_value)
242
+ sub_sup.parameter_two = Math::Formula.new(sup_value)
243
+ sub_sup
244
+ else
245
+ Math::Function::PowerBase.new(
246
+ sub_sup,
247
+ Math::Formula.new(sub_value),
248
+ Math::Formula.new(sup_value),
249
+ )
250
+ end
251
+ end
252
+
253
+ rule(lparen: simple(:lparen),
254
+ text: simple(:text),
255
+ rparen: simple(:rparen)) do
256
+ Math::Formula.new([
257
+ Math::Symbol.new(lparen),
258
+ Math::Function::Text.new(text),
259
+ Math::Symbol.new(rparen),
260
+ ])
261
+ end
262
+
263
+ rule(lparen: simple(:lparen),
264
+ sequence: simple(:sequence),
265
+ rparen: simple(:rparen)) do
266
+ Math::Formula.new([
267
+ Math::Symbol.new(lparen),
268
+ sequence,
269
+ Math::Symbol.new(rparen),
270
+ ])
271
+ end
272
+
273
+ rule(lparen: simple(:lparen),
274
+ sequence: sequence(:sequence),
275
+ rparen: simple(:rparen)) do
276
+ Math::Formula.new([
277
+ Math::Symbol.new(lparen),
278
+ Math::Formula.new(sequence),
279
+ Math::Symbol.new(rparen),
280
+ ])
281
+ end
282
+
283
+ rule(lparen: simple(:lparen),
284
+ number: simple(:number),
285
+ rparen: simple(:rparen)) do
286
+ Math::Formula.new([
287
+ Math::Symbol.new(lparen),
288
+ Math::Number.new(number),
289
+ Math::Symbol.new(rparen),
290
+ ])
291
+ end
292
+
293
+ rule(lparen: simple(:lparen),
294
+ unary_function: simple(:unary_function),
295
+ rparen: simple(:rparen)) do
296
+ Math::Formula.new([
297
+ Math::Symbol.new(lparen),
298
+ unary_function,
299
+ Math::Symbol.new(rparen),
300
+ ])
301
+ end
302
+
303
+ rule(binary: simple(:binary),
304
+ first_value: simple(:first_value),
305
+ second_value: simple(:second_value)) do
306
+ Utility.get_class(binary).new(first_value, second_value)
307
+ end
308
+
309
+ rule(lparen: simple(:lparen),
310
+ text: simple(:text),
311
+ expression: sequence(:expression),
312
+ rparen: simple(:rparen)) do
313
+ Math::Formula.new(
314
+ (
315
+ [
316
+ Math::Symbol.new(lparen),
317
+ Math::Function::Text.new(text),
318
+ ] + expression
319
+ ) << Math::Symbol.new(rparen),
320
+ )
321
+ end
322
+
323
+ rule(lparen: simple(:lparen),
324
+ text: simple(:text),
325
+ expression: simple(:expression),
326
+ rparen: simple(:rparen)) do
327
+ Math::Formula.new([
328
+ Math::Symbol.new(lparen),
329
+ Math::Function::Text.new(text),
330
+ expression,
331
+ Math::Symbol.new(rparen),
332
+ ])
333
+ end
334
+
335
+ rule(lparen: simple(:lparen),
336
+ number: simple(:number),
337
+ expression: simple(:expression),
338
+ rparen: simple(:rparen)) do
339
+ Math::Formula.new([
340
+ Math::Symbol.new(lparen),
341
+ Math::Number.new(number),
342
+ expression,
343
+ Math::Symbol.new(rparen),
344
+ ])
345
+ end
346
+
347
+ rule(lparen: simple(:lparen),
348
+ number: simple(:number),
349
+ expression: sequence(:expression),
350
+ rparen: simple(:rparen)) do
351
+ Math::Formula.new(
352
+ (
353
+ [
354
+ Math::Symbol.new(lparen),
355
+ Math::Number.new(number),
356
+ ] +
357
+ expression
358
+ ) << Math::Symbol.new(rparen),
359
+ )
360
+ end
361
+ end
362
+ end
363
+ 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