plurimath 0.11.0 → 0.11.3

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 (120) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop_todo.yml +311 -58
  4. data/Gemfile +3 -2
  5. data/README.adoc +331 -15
  6. data/lib/plurimath/asciimath/parse.rb +6 -1
  7. data/lib/plurimath/asciimath/transform.rb +2 -0
  8. data/lib/plurimath/base_number_prefix.rb +43 -0
  9. data/lib/plurimath/configuration.rb +9 -1
  10. data/lib/plurimath/deprecation.rb +2 -1
  11. data/lib/plurimath/errors/configuration_error.rb +5 -1
  12. data/lib/plurimath/errors/deprecation_error.rb +2 -1
  13. data/lib/plurimath/errors/evaluation/division_by_zero_error.rb +13 -0
  14. data/lib/plurimath/errors/evaluation/error.rb +9 -0
  15. data/lib/plurimath/errors/evaluation/invalid_binding_error.rb +14 -0
  16. data/lib/plurimath/errors/evaluation/invalid_binding_key_error.rb +14 -0
  17. data/lib/plurimath/errors/evaluation/math_domain_error.rb +9 -0
  18. data/lib/plurimath/errors/evaluation/missing_variable_error.rb +13 -0
  19. data/lib/plurimath/errors/evaluation/non_finite_result_error.rb +13 -0
  20. data/lib/plurimath/errors/evaluation/unsupported_expression_error.rb +13 -0
  21. data/lib/plurimath/errors/evaluation.rb +18 -0
  22. data/lib/plurimath/errors/invalid_number.rb +17 -0
  23. data/lib/plurimath/errors/unsupported_base.rb +18 -0
  24. data/lib/plurimath/errors/{formatter/unsupported_locale.rb → unsupported_locale.rb} +1 -1
  25. data/lib/plurimath/errors.rb +9 -0
  26. data/lib/plurimath/formatter/numbers/base_notation.rb +55 -27
  27. data/lib/plurimath/formatter/numbers/format_options.rb +123 -17
  28. data/lib/plurimath/formatter/numbers/formatted_notation.rb +62 -0
  29. data/lib/plurimath/formatter/numbers/formatted_number.rb +87 -0
  30. data/lib/plurimath/formatter/numbers/fraction.rb +8 -17
  31. data/lib/plurimath/formatter/numbers/integer.rb +3 -0
  32. data/lib/plurimath/formatter/numbers/mathml_renderer.rb +56 -0
  33. data/lib/plurimath/formatter/numbers/notation_renderer.rb +58 -28
  34. data/lib/plurimath/formatter/numbers/number_renderer.rb +26 -13
  35. data/lib/plurimath/formatter/numbers/omml_renderer.rb +74 -0
  36. data/lib/plurimath/formatter/numbers/precision_resolver.rb +16 -3
  37. data/lib/plurimath/formatter/numbers/sign_renderer.rb +2 -1
  38. data/lib/plurimath/formatter/numbers/significant.rb +4 -2
  39. data/lib/plurimath/formatter/numbers/source.rb +46 -6
  40. data/lib/plurimath/formatter/numbers/text_renderer.rb +52 -0
  41. data/lib/plurimath/formatter/numbers.rb +6 -2
  42. data/lib/plurimath/formatter/standard.rb +6 -0
  43. data/lib/plurimath/formatter/supported_locales.rb +1 -1
  44. data/lib/plurimath/formatter.rb +0 -2
  45. data/lib/plurimath/html/parse.rb +5 -0
  46. data/lib/plurimath/html/transform.rb +26 -12
  47. data/lib/plurimath/latex/parse.rb +5 -0
  48. data/lib/plurimath/latex/transform.rb +2 -0
  49. data/lib/plurimath/math/core.rb +69 -14
  50. data/lib/plurimath/math/evaluation/evaluator.rb +147 -0
  51. data/lib/plurimath/math/evaluation/expression_parser.rb +215 -0
  52. data/lib/plurimath/math/evaluation/iteration.rb +63 -0
  53. data/lib/plurimath/math/evaluation.rb +13 -0
  54. data/lib/plurimath/math/formula.rb +9 -0
  55. data/lib/plurimath/math/function/abs.rb +4 -0
  56. data/lib/plurimath/math/function/arccos.rb +4 -0
  57. data/lib/plurimath/math/function/arcsin.rb +4 -0
  58. data/lib/plurimath/math/function/arctan.rb +4 -0
  59. data/lib/plurimath/math/function/ceil.rb +4 -0
  60. data/lib/plurimath/math/function/cos.rb +4 -0
  61. data/lib/plurimath/math/function/cosh.rb +4 -0
  62. data/lib/plurimath/math/function/cot.rb +4 -0
  63. data/lib/plurimath/math/function/coth.rb +4 -0
  64. data/lib/plurimath/math/function/csc.rb +4 -0
  65. data/lib/plurimath/math/function/csch.rb +4 -0
  66. data/lib/plurimath/math/function/exp.rb +4 -0
  67. data/lib/plurimath/math/function/fenced.rb +4 -0
  68. data/lib/plurimath/math/function/floor.rb +4 -0
  69. data/lib/plurimath/math/function/frac.rb +7 -0
  70. data/lib/plurimath/math/function/gcd.rb +9 -0
  71. data/lib/plurimath/math/function/lcm.rb +9 -0
  72. data/lib/plurimath/math/function/lg.rb +4 -0
  73. data/lib/plurimath/math/function/ln.rb +4 -0
  74. data/lib/plurimath/math/function/log.rb +19 -0
  75. data/lib/plurimath/math/function/max.rb +4 -0
  76. data/lib/plurimath/math/function/min.rb +4 -0
  77. data/lib/plurimath/math/function/mod.rb +15 -0
  78. data/lib/plurimath/math/function/overleftrightarrow.rb +2 -2
  79. data/lib/plurimath/math/function/power.rb +10 -0
  80. data/lib/plurimath/math/function/prod.rb +10 -0
  81. data/lib/plurimath/math/function/root.rb +7 -0
  82. data/lib/plurimath/math/function/sec.rb +4 -0
  83. data/lib/plurimath/math/function/sech.rb +4 -0
  84. data/lib/plurimath/math/function/sin.rb +4 -0
  85. data/lib/plurimath/math/function/sinh.rb +4 -0
  86. data/lib/plurimath/math/function/sqrt.rb +4 -0
  87. data/lib/plurimath/math/function/sum.rb +10 -0
  88. data/lib/plurimath/math/function/tan.rb +4 -0
  89. data/lib/plurimath/math/function/tanh.rb +4 -0
  90. data/lib/plurimath/math/function/text.rb +17 -0
  91. data/lib/plurimath/math/number.rb +44 -23
  92. data/lib/plurimath/math/symbols/cdot.rb +4 -0
  93. data/lib/plurimath/math/symbols/div.rb +4 -0
  94. data/lib/plurimath/math/symbols/hat.rb +4 -0
  95. data/lib/plurimath/math/symbols/minus.rb +4 -0
  96. data/lib/plurimath/math/symbols/pi.rb +5 -1
  97. data/lib/plurimath/math/symbols/plus.rb +4 -0
  98. data/lib/plurimath/math/symbols/slash.rb +4 -0
  99. data/lib/plurimath/math/symbols/symbol.rb +45 -0
  100. data/lib/plurimath/math/symbols/times.rb +4 -0
  101. data/lib/plurimath/math.rb +5 -1
  102. data/lib/plurimath/mathml/constants.rb +18 -0
  103. data/lib/plurimath/number_formatter.rb +63 -3
  104. data/lib/plurimath/omml/formula_transformation.rb +2 -1
  105. data/lib/plurimath/omml/translator.rb +4 -1
  106. data/lib/plurimath/setup/opal.rb.erb +13 -0
  107. data/lib/plurimath/unicode_math/parse.rb +98 -54
  108. data/lib/plurimath/unicode_math/parser.rb +7 -4
  109. data/lib/plurimath/unicode_math/parsing_rules/absence_rules.rb +33 -21
  110. data/lib/plurimath/unicode_math/parsing_rules/common_rules.rb +28 -16
  111. data/lib/plurimath/unicode_math/parsing_rules/constants_rules.rb +18 -7
  112. data/lib/plurimath/unicode_math/parsing_rules/masked.rb +35 -15
  113. data/lib/plurimath/unicode_math/parsing_rules/sub_sup.rb +98 -72
  114. data/lib/plurimath/unicode_math/transform.rb +1 -0
  115. data/lib/plurimath/utility.rb +1 -1
  116. data/lib/plurimath/version.rb +1 -1
  117. data/lib/plurimath.rb +2 -0
  118. metadata +24 -5
  119. data/lib/plurimath/errors/formatter/unsupported_base.rb +0 -21
  120. data/lib/plurimath/formatter/numbers/parts_renderer.rb +0 -30
