mirror of
https://github.com/piotr-wiszowaty/foco65.git
synced 2024-06-10 03:29:33 +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):
|
def __init__(self, filename, line, column):
|
||||||
ParseError.__init__(self, "unexpected end of input", 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:
|
class Token:
|
||||||
|
@ -360,11 +364,15 @@ class Forth:
|
||||||
self.word = Word(token.text, self.text_section, label=token.canon())
|
self.word = Word(token.text, self.text_section, label=token.canon())
|
||||||
self.set_state("compile")
|
self.set_state("compile")
|
||||||
elif token == "[include]":
|
elif token == "[include]":
|
||||||
self.inputs.append((self.input, self.current_file_name))
|
token = self.next();
|
||||||
include_file_name = self.next().replace('"', '')
|
include_file_name = token.text.replace('"', '')
|
||||||
with open(include_file_name, "rt") as f:
|
try:
|
||||||
self.parse_input(Input(f.read()), include_file_name)
|
self.inputs.append((self.input, self.current_file_name))
|
||||||
self.input, self.current_file_name = self.inputs.pop()
|
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]":
|
elif token == "[code]":
|
||||||
self.items.append(self.parse_code())
|
self.items.append(self.parse_code())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user