Parser architecture improvement with TypeSlot#48
Merged
Conversation
Introduce TypeSlot class that represents positions where type annotations are expected. This enables explicit tracking of explicit, inferred, and resolved types for each position. - Add IR::TypeSlot class with kind, location, and context - Add type_slot attribute to IR::Parameter - Add return_type_slot attribute to IR::MethodDef - Maintain backward compatibility with existing code Refs #47
- Add TypeSlot creation during parameter parsing in parse_parameter - Add return_type_slot creation in parse_method_def - Pass method_name context to parameter parsers for TypeSlot context - Support all parameter types (regular, rest, keyrest, block, keyword) - Add comprehensive tests for TypeSlot integration - Maintain backward compatibility with existing type_annotation/return_type Refs #47
- Add TRuby::Errors::TypeSlotError class for type-related errors - Support location info (line, column) from TypeSlot - Include context description (parameter/return/variable info) - Support suggestion field for helpful error hints - Provide to_lsp_diagnostic for LSP integration - Add comprehensive tests Refs #47
- Add TRuby::TypeResolution::SlotResolver class - Collect unresolved TypeSlots from IR program - Support resolve_to_untyped for gradual typing fallback - Provide slot_summary for type coverage statistics - Handle method parameters and return types - Traverse ClassDef and ModuleDef for nested methods Refs #47
- Add use_token_parser option to Parser.new for opt-in new parser - Support TRUBY_NEW_PARSER=1 environment variable - Implement parse_with_token_parser using TokenDeclarationParser - Add backward-compatible legacy format conversion - Mark legacy regex-based parser as @deprecated - Add comprehensive facade tests This enables gradual migration from regex-based parsing to the new TokenDeclarationParser with TypeSlot support. Refs #47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Parser architecture improvement with TypeSlot infrastructure. TypeSlot explicitly tracks "positions where types should appear" to enable early validation, better error messages, and enhanced gradual typing support.
Changes
Phase 1: TypeSlot Infrastructure
IR::TypeSlotclass - tracks type positions for parameters, return values, variablestype_slotattribute toIR::Parameterreturn_type_slotattribute toIR::MethodDefPhase 2: TokenDeclarationParser Integration
create_param_type_slothelper methodPhase 3: Error Message System
TRuby::Errors::TypeSlotErrorclassPhase 4: Type Resolution
TRuby::TypeResolution::SlotResolverclassPhase 5: Parser Facade
use_token_parser: trueoption to select new parserTRUBY_NEW_PARSER=1environment variableTest Plan
Closes #47