Rename GrammarParser -> Grammar
This commit is contained in:
parent
23b7782a5d
commit
37ad87d602
@ -1,5 +1,5 @@
|
||||
require_relative "imbecile/cli"
|
||||
require_relative "imbecile/grammar_parser"
|
||||
require_relative "imbecile/grammar"
|
||||
require_relative "imbecile/version"
|
||||
|
||||
module Imbecile
|
||||
@ -7,7 +7,10 @@ module Imbecile
|
||||
class << self
|
||||
|
||||
def run(input_file)
|
||||
gp = GrammarParser.new(input_file)
|
||||
grammar = Grammar.new
|
||||
unless grammar.load(input_file)
|
||||
return 2
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user