plurimath 0.3.1.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70a043b8a7a5e17b083cf66545b6df58d249f1a09c3666f53090cecc14a273ae
4
- data.tar.gz: e9aecbfe1aba0123fac731278428ebdb7b05197c8acbf12f9f64ab1528dea379
3
+ metadata.gz: dc53f153a22d8b615db765dda8d7b22c72d8cf42ee522a678649d52b3eed66b6
4
+ data.tar.gz: d31664e4104fe46e1361adc6b4e1a38d189590d181cf04e668c6d5d8f3a5f1d5
5
5
  SHA512:
6
- metadata.gz: 07fea95bec90f3e4eb135e5fd2246b5460bf0da939111df37140f4cf64462111404558e5a67d5636b66cbf7a72f7d998107ba06273415f13b219c98cddb0df71
7
- data.tar.gz: 0a116326448fb66449949741382473549ef806016e808bb9b67ddd68ff47f7a430685bf88ece03e47655199e9e23998bcae41e5e7559f8cb9c862611f899cc3e
6
+ metadata.gz: 6e8b0ececc1885c1751a0a9753a548f775c4cf740173c423dddbcf76dbfec8bb42db60773f744344402ea83e46e2c6bd99d43f85c54a12386383f0d83448f535
7
+ data.tar.gz: 4313751a9dde187e15adfbf6faa8f0c6fe015a753e286c84c2ea5cb7d5dd57c81c3e2c2e8bdaacffd1db58ff90f08fe82c5803983fe6a4027c9aade374190e8a
@@ -70,7 +70,7 @@ module Plurimath
70
70
  quoted_text |
71
71
  (str("d").as(:d) >> str("x").as(:x)).as(:intermediate_exp) |
72
72
  match["a-zA-Z"].as(:symbol) |
