Skip to content

Commit

Permalink
refactor(compiler): replace ProcessFuncNode with PostProcessorNode #24
Browse files Browse the repository at this point in the history
The commit updates the compiler module by removing the `ProcessFuncNode` class and replacing it with the new `PostProcessorNode` class. This change affects the `HobbitHole` and its associated processing functions, as well as the test cases to reflect the use of the new node type. The `PostProcessor` interface has been extended to include the execution of the `PostProcessorNode`.
  • Loading branch information
phodal committed Jun 26, 2024
1 parent 769c2f8 commit 776f052
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package com.phodal.shirecore.middleware
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.project.Project

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

interface PostProcessor {
val processorName: String

Expand Down Expand Up @@ -47,5 +52,9 @@ interface PostProcessor {
fun allNames(): List<String> {
return EP_NAME.extensionList.map { it.processorName }
}

fun execute(funcNode: List<PostProcessorNode>) {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.phodal.shirecore.action.ShireActionLocation
import com.phodal.shirecore.agent.InteractionType
import com.phodal.shirecore.middleware.PostCodeHandleContext
import com.phodal.shirecore.middleware.PostProcessor
import com.phodal.shirecore.middleware.PostProcessorNode
import com.phodal.shirecore.middleware.select.SelectElementStrategy
import com.phodal.shirelang.compiler.FrontmatterParser
import com.phodal.shirelang.compiler.hobbit._base.Smials
Expand Down Expand Up @@ -80,7 +81,7 @@ open class HobbitHole(
* It allows for the definition of various operations such as logging, metrics collection, code verification,
* execution of code, or parsing code, among others.
*/
val onStreamingEnd: List<ProcessFuncNode> = emptyList(),
val onStreamingEnd: List<PostProcessorNode> = emptyList(),

/**
* TBD, keep it for future use.
Expand Down Expand Up @@ -204,15 +205,15 @@ open class HobbitHole(
}.associateBy { it.variable }.toMutableMap()
}

private fun buildStreamingEndProcessors(item: FrontMatterType): List<ProcessFuncNode> {
val endProcessors: MutableList<ProcessFuncNode> = mutableListOf()
private fun buildStreamingEndProcessors(item: FrontMatterType): List<PostProcessorNode> {
val endProcessors: MutableList<PostProcessorNode> = mutableListOf()
when (item) {
is FrontMatterType.ARRAY -> {
item.toValue().forEach { matterType ->
when (matterType) {
is FrontMatterType.EXPRESSION -> {
val handleName = toFuncName(matterType)
endProcessors.add(ProcessFuncNode(handleName, emptyList()))
endProcessors.add(PostProcessorNode(handleName, emptyList()))
}

else -> {}
Expand All @@ -222,7 +223,7 @@ open class HobbitHole(

is FrontMatterType.STRING -> {
val handleName = item.value as String
endProcessors.add(ProcessFuncNode(handleName, emptyList()))
endProcessors.add(PostProcessorNode(handleName, emptyList()))
}

else -> {}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.phodal.shirelang

import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.phodal.shirecore.middleware.PostProcessor
import com.phodal.shirelang.compiler.ShireCompiler
import com.phodal.shirelang.psi.ShireFile

Expand All @@ -24,10 +25,12 @@ class ShireLifecycleTest: BasePlatformTestCase() {
val compile = ShireCompiler(project, file as ShireFile, myFixture.editor).compile()
val hole = compile.config!!

val postProcessors = hole.onStreamingEnd
val funcNode = hole.onStreamingEnd

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

PostProcessor.execute(funcNode)
}
}

0 comments on commit 776f052

Please sign in to comment.