Make imports expect a string, not an expression
This commit is contained in:
parent
0dbc46bf9c
commit
dd3b933e03
@ -518,7 +518,7 @@ class ForLoop(Statement):
|
||||
|
||||
@dataclass
|
||||
class Import(Statement):
|
||||
file: Expression
|
||||
file: str
|
||||
|
||||
@dataclass
|
||||
class TypeDefinition(Statement):
|
||||
|
@ -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):
|
||||
|
@ -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)):
|
||||
|
Loading…
Reference in New Issue
Block a user