bcdice 3.0.0.pre.alpha.2 → 3.0.0.pre.rc.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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +1 -0
  4. data/i18n/KillDeathBusiness/ja_jp.yml +4 -4
  5. data/i18n/KillDeathBusiness/ko_kr.yml +5 -4
  6. data/i18n/MagicaLogia/ko_kr.yml +564 -0
  7. data/i18n/MonotoneMuseum/ja_jp.yml +37 -1
  8. data/i18n/StratoShout/ja_jp.yml +4 -4
  9. data/i18n/StratoShout/ko_kr.yml +4 -4
  10. data/lib/bcdice.rb +2 -1
  11. data/lib/bcdice/arithmetic.rb +22 -0
  12. data/lib/bcdice/arithmetic/node.rb +112 -43
  13. data/lib/bcdice/arithmetic/parser.rb +240 -0
  14. data/lib/bcdice/arithmetic_evaluator.rb +5 -156
  15. data/lib/bcdice/base.rb +8 -1
  16. data/lib/bcdice/command/lexer.rb +57 -0
  17. data/lib/bcdice/command/parsed.rb +65 -0
  18. data/lib/bcdice/command/parser.rb +489 -0
  19. data/lib/bcdice/common_command/add_dice.rb +1 -1
  20. data/lib/bcdice/common_command/add_dice/node.rb +142 -69
  21. data/lib/bcdice/common_command/add_dice/parser.rb +100 -83
  22. data/lib/bcdice/common_command/barabara_dice/node.rb +7 -1
  23. data/lib/bcdice/common_command/barabara_dice/result.rb +22 -0
  24. data/lib/bcdice/common_command/calc/node.rb +10 -1
  25. data/lib/bcdice/common_command/calc/parser.rb +1 -1
  26. data/lib/bcdice/common_command/d66_dice.rb +3 -1
  27. data/lib/bcdice/common_command/lexer.rb +2 -1
  28. data/lib/bcdice/common_command/upper_dice/parser.rb +118 -97
  29. data/lib/bcdice/common_command/version.rb +1 -1
  30. data/lib/bcdice/deprecated/checker.rb +6 -6
  31. data/lib/bcdice/dice_table.rb +1 -0
  32. data/lib/bcdice/dice_table/d66_parity_table.rb +34 -0
  33. data/lib/bcdice/game_system.rb +3 -0
  34. data/lib/bcdice/game_system/AceKillerGene.rb +1 -1
  35. data/lib/bcdice/game_system/AlchemiaStruggle.rb +312 -0
  36. data/lib/bcdice/game_system/Alshard.rb +0 -1
  37. data/lib/bcdice/game_system/Amadeus.rb +1 -1
  38. data/lib/bcdice/game_system/AnimaAnimus.rb +1 -5
  39. data/lib/bcdice/game_system/BadLife.rb +1 -1
  40. data/lib/bcdice/game_system/BeastBindTrinity.rb +1 -10
  41. data/lib/bcdice/game_system/BeginningIdol.rb +4 -4
  42. data/lib/bcdice/game_system/BeginningIdol_Korean.rb +4 -4
  43. data/lib/bcdice/game_system/BladeOfArcana.rb +4 -4
  44. data/lib/bcdice/game_system/BlindMythos.rb +12 -9
  45. data/lib/bcdice/game_system/BloodCrusade.rb +12 -38
  46. data/lib/bcdice/game_system/BloodMoon.rb +2 -2
  47. data/lib/bcdice/game_system/CardRanker.rb +23 -63
  48. data/lib/bcdice/game_system/ChaosFlare.rb +3 -3
  49. data/lib/bcdice/game_system/CodeLayerd.rb +1 -1
  50. data/lib/bcdice/game_system/ColossalHunter.rb +2 -2
  51. data/lib/bcdice/game_system/Cthulhu7th.rb +2 -2
  52. data/lib/bcdice/game_system/CthulhuTech.rb +0 -1
  53. data/lib/bcdice/game_system/DarkBlaze.rb +4 -4
  54. data/lib/bcdice/game_system/DeadlineHeroes.rb +1 -1
  55. data/lib/bcdice/game_system/DoubleCross.rb +60 -93
  56. data/lib/bcdice/game_system/EmbryoMachine.rb +5 -5
  57. data/lib/bcdice/game_system/EtrianOdysseySRS.rb +0 -1
  58. data/lib/bcdice/game_system/FilledWith.rb +3 -3
  59. data/lib/bcdice/game_system/FullMetalPanic.rb +0 -1
  60. data/lib/bcdice/game_system/GURPS.rb +1 -1
  61. data/lib/bcdice/game_system/Garako.rb +3 -2
  62. data/lib/bcdice/game_system/GardenOrder.rb +1 -1
  63. data/lib/bcdice/game_system/GehennaAn.rb +3 -3
  64. data/lib/bcdice/game_system/Gundog.rb +1 -1
  65. data/lib/bcdice/game_system/GundogRevised.rb +3 -3
  66. data/lib/bcdice/game_system/GundogZero.rb +2 -2
  67. data/lib/bcdice/game_system/GurpsFW.rb +2 -5
  68. data/lib/bcdice/game_system/HatsuneMiku.rb +1 -1
  69. data/lib/bcdice/game_system/HuntersMoon.rb +17 -110
  70. data/lib/bcdice/game_system/JuinKansen.rb +251 -0
  71. data/lib/bcdice/game_system/KanColle.rb +17 -166
  72. data/lib/bcdice/game_system/KillDeathBusiness.rb +35 -44
  73. data/lib/bcdice/game_system/KillDeathBusiness_Korean.rb +2 -1
  74. data/lib/bcdice/game_system/LogHorizon.rb +8 -8
  75. data/lib/bcdice/game_system/LostRoyal.rb +1 -3
  76. data/lib/bcdice/game_system/MagicaLogia.rb +3 -3
  77. data/lib/bcdice/game_system/MagicaLogia_Korean.rb +66 -0
  78. data/lib/bcdice/game_system/MeikyuDays.rb +1 -1
  79. data/lib/bcdice/game_system/MeikyuKingdom.rb +1 -1
  80. data/lib/bcdice/game_system/MeikyuKingdomBasic.rb +1 -1
  81. data/lib/bcdice/game_system/MetalHeadExtream.rb +4 -4
  82. data/lib/bcdice/game_system/MetallicGuardian.rb +0 -1
  83. data/lib/bcdice/game_system/MonotoneMuseum.rb +3 -2
  84. data/lib/bcdice/game_system/MonotoneMuseum_Korean.rb +1 -1
  85. data/lib/bcdice/game_system/NSSQ.rb +2 -2
  86. data/lib/bcdice/game_system/Nechronica.rb +3 -3
  87. data/lib/bcdice/game_system/NightWizard.rb +1 -1
  88. data/lib/bcdice/game_system/NightmareHunterDeep.rb +3 -4
  89. data/lib/bcdice/game_system/NinjaSlayer.rb +26 -28
  90. data/lib/bcdice/game_system/OracleEngine.rb +13 -17
  91. data/lib/bcdice/game_system/Paradiso.rb +2 -2
  92. data/lib/bcdice/game_system/PhantasmAdventure.rb +0 -4
  93. data/lib/bcdice/game_system/Raisondetre.rb +1 -1
  94. data/lib/bcdice/game_system/RecordOfLodossWar.rb +2 -3
  95. data/lib/bcdice/game_system/RokumonSekai2.rb +2 -2
  96. data/lib/bcdice/game_system/RuinBreakers.rb +1 -1
  97. data/lib/bcdice/game_system/Ryutama.rb +1 -1
  98. data/lib/bcdice/game_system/SRS.rb +0 -5
  99. data/lib/bcdice/game_system/SamsaraBallad.rb +4 -3
  100. data/lib/bcdice/game_system/Satasupe.rb +22 -14
  101. data/lib/bcdice/game_system/ScreamHighSchool.rb +2 -2
  102. data/lib/bcdice/game_system/ShinkuuGakuen.rb +1 -1
  103. data/lib/bcdice/game_system/ShinobiGami.rb +75 -39
  104. data/lib/bcdice/game_system/StellarKnights.rb +1 -3
  105. data/lib/bcdice/game_system/SterileLife.rb +1 -1
  106. data/lib/bcdice/game_system/StrangerOfSwordCity.rb +1 -1
  107. data/lib/bcdice/game_system/StratoShout.rb +10 -36
  108. data/lib/bcdice/game_system/StratoShout_Korean.rb +2 -1
  109. data/lib/bcdice/game_system/SwordWorld.rb +5 -5
  110. data/lib/bcdice/game_system/SwordWorld2_5.rb +1 -1
  111. data/lib/bcdice/game_system/TherapieSein.rb +2 -2
  112. data/lib/bcdice/game_system/TokumeiTenkousei.rb +2 -2
  113. data/lib/bcdice/game_system/Torg.rb +1 -1
  114. data/lib/bcdice/game_system/TorgEternity.rb +4 -7
  115. data/lib/bcdice/game_system/TrinitySeven.rb +2 -2
  116. data/lib/bcdice/game_system/TunnelsAndTrolls.rb +6 -6
  117. data/lib/bcdice/game_system/TwilightGunsmoke.rb +1 -1
  118. data/lib/bcdice/game_system/Utakaze.rb +1 -1
  119. data/lib/bcdice/game_system/Warhammer.rb +6 -6
  120. data/lib/bcdice/game_system/Warhammer4.rb +9 -12
  121. data/lib/bcdice/game_system/ZettaiReido.rb +1 -1
  122. data/lib/bcdice/normalize.rb +1 -1
  123. data/lib/bcdice/preprocessor.rb +12 -8
  124. data/lib/bcdice/randomizer.rb +12 -0
  125. data/lib/bcdice/repl.rb +1 -1
  126. data/lib/bcdice/result.rb +2 -0
  127. data/lib/bcdice/user_defined_dice_table.rb +26 -15
  128. data/lib/bcdice/version.rb +1 -1
  129. metadata +14 -25
  130. data/.editorconfig +0 -21
  131. data/.github/.codecov.yaml +0 -10
  132. data/.github/workflows/coverage.yaml +0 -21
  133. data/.github/workflows/lint.yaml +0 -13
  134. data/.github/workflows/test.yml +0 -20
  135. data/.gitignore +0 -14
  136. data/.rubocop.yml +0 -108
  137. data/.rubocop_todo.yml +0 -114
  138. data/Gemfile +0 -14
  139. data/ROADMAP.md +0 -30
  140. data/Rakefile +0 -152
  141. data/bcdice.gemspec +0 -29
  142. data/bin/repl.rb +0 -21
  143. data/docs/README.txt +0 -2028
  144. data/docs/dicebot_sort_key.md +0 -72
  145. data/docs/how_to_make_dicebot.md +0 -453
  146. data/lib/bcdice/command_parser.rb +0 -242
  147. data/lib/bcdice/common_command/add_dice/parser.y +0 -153
  148. data/lib/bcdice/common_command/barabara_dice/parser.y +0 -107
  149. data/lib/bcdice/common_command/calc/parser.y +0 -79
  150. data/lib/bcdice/common_command/reroll_dice/parser.y +0 -158
  151. data/lib/bcdice/common_command/upper_dice/parser.y +0 -143
