• 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

87.88
/lib/t_ruby/parser_combinator/parser.rb
1
# frozen_string_literal: true
2

3
module TRuby
1✔
4
  module ParserCombinator
1✔
5
    # Base parser class for string-based parsing
6
    class Parser
1✔
7
      def parse(input, position = 0)
1✔
NEW
8
        raise NotImplementedError
×
9
      end
10

11
      # Combinators as methods
12

13
      # Sequence: run this parser, then the other
14
      def >>(other)
1✔
15
        Sequence.new(self, other)
8,487✔
16
      end
17

18
      # Alternative: try this parser, if it fails try the other
19
      def |(other)
1✔
20
        Alternative.new(self, other)
457✔
21
      end
22

23
      # Map: transform the result
24
      def map(&block)
1✔
25
        Map.new(self, block)
19,472✔
26
      end
27

28
      # FlatMap: transform with another parser
29
      def flat_map(&block)
1✔
NEW
30
        FlatMap.new(self, block)
×
31
      end
32

33
      # Many: zero or more repetitions
34
      def many
1✔
35
        Many.new(self)
10,687✔
36
      end
37

38
      # Many1: one or more repetitions
39
      def many1
1✔
40
        Many1.new(self)
7✔
41
      end
42

43
      # Optional: zero or one
44
      def optional
1✔
45
        Optional.new(self)
742✔
46
      end
47

48
      # Separated by: parse items separated by delimiter
49
      def sep_by(delimiter)
1✔
50
        SepBy.new(self, delimiter)
367✔
51
      end
52

53
      # Separated by 1: at least one item
54
      def sep_by1(delimiter)
1✔
55
        SepBy1.new(self, delimiter)
1,434✔
56
      end
57

58
      # Between: parse between left and right delimiters
59
      def between(left, right)
1✔
60
        (left >> self << right).map { |(_, val)| val }
2✔
61
      end
62

63
      # Skip right: parse both, keep left result
64
      def <<(other)
1✔
65
        SkipRight.new(self, other)
6,611✔
66
      end
67

68
      # Label: add a descriptive label for error messages
69
      def label(name)
1✔
70
        Label.new(self, name)
358✔
71
      end
72

73
      # Lookahead: check without consuming
74
      def lookahead
1✔
NEW
75
        Lookahead.new(self)
×
76
      end
77

78
      # Not: succeed only if parser fails
79
      def not_followed_by
1✔
NEW
80
        NotFollowedBy.new(self)
×
81
      end
82
    end
83
  end
84
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

© 2025 Coveralls, Inc