@@ -3,6 +3,7 @@
3
3
  module Plurimath
4
4
  class UnicodeMath
5
5
  class Parse < Parslet::Parser
6
+ include Plurimath::BaseNumberPrefix::Parser
6
7
  include ParsingRules::Masked
7
8
  include ParsingRules::SubSup
8
9
  include ParsingRules::CommonRules
@@ -12,8 +13,10 @@ module Plurimath
12
13
  rule(:an) { an_math | an_other }
13
14
  rule(:box) { str("□") >> operand }
14
15
 
15
- rule(:char) { (absent_chars >> unicode.as(:unicode_symbols)) }
16
- rule(:rows) { (str("@").as(:tr) >> space? >> rows.as(:trs).maybe) | (row.as(:tr) >> space? >> str("@") >> space? >> rows.as(:trs).maybe) | row.as(:tr) }
16
+ rule(:char) { absent_chars >> unicode.as(:unicode_symbols) }
17
+ rule(:rows) do
18
+ (str("@").as(:tr) >> space? >> rows.as(:trs).maybe) | (row.as(:tr) >> space? >> str("@") >> space? >> rows.as(:trs).maybe) | row.as(:tr)
19
+ end
17
20
 
18
21
  rule(:space) { match(/\s/).repeat(1) | invisible_times }
19
22
  rule(:other) { other_absent >> alphanumeric.as(:symbol) }
@@ -25,43 +28,81 @@ module Plurimath
25
28
  rule(:n_ascii) { match["0-9"].repeat(1).as(:number) }
26
29
  rule(:a_ascii) { match["A-Za-z"].repeat(1).as(:symbol) }
27
30
  rule(:unicode) { str("&#x") >> match["0-9a-fA-F"].repeat >> str(";") }
28
- rule(:an_math) { space.absent? >> match("[\u{1D400}-\u{1D7FF}\u{2102}-\u{2134}]") }
31
+ rule(:an_math) do
32
+ space.absent? >> match("[\u{1D400}-\u{1D7FF}\u{2102}-\u{2134}]")
33
+ end
29
34
 
30
- rule(:td_value) { expression.as(:exp) >> space? >> td_value.as(:expr).maybe }
31
- rule(:an_other) { (an_math | n_ascii).absent? >> alphanumeric.as(:alphanumeric) }
32
- rule(:function) { root_functions | box | hbrack | arg_function | intent_function }
33
- rule(:op_array) { op_matrixs | op_prefixed_matrixs | str("&") | str("&#xb;") | str("\\array") }
35
+ rule(:td_value) do
36
+ expression.as(:exp) >> space? >> td_value.as(:expr).maybe
37
+ end
38
+ rule(:an_other) do
39
+ (an_math | n_ascii).absent? >> alphanumeric.as(:alphanumeric)
40
+ end
41
+ rule(:function) do
42
+ root_functions | box | hbrack | arg_function | intent_function
43
+ end
44
+ rule(:op_array) do
45
+ op_matrixs | op_prefixed_matrixs | str("&") | str("&#xb;") | str("\\array")
46
+ end
34
47
 
35
- rule(:op_opener) { open_paren | op_open_unicode | op_open_paren | op_open }
36
- rule(:op_closer) { op_close_unicode | close_paren | op_close_paren | op_close }
48
+ rule(:op_opener) do
49
+ open_paren | op_open_unicode | op_open_paren | op_open
50
+ end
51
+ rule(:op_closer) do
52
+ op_close_unicode | close_paren | op_close_paren | op_close
53
+ end
37
54
 
38
55
  rule(:op_decimal) { decimal_marker | str(",") | str(".") }
39
- rule(:diacritics) { (char.as(:char) >> diacritics.as(:diacritics)) | char.as(:char) }
40
- rule(:open_paren) { (op_masked_open >> (op_closer | op_opener)).as(:open_paren) | op_masked_open }
56
+ rule(:diacritics) do
57
+ (char.as(:char) >> diacritics.as(:diacritics)) | char.as(:char)
58
+ end
59
+ rule(:open_paren) do
60
+ (op_masked_open >> (op_closer | op_opener)).as(:open_paren) | op_masked_open
61
+ end
41
62
 
42
- rule(:matrix_only) { non_matrixs_absence? >> (op_matrixs | op_prefixed_matrixs) }
43
- rule(:close_paren) { (op_masked_close >> (op_opener | op_closer)).as(:close_paren) | op_masked_close }
63
+ rule(:matrix_only) do
64
+ non_matrixs_absence? >> (op_matrixs | op_prefixed_matrixs)
65
+ end
66
+ rule(:close_paren) do
67
+ (op_masked_close >> (op_opener | op_closer)).as(:close_paren) | op_masked_close
68
+ end
44
69
 
45
70
  rule(:diacriticbase) { an | n_ascii }
46
71
  rule(:forward_slash) { str("/") | str("&#x2f;") | str("&#x2044;") }
47
72
 
48
73
  rule(:root_functions) { qdrt | cbrt | sqrt | binary_root | nthrt }
49
74
  rule(:op_over_choose) { (str("\\choose") | str("&#x249e;")).as(:choose) }
50
- rule(:op_masked_open) { (str("\\left") | str("\\open") | str("&#x251c;")).as(:paren_open_prefix) >> digits.as(:open_paren_mask).maybe }
75
+ rule(:op_masked_open) do
76
+ (str("\\left") | str("\\open") | str("&#x251c;")).as(:paren_open_prefix) >> digits.as(:open_paren_mask).maybe
77
+ end
51
78
 
52
- rule(:invisible_times) { (str("&#x2062;") | str("&#x2061;") | str("&#x20;") | str("\\itimes") >> space?) }
79
+ rule(:invisible_times) do
80
+ str("&#x2062;") | str("&#x2061;") | str("&#x20;") | (str("\\itimes") >> space?)
81
+ end
53
82
 
54
- rule(:ordinary_symbols) { op_ordinary_symbols | op_prefixed_ordinary_symbols }
83
+ rule(:ordinary_symbols) do
84
+ op_ordinary_symbols | op_prefixed_ordinary_symbols
85
+ end
55
86
  rule(:interval_a_ascii) { match["A-Za-z"].as(:symbol).repeat(1) }
56
87
 
57
- rule(:negatable_symbols) { forward_slash >> negated | negated >> str("&#x338;") }
58
- rule(:invisible_unicode) { str("&#x2592;") | (str("\\naryand") | str("\\of") >> space?) }
88
+ rule(:negatable_symbols) do
89
+ (forward_slash >> negated) | (negated >> str("&#x338;"))
90
+ end
91
+ rule(:invisible_unicode) do
92
+ str("&#x2592;") | (str("\\naryand") | (str("\\of") >> space?))
93
+ end
59
94
 
60
95
  rule(:invisible_unicode?) { invisible_unicode.maybe }
61
- rule(:relational_symbols) { op_relational_unicode | op_relational_symbols }
96
+ rule(:relational_symbols) do
97
+ op_relational_unicode | op_relational_symbols
98
+ end
62
99
 
63
- rule(:hbrack_power_base_check) { (sub_sup_operand >> (power_symbol | base_symbol)).present? }
64
- rule(:spaced_bracketed_operand) { operand >> space? >> spaced_bracketed_operand.as(:expr).maybe }
100
+ rule(:hbrack_power_base_check) do
101
+ (sub_sup_operand >> (power_symbol | base_symbol)).present?
102
+ end
103
+ rule(:spaced_bracketed_operand) do
104
+ operand >> space? >> spaced_bracketed_operand.as(:expr).maybe
105
+ end
65
106
 
66
107
  rule(:hbrack) do
67
108
  (op_h_brackets >> str("(").present? >> exp_bracket.as(:first_value)) |
@@ -76,15 +117,15 @@ module Plurimath
76
117
  op_prefixed_ordinary_negated |
77
118
  op_ordinary_negated |
78
119
  binary_negated |
79
- absent_negated_unicodes >> unicode.as(:negated_operator)
120
+ (absent_negated_unicodes >> unicode.as(:negated_operator))
80
121
  )
81
122
  end
82
123
 
83
124
  rule(:op_over) do
84
125
  str("&#x2044;").as(:bevelled) |
85
- slash >> (str("sdiv") | str("sdivide") | str("sfrac")).as(:bevelled) |
126
+ (slash >> (str("sdiv") | str("sdivide") | str("sfrac")).as(:bevelled)) |
86
127
  str("&#x2298;").as(:no_display_style) |
87
- slash >> (str("ndiv") | str("oslash")).as(:no_display_style) |
128
+ (slash >> (str("ndiv") | str("oslash")).as(:no_display_style)) |
88
129
  (str("&#x2215;") | str("\\ldiv")).as(:ldiv) |
89
130
  forward_slash |
90
131
  str("\\over") |
@@ -95,14 +136,14 @@ module Plurimath
95
136
  end
96
137
 
97
138
  rule(:element_exp_script_validation?) do
98
- (((op_unary_functions | unary_arg_functions).absent? >> atom.as(:factor).maybe) >> (mini_sub_sup_present? >> operator >> mini_fraction.present?).absent?)
139
+ ((op_unary_functions | unary_arg_functions).absent? >> atom.as(:factor).maybe) >> (mini_sub_sup_present? >> operator >> mini_fraction.present?).absent?
99
140
  end
100
141
 
101
142
  rule(:spaced_exp_bracket) do
