Skip to content

Commit

Permalink
feat(shirelang): add default condition and new test for afterStreaming
Browse files Browse the repository at this point in the history
…#24

Add the ability to specify a default condition in the lifecycle configuration of Shirelang. This change also includes a new test file and a test case for the afterStreaming condition.

The commit adheres to the Conventional Commits specification, providing a clear and concise description of the main action.
  • Loading branch information
phodal committed Jun 25, 2024
1 parent c9d6718 commit e5a28cb
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/lifecycle/afterStreaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ afterStreaming: {
condition {
"variable-success" { $selection.length > 1 }
"jsonpath-success" { jsonpath("/bookstore/book[price>35]") }
default { true }
}
case condition {
"variable-sucesss" { done }
Expand Down
2 changes: 1 addition & 1 deletion shirelang/src/main/grammar/ShireParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ frontMatterHeader ::= FRONTMATTER_START NEWLINE frontMatterEntries FRONTMATTER_E

frontMatterEntries ::= frontMatterEntry*
frontMatterEntry ::=
lifecycleId COLON conditionExpr NEWLINE?
lifecycleId COLON (functionStatement | conditionExpr) NEWLINE?
| frontMatterKey COLON (frontMatterValue | patternAction | functionStatement) NEWLINE?

private lifecycleId ::= "when" | "onStreaming" | "onStreamingEnd" | "afterStreaming"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ class ShireParsingTest : ParsingTestCase("parser", "shire", ShireParserDefinitio
fun testMultipleFMVariable() {
doTest(true)
}

fun testAfterStream() {
doTest(true)
}
}
13 changes: 13 additions & 0 deletions shirelang/src/test/testData/parser/AfterStream.shire
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
afterStreaming: {
condition {
"variable-success" { $selection.length > 1 }
"jsonpath-success" { jsonpath("/bookstore/book[price>35]") }
}
case condition {
"variable-sucesss" { done }
"jsonpath-success" { task() }
default { task() }
}
}
---
130 changes: 130 additions & 0 deletions shirelang/src/test/testData/parser/AfterStream.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
ShireFile
ShireFrontMatterHeaderImpl(FRONT_MATTER_HEADER)
PsiElement(ShireTokenType.FRONTMATTER_START)('---')
PsiElement(ShireTokenType.NEWLINE)('\n')
ShireFrontMatterEntriesImpl(FRONT_MATTER_ENTRIES)
ShireFrontMatterEntryImpl(FRONT_MATTER_ENTRY)
PsiElement(ShireTokenType.afterStreaming)('afterStreaming')
PsiElement(ShireTokenType.COLON)(':')
PsiWhiteSpace(' ')
ShireFunctionStatementImpl(FUNCTION_STATEMENT)
PsiElement(ShireTokenType.{)('{')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
ShireFunctionBodyImpl(FUNCTION_BODY)
ShireActionBodyImpl(ACTION_BODY)
ShireActionExprImpl(ACTION_EXPR)
ShireCaseBodyImpl(CASE_BODY)
ShireConditionFlagImpl(CONDITION_FLAG)
PsiElement(ShireTokenType.condition)('condition')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.{)('{')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
ShireConditionStatementImpl(CONDITION_STATEMENT)
ShireCaseConditionImpl(CASE_CONDITION)
PsiElement(ShireTokenType.QUOTE_STRING)('"variable-success"')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.{)('{')
PsiWhiteSpace(' ')
ShireIneqComparisonExprImpl(INEQ_COMPARISON_EXPR)
ShireRefExprImpl(REF_EXPR)
ShireLiteralExprImpl(LITERAL_EXPR)
PsiElement(VARIABLE_START)('$')
PsiElement(ShireTokenType.IDENTIFIER)('selection')
PsiElement(ShireTokenType..)('.')
PsiElement(ShireTokenType.IDENTIFIER)('length')
PsiWhiteSpace(' ')
ShireIneqComparisonOpImpl(INEQ_COMPARISON_OP)
PsiElement(ShireTokenType.>)('>')
PsiWhiteSpace(' ')
ShireLiteralExprImpl(LITERAL_EXPR)
PsiElement(ShireTokenType.NUMBER)('1')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.})('}')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
ShireConditionStatementImpl(CONDITION_STATEMENT)
ShireCaseConditionImpl(CASE_CONDITION)
PsiElement(ShireTokenType.QUOTE_STRING)('"jsonpath-success"')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.{)('{')
PsiWhiteSpace(' ')
ShireCallExprImpl(CALL_EXPR)
ShireRefExprImpl(REF_EXPR)
PsiElement(ShireTokenType.IDENTIFIER)('jsonpath')
PsiElement(ShireTokenType.()('(')
ShireExpressionListImpl(EXPRESSION_LIST)
ShireLiteralExprImpl(LITERAL_EXPR)
PsiElement(ShireTokenType.QUOTE_STRING)('"/bookstore/book[price>35]"')
PsiElement(ShireTokenType.))(')')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.})('}')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.})('}')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.case)('case')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.condition)('condition')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.{)('{')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
ShireCasePatternActionImpl(CASE_PATTERN_ACTION)
ShireCaseConditionImpl(CASE_CONDITION)
PsiElement(ShireTokenType.QUOTE_STRING)('"variable-sucesss"')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.{)('{')
PsiWhiteSpace(' ')
ShireActionExprImpl(ACTION_EXPR)
ShireFuncCallImpl(FUNC_CALL)
ShireFuncNameImpl(FUNC_NAME)
PsiElement(ShireTokenType.IDENTIFIER)('done')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.})('}')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
ShireCasePatternActionImpl(CASE_PATTERN_ACTION)
ShireCaseConditionImpl(CASE_CONDITION)
PsiElement(ShireTokenType.QUOTE_STRING)('"jsonpath-success"')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.{)('{')
PsiWhiteSpace(' ')
ShireActionExprImpl(ACTION_EXPR)
ShireFuncCallImpl(FUNC_CALL)
ShireFuncNameImpl(FUNC_NAME)
PsiElement(ShireTokenType.IDENTIFIER)('task')
PsiElement(ShireTokenType.()('(')
ShirePipelineArgsImpl(PIPELINE_ARGS)
<empty list>
PsiElement(ShireTokenType.))(')')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.})('}')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
ShireCasePatternActionImpl(CASE_PATTERN_ACTION)
ShireCaseConditionImpl(CASE_CONDITION)
PsiElement(ShireTokenType.default)('default')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.{)('{')
PsiWhiteSpace(' ')
ShireActionExprImpl(ACTION_EXPR)
ShireFuncCallImpl(FUNC_CALL)
ShireFuncNameImpl(FUNC_NAME)
PsiElement(ShireTokenType.IDENTIFIER)('task')
PsiElement(ShireTokenType.()('(')
ShirePipelineArgsImpl(PIPELINE_ARGS)
<empty list>
PsiElement(ShireTokenType.))(')')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.})('}')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.})('}')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiWhiteSpace(' ')
PsiElement(ShireTokenType.})('}')
PsiElement(ShireTokenType.NEWLINE)('\n')
PsiElement(ShireTokenType.FRONTMATTER_END)('---')

0 comments on commit e5a28cb

Please sign in to comment.