Skip to content

Commit

Permalink
Use rbs-inline style for Lrama::Lexer::Token
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Jan 13, 2025
1 parent cb384dd commit a6c21d7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
16 changes: 14 additions & 2 deletions lib/lrama/lexer/token.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# rbs_inline: enabled
# frozen_string_literal: true

require_relative 'token/char'
Expand All @@ -9,46 +10,57 @@
module Lrama
class Lexer
class Token
attr_reader :s_value, :location
attr_accessor :alias_name, :referred
attr_reader :s_value #: String
attr_reader :location #: Location
attr_accessor :alias_name #: String
attr_accessor :referred #: bool

# @rbs (s_value: String, ?alias_name: String, ?location: Location) -> void
def initialize(s_value:, alias_name: nil, location: nil)
s_value.freeze
@s_value = s_value
@alias_name = alias_name
@location = location
end

# @rbs () -> String
def to_s
"value: `#{s_value}`, location: #{location}"
end

# @rbs (String string) -> bool
def referred_by?(string)
[self.s_value, self.alias_name].compact.include?(string)
end

# @rbs (Token other) -> bool
def ==(other)
self.class == other.class && self.s_value == other.s_value
end

# @rbs () -> Integer
def first_line
location.first_line
end
alias :line :first_line

# @rbs () -> Integer
def first_column
location.first_column
end
alias :column :first_column

# @rbs () -> Integer
def last_line
location.last_line
end

# @rbs () -> Integer
def last_column
location.last_column
end

# @rbs (Lrama::Grammar::Reference ref, String message) -> bot
def invalid_ref(ref, message)
location = self.location.partial_location(ref.first_column, ref.last_column)
raise location.generate_error_message(message)
Expand Down
29 changes: 26 additions & 3 deletions sig/lrama/lexer/token.rbs → sig/generated/lrama/lexer/token.rbs
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
# Generated from lib/lrama/lexer/token.rb with RBS::Inline

module Lrama
class Lexer
class Token
attr_reader s_value: String
attr_accessor alias_name: String

attr_reader location: Location

attr_accessor alias_name: String

attr_accessor referred: bool

# @rbs (s_value: String, ?alias_name: String, ?location: Location) -> void
def initialize: (s_value: String, ?alias_name: String, ?location: Location) -> void

# @rbs () -> String
def to_s: () -> String

# @rbs (String string) -> bool
def referred_by?: (String string) -> bool

# @rbs (Token other) -> bool
def ==: (Token other) -> bool

# @rbs () -> Integer
def first_line: () -> Integer

alias line first_line

# @rbs () -> Integer
def first_column: () -> Integer

alias column first_column

# @rbs () -> Integer
def last_line: () -> Integer

# @rbs () -> Integer
def last_column: () -> Integer
alias line first_line
alias column first_column

# @rbs (Lrama::Grammar::Reference ref, String message) -> bot
def invalid_ref: (Lrama::Grammar::Reference ref, String message) -> bot
end
end
Expand Down

0 comments on commit a6c21d7

Please sign in to comment.