Rename GrammarParser -> Grammar

This commit is contained in:
josh committed 2021-05-01 09:33:35 -04:00
1 parent 23b7782a5d
commit 37ad87d602
2 files changed
+11 -5

No files matched your search

@@ -1,14 +1,17 @@
module Imbecile
class GrammarParser
class Grammar
def initialize(input_file)
# @return [Boolean]
# Whether loading was successful.
def load(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}"
$stderr.puts "Invalid token name #{name} on line #{line_number}"
return false
end
end
end