generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): add execution logic for variable pattern functions #16
Implemented the execution logic for variable pattern functions in the VariablePatternFunc class. Also updated the SymbolResolver class to execute variable functions with the given key and pipeline functions.
- Loading branch information
Showing
2 changed files
with
55 additions
and
6 deletions.
There are no files selected for viewing
41 changes: 40 additions & 1 deletion
41
shirelang/src/main/kotlin/com/phodal/shirelang/compiler/hobbit/VariablePatternFunc.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
package com.phodal.shirelang.compiler.hobbit | ||
|
||
class VariablePatternFunc(val name: String, val function: PatternFun) | ||
class VariablePatternFunc(val name: String, val function: PatternFun) { | ||
fun execute(input: Any): String { | ||
var result = input | ||
when(function) { | ||
is PatternFun.Prompt -> { | ||
result = function.message | ||
} | ||
is PatternFun.Grep -> { | ||
result = function.patterns.joinToString("\n") | ||
} | ||
is PatternFun.Sed -> { | ||
result = (result as String).replace(function.pattern.toRegex(), function.replacements) | ||
} | ||
is PatternFun.Sort -> { | ||
result = function.arguments.sorted().joinToString("\n") | ||
} | ||
is PatternFun.Uniq -> { | ||
result = function.texts.distinct().joinToString("\n") | ||
} | ||
is PatternFun.Head -> { | ||
result = (result as String).split("\n").take(function.lines.toInt()).joinToString("\n") | ||
} | ||
is PatternFun.Tail -> { | ||
result = (result as String).split("\n").takeLast(function.lines.toInt()).joinToString("\n") | ||
} | ||
|
||
is PatternFun.Cat -> { | ||
result = function.paths.joinToString("\n") | ||
} | ||
is PatternFun.Print -> { | ||
result = function.texts.joinToString("\n") | ||
} | ||
is PatternFun.Xargs -> { | ||
result = function.variables | ||
} | ||
} | ||
|
||
return result.toString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters