mirror of
https://github.com/piotr-wiszowaty/foco65.git
synced 2025-04-09 10:40:01 +00:00
handle missing include file
This commit is contained in:
parent
b273e25a17
commit
de14ad2975
18
foco65
18
foco65
@ -63,6 +63,10 @@ class UnexpectedEndOfStream(ParseError):
|
||||
def __init__(self, filename, line, column):
|
||||
ParseError.__init__(self, "unexpected end of input", filename, line, column)
|
||||
|
||||
class NoSuchFile(ParseError):
|
||||
def __init__(self, filename, token):
|
||||
ParseError.__init__(self, "No such include file '%s'" % token.text, filename, token.line, token.column)
|
||||
|
||||
#####
|
||||
|
||||
class Token:
|
||||
@ -360,11 +364,15 @@ class Forth:
|
||||
self.word = Word(token.text, self.text_section, label=token.canon())
|
||||
self.set_state("compile")
|
||||
elif token == "[include]":
|
||||
self.inputs.append((self.input, self.current_file_name))
|
||||
include_file_name = self.next().replace('"', '')
|
||||
with open(include_file_name, "rt") as f:
|
||||
self.parse_input(Input(f.read()), include_file_name)
|
||||
self.input, self.current_file_name = self.inputs.pop()
|
||||
token = self.next();
|
||||
include_file_name = token.text.replace('"', '')
|
||||
try:
|
||||
self.inputs.append((self.input, self.current_file_name))
|
||||
with open(include_file_name, "rt") as f:
|
||||
self.parse_input(Input(f.read()), include_file_name)
|
||||
self.input, self.current_file_name = self.inputs.pop()
|
||||
except IOError:
|
||||
raise NoSuchFile(self.current_file_name, token)
|
||||
|
||||
elif token == "[code]":
|
||||
self.items.append(self.parse_code())
|
||||
|
Loading…
x
Reference in New Issue
Block a user