Class: TRuby::ParserCombinator::TokenBodyParser
- Inherits:
-
Object
- Object
- TRuby::ParserCombinator::TokenBodyParser
- Defined in:
- lib/t_ruby/parser_combinator/token/token_body_parser.rb
Overview
Token-based body parser - replaces regex-based BodyParser Provides the same interface as BodyParser.parse(lines, start_line, end_line)
Instance Method Summary collapse
-
#initialize ⇒ TokenBodyParser
constructor
A new instance of TokenBodyParser.
-
#parse(lines, start_line, end_line) ⇒ IR::Block
Parse method body from lines array.
-
#parse_expression(expr) ⇒ IR::Node
Parse a single expression string.
Constructor Details
#initialize ⇒ TokenBodyParser
Returns a new instance of TokenBodyParser.
8 9 10 |
# File 'lib/t_ruby/parser_combinator/token/token_body_parser.rb', line 8 def initialize @statement_parser = StatementParser.new end |
Instance Method Details
#parse(lines, start_line, end_line) ⇒ IR::Block
Parse method body from lines array
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/t_ruby/parser_combinator/token/token_body_parser.rb', line 17 def parse(lines, start_line, end_line) # Extract the body source body_lines = lines[start_line...end_line] source = body_lines.join("\n") return IR::Block.new(statements: []) if source.strip.empty? # Scan and parse scanner = TRuby::Scanner.new(source) tokens = scanner.scan_all result = @statement_parser.parse_block(tokens, 0) if result.success? result.value else # Fallback to empty block on parse failure IR::Block.new(statements: []) end end |
#parse_expression(expr) ⇒ IR::Node
Parse a single expression string
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/t_ruby/parser_combinator/token/token_body_parser.rb', line 41 def parse_expression(expr) return nil if expr.nil? || expr.strip.empty? scanner = TRuby::Scanner.new(expr) tokens = scanner.scan_all expression_parser = ExpressionParser.new result = expression_parser.parse_expression(tokens, 0) result.success? ? result.value : IR::RawCode.new(code: expr) end |