plurimath 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +354 -34
  3. data/Gemfile +2 -2
  4. data/README.adoc +49 -9
  5. data/lib/plurimath/deprecation.rb +2 -1
  6. data/lib/plurimath/errors/configuration_error.rb +5 -1
  7. data/lib/plurimath/errors/deprecation_error.rb +2 -1
  8. data/lib/plurimath/errors/invalid_number.rb +17 -0
  9. data/lib/plurimath/errors/unsupported_base.rb +18 -0
  10. data/lib/plurimath/errors/{formatter/unsupported_locale.rb → unsupported_locale.rb} +1 -1
  11. data/lib/plurimath/errors.rb +8 -0
  12. data/lib/plurimath/formatter/numbers/base_notation.rb +7 -2
  13. data/lib/plurimath/formatter/numbers/format_options.rb +123 -17
  14. data/lib/plurimath/formatter/numbers/fraction.rb +7 -16
  15. data/lib/plurimath/formatter/numbers/integer.rb +3 -0
  16. data/lib/plurimath/formatter/numbers/notation_renderer.rb +35 -6
  17. data/lib/plurimath/formatter/numbers/number_renderer.rb +16 -4
  18. data/lib/plurimath/formatter/numbers/precision_resolver.rb +16 -3
  19. data/lib/plurimath/formatter/numbers/sign_renderer.rb +2 -1
  20. data/lib/plurimath/formatter/numbers/significant.rb +4 -2
  21. data/lib/plurimath/formatter/numbers/source.rb +18 -3
  22. data/lib/plurimath/formatter/standard.rb +6 -0
  23. data/lib/plurimath/formatter/supported_locales.rb +1 -1
  24. data/lib/plurimath/formatter.rb +0 -2
  25. data/lib/plurimath/html/transform.rb +24 -12
  26. data/lib/plurimath/math/core.rb +17 -14
  27. data/lib/plurimath/math/function/overleftrightarrow.rb +2 -2
  28. data/lib/plurimath/math/number.rb +11 -1
  29. data/lib/plurimath/math.rb +4 -1
  30. data/lib/plurimath/number_formatter.rb +45 -4
  31. data/lib/plurimath/omml/formula_transformation.rb +2 -1
  32. data/lib/plurimath/omml/translator.rb +4 -1
  33. data/lib/plurimath/unicode_math/parse.rb +93 -53
  34. data/lib/plurimath/unicode_math/parser.rb +7 -4
  35. data/lib/plurimath/unicode_math/parsing_rules/absence_rules.rb +33 -21
  36. data/lib/plurimath/unicode_math/parsing_rules/common_rules.rb +28 -16
  37. data/lib/plurimath/unicode_math/parsing_rules/constants_rules.rb +18 -7
  38. data/lib/plurimath/unicode_math/parsing_rules/masked.rb +35 -15
  39. data/lib/plurimath/unicode_math/parsing_rules/sub_sup.rb +98 -72
  40. data/lib/plurimath/unicode_math/transform.rb +755 -468
  41. data/lib/plurimath/version.rb +1 -1
  42. data/lib/plurimath.rb +1 -0
  43. metadata +5 -4
  44. data/lib/plurimath/errors/formatter/unsupported_base.rb +0 -21
@@ -12,8 +12,10 @@ module Plurimath
12
12
  rule(:an) { an_math | an_other }
13
13
  rule(:box) { str("□") >> operand }
14
14
 
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) }
15
+ rule(:char) { absent_chars >> unicode.as(:unicode_symbols) }
16
+ rule(:rows) do
17
+ (str("@").as(:tr) >> space? >> rows.as(:trs).maybe) | (row.as(:tr) >> space? >> str("@") >> space? >> rows.as(:trs).maybe) | row.as(:tr)
18
+ end
17
19
 
18
20
  rule(:space) { match(/\s/).repeat(1) | invisible_times }
19
21
  rule(:other) { other_absent >> alphanumeric.as(:symbol) }
@@ -25,43 +27,81 @@ module Plurimath
25
27
  rule(:n_ascii) { match["0-9"].repeat(1).as(:number) }
