diff --git a/Steepfile b/Steepfile index a44c3e4e..4bf2d153 100644 --- a/Steepfile +++ b/Steepfile @@ -4,23 +4,23 @@ target :lib do repo_path '.gem_rbs_collection/' signature "sig" + check "lib/lrama/grammar/code" + check "lib/lrama/grammar/parameterizing_rule" + check "lib/lrama/grammar/symbols" + check "lib/lrama/grammar/binding.rb" - check "lib/lrama/grammar/code/destructor_code.rb" - check "lib/lrama/grammar/code/printer_code.rb" check "lib/lrama/grammar/code.rb" check "lib/lrama/grammar/counter.rb" + check "lib/lrama/grammar/destructor.rb" check "lib/lrama/grammar/error_token.rb" - check "lib/lrama/grammar/parameterizing_rule" - check "lib/lrama/grammar/parameterizing_rules" - check "lib/lrama/grammar/symbols" check "lib/lrama/grammar/percent_code.rb" check "lib/lrama/grammar/precedence.rb" - check "lib/lrama/grammar/destructor.rb" check "lib/lrama/grammar/printer.rb" check "lib/lrama/grammar/reference.rb" check "lib/lrama/grammar/rule_builder.rb" check "lib/lrama/grammar/symbol.rb" check "lib/lrama/grammar/type.rb" + check "lib/lrama/lexer" check "lib/lrama/report" check "lib/lrama/bitmap.rb" diff --git a/lib/lrama/grammar/code/rule_action.rb b/lib/lrama/grammar/code/rule_action.rb index d3c0eab6..27db7044 100644 --- a/lib/lrama/grammar/code/rule_action.rb +++ b/lib/lrama/grammar/code/rule_action.rb @@ -41,6 +41,7 @@ def reference_to_c(ref) when ref.type == :dollar && ref.name == "$" # $$ tag = ref.ex_tag || lhs.tag raise_tag_not_found_error(ref) unless tag + # @type var tag: Lexer::Token::Tag "(yyval.#{tag.member})" when ref.type == :at && ref.name == "$" # @$ "(yyloc)" @@ -50,6 +51,7 @@ def reference_to_c(ref) i = -position_in_rhs + ref.index tag = ref.ex_tag || rhs[ref.index - 1].tag raise_tag_not_found_error(ref) unless tag + # @type var tag: Lexer::Token::Tag "(yyvsp[#{i}].#{tag.member})" when ref.type == :at # @n i = -position_in_rhs + ref.index diff --git a/sig/lrama/grammar/code.rbs b/sig/lrama/grammar/code.rbs index 81aaa55d..04eb2c25 100644 --- a/sig/lrama/grammar/code.rbs +++ b/sig/lrama/grammar/code.rbs @@ -3,8 +3,8 @@ module Lrama class Code extend Forwardable - attr_accessor type: Symbol - attr_accessor token_code: Lexer::Token::UserCode + attr_accessor type: ::Symbol + attr_accessor token_code: Grammar::Code # delegated def s_value: -> String @@ -12,7 +12,7 @@ module Lrama def column: -> Integer def references: -> Array[Lrama::Grammar::Reference] - def initialize: (type: Symbol, token_code: Lexer::Token::UserCode) -> void + def initialize: (type: ::Symbol, token_code: Grammar::Code) -> void def translated_code: () -> String diff --git a/sig/lrama/grammar/code/destructor_code.rbs b/sig/lrama/grammar/code/destructor_code.rbs index 8dc4784f..4cbebb5a 100644 --- a/sig/lrama/grammar/code/destructor_code.rbs +++ b/sig/lrama/grammar/code/destructor_code.rbs @@ -2,13 +2,12 @@ module Lrama class Grammar class Code class DestructorCode < Code - @tag: untyped - def initialize: (type: untyped, token_code: untyped, tag: untyped) -> void + @tag: Lexer::Token::Tag + def initialize: (type: ::Symbol, token_code: Grammar::Code, tag: Lexer::Token::Tag) -> void private - # ref: Lrama::Grammar::Code.token_code.references - def reference_to_c: (untyped ref) -> untyped + def reference_to_c: (Reference ref) -> (String | bot) end end end diff --git a/sig/lrama/grammar/code/initial_action_code.rbs b/sig/lrama/grammar/code/initial_action_code.rbs new file mode 100644 index 00000000..de7ab875 --- /dev/null +++ b/sig/lrama/grammar/code/initial_action_code.rbs @@ -0,0 +1,15 @@ +module Lrama + class Grammar + class Code + class InitialActionCode < Code + private + + # * ($$) yylval + # * (@$) yylloc + # * ($1) error + # * (@1) error + def reference_to_c: (Reference ref) -> (String | bot) + end + end + end +end diff --git a/sig/lrama/grammar/code/no_reference_code.rbs b/sig/lrama/grammar/code/no_reference_code.rbs new file mode 100644 index 00000000..3238ab63 --- /dev/null +++ b/sig/lrama/grammar/code/no_reference_code.rbs @@ -0,0 +1,15 @@ +module Lrama + class Grammar + class Code + class NoReferenceCode < Code + private + + # * ($$) error + # * (@$) error + # * ($1) error + # * (@1) error + def reference_to_c: (Reference ref) -> bot + end + end + end +end diff --git a/sig/lrama/grammar/code/printer_code.rbs b/sig/lrama/grammar/code/printer_code.rbs index 0228698b..d8a3541b 100644 --- a/sig/lrama/grammar/code/printer_code.rbs +++ b/sig/lrama/grammar/code/printer_code.rbs @@ -2,13 +2,12 @@ module Lrama class Grammar class Code class PrinterCode < Code - @tag: untyped - def initialize: (type: untyped, token_code: untyped, tag: untyped) -> void + @tag: Lexer::Token::Tag + def initialize: (type: ::Symbol, token_code: Grammar::Code, tag: Lexer::Token::Tag) -> void private - # ref: Lrama::Grammar::Code.token_code.references - def reference_to_c: (untyped ref) -> untyped + def reference_to_c: (Reference ref) -> (String | bot) end end end diff --git a/sig/lrama/grammar/code/rule_action.rbs b/sig/lrama/grammar/code/rule_action.rbs new file mode 100644 index 00000000..fda64170 --- /dev/null +++ b/sig/lrama/grammar/code/rule_action.rbs @@ -0,0 +1,19 @@ +module Lrama + class Grammar + class Code + class RuleAction < Code + @rule: Rule + + def initialize: (type: ::Symbol, token_code: Grammar::Code, rule: Rule) -> void + + private + + def reference_to_c: (Reference ref) -> String + def position_in_rhs: () -> Integer + def rhs: () -> Array[Grammar::Symbol] + def lhs: () -> Grammar::Symbol + def raise_tag_not_found_error: (Reference ref) -> bot + end + end + end +end diff --git a/sig/lrama/grammar/destructor.rbs b/sig/lrama/grammar/destructor.rbs index b00f3308..1374c1c3 100644 --- a/sig/lrama/grammar/destructor.rbs +++ b/sig/lrama/grammar/destructor.rbs @@ -5,7 +5,7 @@ module Lrama attr_accessor token_code: Grammar::Code attr_accessor lineno: Integer - def translated_code: (Lexer::Token member) -> String + def translated_code: (Lexer::Token::Tag tag) -> String end end end diff --git a/sig/lrama/grammar/error_token.rbs b/sig/lrama/grammar/error_token.rbs index 9b6a06dc..6b82296a 100644 --- a/sig/lrama/grammar/error_token.rbs +++ b/sig/lrama/grammar/error_token.rbs @@ -2,10 +2,10 @@ module Lrama class Grammar class ErrorToken attr_accessor ident_or_tags: Array[Lexer::Token::Ident | Lexer::Token::Tag] - attr_accessor token_code: Symbol + attr_accessor token_code: Code attr_accessor lineno: Integer - def translated_code: (Lexer::Token? tag) -> String + def translated_code: (Lexer::Token::Tag tag) -> String end end end diff --git a/sig/lrama/grammar/printer.rbs b/sig/lrama/grammar/printer.rbs index 947273dc..6048cda7 100644 --- a/sig/lrama/grammar/printer.rbs +++ b/sig/lrama/grammar/printer.rbs @@ -5,7 +5,7 @@ module Lrama attr_accessor token_code: Grammar::Code attr_accessor lineno: Integer - def translated_code: (Lexer::Token member) -> String + def translated_code: (Lexer::Token::Tag tag) -> String end end end diff --git a/sig/lrama/grammar/rule.rbs b/sig/lrama/grammar/rule.rbs index c181be5b..5a639022 100644 --- a/sig/lrama/grammar/rule.rbs +++ b/sig/lrama/grammar/rule.rbs @@ -1,13 +1,32 @@ module Lrama class Grammar class Rule + attr_accessor id: Integer + attr_accessor _lhs: Lexer::Token + attr_accessor lhs: Symbol + attr_accessor lhs_tag: untyped + attr_accessor _rhs: untyped + attr_accessor rhs: untyped + attr_accessor token_code: Lexer::Token::UserCode? + attr_accessor position_in_original_rule_rhs: untyped + attr_accessor nullable: bool + attr_accessor precedence_sym: Lexer::Token? + attr_accessor lineno: Integer? attr_accessor original_rule: Rule def initialize: ( - ?id: untyped, ?_lhs: untyped, ?lhs: untyped, ?lhs_tag: untyped, ?_rhs: untyped, ?rhs: untyped, - ?token_code: untyped, ?position_in_original_rule_rhs: untyped, ?nullable: untyped, - ?precedence_sym: untyped, ?lineno: untyped + ?id: Integer, ?_lhs: Lexer::Token, ?lhs: Lexer::Token, ?lhs_tag: untyped, ?_rhs: untyped, ?rhs: untyped, + ?token_code: Lexer::Token::UserCode?, ?position_in_original_rule_rhs: Integer?, ?nullable: bool, + ?precedence_sym: Lexer::Token?, ?lineno: Integer? ) -> void + + def as_comment: -> String + + def empty_rule?: -> bool + + def initial_rule?: -> bool + + def with_actions: -> String end end end diff --git a/sig/lrama/grammar/symbol.rbs b/sig/lrama/grammar/symbol.rbs index aa68e596..3522c355 100644 --- a/sig/lrama/grammar/symbol.rbs +++ b/sig/lrama/grammar/symbol.rbs @@ -4,7 +4,7 @@ module Lrama attr_accessor id: Lexer::Token attr_accessor alias_name: String? attr_accessor number: Integer - attr_accessor tag: Lexer::Token? + attr_accessor tag: Lexer::Token::Tag? attr_accessor term: bool attr_accessor token_id: Integer attr_accessor nullable: bool diff --git a/sig/lrama/grammar/symbols/resolver.rbs b/sig/lrama/grammar/symbols/resolver.rbs index 8f16cd16..b6120efa 100644 --- a/sig/lrama/grammar/symbols/resolver.rbs +++ b/sig/lrama/grammar/symbols/resolver.rbs @@ -12,8 +12,8 @@ module Lrama def initialize: () -> void def symbols: () -> Array[Grammar::Symbol] def sort_by_number!: () -> void - def add_term: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token?, ?token_id: Integer?, ?replace: bool) -> Grammar::Symbol - def add_nterm: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token?) -> Grammar::Symbol? + def add_term: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?, ?token_id: Integer?, ?replace: bool) -> Grammar::Symbol + def add_nterm: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?) -> Grammar::Symbol? def find_symbol_by_s_value: (Grammar::Symbol s_value) -> Grammar::Symbol? def find_symbol_by_s_value!: (Grammar::Symbol s_value) -> Grammar::Symbol def find_symbol_by_id: (Lexer::Token id) -> Grammar::Symbol? diff --git a/sig/lrama/grammar/type.rbs b/sig/lrama/grammar/type.rbs index 2cdd8b13..4d74eb17 100644 --- a/sig/lrama/grammar/type.rbs +++ b/sig/lrama/grammar/type.rbs @@ -2,9 +2,9 @@ module Lrama class Grammar class Type attr_reader id: Lexer::Token - attr_reader tag: Lexer::Token + attr_reader tag: Lexer::Token::Tag - def initialize: (id: Lexer::Token, tag: Lexer::Token) -> void + def initialize: (id: Lexer::Token, tag: Lexer::Token::Tag) -> void def ==: (Grammar::Type other) -> bool end end