Make imports expect a string, not an expression

This commit is contained in:
germax26 2024-08-12 00:16:13 +10:00
parent 0dbc46bf9c
commit dd3b933e03
Signed by: germax26
SSH Key Fingerprint: SHA256:N3w+8798IMWBt7SYH8G1C0iJlIa2HIIcRCXwILT5FvM
3 changed files with 6 additions and 8 deletions

View File

@ -518,7 +518,7 @@ class ForLoop(Statement):
@dataclass
class Import(Statement):
file: Expression
file: str
@dataclass
class TypeDefinition(Statement):

View File

@ -554,14 +554,12 @@ def interpret_statements(statements: List_[Statement], program: ProgramState) ->
case _: assert False, ("Unimplemented", return_value)
case ContinueStatement(): return ContinueResult()
case BreakStatement(): return BreakResult()
case Import(file_):
case Import(file):
# TODO: Maybe an inclusion system within a preprocessor maybe
file = calculate_expression(file_, program)
assert isinstance(file, Str), "Only strings are valid file paths!"
module = interpret_file(file.str, program.modules) if file.str not in program.modules else program.modules[file.str]
module = interpret_file(file, program.modules) if file not in program.modules else program.modules[file]
program.contexts[0] |= module
if file.str not in program.modules:
program.modules[file.str] = module
if file not in program.modules:
program.modules[file] = module
case TypeDefinition(name, expression_):
program.declare_and_assign_variable(name, TypeObject(calculate_type_expression(expression_, program)))
case DeferStatement(statement=statement):

View File

@ -329,7 +329,7 @@ def parse_statement(lexer: Lexer) -> Statement:
body = parse_statement(lexer)
return ForLoop(variable, expression, body)
elif lexer.take_token(KeywordToken(Keyword.Import)):
file = parse_expression(lexer)
file = parse_string(lexer)
lexer.assert_token(SymbolToken(Symbol.Semicolon))
return Import(file)
elif lexer.take_token(KeywordToken(Keyword.Type)):