module Oppen
class Token
module BreakType
FITS = 0
INCONSISTENT = 1
CONSISTENT = 2
end
def width = 0
class String < Token
attr_reader :value
attr_reader :width
def initialize(value, width: value.length)
@value = value
@width = width
super()
end
def to_s = value
end
class Whitespace < ::Oppen::Token::String
end
class Break < Token
attr_reader :line_continuation
attr_reader :offset
attr_reader :str
attr_reader :width
def initialize(str = ' ', width: str.length, line_continuation: '', offset: 0)
raise ArgumentError, 'line_continuation cannot be nil' if line_continuation.nil?
@line_continuation = line_continuation
@offset = offset
@str = str
@width = width
super()
end
def to_s = str
end
class LineBreak < Break
class LineBreakString
def length = 999_999
end
def initialize(line_continuation: '', offset: 0)
super(LineBreakString.new, line_continuation:, offset:)
end
end
class Begin < Token
attr_reader :break_type
attr_reader :offset
def initialize(break_type: BreakType::INCONSISTENT, offset: 2)
@offset = offset
@break_type = break_type
super()
end
def break_type_name
case @break_type
in BreakType::FITS then 'Oppen::Token::BreakType::FITS'
in BreakType::INCONSISTENT then 'Oppen::Token::BreakType::INCONSISTENT'
in BreakType::CONSISTENT then 'Oppen::Token::BreakType::CONSISTENT'
end
end
end
class End < Token
nil
end
class EOF < Token
nil
end
end
end