73
- match(/[^\[{(\\\/@;:.,'"|\]})0-9a-zA-Z\-><$%^&*_=+!`~\s?]/).as(:symbol) |
73
+ match(/[^\[{(\\\/@;:.,'"|\]})0-9a-zA-Z\-><$%^&*_=+!`~\s?ℒℛ]/).as(:symbol) |
74
74
  number
75
75
  end
76
76
 
@@ -127,12 +127,6 @@ module Plurimath
127
127
  new_arr
128
128
  end
129
129
 
130
- rule(sequence: simple(:sequence),
131
- left_right: sequence(:left_right)) do
132
- left_right.insert(0, sequence)
133
- left_right
134
- end
135
-
136
130
  rule(table_row: simple(:table_row),
137
131
  expr: simple(:expr)) do
138
132
  new_arr = [table_row]
@@ -157,6 +151,11 @@ module Plurimath
157
151
  expr.flatten.compact.insert(0, Utility.symbol_object(comma))
158
152
  end
159
153
 
154
+ rule(symbol: simple(:symbol),
155
+ expr: sequence(:expr)) do
156
+ expr.flatten.compact.insert(0, Utility.symbol_object(symbol))
157
+ end
158
+
160
159
  rule(rparen: simple(:rparen),
161
160
  expr: simple(:expr)) do
162
161
  [
@@ -316,19 +315,6 @@ module Plurimath
316
315
  )
317
316
  end
318
317
 
319
- rule(fonts_class: simple(:font_style),
320
- fonts_value: simple(:fonts_value),
321
- power: simple(:power)) do
322
- font_object = Utility::FONT_STYLES[font_style.to_sym].new(
323
- Utility.unfenced_value(fonts_value),
324
- font_style.to_s,
325
- )
326
- Math::Function::Power.new(
327
- font_object,
328
- Utility.unfenced_value(power),
329
- )
330
- end
331
-
332
318
  rule(unary_class: simple(:function),
333
319
  fonts_class: simple(:font_style),
334
320
  fonts_value: simple(:fonts_value)) do
@@ -344,24 +330,18 @@ module Plurimath
344
330
  Utility.get_class(function).new(first_value)
345
331
  end
346
332
 
347
- rule(fonts_class: simple(:font_style),
348
- fonts_value: simple(:fonts_value),
349
- base: simple(:base)) do
350
- font_object = Utility::FONT_STYLES[font_style.to_sym].new(
351
- Utility.unfenced_value(fonts_value),
352
- font_style.to_s,
353
- )
354
- Math::Function::Base.new(
355
- font_object,
356
- Utility.unfenced_value(base),
357
- )
358
- end
359
-
360
333
  rule(power_base: simple(:power_base),
361
334
  expr: subtree(:expr)) do
362
335
  expr.flatten.compact.insert(0, power_base)
363
336
  end
364
337
 
338
+ rule(power_base: simple(:power_base),
339
+ expr: simple(:expr)) do
340
+ new_arr = [power_base]
341
+ new_arr << expr unless expr.to_s.strip.empty?
342
+ new_arr
343
+ end
344
+
365
345
  rule(frac: simple(:frac),
366
346
  expr: subtree(:expr)) do
367
347
  case expr
@@ -386,29 +366,6 @@ module Plurimath
386
366
  new_arr
387
367
  end
388
368
 
389
- rule(sequence: simple(:sequence),
390
- frac: simple(:frac)) do
391
- new_arr = [sequence]
392
- new_arr << frac unless frac.to_s.strip.empty?
393
- new_arr
394
- end
395
-
396
- rule(sequence: simple(:sequence),
397
- base: simple(:base)) do
398
- Math::Function::Base.new(
399
- sequence,
400
- Utility.unfenced_value(base),
401
- )
402
- end
403
-
404
- rule(power_base: simple(:power_base),
405
- power: simple(:power)) do
406
- Math::Function::Power.new(
407
- power_base,
408
- Utility.unfenced_value(power),
409
- )
410
- end
411
-
412
369
  rule(power_base: simple(:power_base),
413
370
  power: sequence(:power)) do
414
371
  first_value = power.shift if Utility.frac_values(power)
@@ -420,16 +377,6 @@ module Plurimath
420
377
  end
421
378
  end
422
379
 
423
- rule(sequence: simple(:sequence),
424
- symbol: simple(:symbol)) do
425
- symbol_object = Utility.symbol_object(
426
- (Constants::SYMBOLS[symbol.to_sym] || symbol).to_s,
427
- )
428
- new_arr = [sequence]
429
- new_arr << symbol_object unless symbol.to_s.strip.empty?
430
- new_arr
431
- end
432
-
433
380
  rule(power_base: simple(:power_base),
434
381
  left_right: simple(:left_right)) do
435
382
  new_arr = [power_base]
@@ -459,10 +406,25 @@ module Plurimath
459
406
 
460
407
  rule(power_base: simple(:power_base),
461
408
  base: simple(:base)) do
462
- Math::Function::Base.new(
463
- power_base,
464
- Utility.unfenced_value(base),
465
- )
409
+ if base.is_a?(Math::Formula) && base.value.any? { |value| Utility.symbol_value(value, ",") }
410
+ sliced = base.value.slice_before { |object| Utility.symbol_value(object, ",") }.to_a
411
+ base_object = Math::Function::Base.new(
412
+ power_base,
413
+ Utility.filter_values(
414
+ Utility.unfenced_value(sliced.shift),
415
+ ),
416
+ )
417
+ [
418
+ base_object,
419
+ sliced.shift.first,
420
+ Utility.filter_values(sliced),
421
+ ].compact
422
+ else
423
+ Math::Function::Base.new(
424
+ power_base,
425
+ Utility.unfenced_value(base),
426
+ )
427
+ end
466
428
  end
467
429
 
468
430
  rule(power_base: simple(:power_base),
@@ -510,16 +472,7 @@ module Plurimath
510
472
  Utility.unfenced_value(base_value),
511
473
  Utility.filter_values(first_value),
512
474
  )
513
- if power_value.empty?
514
- power_base_object
515
- else
516
- Math::Formula.new(
517
- power_value.insert(
518
- 0,
519
- power_base_object,
520
- ),
521
- )
522
- end
475
+ power_value.insert(0, power_base_object)
523
476
  end
524
477
 
525
478
  rule(power_base: simple(:power_base),
@@ -630,37 +583,6 @@ module Plurimath
630
583
  new_arr
631
584
  end
632
585
 
633
- rule(intermediate_exp: simple(:int_exp),
634
- power: simple(:power)) do
635
- Math::Function::Power.new(
636
- int_exp,
637
- Utility.unfenced_value(power),
638
- )
639
- end
640
-
641
- rule(intermediate_exp: simple(:int_exp),
642
- power: sequence(:power)) do
643
- Math::Function::Power.new(
644
- int_exp,
645
- Utility.unfenced_value(power),
646
- )
647
- end
648
-
649
- rule(intermediate_exp: simple(:int_exp),
650
- base: simple(:base)) do
651
- Math::Function::Base.new(
652
- int_exp,
653
- Utility.unfenced_value(base),
654
- )
655
- end
656
-
657
- rule(power_base: simple(:power_base),
658
- expr: simple(:expr)) do
659
- new_arr = [power_base]
660
- new_arr << expr unless expr.to_s.strip.empty?
661
- new_arr
662
- end
663
-
664
586
  rule(power_base: sequence(:power_base),
665
587
  expr: simple(:expr)) do
666
588
  new_arr = power_base
@@ -697,22 +619,6 @@ module Plurimath
697
619
  sequence.flatten.compact + expr.flatten.compact
698
620
  end
699
621
 
700
- rule(unary: simple(:unary),
701
- power: simple(:power)) do
702
- Math::Function::Power.new(
703
- unary,
704
- Utility.unfenced_value(power),
705
- )
706
- end
707
-
708
- rule(unary: simple(:unary),
709
- base: simple(:base)) do
710
- Math::Function::Base.new(
711
- unary,
712
- Utility.unfenced_value(base),
713
- )
714
- end
715
-
716
622
  rule(binary_class: simple(:function),
717
623
  base_value: simple(:base)) do
718
624
  Utility.get_class(function).new(
@@ -720,17 +626,6 @@ module Plurimath
720
626
  )
721
627
  end
722
628
 
723
- rule(binary_class: simple(:function),
724
- base_value: sequence(:base)) do
725
- binary = Utility.get_class(function).new(
726
- Utility.unfenced_value(base.shift),
727
- Utility.unfenced_value(base.shift),
728
- )
729
- new_arr = [binary]
730
- new_arr += base.flatten.compact unless base.empty?
731
- new_arr
732
- end
733
-
734
629
  rule(d: simple(:d),
735
630
  x: simple(:x)) do
736
631
  Math::Formula.new(
@@ -741,52 +636,6 @@ module Plurimath
741
636
  )
742
637
  end
743
638
 
744
- rule(symbol: simple(:symbol),
745
- power: simple(:power)) do
746
- Math::Function::Power.new(
747
- Utility.symbol_object(
748
- (Constants::SYMBOLS[symbol.to_sym] || symbol).to_s,
749
- ),
750
- Utility.unfenced_value(power),
751
- )
752
- end
753
-
754
- rule(symbol: simple(:symbol),
755
- power: sequence(:power)) do
756
- Math::Function::Power.new(
757
- Utility.symbol_object(
758
- (Constants::SYMBOLS[symbol.to_sym] || symbol).to_s,
759
- ),
760
- Utility.unfenced_value(power),
761
- )
762
- end
763
-
764
- rule(symbol: simple(:sym),
765
- expr: sequence(:expr)) do
766
- symbol = Utility.symbol_object(
767
- (Constants::SYMBOLS[sym.to_sym] || sym).to_s,
768
- )
769
- expr.flatten.compact.insert(0, symbol)
770
- end
771
-
772
- rule(symbol: simple(:sym),
773
- expr: simple(:expr)) do
774
- symbol = Utility.symbol_object(
775
- (Constants::SYMBOLS[sym.to_sym] || sym).to_s,
776
- )
777
- [symbol, expr]
778
- end
779
-
780
- rule(symbol: simple(:symbol),
781
- base: simple(:base)) do
782
- Math::Function::Base.new(
783
- Utility.symbol_object(
784
- (Constants::SYMBOLS[symbol.to_sym] || symbol).to_s,
785
- ),
786
- Utility.unfenced_value(base),
787
- )
788
- end
789
-
790
639
  rule(binary_class: simple(:function),
791
640
  base: simple(:base)) do
792
641
  Utility.get_class(function).new(
@@ -831,31 +680,6 @@ module Plurimath
831
680
  )
832
681
  end
833
682
 
834
- rule(binary_class: simple(:function),
835
- base_value: simple(:base),
836
- power_value: simple(:power),
837
- expr: sequence(:expr)) do
838
- [
839
- Utility.get_class(function).new(
840
- Utility.unfenced_value(base),
841
- Utility.unfenced_value(power),
842
- ),
843
- ] + expr
844
- end
845
-
846
- rule(binary_class: simple(:function),
847
- base_value: simple(:base),
848
- power_value: simple(:power),
849
- expr: simple(:expr)) do
850
- [
851
- Utility.get_class(function).new(
852
- Utility.unfenced_value(base),
853
- Utility.unfenced_value(power),
854
- ),
855
- expr,
856
- ]
857
- end
858
-
859
683
  rule(unary_class: simple(:function),
860
684
  intermediate_exp: simple(:int_exp)) do
861
685
  first_value = if Utility::UNARY_CLASSES.include?(function)
@@ -913,54 +737,6 @@ module Plurimath
913
737
  ]
914
738
  end
915
739
 
916
- rule(number: simple(:number),
917
- power: simple(:power)) do
918
- Math::Function::Power.new(
919
- Math::Number.new(number),
920
- Utility.unfenced_value(power),
921
- )
922
- end
923
-
924
- rule(number: simple(:number),
925
- power: sequence(:power)) do
926
- Math::Function::Power.new(
927
- Math::Number.new(number),
928
- Utility.unfenced_value(power),
929
- )
930
- end
931
-
932
- rule(text: simple(:text),
933
- base: simple(:base)) do
934
- Math::Function::Base.new(
935
- Math::Function::Text.new(text),
936
- Utility.unfenced_value(base),
937
- )
938
- end
939
-
940
- rule(text: sequence(:text),
941
- base: simple(:base)) do
942
- Math::Function::Base.new(
943
- Math::Function::Text.new(text.join),
944
- Utility.unfenced_value(base),
945
- )
946
- end
947
-
948
- rule(text: simple(:text),
949
- power: simple(:power)) do
950
- Math::Function::Power.new(
951
- Math::Function::Text.new(text),
952
- Utility.unfenced_value(power),
953
- )
954
- end
955
-
956
- rule(text: sequence(:text),
957
- power: simple(:power)) do
958
- Math::Function::Power.new(
959
- Math::Function::Text.new(text.join),
960
- Utility.unfenced_value(power),
961
- )
962
- end
963
-
964
740
  rule(table: simple(:table),
965
741
  expr: sequence(:expr)) do
966
742
  Math::Formula.new([table] + expr.flatten.compact)
@@ -994,92 +770,6 @@ module Plurimath
994
770
  )
995
771
  end
996
772
 
997
- rule(text: simple(:text),
998
- base_value: simple(:base),
999
- power_value: simple(:power)) do
1000
- Math::Function::PowerBase.new(
1001
- Math::Function::Text.new(text),
1002
- Utility.unfenced_value(base),
1003
- Utility.unfenced_value(power),
1004
- )
1005
- end
1006
-
1007
- rule(number: simple(:number),
1008
- base_value: simple(:base),
1009
- power_value: simple(:power)) do
1010
- Math::Function::PowerBase.new(
1011
- Math::Number.new(number),
1012
- Utility.unfenced_value(base),
1013
- Utility.unfenced_value(power),
1014
- )
1015
- end
1016
-
1017
- rule(unary: simple(:unary),
1018
- base_value: simple(:base),
1019
- power_value: simple(:power)) do
1020
- Math::Function::PowerBase.new(
1021
- unary,
1022
- Utility.unfenced_value(base),
1023
- Utility.unfenced_value(power),
1024
- )
1025
- end
1026
-
1027
- rule(unary: sequence(:unary),
1028
- base_value: simple(:base),
1029
- power_value: simple(:power)) do
1030
- unary.first.new(
1031
- unary.last.new(
1032
- Utility.unfenced_value(base),
1033
- Utility.unfenced_value(power),
1034
- ),
1035
- )
1036
- end
1037
-
1038
- rule(intermediate_exp: simple(:int_exp),
1039
- base_value: simple(:base),
1040
- power_value: simple(:power)) do
1041
- Math::Function::PowerBase.new(
1042
- int_exp,
1043
- Utility.unfenced_value(base),
1044
- Utility.unfenced_value(power),
1045
- )
1046
- end
1047
-
1048
- rule(intermediate_exp: simple(:int_exp),
1049
- base_value: simple(:base),
1050
- power_value: sequence(:power)) do
1051
- Math::Function::PowerBase.new(
1052
- int_exp,
1053
- Utility.unfenced_value(base),
1054
- Utility.filter_values(power),
1055
- )
1056
- end
1057
-
1058
- rule(symbol: simple(:symbol),
1059
- base_value: simple(:base),
1060
- power_value: simple(:power)) do
1061
- Math::Function::PowerBase.new(
1062
- Utility.symbol_object(
1063
- (Constants::SYMBOLS[symbol.to_sym] || symbol).to_s,
1064
- ),
1065
- Utility.unfenced_value(base),
1066
- Utility.unfenced_value(power),
1067
- )
1068
- end
1069
-
1070
- rule(symbol: simple(:symbol),
1071
- base_value: simple(:base),
1072
- power_value: sequence(:power)) do
1073
- symbol_object = Utility.symbol_object(
1074
- (Constants::SYMBOLS[symbol.to_sym] || symbol).to_s,
1075
- )
1076
- Math::Function::PowerBase.new(
1077
- symbol_object,
1078
- Utility.unfenced_value(base),
1079
- Utility.filter_values(power),
1080
- )
1081
- end
1082
-
1083
773
  rule(lparen: simple(:lparen),
1084
774
  expr: simple(:expr),
1085
775
  rparen: simple(:rparen)) do
@@ -1107,18 +797,6 @@ module Plurimath
1107
797
  )
1108
798
  end
1109
799
 
1110
- rule(lparen: simple(:lparen),
1111
- text: simple(:text),
1112
- rparen: simple(:rparen)) do
1113
- Math::Function::Text.new(text)
1114
- end
1115
-
1116
- rule(lparen: simple(:lparen),
1117
- text: sequence(:text),
1118
- rparen: simple(:rparen)) do
1119
- Math::Function::Text.new(text.flatten.compact.join)
1120
- end
1121
-
1122
800
  rule(lparen: simple(:lparen),
1123
801
  rgb_color: sequence(:color),
1124
802
  rparen: simple(:rparen)) do
@@ -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": "&#x5c;",
3790
+ "\\langle": "&#x27e8;",
3791
+ "\\rangle": "&#x27e9;",
3792
+ "\\lfloor": "&#x230a;",
3793
+ "\\rfloor": "&#x230b;",
3794
+ "\\lceil": "&#x2308;",
3795
+ "\\rceil": "&#x2309;",
3796
+ "\\lbrace": "&#x7b;",
3797
+ "\\rbrace": "&#x7d;",
3798
+ "\\lbrack": "&#x5b;",
3799
+ "\\rbrack": "&#x5d;",
3800
+ "\\Vert": "&#x2016;",
3801
+ "\\vert": "&#x7c;",
3802
+ "\\|": "&#x2016;",
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
79
81
  Math::Formula.new(
80
82
  [
81
- Math::Function::Left.new(lparen),
83
+ Utility.left_right_objects(lparen, "left"),
82
84
  Math::Formula.new(expr),
83
- Math::Function::Right.new(rparen),
85
+ Utility.left_right_objects(rparen, "right"),
84
86
  ],
85
87
  )
86
88
  end
87
89
 
88
90
  rule(left: simple(:left),
89
- lparen: simple(:lparen),
91
+ left_paren: simple(:lparen),
92
+ expression: sequence(:expr),
90
93
  right: simple(:right)) do
91
94
  Math::Formula.new(
92
95
  [
93
- Math::Function::Left.new(lparen),
96
+ Utility.left_right_objects(lparen, "left"),
97
+ Math::Formula.new(expr),
94
98
  Math::Function::Right.new,
95
99
  ],
96
100
  )
97
101
  end
98
102
 
99
103
  rule(left: simple(:left),
100
- lparen: simple(:lparen),
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,
112
+ ],
113
+ )
114
+ end
115
+
116
+ rule(left: simple(:left),
117
+ left_paren: simple(:lparen),
118
+ right: simple(:right)) do
119
+ Math::Formula.new(
120
+ [
121
+ Utility.left_right_objects(lparen, "left"),
122
+ Math::Function::Right.new,
123
+ ],
124
+ )
125
+ end
126
+
127
+ rule(left: simple(:left),
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
@@ -258,8 +310,13 @@ module Plurimath
258
310
 
259
311
  rule(unary_functions: simple(:unary),
260
312
  supscript: simple(:supscript)) do
313
+ unary_function = if unary.is_a?(Parslet::Slice)
314
+ Utility.get_class(unary).new
315
+ else
316
+ unary
317
+ end
261
318
  Math::Function::Power.new(
262
- unary,
319
+ unary_function,
263
320
  supscript,
264
321
  )
265
322
  end
@@ -267,8 +324,13 @@ module Plurimath
267
324
  rule(unary_functions: simple(:unary),
268
325
  subscript: simple(:subscript),
269
326
  supscript: simple(:supscript)) do
327
+ unary_function = if unary.is_a?(Parslet::Slice)
328
+ Utility.get_class(unary).new
329
+ else
330
+ unary
331
+ end
270
332
  Math::Function::PowerBase.new(
271
- unary,
333
+ unary_function,
272
334
  subscript,
273
335
  supscript,
274
336
  )
@@ -333,6 +395,14 @@ module Plurimath
333
395
  )
334
396
  end
335
397
 
398
+ rule(intermediate_exp: simple(:int_exp),
399
+ supscript: simple(:supscript)) do
400
+ Math::Function::Power.new(
401
+ int_exp,
402
+ supscript,
403
+ )
404
+ end
405
+
336
406
  rule(unicode_symbols: simple(:sym),
337
407
  subscript: simple(:subscript)) do
338
408
  Math::Function::Base.new(
@@ -451,6 +521,26 @@ module Plurimath
451
521
  Math::Formula.new(expr)
452
522
  end
453
523
 
524
+ rule(left_paren: simple(:lparen),
525
+ expression: simple(:expr),
526
+ right_paren: simple(:rparen)) do
527
+ Math::Function::Fenced.new(
528
+ lparen,
529
+ [expr],
530
+ rparen,
531
+ )
532
+ end
533
+
534
+ rule(left_paren: simple(:lparen),
535
+ expression: sequence(:expr),
536
+ right_paren: simple(:rparen)) do
537
+ Math::Function::Fenced.new(
538
+ lparen,
539
+ expr,
540
+ rparen,
541
+ )
542
+ end
543
+
454
544
  rule(expression: sequence(:expr)) do
455
545
  Math::Formula.new(expr)
456
546
  end
@@ -474,14 +564,6 @@ module Plurimath
474
564
  )
475
565
  end
476
566
 
477
- rule(rparen: simple(:rparen),
478
- supscript: simple(:supscript)) do
479
- Math::Function::Power.new(
480
- Math::Symbol.new(rparen),
481
- supscript,
482
- )
483
- end
484
-
485
567
  rule(expression: simple(:expr),
486
568
  supscript: simple(:supscript)) do
487
569
  Math::Function::Power.new(
@@ -6,6 +6,18 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Dot < UnaryFunction
9
+ def to_mathml_without_math_tag
10
+ first_value = parameter_one&.to_mathml_without_math_tag
11
+ dot_tag = (Utility.ox_element("mo") << ".")
12
+ over_tag = Utility.ox_element("mover")
13
+ Utility.update_nodes(
14
+ over_tag,
15
+ [
16
+ first_value,
17
+ dot_tag,
18
+ ],
19
+ )
20
+ end
9
21
  end
10
22
  end
11
23
  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.2"
4
+ VERSION = "0.3.3"
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.2
4
+ version: 0.3.3
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-11 00:00:00.000000000 Z
11
+ date: 2023-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet