plurimath 0.3.2 → 0.3.4

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: 8c90b0eb8f6510c5a93742653d0a9d395de3adf3b7dfa53f43d53ce4d7821a27
4
- data.tar.gz: 966c4a94fc1245cec98e7290e3761be0774a71d62403e38bfa405aa1db5cd9f8
3
+ metadata.gz: 1b189635567597c62c87de4beda13072f0be78d12993bbf8fb88d5a62447c0d9
4
+ data.tar.gz: 87960dc1944b7328585f44e8d8605dd5d94d00c2e29522ceebbf6e2f09936e18
5
5
  SHA512:
6
- metadata.gz: 364d72c3e42db84c13b5896ec36ea4cdb5f856ebdd970e7ff1058f3c2251cb301dd641cb51e1addcb5c890cfbd83cdebc5cf91df48e495704a8eae355b502d82
7
- data.tar.gz: 607a1cf277fcbdce40ab130397985e8bf5682662adb747debb42823b257201e110d9aa4d7cb1087a191e98efeadab5976e723c2a9a6f64deb4e38bdf8fa513a1
6
+ metadata.gz: 4525b775b5ceb63822c1e4a0777604684b80b3c85403df64a8443d405a6e93bd3c8f354a905788558224f163caaf8a73eaca52f03f6042e409eae112f26d9805
7
+ data.tar.gz: b41b71415e9908bdd5bade1be722f48155473e556b050ecaebf097a21aaec1b478f63a2d72f60ead47b1a972f2c3b13623e6eb4837d426b489b39e7952bf4e0f
@@ -86,8 +86,6 @@
86
86
  * `sec`
87
87
  * `ln`
88
88
  * `ul`
89
- * `g`
90
- * `f`
91
89
 
92
90
 
93
91
  == Symbols
@@ -1588,10 +1586,10 @@
1588
1586
  | `Lbrack` | ⟦
1589
1587
  | `rBrack` | ⟧
1590
1588
  | `Rbrack` | ⟧
1591
- | `langle` | ⟨
1589
+ | `langle` | 〈
1592
1590
  | `lAngle` | ⟪
1593
1591
  | `rAngle` | ⟫
1594
- | `rangle` | ⟩
1592
+ | `rangle` | 〉
1595
1593
  | `lgroup` | ⟮
1596
1594
  | `rgroup` | ⟯
1597
1595
  | `Mapsto` | ⤇
@@ -72,8 +72,6 @@
72
72
  * `sec`
73
73
  * `ln`
74
74
  * `ul`
75
- * `g`
76
- * `f`
77
75
 
78
76
 
79
77
  === Tags
@@ -214,8 +212,8 @@
214
212
  | `\⊨` | ⊨
215
213
  | `\〈` | 〈
216
214
  | `\〉` | 〉
217
- | `\⟨` | ⟨
218
- | `\⟩` | ⟩
215
+ | `\〈` | 〈
216
+ | `\〉` | 〉
219
217
  | `\∫` | ∫
220
218
  | `\∮` | ∮
221
219
  | `\∂` | ∂
@@ -4,13 +4,13 @@ module Plurimath
4
4
  class Asciimath
5
5
  class Constants
6
6
  TABLE_PARENTHESIS = {
7
- "(:": ":)",
7
+ "": "",
8
8
  "ℒ": "ℛ",
9
9
  "[": "]",
10
10
  "(": ")",
11
11
  }.freeze
12
12
  PARENTHESIS = {
13
- "(:": ":)",
13
+ "": "",
14
14
  "ℒ": "ℛ",
15
15
  "(": ")",
16
16
  "{": "}",
@@ -286,8 +286,6 @@ module Plurimath
286
286
  vec
287
287
  ul
288
288
  ln
289
- f
290
- g
291
289
  ].freeze
292
290
  BINARY_CLASSES = %i[
293
291
  underset
@@ -58,8 +58,8 @@ module Plurimath
58
58
  end
59
59
 
60
60
  rule(:quoted_text) do
61
- str('"') >> match("[^\"]").repeat.as(:text) >> str('"') |
62
- str('"') >> str("").as(:text)
61
+ (str('"') >> match("[^\"]").repeat.as(:text) >> str('"')) |
62
+ (str('"') >> str("").as(:text))
63
63
  end
64
64
 
65
65
  rule(:symbol_text_or_integer) do
@@ -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
 
@@ -89,16 +89,15 @@ module Plurimath
89
89
  end
90
90
 
91
91
  rule(:table) do
92
- (open_table.as(:table_left) >> tr >> close_table.as(:table_right)) |
93
- (open_table.as(:table_left) >> tr >> str("}").as(:table_right)) |
94
- (str("norm").as(:norm) >> open_table.as(:table_left) >> tr >> close_table.as(:table_right)) |
95
- (str("{").as(:table_left) >> tr >> close_table.as(:table_right)) |
96
- (str("|").as(:table_left) >> tr >> str("|").as(:table_right)) |
97
- (str("left") >> left_right_open_paren.as(:left) >> tr >> str("right") >> left_right_close_paren.as(:right))
92
+ (str("{").as(:table_left) >> space.maybe >> tr >> space.maybe >> close_table.as(:table_right)) |
93
+ (open_table.as(:table_left) >> space.maybe >> tr >> space.maybe >> close_table.as(:table_right)) |
94
+ (str("norm").as(:norm) >> open_table.as(:table_left) >> space.maybe >> tr >> space.maybe >> close_table.as(:table_right)) |
95
+ (str("|").as(:table_left) >> space.maybe >> tr >> space.maybe >> str("|").as(:table_right)) |
96
+ (str("left") >> left_right_open_paren.as(:left) >> space.maybe >> tr >> space.maybe >> str("right") >> left_right_close_paren.as(:right))
98
97
  end
99
98
 
100
99
  rule(:tr) do
101
- ((left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row) >> comma >> tr.as(:expr)) |
100
+ ((left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row) >> comma >> space.maybe >> tr.as(:expr)) |
102
101
  (left_right_open_paren.as(:open_tr) >> td.as(:tds_list) >> left_right_close_paren).as(:table_row)
103
102
  end
104
103
 
@@ -13,6 +13,8 @@ module Plurimath
13
13
  &.gsub(/(\|:|:\|)/, "|")
14
14
  &.gsub(/(\{:)/, "ℒ")
15
15
  &.gsub(/(:\})/, "ℛ")
16
+ &.gsub(/(\(:)/, "ᑕ")
17
+ &.gsub(/(:\))/, "ᑐ")
16
18
  end
17
19
 
18
20
  def parse
@@ -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
@@ -34,8 +34,6 @@ module Plurimath
34
34
  det
35
35
  ln
36
36
  lg
37
- g
38
- f
39
37
  ].freeze
40
38
  SUB_SUP_CLASSES = {
41
39
  "&prod;": :prod,
@@ -36,6 +36,11 @@ module Plurimath
36
36
  [sequence, expr]
37
37
  end
38
38
 
39
+ rule(sequence: simple(:sequence),
40
+ parse_parenthesis: simple(:parse_paren)) do
41
+ [sequence, parse_paren]
42
+ end
43
+
39
44
  rule(sequence: simple(:sequence),
40
45
  expression: sequence(:expr)) do
41
46
  expr.insert(0, sequence)
@@ -72,6 +77,13 @@ module Plurimath
72
77
  )
73
78
  end
74
79
 
80
+ rule(unary_function: simple(:unary_function),
81
+ sequence: sequence(:sequence)) do
82
+ Math::Formula.new(
83
+ ([unary_function] + sequence),
84
+ )
85
+ end
86
+
75
87
  rule(text: simple(:text),
76
88
  expression: simple(:expr)) do
77
89
  [
@@ -250,6 +262,16 @@ module Plurimath
250
262
  end
251
263
  end
252
264
 
265
+ rule(sub_sup: simple(:sub_sup),
266
+ sup_value: sequence(:sup_value),
267
+ expression: simple(:expression)) do
268
+ power = Math::Function::Power.new(
269
+ sub_sup,
270
+ Math::Formula.new(sup_value),
271
+ )
272
+ [power, expression]
273
+ end
274
+
253
275
  rule(lparen: simple(:lparen),
254
276
  text: simple(:text),
255
277
  rparen: simple(:rparen)) do
@@ -270,6 +292,18 @@ module Plurimath
270
292
  ])
271
293
  end
272
294
 
295
+ rule(lparen: simple(:lparen),
296
+ sequence: simple(:sequence),
297
+ parse_parenthesis: simple(:parse_paren),
298
+ rparen: simple(:rparen)) do
299
+ Math::Formula.new([
300
+ Math::Symbol.new(lparen),
301
+ sequence,
302
+ parse_paren,
303
+ Math::Symbol.new(rparen),
304
+ ])
305
+ end
306
+
273
307
  rule(lparen: simple(:lparen),
274
308
  sequence: sequence(:sequence),
275
309
  rparen: simple(:rparen)) do
@@ -1311,8 +1311,8 @@ module Plurimath
1311
1311
  Lbrack: "&#x27e6;",
1312
1312
  rBrack: "&#x27e7;",
1313
1313
  Rbrack: "&#x27e7;",
1314
- langle: "&#x27e8;",
1315
- rangle: "&#x27e9;",
1314
+ langle: "&#x2329;",
1315
+ rangle: "&#x232a;",
1316
1316
  lAngle: "&#x27ea;",
1317
1317
  rAngle: "&#x27eb;",
1318
1318
  lgroup: "&#x27ee;",
@@ -3787,8 +3787,8 @@ module Plurimath
3787
3787
  ].freeze
3788
3788
  LEFT_RIGHT_PARENTHESIS = {
3789
3789
  "\\backslash": "&#x5c;",
3790
- "\\langle": "&#x27e8;",
3791
- "\\rangle": "&#x27e9;",
3790
+ "\\langle": "&#x2329;",
3791
+ "\\rangle": "&#x232a;",
3792
3792
  "\\lfloor": "&#x230a;",
3793
3793
  "\\rfloor": "&#x230b;",
3794
3794
  "\\lceil": "&#x2308;",
@@ -3828,7 +3828,7 @@ module Plurimath
3828
3828
  |
3829
3829
  }
3830
3830
  {
3831
- ]
3831
+ ].freeze
3832
3832
  end
3833
3833
  end
3834
3834
  end
@@ -90,7 +90,7 @@ module Plurimath
90
90
  (slash >> math_operators_classes) |
91
91
  match["a-zA-Z"].as(:symbols) |
92
92
  match(/\d+(\.[0-9]+)|\d/).repeat(1).as(:number) |
93
- str("\\\\").as("\\\\") >> match(/\s/).repeat |
93
+ (str("\\\\").as("\\\\") >> match(/\s/).repeat) |
94
94
  str("\\ ").as(:space)
95
95
  end
96
96
 
@@ -140,10 +140,10 @@ module Plurimath
140
140
  (expression.repeat.as(:dividend) >> str("\\over") >> expression.repeat.as(:divisor)) |
141
141
  expression.as(:expression).maybe
142
142
  ) >>
143
- (
144
- str("\\right").as(:right).maybe >> (right_parens | str(".").maybe)
145
- )
146
- )
143
+ (
144
+ str("\\right").as(:right).maybe >> (right_parens | str(".").maybe)
145
+ )
146
+ )
147
147
  end
148
148
 
149
149
  rule(:over_class) do
@@ -156,7 +156,7 @@ module Plurimath
156
156
 
157
157
  rule(:iteration) do
158
158
  (sequence.as(:sequence) >> iteration.as(:expression)) |
159
- sequence >> expression.maybe
159
+ (sequence >> expression.maybe)
160
160
  end
161
161
 
162
162
  rule(:expression) do
@@ -204,7 +204,7 @@ module Plurimath
204
204
  when :binary
205
205
  (slashed_value(first_value, :binary) >> intermediate_exp.as(:first_value) >> intermediate_exp.as(:second_value)).as(:binary)
206
206
  when :text
207
- (slashed_value(first_value, :text) >> (str("{") >> (match("[^\}]").repeat).as(:first_value) >> str("}")))
207
+ (slashed_value(first_value, :text) >> (str("{") >> match("[^}]").repeat.as(:first_value) >> str("}")))
208
208
  end
209
209
  end
210
210
 
@@ -310,8 +310,13 @@ module Plurimath
310
310
 
311
311
  rule(unary_functions: simple(:unary),
312
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
313
318
  Math::Function::Power.new(
314
- unary,
319
+ unary_function,
315
320
  supscript,
316
321
  )
317
322
  end
@@ -319,8 +324,13 @@ module Plurimath
319
324
  rule(unary_functions: simple(:unary),
320
325
  subscript: simple(:subscript),
321
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
322
332
  Math::Function::PowerBase.new(
323
- unary,
333
+ unary_function,
324
334
  subscript,
325
335
  supscript,
326
336
  )
@@ -554,14 +564,6 @@ module Plurimath
554
564
  )
555
565
  end
556
566
 
557
- rule(rparen: simple(:rparen),
558
- supscript: simple(:supscript)) do
559
- Math::Function::Power.new(
560
- Math::Symbol.new(rparen),
561
- supscript,
562
- )
563
- end
564
-
565
567
  rule(expression: simple(:expr),
566
568
  supscript: simple(:supscript)) do
567
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
@@ -6,6 +6,11 @@ module Plurimath
6
6
  module Math
7
7
  module Function
8
8
  class Fenced < TernaryFunction
9
+ def initialize(parameter_one = nil, parameter_two = nil, parameter_three = nil)
10
+ super
11
+ circular_parens
12
+ end
13
+
9
14
  def to_asciimath
10
15
  first_value = parameter_one ? parameter_one.to_asciimath : "("
11
16
  third_value = parameter_three ? parameter_three.to_asciimath : ")"
@@ -33,8 +38,8 @@ module Plurimath
33
38
  open_paren = parameter_one ? parameter_one.value : "("
34
39
  fenced_value = parameter_two&.map(&:to_latex)&.join(" ")
35
40
  close_paren = parameter_three ? parameter_three.value : ")"
36
- first_value = latex_paren(open_paren, false)
37
- second_value = latex_paren(close_paren, true)
41
+ first_value = latex_paren(open_paren)
42
+ second_value = latex_paren(close_paren)
38
43
  "#{first_value} #{fenced_value} #{second_value}"
39
44
  end
40
45
 
@@ -52,25 +57,6 @@ module Plurimath
52
57
 
53
58
  protected
54
59
 
55
- def second_value
56
- class_names = ["number", "symbol"].freeze
57
- parameter_two&.map do |object|
58
- e_tag = Utility.ox_element("e", namespace: "m")
59
- e_tag << if class_names.include?(object.class_name)
60
- fenced_omml_value(object)
61
- else
62
- object&.to_omml_without_math_tag
63
- end
64
- end
65
- end
66
-
67
- def fenced_omml_value(object)
68
- r_tag = Utility.ox_element("r", namespace: "m")
69
- t_tag = Utility.ox_element("t", namespace: "m")
70
- t_tag << object&.value
71
- r_tag << t_tag
72
- end
73
-
74
60
  def first_value(dpr)
75
61
  first_value = parameter_one&.value
76
62
  return dpr if first_value.nil? || first_value.empty?
@@ -83,6 +69,18 @@ module Plurimath
83
69
  )
84
70
  end
85
71
 
72
+ def second_value
73
+ class_names = ["number", "symbol"].freeze
74
+ parameter_two&.map do |object|
75
+ e_tag = Utility.ox_element("e", namespace: "m")
76
+ e_tag << if class_names.include?(object.class_name)
77
+ fenced_omml_value(object)
78
+ else
79
+ object&.to_omml_without_math_tag
80
+ end
81
+ end
82
+ end
83
+
86
84
  def third_value(dpr)
87
85
  third_value = parameter_three&.value
88
86
  return dpr if third_value.nil? || third_value.empty?
@@ -95,11 +93,19 @@ module Plurimath
95
93
  )
96
94
  end
97
95
 
98
- def latex_paren(paren, right)
96
+ def fenced_omml_value(object)
97
+ r_tag = Utility.ox_element("r", namespace: "m")
98
+ t_tag = Utility.ox_element("t", namespace: "m")
99
+ t_tag << object&.value
100
+ r_tag << t_tag
101
+ end
102
+
103
+ def latex_paren(paren)
99
104
  return "" if paren.nil? || paren.empty?
100
105
 
101
106
  paren = %w[{ }].include?(paren) ? "\\#{paren}" : paren
102
- "#{paren}"
107
+ paren = "\\#{Latex::Constants::UNICODE_SYMBOLS.invert[paren]}" if paren.to_s.match?(/\&#x.{0,4};/)
108
+ paren.to_s
103
109
  end
104
110
 
105
111
  def mathml_paren(field)
@@ -107,6 +113,11 @@ module Plurimath
107
113
 
108
114
  field&.value
109
115
  end
116
+
117
+ def circular_parens
118
+ parameter_one&.value = "&#x2329;" if Utility.symbol_value(parameter_one, "ᑕ")
119
+ parameter_three&.value = "&#x232a;" if Utility.symbol_value(parameter_three, "ᑐ")
120
+ end
110
121
  end
111
122
  end
112
123
  end
@@ -27,7 +27,7 @@ module Plurimath
27
27
  end
28
28
 
29
29
  def to_latex
30
- "\\left #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || "."}"
30
+ "\\left #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || '.'}"
31
31
  end
32
32
 
33
33
  protected
@@ -27,7 +27,7 @@ module Plurimath
27
27
  end
28
28
 
29
29
  def to_latex
30
- "\\right #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || "."}"
30
+ "\\right #{Latex::Constants::LEFT_RIGHT_PARENTHESIS.invert[parameter_one] || '.'}"
31
31
  end
32
32
 
33
33
  protected
@@ -71,7 +71,7 @@ module Plurimath
71
71
  end
72
72
 
73
73
  def explicit_checks(unicode)
74
- return true if [unicode, value].any?{|v| ["∣", "|"].include?(v) }
74
+ return true if [unicode, value].any? { |v| ["∣", "|"].include?(v) }
75
75
  end
76
76
 
77
77
  def specific_values
@@ -93,8 +93,8 @@ module Plurimath
93
93
  "&#x22a8;": "|==",
94
94
  "&#x2329;": "(:",
95
95
  "&#x232a;": ":)",
96
- "&#x27e8;": "<<",
97
- "&#x27e9;": ">>",
96
+ "&#x2329;": "<<",
97
+ "&#x232a;": ">>",
98
98
  "&#x222b;": "int",
99
99
  "&#x222e;": "oint",
100
100
  "&#x2202;": "del",
@@ -225,8 +225,6 @@ module Plurimath
225
225
  log
226
226
  ul
227
227
  ln
228
- f
229
- g
230
228
  ].freeze
231
229
  OPERATORS = [
232
230
  "&#x00a0;&#x00a0;&#x00a0;&#x00a0;",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.4"
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.2
4
+ version: 0.3.4
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-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -101,7 +101,6 @@ files:
101
101
  - lib/plurimath/math/function/dim.rb
102
102
  - lib/plurimath/math/function/dot.rb
103
103
  - lib/plurimath/math/function/exp.rb
104
- - lib/plurimath/math/function/f.rb
105
104
  - lib/plurimath/math/function/fenced.rb
106
105
  - lib/plurimath/math/function/floor.rb
107
106
  - lib/plurimath/math/function/font_style.rb
@@ -114,7 +113,6 @@ files:
114
113
  - lib/plurimath/math/function/font_style/sans-serif.rb
115
114
  - lib/plurimath/math/function/font_style/script.rb
116
115
  - lib/plurimath/math/function/frac.rb
117
- - lib/plurimath/math/function/g.rb
118
116
  - lib/plurimath/math/function/gcd.rb
119
117
  - lib/plurimath/math/function/glb.rb
120
118
  - lib/plurimath/math/function/hat.rb
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "unary_function"
4
-
5
- module Plurimath
6
- module Math
7
- module Function
8
- class F < UnaryFunction
9
- def to_asciimath
10
- "f#{parameter_one&.to_asciimath}"
11
- end
12
-
13
- def to_latex
14
- first_value = latex_value if parameter_one
15
- "f#{first_value}"
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "unary_function"
4
-
5
- module Plurimath
6
- module Math
7
- module Function
8
- class G < UnaryFunction
9
- def to_asciimath
10
- "g#{parameter_one&.to_asciimath}"
11
- end
12
-
13
- def to_latex
14
- "g#{parameter_one&.to_latex}"
15
- end
16
- end
17
- end
18
- end
19
- end