Skip to content

Commit

Permalink
refactor(parser): replace FrontmatterParser with HobbitHoleParser #36
Browse files Browse the repository at this point in the history
- Update references to FrontmatterParser with HobbitHoleParser for consistency and clarity in codebase.
  • Loading branch information
phodal committed Jul 9, 2024
1 parent 0765fd2 commit dd843d4
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 17 deletions.
19 changes: 19 additions & 0 deletions .shire/docs/hobbit-hole.shire
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: "Context Variable"
description: "Here is a description of the action."
interaction: RunPanel
variables:
"currentCode": /ShireCompileTest\.kt/ { cat }
"currentDoc": /shire-hobbit-hole.md/ { cat }
---

根据如下的代码用例,更新文档中的用例:

代码用例如下:

$currentCode

现有文档如下:

$currentDoc

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.intellij.psi.search.FileTypeIndex
import com.intellij.psi.search.GlobalSearchScope
import com.phodal.shirelang.actions.base.DynamicShireActionConfig
import com.phodal.shirelang.actions.base.DynamicShireActionService
import com.phodal.shirelang.compiler.parser.FrontmatterParser
import com.phodal.shirelang.compiler.parser.HobbitHoleParser
import com.phodal.shirelang.psi.ShireFile


Expand All @@ -27,7 +27,7 @@ class ShireActionStartupActivity : ProjectActivity {
smartReadAction(project) {
obtainShireFiles(project).forEach {
val shireConfig = try {

Check warning on line 29 in shirelang/src/main/kotlin/com/phodal/shirelang/ShireActionStartupActivity.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of redundant or deprecated syntax or deprecated symbols

Elvis operator (?:) always returns the left operand of non-nullable type Nothing
FrontmatterParser.parse(it)
HobbitHoleParser.parse(it)
} catch (e: Exception) {
logger.warn("parse shire config error for file: ${it.virtualFile.path}", e)
return@forEach
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.phodal.shirelang.actions.base

import com.intellij.openapi.editor.Editor
import com.phodal.shirelang.compiler.parser.FrontmatterParser
import com.phodal.shirelang.compiler.parser.HobbitHoleParser
import com.phodal.shirelang.compiler.hobbit.HobbitHole
import com.phodal.shirelang.psi.ShireFile

Expand All @@ -13,7 +13,7 @@ data class DynamicShireActionConfig(
) {
companion object {
fun from(file: ShireFile): DynamicShireActionConfig {
val hole = FrontmatterParser.parse(file)
val hole = HobbitHoleParser.parse(file)
return DynamicShireActionConfig(file.name, hole, file)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.intellij.psi.util.elementType
import com.phodal.shirecore.agent.CustomAgent
import com.phodal.shirelang.compile.VariableTemplateCompiler
import com.phodal.shirelang.compiler.exec.*
import com.phodal.shirelang.compiler.parser.FrontmatterParser
import com.phodal.shirelang.compiler.parser.HobbitHoleParser
import com.phodal.shirelang.compiler.variable.VariableTable
import com.phodal.shirelang.completion.dataprovider.BuiltinCommand
import com.phodal.shirelang.completion.dataprovider.CustomCommand
Expand Down Expand Up @@ -93,11 +93,11 @@ class ShireSyntaxAnalyzer(
val nextElement = PsiTreeUtil.findChildOfType(
psiElement.parent, ShireFrontMatterHeader::class.java
) ?: continue
result.config = FrontmatterParser.parse(nextElement)
result.config = HobbitHoleParser.parse(nextElement)
}

ShireTypes.FRONT_MATTER_HEADER -> {

Check warning on line 99 in shirelang/src/main/kotlin/com/phodal/shirelang/compiler/ShireSyntaxAnalyzer.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant conditions

'when' branch is never reachable
result.config = FrontmatterParser.parse(psiElement as ShireFrontMatterHeader)
result.config = HobbitHoleParser.parse(psiElement as ShireFrontMatterHeader)
}

WHITE_SPACE, DUMMY_BLOCK -> output.append(psiElement.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.phodal.shirecore.middleware.PostProcessor
import com.phodal.shirecore.middleware.PostProcessorNode
import com.phodal.shirecore.middleware.select.SelectElementStrategy
import com.phodal.shirecore.middleware.select.SelectedEntry
import com.phodal.shirelang.compiler.parser.FrontmatterParser
import com.phodal.shirelang.compiler.parser.HobbitHoleParser
import com.phodal.shirelang.compiler.hobbit.base.Smials
import com.phodal.shirelang.compiler.hobbit.ast.FrontMatterType
import com.phodal.shirelang.compiler.hobbit.ast.MethodCall
Expand All @@ -25,8 +25,21 @@ import com.phodal.shirelang.compiler.patternaction.PatternActionTransform
import com.phodal.shirelang.psi.ShireFile

/**
* - Normal: the action is a normal action
* - Flow: each action can be a task in a flow, which will build a DAG
* Hobbit Hole 用于定义 IDE 交互逻辑与用户数据的流处理。
* 示例
* ```shire
* ---
* name: "Summary"
* description: "Generate Summary"
* interaction: AppendCursor
* actionLocation: ContextMenu
* ---
* ```
*
* 完整示例如下:
* ```shire
*
* ```
*/
open class HobbitHole(
/**
Expand Down Expand Up @@ -150,7 +163,7 @@ open class HobbitHole(
const val SHORTCUT = "shortcut"

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

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'SHORTCUT' could be private

fun from(file: ShireFile): HobbitHole? {
return FrontmatterParser.parse(file)
return HobbitHoleParser.parse(file)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.phodal.shirelang.compiler.hobbit.ast.*
import com.phodal.shirelang.compiler.patternaction.PatternActionFunc
import com.phodal.shirelang.psi.*

object FrontmatterParser {
private val logger = logger<FrontmatterParser>()
object HobbitHoleParser {
private val logger = logger<HobbitHoleParser>()

fun hasFrontMatter(file: ShireFile): Boolean {
return PsiTreeUtil.getChildrenOfTypeAsList(file, ShireFrontMatterHeader::class.java).isNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ object ShireAstQLParser {
}

private fun parseWhere(whereClause: ShireWhereClause): Statement? {
return FrontmatterParser.parseExpr(whereClause.expr)
return HobbitHoleParser.parseExpr(whereClause.expr)
}

private fun parseSelect(selectClause: ShireSelectClause): List<Statement> {
return selectClause.exprList.mapNotNull {
FrontmatterParser.parseExpr(it)
HobbitHoleParser.parseExpr(it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.phodal.shirelang
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.phodal.shirecore.config.ShireActionLocation
import com.phodal.shirecore.config.InteractionType
import com.phodal.shirelang.compiler.parser.FrontmatterParser
import com.phodal.shirelang.compiler.parser.HobbitHoleParser
import com.phodal.shirelang.compiler.ShireSyntaxAnalyzer
import com.phodal.shirelang.compiler.hobbit.ast.LogicalExpression
import com.phodal.shirelang.compiler.patternaction.PatternActionFunc
Expand Down Expand Up @@ -80,7 +80,7 @@ class ShireCompileTest : BasePlatformTestCase() {

val file = myFixture.configureByText("test.shire", code)

val isFrontMatterPresent = FrontmatterParser.hasFrontMatter(file as ShireFile)
val isFrontMatterPresent = HobbitHoleParser.hasFrontMatter(file as ShireFile)
assertTrue(isFrontMatterPresent)
}

Expand Down

0 comments on commit dd843d4

Please sign in to comment.