class BCDice::GameSystem::SwordWorld::RatingLexer

Constants

SYMBOLS

Public Class Methods

new(source) click to toggle source
# 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

Public Instance Methods

next_token() click to toggle source
# 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() click to toggle source
# File lib/bcdice/game_system/sword_world/rating_lexer.rb, line 41
def source
  @scanner.string
end