plurimath 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +8 -11
- data/.gitignore +1 -0
- data/AsciiMath-Supported-Data.adoc +280 -0
- data/Gemfile +1 -0
- data/Latex-Supported-Data.adoc +1872 -0
- data/MathML-Supported-Data.adoc +270 -0
- data/README.adoc +94 -0
- data/lib/plurimath/asciimath/constants.rb +215 -222
- data/lib/plurimath/asciimath/parse.rb +45 -11
- data/lib/plurimath/asciimath/parser.rb +4 -3
- data/lib/plurimath/asciimath/transform.rb +222 -131
- data/lib/plurimath/asciimath.rb +1 -1
- data/lib/plurimath/html/constants.rb +50 -0
- data/lib/plurimath/html/parse.rb +149 -0
- data/lib/plurimath/html/parser.rb +26 -0
- data/lib/plurimath/html/transform.rb +363 -0
- data/lib/plurimath/html.rb +1 -1
- data/lib/plurimath/latex/constants.rb +1885 -1858
- data/lib/plurimath/latex/parse.rb +127 -34
- data/lib/plurimath/latex/parser.rb +5 -4
- data/lib/plurimath/latex/transform.rb +324 -164
- data/lib/plurimath/math/formula.rb +9 -1
- data/lib/plurimath/math/function/bar.rb +1 -1
- data/lib/plurimath/math/function/base.rb +7 -1
- data/lib/plurimath/math/function/binary_function.rb +10 -5
- data/lib/plurimath/math/function/color.rb +4 -4
- data/lib/plurimath/math/function/fenced.rb +7 -2
- data/lib/plurimath/math/function/font_style/bold.rb +18 -0
- data/lib/plurimath/math/function/font_style/double_struck.rb +18 -0
- data/lib/plurimath/math/function/font_style/fraktur.rb +18 -0
- data/lib/plurimath/math/function/font_style/monospace.rb +18 -0
- data/lib/plurimath/math/function/font_style/sans-serif.rb +18 -0
- data/lib/plurimath/math/function/font_style/script.rb +18 -0
- data/lib/plurimath/math/function/font_style.rb +2 -22
- data/lib/plurimath/math/function/frac.rb +4 -4
- data/lib/plurimath/math/function/inf.rb +0 -1
- data/lib/plurimath/math/function/left.rb +3 -6
- data/lib/plurimath/math/function/limits.rb +0 -1
- data/lib/plurimath/math/function/log.rb +6 -0
- data/lib/plurimath/math/function/mod.rb +6 -0
- data/lib/plurimath/math/function/multiscript.rb +11 -0
- data/lib/plurimath/math/function/norm.rb +2 -1
- data/lib/plurimath/math/function/over.rb +29 -0
- data/lib/plurimath/math/function/overset.rb +2 -2
- data/lib/plurimath/math/function/power.rb +7 -1
- data/lib/plurimath/math/function/power_base.rb +14 -7
- data/lib/plurimath/math/function/prod.rb +6 -0
- data/lib/plurimath/math/function/right.rb +24 -0
- data/lib/plurimath/math/function/root.rb +5 -4
- data/lib/plurimath/math/function/sqrt.rb +1 -1
- data/lib/plurimath/math/function/substack.rb +0 -1
- data/lib/plurimath/math/function/sum.rb +6 -0
- data/lib/plurimath/math/function/table/align.rb +24 -0
- data/lib/plurimath/math/function/table/array.rb +25 -0
- data/lib/plurimath/math/function/table/bmatrix.rb +26 -0
- data/lib/plurimath/math/function/table/matrix.rb +24 -0
- data/lib/plurimath/math/function/table/multline.rb +24 -0
- data/lib/plurimath/math/function/table/pmatrix.rb +24 -0
- data/lib/plurimath/math/function/table/split.rb +24 -0
- data/lib/plurimath/math/function/table/vmatrix.rb +25 -0
- data/lib/plurimath/math/function/table.rb +17 -5
- data/lib/plurimath/math/function/td.rb +6 -1
- data/lib/plurimath/math/function/ternary_function.rb +16 -6
- data/lib/plurimath/math/function/text.rb +19 -7
- data/lib/plurimath/math/function/tr.rb +6 -1
- data/lib/plurimath/math/function/unary_function.rb +5 -0
- data/lib/plurimath/math/function/vec.rb +4 -0
- data/lib/plurimath/math/function.rb +13 -2
- data/lib/plurimath/math/number.rb +8 -0
- data/lib/plurimath/math/symbol.rb +12 -3
- data/lib/plurimath/math.rb +9 -4
- data/lib/plurimath/mathml/constants.rb +2 -34
- data/lib/plurimath/mathml/parse.rb +7 -2
- data/lib/plurimath/mathml/parser.rb +2 -1
- data/lib/plurimath/mathml/transform.rb +73 -68
- data/lib/plurimath/mathml.rb +1 -1
- data/lib/plurimath/omml/constants.rb +154 -0
- data/lib/plurimath/omml/parser.rb +22 -0
- data/lib/plurimath/omml/transform.rb +216 -0
- data/lib/plurimath/omml.rb +1 -1
- data/lib/plurimath/unitsml.rb +4 -0
- data/lib/plurimath/utility.rb +73 -0
- data/lib/plurimath/version.rb +1 -1
- data/plurimath.gemspec +1 -0
- metadata +49 -7
- data/README.md +0 -40
@@ -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
|