feat: ignore newlines in import statements and add test for multiline imports
Add calls to ignoreNewlines in the import compiler function to allow newlines between the import keyword and the module string, and between the module string and the for clause. Create a new test case test/language/module/newlines/ that verifies multiline import syntax works correctly with both bare imports and imports with variable bindings.
This commit is contained in:
@@ -3237,6 +3237,7 @@ static void classDefinition(Compiler* compiler, bool isForeign)
|
|||||||
// Compiles an "import" statement.
|
// Compiles an "import" statement.
|
||||||
static void import(Compiler* compiler)
|
static void import(Compiler* compiler)
|
||||||
{
|
{
|
||||||
|
ignoreNewlines(compiler);
|
||||||
consume(compiler, TOKEN_STRING, "Expect a string after 'import'.");
|
consume(compiler, TOKEN_STRING, "Expect a string after 'import'.");
|
||||||
int moduleConstant = addConstant(compiler, compiler->parser->previous.value);
|
int moduleConstant = addConstant(compiler, compiler->parser->previous.value);
|
||||||
|
|
||||||
@@ -3252,6 +3253,7 @@ static void import(Compiler* compiler)
|
|||||||
// Compile the comma-separated list of variables to import.
|
// Compile the comma-separated list of variables to import.
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
ignoreNewlines(compiler);
|
||||||
int slot = declareNamedVariable(compiler);
|
int slot = declareNamedVariable(compiler);
|
||||||
|
|
||||||
// Define a string constant for the variable name.
|
// Define a string constant for the variable name.
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// nontest
|
||||||
|
System.print("ran module")
|
||||||
|
|
||||||
|
var A = "a"
|
||||||
|
var B = "b"
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import
|
||||||
|
|
||||||
|
|
||||||
|
"module"
|
||||||
|
|
||||||
|
import "module" for
|
||||||
|
|
||||||
|
A,
|
||||||
|
|
||||||
|
B
|
||||||
|
|
||||||
|
// expect: ran module
|
||||||
|
|
||||||
|
System.print(A) // expect: a
|
||||||
|
System.print(B) // expect: b
|
||||||
Reference in New Issue
Block a user