Skip to content

Commit

Permalink
Merge pull request #497 from ydah/add-rbs-inline-style-type
Browse files Browse the repository at this point in the history
Add RBS type signatures for TraceReporter and generate RBS file
  • Loading branch information
ydah authored Jan 2, 2025
2 parents 214c511 + 0c551f0 commit c4871ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ target :lib do
check "lib/lrama/digraph.rb"
check "lib/lrama/grammar.rb"
check "lib/lrama/options.rb"
check "lib/lrama/trace_reporter.rb"
check "lib/lrama/warning.rb"
end
6 changes: 6 additions & 0 deletions lib/lrama/trace_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
# rbs_inline: enabled
# frozen_string_literal: true

module Lrama
class TraceReporter
# @rbs (Lrama::Grammar grammar) -> void
def initialize(grammar)
@grammar = grammar
end

# @rbs (**Hash[Symbol, bool] options) -> void
def report(**options)
_report(**options)
end

private

# @rbs rules: (bool rules, bool actions, **untyped _) -> void
def _report(rules: false, actions: false, **_)
report_rules if rules
report_actions if actions
end

# @rbs () -> void
def report_rules
puts "Grammar rules:"
@grammar.rules.each { |rule| puts rule.display_name }
end

# @rbs () -> void
def report_actions
puts "Grammar rules with actions:"
@grammar.rules.each { |rule| puts rule.with_actions }
Expand Down
22 changes: 22 additions & 0 deletions sig/generated/lrama/trace_reporter.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated from lib/lrama/trace_reporter.rb with RBS::Inline

module Lrama
class TraceReporter
# @rbs (Lrama::Grammar grammar) -> void
def initialize: (Lrama::Grammar grammar) -> void

# @rbs (**Hash[Symbol, bool] options) -> void
def report: (**Hash[Symbol, bool] options) -> void

private

# @rbs rules: (bool rules, bool actions, **untyped _) -> void
def _report: (?rules: untyped, ?actions: untyped, **untyped _) -> untyped

# @rbs () -> void
def report_rules: () -> void

# @rbs () -> void
def report_actions: () -> void
end
end

0 comments on commit c4871ec

Please sign in to comment.