26
28
  rule(:a_ascii) { match["A-Za-z"].repeat(1).as(:symbol) }
27
29
  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}]") }
30
+ rule(:an_math) do
31
+ space.absent? >> match("[\u{1D400}-\u{1D7FF}\u{2102}-\u{2134}]")
32
+ end
29
33
 
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("") | str("\\array") }
34
+ rule(:td_value) do
35
+ expression.as(:exp) >> space? >> td_value.as(:expr).maybe
36
+ end
37
+ rule(:an_other) do
38
+ (an_math | n_ascii).absent? >> alphanumeric.as(:alphanumeric)
39
+ end
40
+ rule(:function) do
41
+ root_functions | box | hbrack | arg_function | intent_function
42
+ end
43
+ rule(:op_array) do
44
+ op_matrixs | op_prefixed_matrixs | str("&") | str("") | str("\\array")
45
+ end
34
46
 
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 }
47
+ rule(:op_opener) do
48
+ open_paren | op_open_unicode | op_open_paren | op_open
49
+ end
50
+ rule(:op_closer) do
51
+ op_close_unicode | close_paren | op_close_paren | op_close
52
+ end
37
53
 
38
54
  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 }
55
+ rule(:diacritics) do
56
+ (char.as(:char) >> diacritics.as(:diacritics)) | char.as(:char)
57
+ end
58
+ rule(:open_paren) do
59
+ (op_masked_open >> (op_closer | op_opener)).as(:open_paren) | op_masked_open
60
+ end
41
61
 
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 }
62
+ rule(:matrix_only) do
63
+ non_matrixs_absence? >> (op_matrixs | op_prefixed_matrixs)
64
+ end
65
+ rule(:close_paren) do
66
+ (op_masked_close >> (op_opener | op_closer)).as(:close_paren) | op_masked_close
67
+ end
44
68
 
45
69
  rule(:diacriticbase) { an | n_ascii }
46
70
  rule(:forward_slash) { str("/") | str("/") | str("⁄") }
47
71
 
48
72
  rule(:root_functions) { qdrt | cbrt | sqrt | binary_root | nthrt }
49
73
  rule(:op_over_choose) { (str("\\choose") | str("⒞")).as(:choose) }
50
- rule(:op_masked_open) { (str("\\left") | str("\\open") | str("├")).as(:paren_open_prefix) >> digits.as(:open_paren_mask).maybe }
74
+ rule(:op_masked_open) do
75
+ (str("\\left") | str("\\open") | str("├")).as(:paren_open_prefix) >> digits.as(:open_paren_mask).maybe
76
+ end
51
77
 
52
- rule(:invisible_times) { (str("⁢") | str("⁡") | str(" ") | str("\\itimes") >> space?) }
78
+ rule(:invisible_times) do
79
+ str("⁢") | str("⁡") | str(" ") | (str("\\itimes") >> space?)
80
+ end
53
81
 
54
- rule(:ordinary_symbols) { op_ordinary_symbols | op_prefixed_ordinary_symbols }
82
+ rule(:ordinary_symbols) do
83
+ op_ordinary_symbols | op_prefixed_ordinary_symbols
84
+ end
55
85
  rule(:interval_a_ascii) { match["A-Za-z"].as(:symbol).repeat(1) }
56
86
 
57
- rule(:negatable_symbols) { forward_slash >> negated | negated >> str("̸") }
58
- rule(:invisible_unicode) { str("▒") | (str("\\naryand") | str("\\of") >> space?) }
87
+ rule(:negatable_symbols) do
88
+ (forward_slash >> negated) | (negated >> str("̸"))
89
+ end
90
+ rule(:invisible_unicode) do
91
+ str("▒") | (str("\\naryand") | (str("\\of") >> space?))
92
+ end
59
93
 
60
94
  rule(:invisible_unicode?) { invisible_unicode.maybe }
61
- rule(:relational_symbols) { op_relational_unicode | op_relational_symbols }
95
+ rule(:relational_symbols) do
96
+ op_relational_unicode | op_relational_symbols
97
+ end
62
98
 
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 }
99
+ rule(:hbrack_power_base_check) do
100
+ (sub_sup_operand >> (power_symbol | base_symbol)).present?
101
+ end
102
+ rule(:spaced_bracketed_operand) do
103
+ operand >> space? >> spaced_bracketed_operand.as(:expr).maybe
104
+ end
65
105
 
66
106
  rule(:hbrack) do
67
107
  (op_h_brackets >> str("(").present? >> exp_bracket.as(:first_value)) |
@@ -76,15 +116,15 @@ module Plurimath
76
116
  op_prefixed_ordinary_negated |
77
117
  op_ordinary_negated |
78
118
  binary_negated |
79
- absent_negated_unicodes >> unicode.as(:negated_operator)
119
+ (absent_negated_unicodes >> unicode.as(:negated_operator))
80
120
  )
81
121
  end
82
122
 
83
123
  rule(:op_over) do
84
124
  str("⁄").as(:bevelled) |
85
- slash >> (str("sdiv") | str("sdivide") | str("sfrac")).as(:bevelled) |
125
+ (slash >> (str("sdiv") | str("sdivide") | str("sfrac")).as(:bevelled)) |
86
126
  str("⊘").as(:no_display_style) |
87
- slash >> (str("ndiv") | str("oslash")).as(:no_display_style) |
127
+ (slash >> (str("ndiv") | str("oslash")).as(:no_display_style)) |
88
128
  (str("∕") | str("\\ldiv")).as(:ldiv) |
89
129
  forward_slash |
90
130
  str("\\over") |
@@ -95,14 +135,14 @@ module Plurimath
95
135
  end
96
136
 
97
137
  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?)
138
+ ((op_unary_functions | unary_arg_functions).absent? >> atom.as(:factor).maybe) >> (mini_sub_sup_present? >> operator >> mini_fraction.present?).absent?
99
139
  end
100
140
 
101
141
  rule(:spaced_exp_bracket) do
102
- expression >> space? >> spaced_exp_bracket.as(:exp) |
103
- mid_symbols >> space? >> spaced_exp_bracket.as(:expr) |
104
- str("−").as(:symbol) >> space? >> spaced_exp_bracket.as(:expr) |
105
- expression >> space?
142
+ (expression >> space? >> spaced_exp_bracket.as(:exp)) |
143
+ (mid_symbols >> space? >> spaced_exp_bracket.as(:expr)) |
144
+ (str("−").as(:symbol) >> space? >> spaced_exp_bracket.as(:expr)) |
145
+ (expression >> space?)
106
146
  end
107
147
 
108
148
  rule(:row) do
@@ -117,8 +157,8 @@ module Plurimath
117
157
  end
118
158
 
119
159
  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)
160
+ (absent_slashed_values >> str("\\") >> (str("\\") | unicode | (n_ascii | a_ascii).repeat(1) | any).as(:slashed_value)) |
161
+ (absent_slashed_values >> str("\\").as(:slashed_value))
122
162
  end
123
163
 
124
164
  rule(:number) do
@@ -128,10 +168,10 @@ module Plurimath
128
168
  end
129
169
 
130
170
  rule(:numerator) do
131
- (relational_symbols.absent? | exp_script.present?) >> (
171
+ (relational_symbols.absent? | exp_script.present?) >> (
132
172
  (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 |
173
+ (((absent_numerator_exp_script? >> op_nary.absent?) >> mini_fraction_exp_script_absent? >> exp_script >> space) >> numerator.as(:recursive_numerator).maybe) |
174
+ ((absent_numerator_exp_script? >> mini_fraction_exp_script_absent? >> exp_script) >> numerator.as(:recursive_numerator).maybe) |
135
175
  (accents.as(:base) >> accents_subsup).as(:accents_subsup) |
136
176
  sub_paren |
137
177
  sup_paren |
@@ -139,7 +179,7 @@ module Plurimath
139
179
  unary_arg_functions |
140
180
  (frac_binary_absent >> numerator.as(:recursive_numerator)) |
141
181
  (factor >> frac_binary_absent.maybe >> numerator.as(:recursive_numerator).maybe) |
142
- operator.absent? >> operand >> frac_binary_absent.maybe |
182
+ (operator.absent? >> operand >> frac_binary_absent.maybe) |
143
183
  frac_binary_absent
144
184
  )
145
185
  end
@@ -172,9 +212,9 @@ module Plurimath
172
212
  end
173
213
 
174
214
  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)
215
+ (str("(").as(:open_paren) >> interval_value.as(:left_value) >> str(",").as(:comma) >> interval_value.as(:right_value) >> str("]").as(:close_paren)) |
216
+ (str("[").as(:open_paren) >> interval_value.as(:left_value) >> str(",").as(:comma) >> interval_value.as(:right_value) >> str(")").as(:close_paren)) |
217
+ ((str("[") | str("]")).as(:open_paren) >> interval_value.as(:left_value) >> str(",").as(:comma) >> interval_value.as(:right_value) >> (str("[") | str("]")).as(:close_paren))
178
218
  end
179
219
 
180
220
  rule(:interval_value) do
@@ -191,15 +231,15 @@ module Plurimath
191
231
  end
192
232
 
193
233
  rule(:denominator) do
194
- operator.absent? >> fraction.as(:frac) |
234
+ (operator.absent? >> fraction.as(:frac)) |
195
235
  exp_script |
196
236
  sub_paren |
197
237
  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) |
238
+ (frac_binary_absent >> invisible_times.maybe >> relational_symbols.absent? >> denominator.as(:recursive_denominator)) |
239
+ (operator.absent? >> factor >> invisible_times.maybe >> relational_symbols.absent? >> denominator.as(:recursive_denominator)) |
240
+ (operator.absent? >> operand >> invisible_times.maybe >> relational_symbols.absent? >> denominator.as(:recursive_denominator)) |
201
241
  frac_binary_absent |
202
- operator.absent? >> operand
242
+ (operator.absent? >> operand)
203
243
  end
204
244
 
205
245
  rule(:op_masked_close) do
@@ -207,10 +247,10 @@ module Plurimath
207
247
  end
208
248
 
209
249
  rule(:element) do
210
- accents.present? >> (accents.as(:base) >> accents_subsup).as(:accents_subsup) |
211
- accents.present? >> fraction.as(:frac) |
250
+ (accents.present? >> (accents.as(:base) >> accents_subsup).as(:accents_subsup)) |
251
+ (accents.present? >> fraction.as(:frac)) |
212
252
  ((op_unary_functions | unary_arg_functions).present? >> fraction.as(:frac)) |
213
- mini_sub_sup_present? >> operator >> mini_fraction.as(:frac) |
253
+ (mini_sub_sup_present? >> operator >> mini_fraction.as(:frac)) |
214
254
  accents |
215
255
  diacritics_accents |
216
256
  op_unicode_fractions |
@@ -218,7 +258,7 @@ module Plurimath
218
258
  monospace_fonts |
219
259
  array |
220
260
  exp_script |
221
- element_exp_script_validation? >> space? >> exp_script |
261
+ (element_exp_script_validation? >> space? >> exp_script) |
222
262
  unary_arg_functions |
223
263
  combined_symbols |
224
264
  wrapper_symbols |
@@ -232,13 +272,13 @@ module Plurimath
232
272
  end
233
273
 
234
274
  rule(:expression) do
235
- element >> other.as(:other) >> expression.as(:expr) |
236
- element >> relational_symbols >> expression.as(:expr).maybe |
275
+ (element >> other.as(:other) >> expression.as(:expr)) |
276
+ (element >> relational_symbols >> expression.as(:expr).maybe) |
237
277
  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
278
+ (element >> space? >> expression.as(:expr)) |
279
+ (slashed_operator >> space? >> expression.as(:expr).maybe) |
280
+ (element >> space? >> expression.as(:expr) >> space? >> expression.as(:expression).maybe) |
281
+ (mini_values >> space? >> expression.as(:expr).maybe)
242
282
  end
