Class: Antlr4ruby::CharStreams
- Inherits:
-
Object
- Object
- Antlr4ruby::CharStreams
- Defined in:
- lib/antlr4ruby/char_streams.rb
Class Method Summary collapse
- .from_file(file) ⇒ Object
- .from_file_name(filename, charset) ⇒ Object
- .from_path(path, charset) ⇒ Object
- .from_string(input, source_name = IntStream.UNKNOWN_SOURCE_NAME) ⇒ Object
Class Method Details
.from_file(file) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/antlr4ruby/char_streams.rb', line 16 def from_file(file) input = file.read if input from_string(input) else raise "文件读取异常" end end |
.from_file_name(filename, charset) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/antlr4ruby/char_streams.rb', line 9 def from_file_name(filename, charset) mode = charset ? "rb:#{charset}" : 'r' File.open(filename, mode) do |file| from_file(file) end end |
.from_path(path, charset) ⇒ Object
5 6 7 |
# File 'lib/antlr4ruby/char_streams.rb', line 5 def from_path(path, charset) # from_file(path, charset) end |
.from_string(input, source_name = IntStream.UNKNOWN_SOURCE_NAME) ⇒ Object
25 26 27 28 |
# File 'lib/antlr4ruby/char_streams.rb', line 25 def from_string(input, source_name = IntStream.UNKNOWN_SOURCE_NAME) # 首先将字符串转换为整数数组 CodePointCharStream.from_string(input, source_name) end |