Grammar takes in input string instead of file name

This commit is contained in:
Josh Holtrop 2021-06-06 10:09:53 -04:00
parent e4370cac62
commit 03b2e87186
2 changed files with 3 additions and 3 deletions

View File

@ -21,7 +21,7 @@ module Imbecile
def run(input_file, output_file) def run(input_file, output_file)
begin begin
grammar = Grammar.new(input_file) grammar = Grammar.new(File.read(input_file))
rescue Error => e rescue Error => e
$stderr.puts e.message $stderr.puts e.message
return 2 return 2

View File

@ -7,10 +7,10 @@ module Imbecile
# @return [String, nil] Class name. # @return [String, nil] Class name.
attr_reader :classname attr_reader :classname
def initialize(input_file) def initialize(input)
@tokens = {} @tokens = {}
@rules = {} @rules = {}
File.read(input_file).each_line.each_with_index do |line, line_index| input.each_line.each_with_index do |line, line_index|
line = line.chomp line = line.chomp
line_number = line_index + 1 line_number = line_index + 1
if line =~ /^\s*#/ if line =~ /^\s*#/