102
- expression >> space? >> spaced_exp_bracket.as(:exp) |
103
- mid_symbols >> space? >> spaced_exp_bracket.as(:expr) |
104
- str("&#x2212;").as(:symbol) >> space? >> spaced_exp_bracket.as(:expr) |
105
- expression >> space?
143
+ (expression >> space? >> spaced_exp_bracket.as(:exp)) |
144
+ (mid_symbols >> space? >> spaced_exp_bracket.as(:expr)) |
145
+ (str("&#x2212;").as(:symbol) >> space? >> spaced_exp_bracket.as(:expr)) |
146
+ (expression >> space?)
106
147
  end
107
148
 
108
149
  rule(:row) do
@@ -117,21 +158,24 @@ module Plurimath
117
158
  end
118
159
 
119
160
  rule(:slashed_operator) do
120
- absent_slashed_values >> str("\\") >> (str("\\") | unicode | (n_ascii | a_ascii).repeat(1) | any).as(:slashed_value) |
121
- absent_slashed_values >> str("\\").as(:slashed_value)
161
+ (absent_slashed_values >> str("\\") >> (str("\\") | unicode | (n_ascii | a_ascii).repeat(1) | any).as(:slashed_value)) |
162
+ (absent_slashed_values >> str("\\").as(:slashed_value))
122
163
  end
123
164
 
124
165
  rule(:number) do
125
- (digits.as(:whole) >> op_decimal.as(:decimal) >> digits.as(:fractional)).as(:decimal_number) |
166
+ hex_number |
167
+ binary_number |
168
+ octal_number |
169
+ (digits.as(:whole) >> op_decimal.as(:decimal) >> digits.as(:fractional)).as(:decimal_number) |
126
170
  (op_decimal.as(:decimal) >> digits.as(:whole) >> space?).as(:decimal_number) |
127
171
  digits.as(:digit)
128
172
  end
129
173
 
130
174
  rule(:numerator) do
