• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

type-ruby / t-ruby / 20560723383

28 Dec 2025 10:58PM UTC coverage: 79.074% (+1.7%) from 77.331%
20560723383

Pull #29

github

web-flow
Merge 5876e651d into fda099366
Pull Request #29: refactor: migrate parser from regex to token-based parser combinator

1848 of 2097 new or added lines in 53 files covered. (88.13%)

6 existing lines in 2 files now uncovered.

6643 of 8401 relevant lines covered (79.07%)

908.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.18
/lib/t_ruby/parser_combinator/token/token_body_parser.rb
1
# frozen_string_literal: true
2

3
module TRuby
1✔
4
  module ParserCombinator
1✔
5
    # Token-based body parser - replaces regex-based BodyParser
6
    # Provides the same interface as BodyParser.parse(lines, start_line, end_line)
7
    class TokenBodyParser
1✔
8
      def initialize
1✔
9
        @statement_parser = StatementParser.new
284✔
10
      end
11

12
      # Parse method body from lines array
13
      # @param lines [Array<String>] source code lines
14
      # @param start_line [Integer] starting line index (0-based)
15
      # @param end_line [Integer] ending line index (exclusive)
16
      # @return [IR::Block] parsed block of statements
17
      def parse(lines, start_line, end_line)
1✔
18
        # Extract the body source
19
        body_lines = lines[start_line...end_line]
3,630✔
20
        source = body_lines.join("\n")
3,630✔
21

22
        return IR::Block.new(statements: []) if source.strip.empty?
3,630✔
23

24
        # Scan and parse
25
        scanner = TRuby::Scanner.new(source)
3,630✔
26
        tokens = scanner.scan_all
3,630✔
27

28
        result = @statement_parser.parse_block(tokens, 0)
3,630✔
29

30
        if result.success?
3,630✔
31
          result.value
3,630✔
32
        else
33
          # Fallback to empty block on parse failure
NEW
34
          IR::Block.new(statements: [])
×
35
        end
36
      end
37

38
      # Parse a single expression string
39
      # @param expr [String] expression to parse
40
      # @return [IR::Node] parsed expression node
41
      def parse_expression(expr)
1✔
NEW
42
        return nil if expr.nil? || expr.strip.empty?
×
43

NEW
44
        scanner = TRuby::Scanner.new(expr)
×
NEW
45
        tokens = scanner.scan_all
×
46

NEW
47
        expression_parser = ExpressionParser.new
×
NEW
48
        result = expression_parser.parse_expression(tokens, 0)
×
49

NEW
50
        result.success? ? result.value : IR::RawCode.new(code: expr)
×
51
      end
52
    end
53
  end
54
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc