Skip to content

Commit

Permalink
feat(core): allow null values in compiledVariables and refactor file …
Browse files Browse the repository at this point in the history
…execution

Allow null values in the compiledVariables map in PostCodeHandleContext. Refactor the runFile method in ShireRunFileAction to executeFile and update its usage in PatternFuncProcessor. Also, remove the dollar sign from all variable names before executing the file. Add a variableMap in PatternActionProcessor to store the result of each action execution. Finally, use the compiledVariables from the context as the variableTable in TaskRoutes.
  • Loading branch information
phodal committed Jul 23, 2024
1 parent 043488e commit 20eed68
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PostCodeHandleContext(

var lastTaskOutput: String? = null,

var compiledVariables: Map<String, Any> = mapOf(),
var compiledVariables: Map<String, Any?> = mapOf(),
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ShireRunFileAction : DumbAwareAction() {
ExecutionManager.getInstance(project).restartRunProfile(executionEnvironment)
}

fun runFile(
fun executeFile(
myProject: Project,
fileName: String,
variableNames: Array<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ data class TaskRoutes(
) {
fun execute(myProject: Project, context: PostCodeHandleContext, hobbitHole: HobbitHole): Any? {
val conditionResult = mutableMapOf<String, Any?>()
val variableTable = mutableMapOf<String, Any?>()

/// todo: get processor variable table
val variableTable = context.compiledVariables.toMutableMap()
variableTable["output"] = context.genText

val processor = FunctionStatementProcessor(myProject, hobbitHole)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.phodal.shirelang.compiler.patternaction.PatternActionTransform

class PatternActionProcessor(override val myProject: Project, override val hole: HobbitHole) :
PatternFuncProcessor(myProject, hole) {
val variableMap: MutableMap<String, Any?> = mutableMapOf()

/**
* We should execute the variable function with the given key and pipeline functions.
*
Expand Down Expand Up @@ -48,9 +50,10 @@ PatternFuncProcessor(myProject, hole) {
suspend fun execute(transform: PatternActionTransform, input: Any): String {
var result = input
transform.patternActionFuncs.forEach { action ->
result = patternFunctionExecute(action, result, input)
result = patternFunctionExecute(action, result, input, variableMap)
}

variableMap[transform.variable] = result
return result.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ open class PatternFuncProcessor(open val myProject: Project, open val hole: Hobb
}

is PatternActionFunc.ExecuteShire -> {
ShireRunFileAction.runFile(myProject, action.filename, action.variableNames, variableTable)
// remove $ for all variableName
val variables: Array<String> = action.variableNames.map {
if (it.startsWith("\$")) {
it.substring(1)
} else {
it
}
}.toTypedArray()

ShireRunFileAction.executeFile(myProject, action.filename, variables, variableTable)
}

is PatternActionFunc.Notify -> {
Expand Down

0 comments on commit 20eed68

Please sign in to comment.