@@ -1,167 +1,16 @@
1
1
  module BCDice
2
- #
3
- # 四則演算を評価するクラス
4
- #
5
- class ArithmeticEvaluator
2
+ module ArithmeticEvaluator
6
3
  class << self
7
4
  # 四則演算を評価する
8
- # @param expr [String] 評価する式
5
+ # @deprecated +Arithmetic.#eval+ を利用してください。
6
+ # @param expr [String, nil] 評価する式
9
7
  # @param round_type [Symbol] 端数処理の種類
10
8
  # @return [Integer] 評価結果を返す。不正な式の場合には0を返す。
11
9
  def eval(expr, round_type: RoundType::FLOOR)
12
- ArithmeticEvaluator.new(expr, round_type: round_type).eval()
13
- end
14
- end
15
-
16
- # @param [String, nil] expr 評価する式
17
- # @param [Symbol] round_type 端数処理の種類
18
- def initialize(expr, round_type: RoundType::FLOOR)
19
- @expr = expr
20
- @round_type = round_type
21
-
22
- @error = false
23
- end
24
-
25
- # @return [Boolean] 式の評価時にエラーが発生したか
26
- def error?
27
- @error
28
- end
29
-
30
- # 四則演算を評価する
31
- # 同一インスタンスでevalを二回以上実行した場合の挙動は未定義とする
32
- #
33
- # @return [Integer] 評価結果を返す。不正な式の場合には0を返す。
34
- def eval
35
- if @expr.nil?
36
- return 0
37
- end
38
-
39
- unless @expr.is_a?(String)
40
- raise TypeError, "expr must be String, not #{@expr.class}"
41
- end
42
-
43
- @tokens = tokenize(@expr)
44
- @idx = 0
45
- @error = false
46
-
47
- ret = expr()
48
- if @error
49
- return 0
50
- else
51
- return ret
52
- end
53
- end
54
-
55
- private
56
-
57
- def tokenize(expr)
58
- expr.gsub(%r{[\(\)\+\-\*/]}) { |e| " #{e} " }.split(" ")
59
- end
60
-
61
- def add
62
- ret = mul()
63
-
64
- loop do
65
- if consume("+")
66
- ret += mul()
67
- elsif consume("-")
68
- ret -= mul()
69
- else
70
- break
71
- end
72
- end
73
-
74
- return ret
75
- end
76
- alias expr add
77
-
78
- def mul
79
- ret = unary()
80
-
81
- loop do
82
- if consume("*")
83
- ret *= unary()
84
- elsif consume("/")
85
- ret = div(ret, unary())
86
- else
87
- break
88
- end
89
- end
90
-
91
- return ret
92
- end
10
+ return 0 unless expr
93
11
 
94
- def div(left, right)
95
- if right.zero?
96
- @error = true
97
- return 0
12
+ Arithmetic.eval(expr, round_type) || 0
98
13
  end
99
-
100
- case @round_type
101
- when RoundType::CEIL
102
- return (left.to_f / right).ceil
103
- when RoundType::ROUND
104
- return (left.to_f / right).round
105
- when RoundType::FLOOR
106
- return left / right
107
- else
108
- raise ArgumentError, "unknown round type: #{@round_type.inspect}"
109
- end
110
- end
111
-
112
- def unary
113
- if consume("+")
114
- unary()
115
- elsif consume("-")
116
- -unary()
117
- else
118
- term()
119
- end
120
- end
121
-
122
- def term
123
- if consume("(")
124
- ret = expr()
125
- expect(")")
126
- return ret
127
- else
128
- return expect_number()
129
- end
130
- end
131
-
132
- def consume(str)
133
- if @tokens[@idx] != str
134
- return false
135
- end
136
-
137
- @idx += 1
138
- return true
139
- end
140
-
141
- def expect(str)
142
- if @tokens[@idx] != str
143
- @error = true
144
- end
145
-
146
- @idx += 1
147
- end
148
-
149
- def expect_number()
150
- unless integer?(@tokens[@idx])
151
- @error = true
152
- @idx += 1
153
- return 0
154
- end
155
-
156
- ret = @tokens[@idx].to_i
157
- @idx += 1
158
- return ret
159
- end
160
-
161
- def integer?(str)
162
- # Ruby 1.9 以降では Kernel.#Integer を使うべき
163
- # Ruby 1.8 にもあるが、基数を指定できない問題がある
164
- !/^\d+$/.match(str).nil?
165
14
  end
