Class: BCDice::GameSystem::SwordWorld::RatingLexer
- Inherits:
-
Object
- Object
- BCDice::GameSystem::SwordWorld::RatingLexer
- Defined in:
- lib/bcdice/game_system/sword_world/rating_lexer.rb
Constant Summary collapse
- SYMBOLS =
{ "+" => :PLUS, "-" => :MINUS, "*" => :ASTERISK, "/" => :SLASH, "(" => :PARENL, ")" => :PARENR, "[" => :BRACKETL, "]" => :BRACKETR, "@" => :AT, "#" => :SHARP, "$" => :DOLLAR, }.freeze
Instance Method Summary collapse
-
#initialize(source) ⇒ RatingLexer
constructor
A new instance of RatingLexer.
- #next_token ⇒ Object
- #source ⇒ Object
Constructor Details
#initialize(source) ⇒ RatingLexer
Returns a new instance of RatingLexer.
23 24 25 26 27 |
# File 'lib/bcdice/game_system/sword_world/rating_lexer.rb', line 23 def initialize(source) # sourceが空文字だとString#splitが空になる source = source&.split(" ", 2)&.first || "" @scanner = StringScanner.new(source) end |
Instance Method Details
#next_token ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bcdice/game_system/sword_world/rating_lexer.rb', line 29 def next_token return [false, "$"] if @scanner.eos? if (number = @scanner.scan(/\d+/)) [:NUMBER, number.to_i] else char = @scanner.getch.upcase type = SYMBOLS[char] || char.to_sym [type, char] end end |
#source ⇒ Object
41 42 43 |
# File 'lib/bcdice/game_system/sword_world/rating_lexer.rb', line 41 def source @scanner.string end |