plurimath 0.3.1 → 0.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80f221bdd7b1327b1773cb34581837b8e1dce2dd869d8908ce6da6c70cd6af33
4
- data.tar.gz: abf97a179d3b56a42a36cdeedd5323caf9873125c88cbc1109ecbd32c13be70e
3
+ metadata.gz: 8c90b0eb8f6510c5a93742653d0a9d395de3adf3b7dfa53f43d53ce4d7821a27
4
+ data.tar.gz: 966c4a94fc1245cec98e7290e3761be0774a71d62403e38bfa405aa1db5cd9f8
5
5
  SHA512:
6
- metadata.gz: efa17041d13cb3107a5364777b0cf9cff7e20daf37a885ecf43680a9e9a01d47df2610416042316068fc85a92145aeb888635800994d917dbcb67b91333c2b59
7
- data.tar.gz: 9f2af614455c09f6475692431db914ac750dfe405cdf0af4ed38a9dc8e0d6adc7b5d5cf3f2e3e331818b4532c9b4a200f88cdee0ac03e907b2c6fcb26ca994c9
6
+ metadata.gz: 364d72c3e42db84c13b5896ec36ea4cdb5f856ebdd970e7ff1058f3c2251cb301dd641cb51e1addcb5c890cfbd83cdebc5cf91df48e495704a8eae355b502d82
7
+ data.tar.gz: 607a1cf277fcbdce40ab130397985e8bf5682662adb747debb42823b257201e110d9aa4d7cb1087a191e98efeadab5976e723c2a9a6f64deb4e38bdf8fa513a1
@@ -3715,6 +3715,8 @@ module Plurimath
3715
3715
  PARENTHESIS = {
3716
3716
  "[" => "]",
3717
3717
  "(" => ")",
3718
+ "\\(" => "\\)",
3719
+ "\\[" => "\\]",
3718
3720
  "\\{" => "\\}",
3719
3721
  }.freeze
3720
3722
  MATRICES_PARENTHESIS = {
@@ -3783,6 +3785,50 @@ module Plurimath
3783
3785
  bmod
3784
3786
  pmod
3785
3787
  ].freeze
3788
+ LEFT_RIGHT_PARENTHESIS = {
3789
+ "\\backslash": "\",
3790
+ "\\langle": "⟨",
3791
+ "\\rangle": "⟩",
3792
+ "\\lfloor": "⌊",
3793
+ "\\rfloor": "⌋",
3794
+ "\\lceil": "⌈",
3795
+ "\\rceil": "⌉",
3796
+ "\\lbrace": "{",
3797
+ "\\rbrace": "}",
3798
+ "\\lbrack": "[",
3799
+ "\\rbrack": "]",
3800
+ "\\Vert": "‖",
3801
+ "\\vert": "|",
3802
+ "\\|": "‖",
3803
+ "\\}": "}",
3804
+ "\\{": "{",
3805
+ "(": "(",
3806
+ ")": ")",
3807
+ "<": "<",
3808
+ ">": ">",
3809
+ "/": "/",
3810
+ "|": "|",
3811
+ "[": "[",
3812
+ "]": "]",
3813
+ }.freeze
3814
+ SLASHED_SYMBOLS = %w[
3815
+ backslash
3816
+ langle
3817
+ rangle
3818
+ lfloor
3819
+ rfloor
3820
+ lbrace
3821
+ rbrace
3822
+ lbrack
3823
+ rbrack
3824
+ lceil
3825
+ rceil
3826
+ Vert
3827
+ vert
3828
+ |
3829
+ }
3830
+ {
3831
+ ]
3786
3832
  end
3787
3833
  end
3788
3834
  end
@@ -42,6 +42,14 @@ module Plurimath
42
42
  arr_to_expression(Constants::PARENTHESIS.values, :rparen)
43
43
  end
44
44
 
45
+ rule(:left_parens) do
46
+ arr_to_expression(Constants::LEFT_RIGHT_PARENTHESIS.keys, :left_paren)
47
+ end
48
+
49
+ rule(:right_parens) do
50
+ arr_to_expression(Constants::LEFT_RIGHT_PARENTHESIS.keys, :right_paren)
51
+ end
52
+
45
53
  rule(:environment) do
46
54
  arr_to_expression(Constants::MATRICES.keys, :environment)
47
55
  end