166
15
  end
167
16
  end
@@ -7,7 +7,7 @@ require "bcdice/dice_table"
7
7
  require "bcdice/enum"
8
8
  require "bcdice/translate"
9
9
  require "bcdice/result"
10
- require "bcdice/command_parser"
10
+ require "bcdice/command/parser"
11
11
  require "bcdice/deprecated/checker"
12
12
 
13
13
  module BCDice
@@ -83,6 +83,8 @@ module BCDice
83
83
 
84
84
  @round_type = RoundType::FLOOR # 割り算をした時の端数の扱い (FLOOR: 切り捨て, CEIL: 切り上げ, ROUND: 四捨五入)
85
85
 
86
+ @sides_implicit_d = 6 # 1D のようにダイスの面数が指定されていない場合に何面ダイスにするか
87
+
86
88
  @upper_dice_reroll_threshold = nil # UpperDiceで振り足しをする出目の閾値 nilの場合デフォルト設定なし
87
89
  @reroll_dice_reroll_threshold = nil # RerollDiceで振り足しをする出目の閾値 nilの場合デフォルト設定なし
88
90
 
@@ -109,6 +111,11 @@ module BCDice
109
111
  # @return [Symbol]
110
112
  attr_reader :round_type
111
113
 
114
+ # ダイスの面数が指定されていない場合に何面ダイスにするか
115
+ #
116
+ # @return [Integer]
117
+ attr_reader :sides_implicit_d
118
+
112
119
  # UpperDiceで振り足しをする出目の閾値
113
120
  #
