summaryrefslogtreecommitdiff
path: root/tool/lrama/lib/lrama/lexer/grammar_file.rb
blob: 3d3368625da5b6400fb4ff50f57f8cfd81cd8525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Lrama
  class Lexer
    class GrammarFile
      class Text < String
        def inspect
          length <= 50 ? super : "#{self[0..47]}...".inspect
        end
      end

      attr_reader :path, :text

      def initialize(path, text)
        @path = path
        @text = Text.new(text).freeze
      end

      def inspect
        "<#{self.class}: @path=#{path}, @text=#{text.inspect}>"
      end

      def ==(other)
        self.class == other.class &&
        self.path == other.path
      end

      def lines
        @lines ||= text.split("\n")
      end
    end
  end
end