@@ -83,13 +91,12 @@ module Plurimath
83
91
  match["a-zA-Z"].as(:symbols) |
84
92
  match(/\d+(\.[0-9]+)|\d/).repeat(1).as(:number) |
85
93
  str("\\\\").as("\\\\") >> match(/\s/).repeat |
86
- (slash >> (lparen | rparen).as(:symbols)) |
87
- lparen |
88
94
  str("\\ ").as(:space)
89
95
  end
90
96
 
91
97
  rule(:intermediate_exp) do
92
- (str("{") >> expression.maybe.as(:expression) >> str("}")) |
98
+ (lparen.as(:left_paren) >> expression.maybe.as(:expression) >> rparen.as(:right_paren)).as(:intermediate_exp) |
99
+ (str("{") >> expression.maybe.as(:expression) >> str("}")) |
93
100
  symbol_text_or_integer
94
101
  end
95
102
 
@@ -123,20 +130,19 @@ module Plurimath
123
130
  (begining >> expression.as(:table_data) >> ending).as(:environment) |
124
131
  (slash >> environment >> intermediate_exp).as(:table_data) |
125
132
  power_base |
126
- (rparen >> (base >> sequence.as(:subscript)).maybe >> power >> sequence.as(:supscript)).as(:power_base) |
127
- (rparen >> (power >> sequence.as(:supscript)) >> base >> sequence.as(:subscript)).as(:power_base) |
128
- rparen |
129
133
  intermediate_exp
130
134
  end
131
135
 
132
136
  rule(:left_right) do
133
137
  (
134
- str("\\left").as(:left) >> lparen.maybe >>
138
+ str("\\left").as(:left) >> (left_parens | str(".").maybe) >>
139
+ (
140
+ (expression.repeat.as(:dividend) >> str("\\over") >> expression.repeat.as(:divisor)) |
141
+ expression.as(:expression).maybe
142
+ ) >>
135
143
  (
136
- (expression.repeat.as(:dividend) >> str("\\over") >> expression.repeat.as(:divisor)) |
137
- expression.as(:expression).maybe
138
- ) >>
139
- str("\\right").as(:right).maybe >> (rparen | str(".").maybe)
144
+ str("\\right").as(:right).maybe >> (right_parens | str(".").maybe)
145
+ )
140
146
  )
141
147
  end
142
148
 
@@ -149,14 +155,14 @@ module Plurimath
149
155
  end
150
156
 
151
157
  rule(:iteration) do
152
- (sequence.as(:sequence) >> expression.as(:expression)) |
153
- sequence
158
+ (sequence.as(:sequence) >> iteration.as(:expression)) |
159
+ sequence >> expression.maybe
154
160
  end
155
161
 
156
162
  rule(:expression) do
157
163
  (iteration >> expression) |
158
164
  iteration |
159
- ((iteration.as(:dividend) >> str("\\over") >> iteration.as(:divisor)) >> expression.repeat)
165
+ ((iteration.as(:dividend) >> str("\\over") >> iteration.as(:divisor)) >> expression.maybe)
160
166
  end
161
167
 
162
168
  root :expression
@@ -208,8 +214,9 @@ module Plurimath
208
214
 
209
215
  def unary_rules(first_value)
210
216
  (slashed_value(first_value, :unary_functions) >> dynamic_power_base) |
211
- (slashed_value(first_value, :unary) >> (left_right | intermediate_exp).as(:first_value)).as(:unary_functions) |
212
- (slashed_value(first_value, :unary))
217
+ (slashed_value(first_value, :unary) >> left_right.as(:first_value)).as(:unary_functions) |
218
+ (slashed_value(first_value, :unary) >> intermediate_exp.as(:first_value)).as(:unary_functions) |
219
+ slashed_value(first_value, :unary)
213
220
  end
214
221
 
215
222
  def dynamic_power_base
@@ -24,6 +24,8 @@ module Plurimath
24
24
  rule(power_base: simple(:power_base)) { power_base }
25
25
  rule(table_data: simple(:table_data)) { table_data }
26
26
 
27
+ rule(intermediate_exp: simple(:int_exp)) { int_exp }
28
+
27
29
  rule(numeric_values: simple(:value)) do
28
30
  Math::Symbol.new(value)
29
31
  end
@@ -72,57 +74,107 @@ module Plurimath
72
74
  end
73
75
 
74
76
  rule(left: simple(:left),
75
- lparen: simple(:lparen),
77
+ left_paren: simple(:lparen),
76
78
  expression: sequence(:expr),
77
79
  right: simple(:right),
78
- rparen: simple(:rparen)) do
80
+ right_paren: simple(:rparen)) do
81
+ Math::Formula.new(
82
+ [
83
+ Utility.left_right_objects(lparen, "left"),
84
+ Math::Formula.new(expr),
85
+ Utility.left_right_objects(rparen, "right"),
86
+ ],
87
+ )
88
+ end
89
+
90
+ rule(left: simple(:left),
91
+ left_paren: simple(:lparen),
92
+ expression: sequence(:expr),
93
+ right: simple(:right)) do
79
94
  Math::Formula.new(
80
95
  [
81
- Math::Function::Left.new(lparen),
96
+ Utility.left_right_objects(lparen, "left"),
82
97
  Math::Formula.new(expr),
83
- Math::Function::Right.new(rparen),
98
+ Math::Function::Right.new,
99
+ ],
100
+ )
101
+ end
102
+
103
+ rule(left: simple(:left),
104
+ left_paren: simple(:lparen),
105
+ expression: simple(:expr),
106
+ right: simple(:right)) do
107
+ Math::Formula.new(
108
+ [
109
+ Utility.left_right_objects(lparen, "left"),
110
+ expr,
111
+ Math::Function::Right.new,
84
112
  ],
85
113
  )
86
114
  end
87
115
 
88
116
  rule(left: simple(:left),
89
- lparen: simple(:lparen),
117
+ left_paren: simple(:lparen),
90
118
  right: simple(:right)) do
91
119
  Math::Formula.new(
92
120
  [
93
- Math::Function::Left.new(lparen),
121
+ Utility.left_right_objects(lparen, "left"),
94
122
  Math::Function::Right.new,
95
123
  ],
96
124
  )
97
125
  end
98
126
 
99
127
  rule(left: simple(:left),
100
- lparen: simple(:lparen),
128
+ left_paren: simple(:lparen),
101
129
  right: simple(:right),
102
- rparen: simple(:rparen)) do
130
+ right_paren: simple(:rparen)) do
103
131
  Math::Formula.new(
104
132
  [
105
- Math::Function::Left.new(lparen),
106
- Math::Function::Right.new(rparen),
133
+ Utility.left_right_objects(lparen, "left"),
134
+ Utility.left_right_objects(rparen, "right"),
107
135
  ],
108
136
  )
109
137
  end
110
138
 
111
139
  rule(left: simple(:left),
112
- lparen: simple(:lparen)) do
113
- Math::Function::Left.new(lparen)
140
+ left_paren: simple(:lparen)) do
141
+ Utility.left_right_objects(lparen, "left")
114
142
  end
115
143
 
116
144
  rule(left: simple(:left),
117
- lparen: simple(:lparen),
145
+ left_paren: simple(:lparen),
118
146
  expression: simple(:expr),
119
147
  right: simple(:right),
120
- rparen: simple(:rparen)) do
148
+ right_paren: simple(:rparen)) do
149
+ Math::Formula.new(
150
+ [
151
+ Utility.left_right_objects(lparen, "left"),
152
+ expr,
153
+ Utility.left_right_objects(rparen, "right"),
154
+ ],
155
+ )
156
+ end
157
+
158
+ rule(left: simple(:left),
159
+ expression: simple(:expr),
160
+ right: simple(:right)) do
121
161
  Math::Formula.new(
122
162
  [
123
- Math::Function::Left.new(lparen),
163
+ Math::Function::Left.new,
124
164
  expr,
125
- Math::Function::Right.new(rparen),
165
+ Math::Function::Right.new,
166
+ ],
167
+ )
168
+ end
169
+
170
+ rule(left: simple(:left),
171
+ expression: sequence(:expr),
172
+ right: simple(:right)) do
173
+ Math::Formula.new(
174
+ [
175
+ Math::Function::Left.new,
176
+ Math::Formula.new(expr),
177
+ Math::Function::Right.new,
126
178
  ],
127
179
  )
128
180
  end
@@ -168,14 +220,14 @@ module Plurimath
168
220
  end
169
221
 