114
121
  # @return [Integer, nil]
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strscan"
4
+ require "bcdice/normalize"
5
+
6
+ module BCDice
7
+ module Command
8
+ class Lexer
9
+ SYMBOLS = {
10
+ "+" => :PLUS,
11
+ "-" => :MINUS,
12
+ "*" => :ASTERISK,
13
+ "/" => :SLASH,
14
+ "(" => :PARENL,
15
+ ")" => :PARENR,
16
+ "?" => :QUESTION,
17
+ "@" => :AT,
18
+ "#" => :SHARP,
19
+ "$" => :DOLLAR,
20
+ }.freeze
21
+
22
+ def initialize(source, notations)
23
+ # sourceが空文字だとString#splitが空になる
24
+ source = source&.split(" ", 2)&.first || ""
25
+ @scanner = StringScanner.new(source)
26
+ @notations = notations.map do |n|
27
+ n.is_a?(String) ? Regexp.new(n) : n
28
+ end
29
+ end
30
+
31
+ def next_token
32
+ return [false, "$"] if @scanner.eos?
33
+
34
+ @notations.each do |n|
35
+ token = @scanner.scan(n)
36
+ return [:NOTATION, token] if token
37
+ end
38
+
39
+ if (number = @scanner.scan(/\d+/))
40
+ [:NUMBER, number.to_i]
41
+ elsif (cmp_op = @scanner.scan(/[<>!=]+/))
42
+ cmp_op = Normalize.comparison_operator(cmp_op)
43
+ type = cmp_op ? :CMP_OP : :ILLEGAL
44
+ [type, cmp_op]
45
+ else
46
+ char = @scanner.getch.upcase
47
+ type = SYMBOLS[char] || char.to_sym
48
+ [type, char]
49
+ end
50
+ end
51
+
52
+ def source
53
+ @scanner.string
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BCDice
4
+ module Command
5
+ class Parsed
6
+ # @return [String]
7
+ attr_accessor :command
8
+
9
+ # @return [Integer, nil]
10
+ attr_accessor :critical
11
+
12
+ # @return [Integer, nil]
13
+ attr_accessor :fumble
14
+
15
+ # @return [Integer, nil]
16
+ attr_accessor :dollar
17
+
18
+ # @return [Integer]
19
+ attr_accessor :modify_number
20
+
21
+ # @return [Symbol, nil]
22
+ attr_accessor :cmp_op
23
+
24
+ # @return [Integer, nil]
25
+ attr_accessor :target_number
26
+
27
+ # @param value [Boolean]
28
+ # @return [Boolean]
29
+ attr_writer :question_target
30
+
31
+ def initialize
32
+ @critical = nil
33
+ @fumble = nil
34
+ @dollar = nil
35
+ @cmp_op = nil
36
+ @target_number = nil
37
+ @question_target = false
38
+ end
39
+
40
+ # @return [Boolean]
41
+ def question_target?
42
+ @question_target
43
+ end
44
+
45
+ # @param suffix_position [Symbol] クリティカルなどの表示位置
46
+ # @return [String]
47
+ def to_s(suffix_position = :after_command)
48
+ c = @critical ? "@#{@critical}" : nil
49
+ f = @fumble ? "##{@fumble}" : nil
50
+ d = @dollar ? "$#{@dollar}" : nil
51
+ m = Format.modifier(@modify_number)
52
+ target = @question_target ? "?" : @target_number
53
+
54
+ case suffix_position
55
+ when :after_command
56
+ [@command, c, f, d, m, @cmp_op, target].join()
57
+ when :after_modify_number
58
+ [@command, m, c, f, d, @cmp_op, target].join()
59
+ when :after_target_number
60
+ [@command, m, @cmp_op, target, c, f, d].join()
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,489 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.5.1
4
+ # from Racc grammar file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+
10
+ require "bcdice/arithmetic/node"
11
+ require "bcdice/command/lexer"
12
+ require "bcdice/command/parsed"
13
+
14
+ # よくある形式のコマンドのパースを補助するクラス
15
+ #
16
+ # @example Literal by String
17
+ # parser = Command::Parser.new("MC", round_type: BCDice::RoundType::FLOOR)
18
+ # .enable_critical
19
+ # parsed = parser.parse("MC+2*3@30<=10/2-3") #=> <Command::Parsed>
20
+ #
21
+ # parsed.command #=> "MC"
22
+ # parsed.modify_number #=> 6
23
+ # parsed.critical #=> 30
24
+ # parsed.cmp_op #=> #>=
25
+ # parsed.target_number #=> 2
26
+ #
27
+ # @example Literal by Regexp
28
+ # parser = Command::Parser.new(/RE\d+/)
29
+ # parsed = parser.parse("RE44+20") #=> <Command::Parsed>
30
+ #
31
+ # parsed.command #=> "RE44"
32
+ # parsed.modify_number #=> 20
33
+ class BCDice::Command::Parser < Racc::Parser; end
34
+
35
+ module BCDice
36
+ module Command
37
+ class Parser < Racc::Parser
38
+
39
+
40
+ def initialize(*notations, round_type:)
41
+ super()
42
+ @notations = notations
43
+ @round_type = round_type
44
+ @modifier = true
45
+ @critical = false
46
+ @fumble = false
47
+ @dollar = false
48
+ @allowed_cmp_op = [nil, :>=, :>, :<=, :<, :==, :!=]
49
+ @question_target = false
50
+ end
51
+
52
+ # 修正値は受け付けないようにする
53
+ # @return [BCDice::Command::Parser]
54
+ def disable_modifier
55
+ @modifier = false
56
+ self
57
+ end
58
+
59
+ # +@+によるクリティカル値の指定を許可する
60
+ # @return [BCDice::Command::Parser]
61
+ def enable_critical
62
+ @critical = true
63
+ self
64
+ end
65
+
66
+ # +#+によるファンブル値の指定を許可する
67
+ # @return [BCDice::Command::Parser]
68
+ def enable_fumble
69
+ @fumble = true
70
+ self
71
+ end
72
+
73
+ # +$+による値の指定を許可する
74
+ # @return [BCDice::Command::Parser]
75
+ def enable_dollar
76
+ @dollar = true
77
+ self
78
+ end
79
+
80
+ # 使用できる比較演算子を制限する。
81
+ # 目標値未入力を許可する場合には+nil+を指定する。
82
+ # @param ops [Array<nil, Symbol>] 許可する比較演算子の一覧
83
+ # @return [BCDice::Command::Parser]
84
+ def restrict_cmp_op_to(*ops)
85
+ @allowed_cmp_op = ops
86
+ self
87
+ end
88
+
89
+ # 目標値"?"の指定を許可する
90
+ # @return [BCDice::Command::Parser]
91
+ def enable_question_target
92
+ @question_target = true
93
+ self
94
+ end
95
+
96
+ # @param source [String]
97
+ # @return [BCDice::Command::Parsed, nil]
98
+ def parse(source)
99
+ @lexer = Lexer.new(source, @notations)
100
+ do_parse()
101
+ rescue ParseError, ZeroDivisionError
102
+ nil
103
+ end
104
+
105
+ private
106
+
107
+ def parsed(notation, option, modifier, target)
108
+ Parsed.new.tap do |p|
109
+ p.command = notation
110
+ p.critical = option[:critical]&.eval(@round_type)
111
+ p.fumble = option[:fumble]&.eval(@round_type)
112
+ p.dollar = option[:dollar]&.eval(@round_type)
113
+ p.modify_number = modifier.eval(@round_type)
114
+ p.cmp_op = target[:cmp_op]
115
+ if target[:target] == "?"
116
+ p.question_target = true
117
+ p.target_number = 0
118
+ else
119
+ p.question_target = false
120
+ p.target_number = target[:target]&.eval(@round_type)
121
+ end
122
+ end
123
+ end
124
+
125
+ def next_token
126
+ @lexer.next_token
127
+ end
128
+ ##### State transition tables begin ###
129
+
130
+ racc_action_table = [
131
+ 24, 6, 7, 16, 17, 20, 21, 16, 17, 23,
132
+ 6, 7, 14, 36, 37, 31, 11, 12, 13, 14,
133
+ 24, 2, 24, 36, 37, 20, 21, 20, 21, 23,
134
+ 24, 23, 24, 41, 42, 20, 21, 20, 21, 23,
135
+ 24, 23, 24, 36, 37, 20, 21, 20, 21, 23,
136
+ 24, 23, 24, 36, 37, 20, 21, 20, 21, 23,
137
+ 24, 23, 24, 36, 37, 20, 21, 20, 21, 23,
138
+ 24, 23, 24, 36, 37, 20, 21, 20, 21, 23,
139
+ 24, 23, 24, 36, 37, 20, 21, 20, 21, 23,
140
+ 3, 23, 41, 42, 8, nil, nil, 45, 11, 12,
141
+ 13, 14, 51, 49, 50, 52 ]
142
+
143
+ racc_action_check = [
144
+ 14, 2, 2, 9, 9, 14, 14, 5, 5, 14,
145
+ 4, 4, 9, 18, 18, 14, 4, 4, 4, 4,
146
+ 6, 0, 7, 25, 25, 6, 6, 7, 7, 6,
147
+ 11, 7, 12, 30, 30, 11, 11, 12, 12, 11,
148
+ 13, 12, 16, 32, 32, 13, 13, 16, 16, 13,
149
+ 17, 16, 20, 34, 34, 17, 17, 20, 20, 17,
150
+ 21, 20, 23, 35, 35, 21, 21, 23, 23, 21,
151
+ 36, 23, 37, 46, 46, 36, 36, 37, 37, 36,
152
+ 41, 37, 42, 47, 47, 41, 41, 42, 42, 41,
153
+ 1, 42, 40, 40, 3, nil, nil, 40, 15, 15,
154
+ 15, 15, 44, 44, 44, 44 ]
155
+
156
+ racc_action_pointer = [
157
+ 3, 90, -6, 94, 3, 0, 18, 20, nil, -4,
158
+ nil, 28, 30, 38, -2, 85, 40, 48, 4, nil,
159
+ 50, 58, nil, 60, nil, 14, nil, nil, nil, nil,
160
+ 26, nil, 34, nil, 44, 54, 68, 70, nil, nil,
161
+ 85, 78, 80, nil, 99, nil, 64, 74, nil, nil,
162
+ nil, nil, nil ]
163
+
164
+ racc_action_default = [
165
+ -31, -31, -4, -31, -12, -4, -31, -31, 53, -12,
166
+ -3, -31, -31, -31, -31, -12, -31, -31, -8, -20,
167
+ -31, -31, -28, -31, -30, -9, -1, -5, -6, -7,
168
+ -13, -14, -17, -2, -10, -11, -31, -31, -26, -27,
169
+ -31, -31, -31, -18, -21, -29, -15, -16, -19, -22,
170
+ -23, -24, -25 ]
171
+
172
+ racc_goto_table = [
173
+ 18, 25, 1, 27, 28, 29, 30, 48, nil, 10,
174
+ 34, 35, 38, 39, 26, 40, 4, nil, nil, 15,
175
+ 33, 5, nil, 9, nil, nil, nil, nil, 43, 44,
176
+ nil, nil, nil, nil, nil, 46, 47 ]
177
+
178
+ racc_goto_check = [
179
+ 6, 6, 1, 5, 5, 5, 7, 8, nil, 4,
180
+ 6, 6, 5, 5, 4, 7, 2, nil, nil, 2,
181
+ 4, 3, nil, 3, nil, nil, nil, nil, 5, 5,
182
+ nil, nil, nil, nil, nil, 6, 6 ]
183
+
184
+ racc_goto_pointer = [
185
+ nil, 2, 14, 19, 5, -8, -6, -8, -37, nil ]
186
+
187
+ racc_goto_default = [
188
+ nil, nil, nil, nil, nil, 19, 32, nil, nil, 22 ]
189
+
190
+ racc_reduce_table = [
191
+ 0, 0, :racc_error,
192
+ 4, 20, :_reduce_1,
193
+ 4, 20, :_reduce_2,
194
+ 3, 20, :_reduce_3,
195
+ 0, 21, :_reduce_4,
196
+ 3, 21, :_reduce_5,
197
+ 3, 21, :_reduce_6,
198
+ 3, 21, :_reduce_7,
199
+ 2, 22, :_reduce_8,
200
+ 2, 22, :_reduce_9,
201
+ 3, 22, :_reduce_10,
202
+ 3, 22, :_reduce_11,
203
+ 0, 23, :_reduce_12,
204
+ 2, 23, :_reduce_13,
205
+ 2, 23, :_reduce_14,
206
+ 3, 26, :_reduce_15,
207
+ 3, 26, :_reduce_16,
208
+ 1, 26, :_reduce_none,
209
+ 3, 25, :_reduce_18,
210
+ 4, 25, :_reduce_19,
211
+ 1, 25, :_reduce_none,
212
+ 0, 27, :_reduce_21,
213
+ 1, 27, :_reduce_22,
214
+ 1, 27, :_reduce_23,
215
+ 1, 27, :_reduce_24,
216
+ 1, 27, :_reduce_25,
217
+ 2, 24, :_reduce_26,
218
+ 2, 24, :_reduce_27,
219
+ 1, 24, :_reduce_none,
220
+ 3, 28, :_reduce_29,
221
+ 1, 28, :_reduce_30 ]
222
+
223
+ racc_reduce_n = 31
224
+
225
+ racc_shift_n = 53
226
+
227
+ racc_token_table = {
228
+ false => 0,
229
+ :error => 1,
230
+ :NUMBER => 2,
231
+ :R => 3,
232
+ :U => 4,
233
+ :C => 5,
234
+ :F => 6,
235
+ :PLUS => 7,
236
+ :MINUS => 8,
237
+ :ASTERISK => 9,
238
+ :SLASH => 10,
239
+ :PARENL => 11,
240
+ :PARENR => 12,
241
+ :AT => 13,
242
+ :SHARP => 14,
243
+ :DOLLAR => 15,
244
+ :CMP_OP => 16,
245
+ :QUESTION => 17,
246
+ :NOTATION => 18 }
247
+
248
+ racc_nt_base = 19
249
+
250
+ racc_use_result_var = true
251
+
252
+ Racc_arg = [
253
+ racc_action_table,
254
+ racc_action_check,
255
+ racc_action_default,
256
+ racc_action_pointer,
257
+ racc_goto_table,
258
+ racc_goto_check,
259
+ racc_goto_default,
260
+ racc_goto_pointer,
261
+ racc_nt_base,
262
+ racc_reduce_table,
263
+ racc_token_table,
264
+ racc_shift_n,
265
+ racc_reduce_n,
266
+ racc_use_result_var ]
267
+
268
+ Racc_token_to_s_table = [
269
+ "$end",
270
+ "error",
271
+ "NUMBER",
272
+ "R",
273
+ "U",
274
+ "C",
275
+ "F",
276
+ "PLUS",
277
+ "MINUS",
278
+ "ASTERISK",
279
+ "SLASH",
280
+ "PARENL",
281
+ "PARENR",
282
+ "AT",
283
+ "SHARP",
284
+ "DOLLAR",
285
+ "CMP_OP",
286
+ "QUESTION",
287
+ "NOTATION",
288
+ "$start",
289
+ "expr",
290
+ "option",
291
+ "modifier",
292
+ "target",
293
+ "unary",
294
+ "mul",
295
+ "add",
296
+ "round_type",
297
+ "term" ]
298
+
299
+ Racc_debug_parser = false
300
+
301
+ ##### State transition tables end #####
302
+
303
+ # reduce 0 omitted
304
+
305
+ def _reduce_1(val, _values, result)
306
+ raise ParseError unless @modifier
307
+ notation, option, modifier, target = val
308
+ result = parsed(notation, option, modifier, target)
309
+
310
+ result
311
+ end
312
+
313
+ def _reduce_2(val, _values, result)
314
+ raise ParseError unless @modifier
315
+ notation, modifier, option, target = val
316
+ result = parsed(notation, option, modifier, target)
317
+
318
+ result
319
+ end
320
+
321
+ def _reduce_3(val, _values, result)
322
+ notation, option, target = val
323
+ result = parsed(notation, option, Arithmetic::Node::Number.new(0), target)
324
+
325
+ result
326
+ end
327
+
328
+ def _reduce_4(val, _values, result)
329
+ result = {}
330
+
331
+ result
332
+ end
333
+
334
+ def _reduce_5(val, _values, result)
335
+ option, _, term = val
336
+ raise ParseError unless @critical && option[:critical].nil?
337
+
338
+ option[:critical] = term
339
+ result = option
340
+
341
+ result
342
+ end
343
+
344
+ def _reduce_6(val, _values, result)
345
+ option, _, term = val
346
+ raise ParseError unless @fumble && option[:fumble].nil?
347
+
348
+ option[:fumble] = term
349
+ result = option
350
+
351
+ result
352
+ end
353
+
354
+ def _reduce_7(val, _values, result)
355
+ option, _, term = val
356
+ raise ParseError unless @dollar && option[:dollar].nil?
357
+
358
+ option[:dollar] = term
359
+ result = option
360
+
361
+ result
362
+ end
363
+
364
+ def _reduce_8(val, _values, result)
365
+ result = val[1]
366
+ result
367
+ end
368
+
369
+ def _reduce_9(val, _values, result)
370
+ result = Arithmetic::Node::Negative.new(val[1])
371
+ result
372
+ end
373
+
374
+ def _reduce_10(val, _values, result)
375
+ result = Arithmetic::Node::BinaryOp.new(val[0], :+, val[2])
376
+ result
377
+ end
378
+
379
+ def _reduce_11(val, _values, result)
380
+ result = Arithmetic::Node::BinaryOp.new(val[0], :-, val[2])
381
+ result
382
+ end
383
+
384
+ def _reduce_12(val, _values, result)
385
+ raise ParseError unless @allowed_cmp_op.include?(nil)
386
+ result = {}
387
+
388
+ result
389
+ end
390
+
391
+ def _reduce_13(val, _values, result)
392
+ cmp_op, target = val
393
+ raise ParseError unless @allowed_cmp_op.include?(cmp_op)
394
+
395
+ result = {cmp_op: cmp_op, target: target}
396
+
397
+ result
398
+ end
399
+
400
+ def _reduce_14(val, _values, result)
401
+ cmp_op = val[0]
402
+ raise ParseError unless @question_target
403
+ raise ParseError unless @allowed_cmp_op.include?(cmp_op)
404
+
405
+ result = {cmp_op: cmp_op, target: "?"}
406
+
407
+ result
408
+ end
409
+
410
+ def _reduce_15(val, _values, result)
411
+ result = Arithmetic::Node::BinaryOp.new(val[0], :+, val[2])
412
+ result
413
+ end
414
+
415
+ def _reduce_16(val, _values, result)
416
+ result = Arithmetic::Node::BinaryOp.new(val[0], :-, val[2])
417
+ result
418
+ end
419
+
420
+ # reduce 17 omitted
421
+
422
+ def _reduce_18(val, _values, result)
423
+ result = Arithmetic::Node::BinaryOp.new(val[0], :*, val[2])
424
+ result
425
+ end
426
+
427
+ def _reduce_19(val, _values, result)
428
+ divied_class = val[3]
429
+ result = divied_class.new(val[0], val[2])
430
+
431
+ result
432
+ end
433
+
434
+ # reduce 20 omitted
435
+
436
+ def _reduce_21(val, _values, result)
437
+ result = Arithmetic::Node::DivideWithGameSystemDefault
438
+ result
439
+ end
440
+
441
+ def _reduce_22(val, _values, result)
442
+ result = Arithmetic::Node::DivideWithCeil
443
+ result
444
+ end
445
+
446
+ def _reduce_23(val, _values, result)
447
+ result = Arithmetic::Node::DivideWithCeil
448
+ result
449
+ end
450
+
451
+ def _reduce_24(val, _values, result)
452
+ result = Arithmetic::Node::DivideWithRound
453
+ result
454
+ end
455
+
456
+ def _reduce_25(val, _values, result)
457
+ result = Arithmetic::Node::DivideWithFloor
458
+ result
459
+ end
460
+
461
+ def _reduce_26(val, _values, result)
462
+ result = val[1]
463
+ result
464
+ end
465
+
466
+ def _reduce_27(val, _values, result)
467
+ result = Arithmetic::Node::Negative.new(val[1])
468
+ result
469
+ end
470
+
471
+ # reduce 28 omitted
472
+
473
+ def _reduce_29(val, _values, result)
474
+ result = val[1]
475
+ result
476
+ end
477
+
478
+ def _reduce_30(val, _values, result)
479
+ result = Arithmetic::Node::Number.new(val[0])
480
+ result
481
+ end
482
+
483
+ def _reduce_none(val, _values, result)
484
+ val[0]
485
+ end
486
+
487
+ end # class Parser
488
+ end # module Command
489
+ end # module BCDice