243
283
 
244
284
  root :expression
@@ -13,8 +13,11 @@ module Plurimath
13
13
  @text = @text.gsub("&", "&")
14
14
  @text = @text.gsub(""", "\"")
15
15
  @text = @text.gsub(/⫷.*⫸/, "")
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("█") | str("cases") | str("Ⓒ")).absent? }
13
+ rule(:non_matrixs_absence?) do
14
+ (str("eqarray") | str("█") | str("cases") | str("Ⓒ")).absent?
15
+ end
12
16
 
13
- rule(:sub_sup_binary_absent) { ((slash >> str("times")) | str("×")).absent? >> binary_symbols }
17
+ rule(:sub_sup_binary_absent) do
18
+ ((slash >> str("times")) | str("×")).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("×") | str("&#x2260"))).absent? }
23
+ rule(:frac_binary_absent_symbols?) do
24
+ ((slash >> (str("times") | str("neq") | str("ne"))) | (str("×") | str("&#x2260"))).absent?
25
+ end
18
26
 
19
- rule(:binary_negated_absent_symbols?) { ((slash >> str("dd")) | str("ⅆ")).absent? }
27
+ rule(:binary_negated_absent_symbols?) do
28
+ ((slash >> str("dd")) | str("ⅆ")).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("∣").as(:mid_symbol) }
18
+ rule(:mid_symbols) do
19
+ (slash >> str("mid").as(:mid_symbol)) | str("∣").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(" ").maybe >> repeated_accent_symbols).as(:accents) |
57
69
  (str(" ").absent? >> factor.as(:first_value) >> str(" ").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("⁗") | str("‴") | str("″") | str("′") | str("'") | str("'") }
11
+ rule(:primes) do
12
+ str("⁗") | str("‴") | str("″") | str("′") | str("'") | 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("Ⅎ") >> arr_to_expression(Constants::SIZE_OVERRIDES_SYMBOLS.keys, :size_overrides) }
87
+ rule(:op_size_overrides_symbols) do
88
+ str("Ⅎ") >> 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("∛") | str("\\cbrt") }
20
32
  rule(:qdrt_symbols) { str("∜") | str("\\cbrt") }
21
33
  rule(:rect_symbols) { str("▭") | str("\\rect") }
22
34
  rule(:sqrt_symbols) { str("√") | str("\\sqrt") | str("\\surd") }
23
- rule(:root_symbols) { str("⒭") | str("√") | str("\\root") | str("\\surd") }
35
+ rule(:root_symbols) do
36
+ str("⒭") | str("√") | str("\\root") | str("\\surd")
37
+ end
24
38
  rule(:arg_function) do
25
- str("ⓐ").as(:arg) >> str("(") >> a_ascii.as(:arg_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")") |
26
- str("ⓐ").as(:arg) >> a_ascii.as(:arg_arguments).maybe >> space? >> expression.as(:first_value).maybe
39
+ (str("ⓐ").as(:arg) >> str("(") >> a_ascii.as(:arg_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")")) |
40
+ (str("ⓐ").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("✎") | str("\\color") }
30
44
  rule(:phantom_symbols) { str("⟡") | str("\\phantom") }
31
- rule(:monospace_fonts) { (str("ᅲ") >> str("(") >> space? >> expression.as(:monospace_value) >> space? >> str(")")).as(:monospace) }
45
+ rule(:monospace_fonts) do
46
+ (str("ᅲ") >> str("(") >> space? >> expression.as(:monospace_value) >> space? >> str(")")).as(:monospace)
47
+ end
32
48
 
33
49
  rule(:backcolor_symbols) { str("☁") | 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("ⓘ").as(:intent) >> str("(").as(:open_paren) >> parsing_text.as(:intent_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")").as(:close_paren) |
48
- str("ⓘ").as(:intent) >> expression.as(:intent_expr)
67
+ (str("ⓘ").as(:intent) >> str("(").as(:open_paren) >> parsing_text.as(:intent_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")").as(:close_paren)) |
68
+ (str("ⓘ").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