Skip to content

Commit

Permalink
refactor(compiler): change PostProcessor to ProcessFuncNode usage #24
Browse files Browse the repository at this point in the history
This commit updates the `HobbitHole.kt` and associated test cases to replace the `PostProcessor` with the new `ProcessFuncNode` data class. It involves changing the type of the `onStreamingEnd` list and the corresponding processing logic. The commit also includes the addition of the new `ProcessFuncNode` class file and updates the test assertions to reflect these changes.
  • Loading branch information
phodal committed Jun 26, 2024
1 parent ee424b5 commit 5e9d8ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ open class HobbitHole(
* Logging, Metrics, CodeVerify, RunCode, ParseCode etc.
*
*/
val onStreamingEnd: List<PostProcessor> = emptyList(),
val onStreamingEnd: List<ProcessFuncNode> = emptyList(),

/**
* TBD
Expand All @@ -104,8 +104,8 @@ open class HobbitHole(
fun setupStreamingEndProcessor(project: Project, editor: Editor?, file: PsiFile?) {
val language = file?.language?.id
val context = PostCodeHandleContext(null, language, file)
onStreamingEnd.forEach {
it.setup(context)
onStreamingEnd.forEach { funcNode ->
PostProcessor.handler(funcNode.funName)?.setup(context)
}
}

Expand Down Expand Up @@ -154,17 +154,15 @@ open class HobbitHole(

val selectionStrategy = frontMatterMap[STRATEGY_SELECTION]?.value as? String ?: ""

val endProcessors: MutableList<PostProcessor> = mutableListOf()
val endProcessors: MutableList<ProcessFuncNode> = mutableListOf()
frontMatterMap[ON_STREAMING_END]?.let { item ->
when (item) {
is FrontMatterType.ARRAY -> {
(item.value as List<FrontMatterType>).forEach { matterType ->
when (matterType) {
is FrontMatterType.EXPRESSION -> {
val handleName = toFuncName(matterType)
PostProcessor.handler(handleName)?.let {
endProcessors.add(it)
}
endProcessors.add(ProcessFuncNode(handleName, emptyList()))
}

else -> {}
Expand All @@ -173,9 +171,8 @@ open class HobbitHole(
}

is FrontMatterType.STRING -> {
PostProcessor.handler(item as String)?.let {
endProcessors.add(it)
}
val handleName = item.value as String
endProcessors.add(ProcessFuncNode(handleName, emptyList()))
}

else -> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.phodal.shirelang.compiler.hobbit

data class ProcessFuncNode(
val funName: String,
val args: List<Any>,
) {

Check notice on line 6 in shirelang/src/main/kotlin/com/phodal/shirelang/compiler/hobbit/ProcessFuncNode.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Replace empty class body

Redundant empty class body

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ShireLifecycleTest: BasePlatformTestCase() {

val postProcessors = hole.onStreamingEnd

println(postProcessors)

// assertEquals(postProcessors.size, 2)
assertEquals(postProcessors.size, 2)
assertEquals(postProcessors[0].funName, "verifyCode")
assertEquals(postProcessors[1].funName, "runCode")
}
}

0 comments on commit 5e9d8ca

Please sign in to comment.