170
222
  rule(left: simple(:left),
171
- lparen: simple(:lparen),
223
+ left_paren: simple(:lparen),
172
224
  dividend: subtree(:dividend),
173
225
  divisor: subtree(:divisor),
174
226
  right: simple(:right),
175
- rparen: simple(:rparen)) do
227
+ right_paren: simple(:rparen)) do
176
228
  Math::Formula.new(
177
229
  [
178
- Math::Function::Left.new(lparen),
230
+ Utility.left_right_objects(lparen, "left"),
179
231
  Math::Function::Over.new(
180
232
  Math::Formula.new(
181
233
  Array(dividend).flatten,
@@ -184,7 +236,7 @@ module Plurimath
184
236
  Array(divisor).flatten,
185
237
  ),
186
238
  ),
187
- Math::Function::Right.new(rparen),
239
+ Utility.left_right_objects(rparen, "right"),
188
240
  ],
189
241
  )
190
242
  end
@@ -333,6 +385,14 @@ module Plurimath
333
385
  )
334
386
  end
335
387
 
388
+ rule(intermediate_exp: simple(:int_exp),
389
+ supscript: simple(:supscript)) do
390
+ Math::Function::Power.new(
391
+ int_exp,
392
+ supscript,
393
+ )
394
+ end
395
+
336
396
  rule(unicode_symbols: simple(:sym),
337
397
  subscript: simple(:subscript)) do
338
398
  Math::Function::Base.new(
@@ -451,6 +511,26 @@ module Plurimath
451
511
  Math::Formula.new(expr)
452
512
  end
453
513
 
514
+ rule(left_paren: simple(:lparen),
515
+ expression: simple(:expr),
516
+ right_paren: simple(:rparen)) do
517
+ Math::Function::Fenced.new(
518
+ lparen,
519
+ [expr],
520
+ rparen,
521
+ )
522
+ end
523
+
524
+ rule(left_paren: simple(:lparen),
525
+ expression: sequence(:expr),
526
+ right_paren: simple(:rparen)) do
527
+ Math::Function::Fenced.new(
528
+ lparen,
529
+ expr,
530
+ rparen,
531
+ )
532
+ end
533
+
454
534
  rule(expression: sequence(:expr)) do
455
535
  Math::Formula.new(expr)
456
536
  end
@@ -35,7 +35,7 @@ module Plurimath
35
35
  close_paren = parameter_three ? parameter_three.value : ")"
36
36
  first_value = latex_paren(open_paren, false)
37
37
  second_value = latex_paren(close_paren, true)
38
- "#{first_value}#{fenced_value}#{second_value}"
38
+ "#{first_value} #{fenced_value} #{second_value}"
39
39
  end
40
40
 
41
41
  def to_omml_without_math_tag
@@ -96,11 +96,10 @@ module Plurimath
96
96
  end
97
97
 
98
98
  def latex_paren(paren, right)
99
- paren_side = right ? "\\right" : "\\left"
100
- return "#{paren_side} ." if paren&.include?(":")
99
+ return "" if paren.nil? || paren.empty?
101
100
 
102
101
  paren = %w[{ }].include?(paren) ? "\\#{paren}" : paren
103
- " #{paren_side} #{paren} "
102
+ "#{paren}"
104
103
  end
105
104
 
106
105
  def mathml_paren(field)
@@ -27,8 +27,7 @@ module Plurimath
27
27
  end
28
28
 
29
29
  def to_latex
30
- prefix = "\\" if parameter_one == "{"
31
- "\\left #{prefix}#{parameter_one}"
30
+ "\\left #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || "."}"
32
31
  end
33
32
 
34
33
  protected
@@ -27,8 +27,7 @@ module Plurimath
27
27
  end
28
28
 
29
29
  def to_latex
30
- prefix = "\\" if parameter_one == "}"
31
- "\\right #{prefix}#{parameter_one}"
30
+ "\\right #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || "."}"
32
31
  end
33
32
 
34
33
  protected
@@ -407,6 +407,15 @@ module Plurimath
407
407
  end
408
408
  end
409
409
  end
410
+
411
+ def left_right_objects(paren, function)
412
+ paren = if paren.to_s.match?(/\\{|\\}/)
413
+ paren.to_s.gsub(/\\/, "")
414
+ else
415
+ Latex::Constants::LEFT_RIGHT_PARENTHESIS[paren.to_sym]
416
+ end
417
+ get_class(function).new(paren)
418
+ end
410
419
  end
411
420
  end
412
421
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plurimath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-09 00:00:00.000000000 Z
11
+ date: 2023-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet