summaryrefslogtreecommitdiff
path: root/tool/lrama/lib/lrama/lexer/grammar_file.rb
diff options
context:
space:
mode:
Diffstat (limited to 'tool/lrama/lib/lrama/lexer/grammar_file.rb')
-rw-r--r--tool/lrama/lib/lrama/lexer/grammar_file.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/tool/lrama/lib/lrama/lexer/grammar_file.rb b/tool/lrama/lib/lrama/lexer/grammar_file.rb
new file mode 100644
index 0000000000..3d3368625d
--- /dev/null
+++ b/tool/lrama/lib/lrama/lexer/grammar_file.rb
@@ -0,0 +1,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