Skip to content

Commit

Permalink
Report open-ended loop as an error. Fixes issue #22.
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushieno committed Oct 25, 2021
1 parent a0d7325 commit 3a7a113
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ class MmlEventStreamGenerator(private val source: MmlSemanticTreeSet, private va
processMacroCall(track, rctx, oper, extraTailArgsIfApplied ?: listOf())
}
}

if (rctx.loops.any())
reporter(
MmlDiagnosticVerbosity.Error,
list[rctx.loops.last().beginAt!!.source].location,
"There is an unclosed loop")
}

private val expansionStack = mutableListOf<MmlSemanticMacro>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.nio.file.Files
import java.nio.file.Path
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFails
import kotlin.test.assertFalse
import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull
Expand Down Expand Up @@ -386,4 +387,10 @@ class MmlCompilerTest {
val music = createDefaultCompiler().compile2(true, false,
Files.readString(Path.of("../samples/mars.mugene")))
}

@Test
fun reportUnclosedLoop() {
// https://github.com/atsushieno/mugene-ng/issues/22
assertFails("should report unclosed loop") { MmlTestUtility.testCompile("mml", "1 [ceg") }
}
}

0 comments on commit 3a7a113

Please sign in to comment.