131
- (relational_symbols.absent? | exp_script.present?) >> (
175
+ (relational_symbols.absent? | exp_script.present?) >> (
132
176
  (unary_arg_functions >> numerator.as(:recursive_numerator).maybe) |
133
- ((absent_numerator_exp_script? >> op_nary.absent?) >> mini_fraction_exp_script_absent? >> exp_script >> space) >> numerator.as(:recursive_numerator).maybe |
134
- (absent_numerator_exp_script? >> mini_fraction_exp_script_absent? >> exp_script) >> numerator.as(:recursive_numerator).maybe |
177
+ (((absent_numerator_exp_script? >> op_nary.absent?) >> mini_fraction_exp_script_absent? >> exp_script >> space) >> numerator.as(:recursive_numerator).maybe) |
178
+ ((absent_numerator_exp_script? >> mini_fraction_exp_script_absent? >> exp_script) >> numerator.as(:recursive_numerator).maybe) |
135
179
  (accents.as(:base) >> accents_subsup).as(:accents_subsup) |
136
180
  sub_paren |
137
181
  sup_paren |
@@ -139,7 +183,7 @@ module Plurimath
139
183
  unary_arg_functions |
140
184
  (frac_binary_absent >> numerator.as(:recursive_numerator)) |
141
185
  (factor >> frac_binary_absent.maybe >> numerator.as(:recursive_numerator).maybe) |
142
- operator.absent? >> operand >> frac_binary_absent.maybe |
186
+ (operator.absent? >> operand >> frac_binary_absent.maybe) |
143
187
  frac_binary_absent
144
188
  )
145
189
  end
@@ -172,9 +216,9 @@ module Plurimath
172
216
  end
173
217
 
174
218
  rule(:interval_exp_bracket) do
175
- str("(").as(:open_paren) >> interval_value.as(:left_value) >> str(",").as(:comma) >> interval_value.as(:right_value) >> str("]").as(:close_paren) |
176
- str("[").as(:open_paren) >> interval_value.as(:left_value) >> str(",").as(:comma) >> interval_value.as(:right_value) >> str(")").as(:close_paren) |
177
- (str("[") | str("]")).as(:open_paren) >> interval_value.as(:left_value) >> str(",").as(:comma) >> interval_value.as(:right_value) >> (str("[") | str("]")).as(:close_paren)
219
+ (str("(").as(:open_paren) >> interval_value.as(:left_value) >> str(",").as(:comma) >> interval_value.as(:right_value) >> str("]").as(:close_paren)) |
220
+ (str("[").as(:open_paren) >> interval_value.as(:left_value) >> str(",").as(:comma) >> interval_value.as(:right_value) >> str(")").as(:close_paren)) |
221
+ ((str("[") | str("]")).as(:open_paren) >> interval_value.as(:left_value) >> str(",").as(:comma) >> interval_value.as(:right_value) >> (str("[") | str("]")).as(:close_paren))
178
222
  end
179
223
 
180
224
  rule(:interval_value) do
@@ -191,15 +235,15 @@ module Plurimath
191
235
  end
192
236
 
193
237
  rule(:denominator) do
194
- operator.absent? >> fraction.as(:frac) |
238
+ (operator.absent? >> fraction.as(:frac)) |
195
239
  exp_script |
196
240
  sub_paren |
197
241
  sup_paren |
198
- frac_binary_absent >> invisible_times.maybe >> relational_symbols.absent? >> denominator.as(:recursive_denominator) |
199
- operator.absent? >> factor >> invisible_times.maybe >> relational_symbols.absent? >> denominator.as(:recursive_denominator) |
200
- operator.absent? >> operand >> invisible_times.maybe >> relational_symbols.absent? >> denominator.as(:recursive_denominator) |
242
+ (frac_binary_absent >> invisible_times.maybe >> relational_symbols.absent? >> denominator.as(:recursive_denominator)) |
243
+ (operator.absent? >> factor >> invisible_times.maybe >> relational_symbols.absent? >> denominator.as(:recursive_denominator)) |
244
+ (operator.absent? >> operand >> invisible_times.maybe >> relational_symbols.absent? >> denominator.as(:recursive_denominator)) |
201
245
  frac_binary_absent |
202
- operator.absent? >> operand
246
+ (operator.absent? >> operand)
203
247
  end
204
248
 
205
249
  rule(:op_masked_close) do
@@ -207,10 +251,10 @@ module Plurimath
207
251
  end
208
252
 
209
253
  rule(:element) do
210
- accents.present? >> (accents.as(:base) >> accents_subsup).as(:accents_subsup) |
211
- accents.present? >> fraction.as(:frac) |
254
+ (accents.present? >> (accents.as(:base) >> accents_subsup).as(:accents_subsup)) |
255
+ (accents.present? >> fraction.as(:frac)) |
212
256
  ((op_unary_functions | unary_arg_functions).present? >> fraction.as(:frac)) |
213
- mini_sub_sup_present? >> operator >> mini_fraction.as(:frac) |
257
+ (mini_sub_sup_present? >> operator >> mini_fraction.as(:frac)) |
214
258
  accents |
215
259
  diacritics_accents |
216
260
  op_unicode_fractions |
@@ -218,7 +262,7 @@ module Plurimath
218
262
  monospace_fonts |
219
263
  array |
220
264
  exp_script |
221
- element_exp_script_validation? >> space? >> exp_script |
265
+ (element_exp_script_validation? >> space? >> exp_script) |
222
266
  unary_arg_functions |
223
267
  combined_symbols |
224
268
  wrapper_symbols |
@@ -232,13 +276,13 @@ module Plurimath
232
276
  end
233
277
 
234
278
  rule(:expression) do
235
- element >> other.as(:other) >> expression.as(:expr) |
236
- element >> relational_symbols >> expression.as(:expr).maybe |
279
+ (element >> other.as(:other) >> expression.as(:expr)) |
280
+ (element >> relational_symbols >> expression.as(:expr).maybe) |
237
281
  element |
238
- element >> space? >> expression.as(:expr) |
239
- slashed_operator >> space? >> expression.as(:expr).maybe |
240
- element >> space? >> expression.as(:expr) >> space? >> expression.as(:expression).maybe |
241
- mini_values >> space? >> expression.as(:expr).maybe
282
+ (element >> space? >> expression.as(:expr)) |
283
+ (slashed_operator >> space? >> expression.as(:expr).maybe) |
284
+ (element >> space? >> expression.as(:expr) >> space? >> expression.as(:expression).maybe) |
285
+ (mini_values >> space? >> expression.as(:expr).maybe)
242
286
  end
243
287
 
244
288
  root :expression
@@ -13,8 +13,11 @@ module Plurimath
13
13
  @text = @text.gsub("&#x26;", "&")
14
14
  @text = @text.gsub("&#x22;", "\"")
15
15
  @text = @text.gsub(/&#x2af7;.*&#x2af8;/, "")
16
- @text = @text.gsub(/\\\\/, "\\")
17
- @text = @text.gsub(/\\u([\da-fA-F]{1,5})\w{0,5}/) { "&#x#{$1};" } # Converting \u#{xxxx} encoding to &#x#{xxxx};
16
+ @text = @text.gsub("\\\\", "\\")
17
+ @text = # Converting \u#{xxxx} encoding to &#x#{xxxx};
18
+ @text.gsub(/\\u([\da-fA-F]{1,5})\w{0,5}/) do
19
+ "&#x#{$1};"
20
+ end
18
21
  @text = @text.strip
19
22
  end
20
23
 
@@ -33,7 +36,7 @@ module Plurimath
33
36
  def post_processing(tree)
34
37
  {
35
38
  labeled_tr_value: tree,
36
- labeled_tr_id: @splitted
39
+ labeled_tr_id: @splitted,
37
40
  }
38
41
  end
39
42
 
@@ -41,7 +44,7 @@ module Plurimath
41
44
  text unless text.include?("#") && !text.match?(LABELED_TR_REGEX)
42
45
 
43
46
  text = text.gsub(/✎\(.*(\#).*\)/) do |str|
44
- str = str.gsub("#", "\"replacement\"")
47
+ str.gsub("#", "\"replacement\"")
45
48
  end
46
49
  splitted = text.split("#")
47
50
  splitted[0] = splitted.first.gsub("\"replacement\"", "#")
@@ -6,19 +6,31 @@ module Plurimath
6
6
  module AbsenceRules
7
7
  include Helper
8
8
 
9
- rule(:frac_binary_absent) { frac_binary_absent_symbols? >> binary_symbols }
9
+ rule(:frac_binary_absent) do
10
+ frac_binary_absent_symbols? >> binary_symbols
11
+ end
10
12
 
11
- rule(:non_matrixs_absence?) { (str("eqarray") | str("&#x2588;") | str("cases") | str("&#x24b8;")).absent? }
13
+ rule(:non_matrixs_absence?) do
14
+ (str("eqarray") | str("&#x2588;") | str("cases") | str("&#x24b8;")).absent?
15
+ end
12
16
 
13
- rule(:sub_sup_binary_absent) { ((slash >> str("times")) | str("&#xd7;")).absent? >> binary_symbols }
17
+ rule(:sub_sup_binary_absent) do
18
+ ((slash >> str("times")) | str("&#xd7;")).absent? >> binary_symbols
19
+ end
14
20
 
15
21
  rule(:absent_negated_unicodes) { sqrt_symbols | root_symbols }
16
22
 
17
- rule(:frac_binary_absent_symbols?) { ((slash >> (str("times") | str("neq") | str("ne"))) | (str("&#xd7;") | str("&#x2260"))).absent? }
23
+ rule(:frac_binary_absent_symbols?) do
24
+ ((slash >> (str("times") | str("neq") | str("ne"))) | (str("&#xd7;") | str("&#x2260"))).absent?
25
+ end
18
26
 
19
- rule(:binary_negated_absent_symbols?) { ((slash >> str("dd")) | str("&#x2146;")).absent? }
27
+ rule(:binary_negated_absent_symbols?) do
28
+ ((slash >> str("dd")) | str("&#x2146;")).absent?
29
+ end
20
30
 
21
- rule(:mini_fraction_exp_script_absent?) { (operator >> mini_fraction).absent? }
31
+ rule(:mini_fraction_exp_script_absent?) do
32
+ (operator >> mini_fraction).absent?
33
+ end
22
34
 
23
35
  rule(:absent_chars) do
24
36
  (
@@ -86,28 +98,28 @@ module Plurimath
86
98
  op_prefixed_ordinary_symbols |
87
99
  op_binary_symbols_prefixed |
88
100
  op_prefixed_unary_symbols |
89
- slash >> str("backcolor") |
90
- slash >> str("naryand") |
91
- slash >> str("sdivide") |
92
- slash >> str("oslash") |
93
- slash >> str("color") |
101
+ (slash >> str("backcolor")) |
102
+ (slash >> str("naryand")) |
103
+ (slash >> str("sdivide")) |
104
+ (slash >> str("oslash")) |
105
+ (slash >> str("color")) |
94
106
  op_relational_symbols |
95
107
  op_h_bracket_prefixed |
96
108
  op_alphanumeric_fonts |
97
109
  skip_symbols_prefixed |
98
- slash >> str("sfrac") |
99
- slash >> str("rect") |
100
- slash >> str("sqrt") |
101
- slash >> str("qdrt") |
102
- slash >> str("cbrt") |
103
- slash >> str("root") |
104
- slash >> str("sdiv") |
105
- slash >> str("ndiv") |
106
- slash >> str("ldiv") |
110
+ (slash >> str("sfrac")) |
111
+ (slash >> str("rect")) |
112
+ (slash >> str("sqrt")) |
113
+ (slash >> str("qdrt")) |
114
+ (slash >> str("cbrt")) |
115
+ (slash >> str("root")) |
116
+ (slash >> str("sdiv")) |
117
+ (slash >> str("ndiv")) |
118
+ (slash >> str("ldiv")) |
107
119
  op_prefixed_matrixs |
108
120
  op_binary_symbols_prefixed |
109
121
  op_prefixed_negated |
110
- slash >> str("mid") |
122
+ (slash >> str("mid")) |
111
123
  op_accent_prefixed |
112
124
  prefixed_primes |
113
125
  op_nary_text |
@@ -7,22 +7,34 @@ module Plurimath
7
7
  include Helper
8
8
 
9
9
  rule(:atom) { (diacritics >> diacriticbase.maybe) | an }
10
- rule(:atoms) { (atom.as(:atom) >> atoms.as(:atoms).maybe) }
10
+ rule(:atoms) { atom.as(:atom) >> atoms.as(:atoms).maybe }
11
11
  rule(:entity) { atoms | number }
12
12
 
13
13
  rule(:operator) { match["-+*=.?:,`"].as(:operator) }
14
- rule(:op_unary) { op_prefixed_unary_arg_functions | op_unary_arg_functions | op_prefixed_unary_symbols | op_unary_symbols }
14
+ rule(:op_unary) do
15
+ op_prefixed_unary_arg_functions | op_unary_arg_functions | op_prefixed_unary_symbols | op_unary_symbols
16
+ end
15
17
 
16
- rule(:mid_symbols) { (slash >> str("mid").as(:mid_symbol)) | str("&#x2223;").as(:mid_symbol) }
18
+ rule(:mid_symbols) do
19
+ (slash >> str("mid").as(:mid_symbol)) | str("&#x2223;").as(:mid_symbol)
20
+ end
17
21
 
18
22
  rule(:unary_spaces) { space | invisible_unicode }
19
23
  rule(:custom_fonts) { str("double") | str("fraktur") | str("script") }
20
- rule(:parsing_text) { str("\"") >> match("[^\"]").repeat(1).as(:text) >> str("\"") }
21
- rule(:alphanumeric) { match("[\u{0041}-\u{005A}\u{0061}-\u{007A}\u{0391}-\u{2207}\u{3B1}-\u{3DD}\u{30}-\u{39}]") }
24
+ rule(:parsing_text) do
25
+ str("\"") >> match("[^\"]").repeat(1).as(:text) >> str("\"")
26
+ end
27
+ rule(:alphanumeric) do
28
+ match("[\u{0041}-\u{005A}\u{0061}-\u{007A}\u{0391}-\u{2207}\u{3B1}-\u{3DD}\u{30}-\u{39}]")
29
+ end
22
30
 
23
31
  rule(:op_h_brackets) { op_h_bracket | op_h_bracket_prefixed }
24
- rule(:nary_functions) { (op_unary >> unary_spaces.maybe) | (op_unary_functions >> unary_spaces) }
25
- rule(:exclamation_symbols) { (str("!") | str("!!")).as(:exclamation_symbol) }
32
+ rule(:nary_functions) do
33
+ (op_unary >> unary_spaces.maybe) | (op_unary_functions >> unary_spaces)
34
+ end
35
+ rule(:exclamation_symbols) do
36
+ (str("!") | str("!!")).as(:exclamation_symbol)
37
+ end
26
38
  rule(:exclamation_symbols?) { exclamation_symbols.maybe }
27
39
 
28
40
  rule(:mini_fraction) do
@@ -36,15 +48,15 @@ module Plurimath
36
48
  rule(:fraction) do
37
49
  mini_fraction |
38
50
  binomial_fraction |
39
- numerator.as(:numerator) >> space? >> (negatable_symbols.absent? >> op_over) >> space? >> denominator.as(:denominator)
51
+ (numerator.as(:numerator) >> space? >> (negatable_symbols.absent? >> op_over) >> space? >> denominator.as(:denominator))
40
52
  end
41
53
 
42
54
  rule(:fonts) do
43
55
  unicoded_fonts |
44
- str("\\") >> custom_fonts.as(:unicoded_font_class) >> str("H").as(:symbol) |
45
- str("\\") >> str("mitBbb").as(:unicoded_font_class) >> match(/D|d|e|i|j/).as(:symbol)|
46
- op_fonts >> match["A-Za-z"].as(:symbol) |
47
- op_alphanumeric_fonts >> (match["A-Za-z"].as(:symbol) | match("[0-9]").as(:number))
56
+ (str("\\") >> custom_fonts.as(:unicoded_font_class) >> str("H").as(:symbol)) |
57
+ (str("\\") >> str("mitBbb").as(:unicoded_font_class) >> match(/D|d|e|i|j/).as(:symbol)) |
58
+ (op_fonts >> match["A-Za-z"].as(:symbol)) |
59
+ (op_alphanumeric_fonts >> (match["A-Za-z"].as(:symbol) | match("[0-9]").as(:number)))
48
60
  end
49
61
 
50
62
  rule(:unary_arg_functions) do
@@ -52,7 +64,7 @@ module Plurimath
52
64
  (nary_functions >> space? >> (exp_bracket | soperand).as(:first_value)).as(:unary_function)
53
65
  end
54
66
 
55
- rule(:accents) do
67
+ rule(:accents) do
56
68
  (exp_bracket.as(:intermediate_exp).as(:first_value) >> str("&#xa0;").maybe >> repeated_accent_symbols).as(:accents) |
57
69
  (str("&#xa0;").absent? >> factor.as(:first_value) >> str("&#xa0;").maybe >> repeated_accent_symbols).as(:accents)
58
70
  end
@@ -65,12 +77,12 @@ module Plurimath
65
77
  end
66
78
 
67
79
  rule(:repeated_accent_symbols) do
68
- (op_accent | op_accent_prefixed).repeat(1) >> prime_symbols.maybe |
80
+ ((op_accent | op_accent_prefixed).repeat(1) >> prime_symbols.maybe) |
69
81
  prime_symbols
70
82
  end
71
83
 
72
84
  rule(:prime_symbols) do
73
- ((slash >> prefixed_primes.as(:prefixed_prime) | primes).repeat(1).as(:prime_accent_symbols))
85
+ ((slash >> prefixed_primes.as(:prefixed_prime)) | primes).repeat(1).as(:prime_accent_symbols)
74
86
  end
75
87
 
76
88
  rule(:operand) do
@@ -94,7 +106,7 @@ module Plurimath
94
106
  monospace_fonts |
95
107
  relational_symbols |
96
108
  unary_arg_functions |
97
- op_unary_functions >> unary_spaces >> (operand | exp_bracket).absent? |
109
+ (op_unary_functions >> unary_spaces >> (operand | exp_bracket).absent?) |
98
110
  wrapper_symbols |
99
111
  ordinary_symbols |
100
112
  negatable_symbols |
@@ -8,7 +8,9 @@ module Plurimath
8
8
 
9
9
  rule(:slash) { str("\\") }
10
10
  rule(:slash?) { slash.maybe }
11
- rule(:primes) { str("&#x2057;") | str("&#x2034;") | str("&#x2033;") | str("&#x2032;") | str("&#x27;") | str("'") }
11
+ rule(:primes) do
12
+ str("&#x2057;") | str("&#x2034;") | str("&#x2033;") | str("&#x2032;") | str("&#x27;") | str("'")
13
+ end
12
14
 
13
15
  rule(:op_open) { slash >> arr_to_expression(Constants::OPEN_SYMBOLS.keys, :open_paren) }
14
16
 
@@ -33,13 +35,19 @@ module Plurimath
33
35
 
34
36
  rule(:binary_symbols) { op_binary_symbols | op_binary_symbols_prefixed }
35
37
  rule(:op_close_paren) { arr_to_expression(Constants::CLOSE_PARENTHESIS, :close_paren) }
36
- rule(:binary_negated) { binary_negated_absent_symbols? >> (op_binary_negated | op_prefixed_binary_negated) }
38
+ rule(:binary_negated) do
39
+ binary_negated_absent_symbols? >> (op_binary_negated | op_prefixed_binary_negated)
40
+ end
37
41
  rule(:unicoded_fonts) { unicoded_fonts_to_expression(Constants::UNICODED_FONTS, :symbol) }
38
42
 
39
- rule(:wrapper_symbols) { arr_to_expression(Constants.wrapper_symbols, :symbol) }
43
+ rule(:wrapper_symbols) do
44
+ arr_to_expression(Constants.wrapper_symbols, :symbol)
45
+ end
40
46
  rule(:op_nary_symbols) { arr_to_expression(Constants::NARY_SYMBOLS.values, :nary_class) }
41
47
  rule(:op_open_unicode) { arr_to_expression(Constants::OPEN_SYMBOLS.values, :open_paren) }
42
- rule(:prefixed_primes) { str("pppprime") | str("ppprime") | str("pprime") | str("prime") }
48
+ rule(:prefixed_primes) do
49
+ str("pppprime") | str("ppprime") | str("pprime") | str("prime")
50
+ end
43
51
 
44
52
  rule(:combined_symbols) { op_combined_symbols | op_combined_unicode }
45
53
  rule(:op_close_unicode) { arr_to_expression(Constants::CLOSE_SYMBOLS.values, :close_paren) }
@@ -76,7 +84,10 @@ module Plurimath
76
84
  rule(:op_unary_arg_functions) { arr_to_expression(Constants::UNARY_ARG_FUNCTIONS.values, :unary_arg_functions) }
77
85
 
78
86
  rule(:op_prefixed_unary_symbols) { slash >> arr_to_expression(Constants::UNARY_SYMBOLS.keys, :unary_symbols) }
79
- rule(:op_size_overrides_symbols) { str("&#x2132;") >> arr_to_expression(Constants::SIZE_OVERRIDES_SYMBOLS.keys, :size_overrides) }
87
+ rule(:op_size_overrides_symbols) do
88
+ str("&#x2132;") >> arr_to_expression(Constants::SIZE_OVERRIDES_SYMBOLS.keys,
89
+ :size_overrides)
90
+ end
80
91
 
81
92
  rule(:op_binary_symbols_prefixed) { slash >> arr_to_expression(Constants::BINARY_SYMBOLS.keys, :binary_symbols) }
82
93
  rule(:op_prefixed_binary_negated) { slash >> arr_to_expression(Constants::BINARY_SYMBOLS.keys, :binary_negated_operator) }
@@ -98,7 +109,7 @@ module Plurimath
98
109
  end
99
110
  end
100
111
 
101
- def unicoded_fonts_to_expression(hash, name = nil)
112
+ def unicoded_fonts_to_expression(hash, _name = nil)
102
113
  type = hash.first.class
103
114
  hash.reduce do |expression, expr_hash|
104
115
  if expression.is_a?(type)
@@ -113,7 +124,7 @@ module Plurimath
113
124
  type = expr_hash.first.class
114
125
  expr_hash.reduce do |expression, (_, hex_code)|
115
126
  expression = str(name).absent?.as(name).as(:unicoded_font_class) >> str(expression.last).as(:symbol) if expression.is_a?(type)
116
- expression | str(name).absent?.as(name).as(:unicoded_font_class) >> str(hex_code).as(:symbol)
127
+ expression | (str(name).absent?.as(name).as(:unicoded_font_class) >> str(hex_code).as(:symbol))
117
128
  end
118
129
  else
119
130
  str(expr_hash.values.last)
@@ -7,33 +7,53 @@ module Plurimath
7
7
  include Helper
8
8
 
9
9
  rule(:rect) { rect_symbols >> space? >> bracketed_masked_value(:rect) }
10
- rule(:sqrt) { (sqrt_symbols.as(:root_symbol) >> (exp_script | operand).as(:first_value)).as(:root) }
11
- rule(:qdrt) { (qdrt_symbols.as(:root_symbol) >> (exp_script | operand).as(:first_value)).as(:root) }
12
- rule(:cbrt) { (cbrt_symbols.as(:root_symbol) >> (exp_script | operand).as(:first_value)).as(:root) }
10
+ rule(:sqrt) do
11
+ (sqrt_symbols.as(:root_symbol) >> (exp_script | operand).as(:first_value)).as(:root)
12
+ end
13
+ rule(:qdrt) do
14
+ (qdrt_symbols.as(:root_symbol) >> (exp_script | operand).as(:first_value)).as(:root)
15
+ end
16
+ rule(:cbrt) do
17
+ (cbrt_symbols.as(:root_symbol) >> (exp_script | operand).as(:first_value)).as(:root)
18
+ end
13
19
 
14
- rule(:color) { color_symbols >> space? >> bracketed_masked_value(:color) }
15
- rule(:phant) { phantom_symbols >> space? >> bracketed_masked_value(:phantom) }
20
+ rule(:color) do
21
+ color_symbols >> space? >> bracketed_masked_value(:color)
22
+ end
23
+ rule(:phant) do
24
+ phantom_symbols >> space? >> bracketed_masked_value(:phantom)
25
+ end
16
26
 
17
- rule(:backcolor) { backcolor_symbols >> space? >> bracketed_masked_value(:backcolor) }
27
+ rule(:backcolor) do
28
+ backcolor_symbols >> space? >> bracketed_masked_value(:backcolor)
29
+ end
18
30
 
19
31
  rule(:cbrt_symbols) { str("&#x221b;") | str("\\cbrt") }
20
32
  rule(:qdrt_symbols) { str("&#x221c;") | str("\\cbrt") }
21
33
  rule(:rect_symbols) { str("&#x25ad;") | str("\\rect") }
22
34
  rule(:sqrt_symbols) { str("&#x221a;") | str("\\sqrt") | str("\\surd") }
23
- rule(:root_symbols) { str("&#x24ad;") | str("&#x221a;") | str("\\root") | str("\\surd") }
35
+ rule(:root_symbols) do
36
+ str("&#x24ad;") | str("&#x221a;") | str("\\root") | str("\\surd")
37
+ end
24
38
  rule(:arg_function) do
25
- str("&#x24d0;").as(:arg) >> str("(") >> a_ascii.as(:arg_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")") |
26
- str("&#x24d0;").as(:arg) >> a_ascii.as(:arg_arguments).maybe >> space? >> expression.as(:first_value).maybe
39
+ (str("&#x24d0;").as(:arg) >> str("(") >> a_ascii.as(:arg_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")")) |
40
+ (str("&#x24d0;").as(:arg) >> a_ascii.as(:arg_arguments).maybe >> space? >> expression.as(:first_value).maybe)
27
41
  end
28
42
 
29
43
  rule(:color_symbols) { str("&#x270e;") | str("\\color") }
30
44
  rule(:phantom_symbols) { str("&#x27e1;") | str("\\phantom") }
31
- rule(:monospace_fonts) { (str("&#xffd7;") >> str("(") >> space? >> expression.as(:monospace_value) >> space? >> str(")")).as(:monospace) }
45
+ rule(:monospace_fonts) do
46
+ (str("&#xffd7;") >> str("(") >> space? >> expression.as(:monospace_value) >> space? >> str(")")).as(:monospace)
47
+ end
32
48
 
33
49
  rule(:backcolor_symbols) { str("&#x2601;") | str("\\backcolor") }
34
- rule(:masked_recursive_value) { (space? >> expression | exp_bracket | exp_script).as(:expr) >> masked_recursive_value.as(:func_expr).maybe }
50
+ rule(:masked_recursive_value) do
51
+ ((space? >> expression) | exp_bracket | exp_script).as(:expr) >> masked_recursive_value.as(:func_expr).maybe
52
+ end
35
53
 
36
- rule(:root_invisible_character?) { (str("\\naryand").absent? >> invisible_unicode).maybe }
54
+ rule(:root_invisible_character?) do
55
+ (str("\\naryand").absent? >> invisible_unicode).maybe
56
+ end
37
57
 
38
58
  rule(:nthrt) do
39
59
  (sqrt_symbols >> str("(") >> masked_recursive_value.as(:first_value) >> str("&") >> masked_recursive_value.as(:second_value) >> str(")")).as(:root)
@@ -44,8 +64,8 @@ module Plurimath
44
64
  end
45
65
 
46
66
  rule(:intent_function) do
47
- str("&#x24d8;").as(:intent) >> str("(").as(:open_paren) >> parsing_text.as(:intent_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")").as(:close_paren) |
48
- str("&#x24d8;").as(:intent) >> expression.as(:intent_expr)
67
+ (str("&#x24d8;").as(:intent) >> str("(").as(:open_paren) >> parsing_text.as(:intent_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")").as(:close_paren)) |
68
+ (str("&#x24d8;").as(:intent) >> expression.as(:intent_expr))
49
69
  end
50
70
 
51
71
  def masked_value(func_name)
@@ -53,7 +73,7 @@ module Plurimath
53
73
  end
54
74
 
55
75
  def bracketed_masked_value(func_name)
56
- str("(") >> (masked_value(func_name).as(func_name)) >> str(")")
76
+ str("(") >> masked_value(func_name).as(func_name) >> str(")")
57
77
  end
58
78
  end
59
79
  end