Skip to content

Commit 9cc5177

Browse files
committed
refactor: migrate parser from regex to token-based parser combinator
- Replace monolithic parser_combinator.rb (2833 lines) with modular architecture - Add Scanner for tokenization with regex literal support - Create IR::InterpolatedString for string interpolation parsing - Fix type inference for interpolated strings (returns String) - Add TRuby::ParseError for unified error handling - Organize parsers into primitives/, combinators/, and token/ directories - Each file contains exactly one class (snake_case filename matches PascalCase class)
1 parent fda0993 commit 9cc5177

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+5951
-1503
lines changed

lib/t_ruby.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
require_relative "t_ruby/string_utils"
1111
require_relative "t_ruby/ir"
1212
require_relative "t_ruby/parser_combinator"
13+
require_relative "t_ruby/scanner"
1314
require_relative "t_ruby/smt_solver"
1415

1516
# Basic components
1617
require_relative "t_ruby/type_alias_registry"
1718
require_relative "t_ruby/heredoc_detector"
18-
require_relative "t_ruby/body_parser"
1919
require_relative "t_ruby/parser"
2020
require_relative "t_ruby/union_type_parser"
2121
require_relative "t_ruby/generic_type_parser"
@@ -51,4 +51,15 @@
5151
require_relative "t_ruby/docs_badge_generator"
5252

5353
module TRuby
54+
# Parse error for T-Ruby source code
55+
class ParseError < StandardError
56+
attr_reader :line, :column, :source
57+
58+
def initialize(message, line: nil, column: nil, source: nil)
59+
@line = line
60+
@column = column
61+
@source = source
62+
super(message)
63+
end
64+
end
5465
end

lib/t_ruby/ast_type_inferrer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ def infer_expression(node, env)
158158
type = case node
159159
when IR::Literal
160160
infer_literal(node)
161+
when IR::InterpolatedString
162+
"String" # Interpolated strings always produce String
161163
when IR::VariableRef
162164
infer_variable_ref(node, env)
163165
when IR::BinaryOp

0 commit comments

Comments
 (0)