Begin parsing grammar

This commit is contained in:
Josh Holtrop 2021-05-01 09:31:12 -04:00
parent 0cc4516c0e
commit 23b7782a5d

View File

@ -2,6 +2,16 @@ module Imbecile
class GrammarParser class GrammarParser
def initialize(input_file) def initialize(input_file)
File.read(input_file).each_line.each_with_index do |line, line_index|
line = line.chomp
line_number = line_index + 1
if line =~ /^\s*token\s+(\S+)\s+(.*)$/
name, expr = $1, $2
unless name =~ /^[a-zA-Z_][a-zA-Z_0-9]*$/
raise "Invalid token name #{name} on line #{line_number}"
end
end
end
end end
end end