From 882444a62f0053e44705a058632a4c73abd784ef Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Mon, 24 Jun 2024 17:35:53 +0800 Subject: [PATCH] feat(lexer): add brace level tracking and state transitions #16 Updated ShireLexer.flex to track brace levels and state transitions in pattern action blocks and comment blocks. This includes handling of white space and new line characters, and transitioning to the front matter value block when necessary. --- shirelang/src/main/grammar/ShireLexer.flex | 43 +- .../testData/parser/PatternCaseAction.txt | 370 +++++++++--------- .../parser/ShirePsiQueryExpression.txt | 169 ++++++-- 3 files changed, 354 insertions(+), 228 deletions(-) diff --git a/shirelang/src/main/grammar/ShireLexer.flex b/shirelang/src/main/grammar/ShireLexer.flex index d22419e31..e4f8c6052 100644 --- a/shirelang/src/main/grammar/ShireLexer.flex +++ b/shirelang/src/main/grammar/ShireLexer.flex @@ -105,6 +105,8 @@ AND =and private boolean isInsideShireTemplate = false; private boolean isInsideQueryExpression = false; private boolean isInsideFrontMatter = false; + private boolean patternActionBraceStart = false; + private int patternActionBraceLevel = 0; %} %{ @@ -260,22 +262,31 @@ AND =and "<=" { return LTE; } ">" { return GT; } ">=" { return GTE; } - {WHITE_SPACE} { return TokenType.WHITE_SPACE; } "$" { return VARIABLE_START; } "(" { return LPAREN; } ")" { return RPAREN; } + {WHITE_SPACE} { return TokenType.WHITE_SPACE; } [^] { yypushback(yylength()); yybegin(FRONT_MATTER_BLOCK); } } { - "{" { return OPEN_BRACE; } - "}" { return CLOSE_BRACE; } + "{" { patternActionBraceStart = true; patternActionBraceLevel++; return OPEN_BRACE; } + "}" { patternActionBraceLevel--; return CLOSE_BRACE; } "|" { return PIPE; } "," { return COMMA; } "(" { return LPAREN; } ")" { return RPAREN; } - {WHITE_SPACE} { return TokenType.WHITE_SPACE; } + {WHITE_SPACE} { + if (patternActionBraceStart && patternActionBraceLevel == 0) { + patternActionBraceStart = false; + yybegin(FRONT_MATTER_VAL_OBJECT); + return INDENT; + } else { + return TokenType.WHITE_SPACE; + } + } + {NEWLINE} { return NEWLINE; } // keywords @@ -287,7 +298,7 @@ AND =and {QUOTE_STRING} { return QUOTE_STRING; } {PATTERN_EXPR} { return PATTERN_EXPR; } "=>" { return ARROW; } - [^] { yypushback(yylength()); yybegin(FRONT_MATTER_VALUE_BLOCK); } + [^] { patternActionBraceStart = false; yypushback(yylength()); yybegin(FRONT_MATTER_VALUE_BLOCK); } } { @@ -299,20 +310,24 @@ AND =and "from" { return FROM; } "where" { return WHERE; } "select" { return SELECT; } - - "{" { isInsideQueryExpression = true; yybegin(EXPR_BLOCK); return OPEN_BRACE; } - "}" { isInsideQueryExpression = false; return CLOSE_BRACE; } - + "{" { patternActionBraceLevel++; isInsideQueryExpression = true; yybegin(EXPR_BLOCK); return OPEN_BRACE; } + "}" { patternActionBraceLevel--; if (patternActionBraceLevel == 0) { isInsideQueryExpression = false; } return CLOSE_BRACE; } {IDENTIFIER} { if (isInsideQueryExpression) { yypushback(yylength()); yybegin(EXPR_BLOCK); } else { return IDENTIFIER; } } - {COMMENT} { return COMMENT; } {BLOCK_COMMENT} { return BLOCK_COMMENT; } + {COMMA} { return COMMA; } - {WHITE_SPACE} { return TokenType.WHITE_SPACE; } {NEWLINE} { return NEWLINE; } - - {COMMA} { return COMMA; } - [^] { yypushback(yylength()); yybegin(FRONT_MATTER_BLOCK); } + {WHITE_SPACE} { + if (isInsideQueryExpression && patternActionBraceLevel == 0) { + isInsideQueryExpression = false; + yybegin(FRONT_MATTER_VAL_OBJECT); + return INDENT; + } else { + return TokenType.WHITE_SPACE; + } + } + [^] { isInsideQueryExpression = false; yypushback(yylength()); yybegin(FRONT_MATTER_BLOCK); } } { diff --git a/shirelang/src/test/testData/parser/PatternCaseAction.txt b/shirelang/src/test/testData/parser/PatternCaseAction.txt index 8babb5177..f27fe9685 100644 --- a/shirelang/src/test/testData/parser/PatternCaseAction.txt +++ b/shirelang/src/test/testData/parser/PatternCaseAction.txt @@ -66,196 +66,198 @@ ShireFile PsiElement(ShireTokenType.))(')') PsiElement(ShireTokenType.})('}') PsiElement(ShireTokenType.NEWLINE)('\n') - PsiWhiteSpace(' ') - ShireFrontMatterEntryImpl(FRONT_MATTER_ENTRY) - ShireFrontMatterKeyImpl(FRONT_MATTER_KEY) - PsiElement(ShireTokenType.QUOTE_STRING)('"var3"') - PsiElement(ShireTokenType.COLON)(':') - PsiWhiteSpace(' ') - ShirePatternActionImpl(PATTERN_ACTION) - PatternElement(PATTERN) - PsiElement(ShireTokenType.PATTERN_EXPR)('/.*.log/') - PsiWhiteSpace(' ') - ShireActionBlockImpl(ACTION_BLOCK) - PsiElement(ShireTokenType.{)('{') - PsiElement(ShireTokenType.NEWLINE)('\n') - PsiWhiteSpace(' ') - ShireActionBodyImpl(ACTION_BODY) - ShireActionExprImpl(ACTION_EXPR) - ShireCaseBodyImpl(CASE_BODY) - PsiElement(ShireTokenType.case)('case') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.QUOTE_STRING)('"$0"') + PsiElement(ShireTokenType.INDENT)(' ') + ShireKeyValueImpl(KEY_VALUE) + ShireFrontMatterEntryImpl(FRONT_MATTER_ENTRY) + ShireFrontMatterKeyImpl(FRONT_MATTER_KEY) + PsiElement(ShireTokenType.QUOTE_STRING)('"var3"') + PsiElement(ShireTokenType.COLON)(':') + PsiWhiteSpace(' ') + ShirePatternActionImpl(PATTERN_ACTION) + PatternElement(PATTERN) + PsiElement(ShireTokenType.PATTERN_EXPR)('/.*.log/') PsiWhiteSpace(' ') - PsiElement(ShireTokenType.{)('{') - PsiElement(ShireTokenType.NEWLINE)('\n') - PsiWhiteSpace(' ') - ShireCasePatternActionImpl(CASE_PATTERN_ACTION) - ShireCaseConditionImpl(CASE_CONDITION) - PsiElement(ShireTokenType.QUOTE_STRING)('"error"') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.{)('{') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('grep') - PsiElement(ShireTokenType.()('(') - ShirePipelineArgsImpl(PIPELINE_ARGS) - ShirePipelineArgImpl(PIPELINE_ARG) - PsiElement(ShireTokenType.QUOTE_STRING)('"ERROR"') - PsiElement(ShireTokenType.))(')') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.|)('|') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('sort') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.|)('|') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('xargs') - PsiElement(ShireTokenType.()('(') - ShirePipelineArgsImpl(PIPELINE_ARGS) - ShirePipelineArgImpl(PIPELINE_ARG) - PsiElement(ShireTokenType.QUOTE_STRING)('"notify_admin"') - PsiElement(ShireTokenType.))(')') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.})('}') - PsiElement(ShireTokenType.NEWLINE)('\n') - PsiWhiteSpace(' ') - ShireCasePatternActionImpl(CASE_PATTERN_ACTION) - ShireCaseConditionImpl(CASE_CONDITION) - PsiElement(ShireTokenType.QUOTE_STRING)('"warn"') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.{)('{') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('grep') - PsiElement(ShireTokenType.()('(') - ShirePipelineArgsImpl(PIPELINE_ARGS) - ShirePipelineArgImpl(PIPELINE_ARG) - PsiElement(ShireTokenType.QUOTE_STRING)('"WARN"') - PsiElement(ShireTokenType.))(')') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.|)('|') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('sort') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.|)('|') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('xargs') - PsiElement(ShireTokenType.()('(') - ShirePipelineArgsImpl(PIPELINE_ARGS) - ShirePipelineArgImpl(PIPELINE_ARG) - PsiElement(ShireTokenType.QUOTE_STRING)('"notify_admin"') - PsiElement(ShireTokenType.))(')') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.})('}') - PsiElement(ShireTokenType.NEWLINE)('\n') - PsiWhiteSpace(' ') - ShireCasePatternActionImpl(CASE_PATTERN_ACTION) - ShireCaseConditionImpl(CASE_CONDITION) - PsiElement(ShireTokenType.QUOTE_STRING)('"info"') - PsiWhiteSpace(' ') + ShireActionBlockImpl(ACTION_BLOCK) PsiElement(ShireTokenType.{)('{') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('grep') - PsiElement(ShireTokenType.()('(') - ShirePipelineArgsImpl(PIPELINE_ARGS) - ShirePipelineArgImpl(PIPELINE_ARG) - PsiElement(ShireTokenType.QUOTE_STRING)('"INFO"') - PsiElement(ShireTokenType.))(')') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.|)('|') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('sort') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.|)('|') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('xargs') - PsiElement(ShireTokenType.()('(') - ShirePipelineArgsImpl(PIPELINE_ARGS) - ShirePipelineArgImpl(PIPELINE_ARG) - PsiElement(ShireTokenType.QUOTE_STRING)('"notify_user"') - PsiElement(ShireTokenType.))(')') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.})('}') PsiElement(ShireTokenType.NEWLINE)('\n') - PsiWhiteSpace(' ') - ShireCasePatternActionImpl(CASE_PATTERN_ACTION) - ShireCaseConditionImpl(CASE_CONDITION) - PsiElement(ShireTokenType.default)('default') + PsiWhiteSpace(' ') + ShireActionBodyImpl(ACTION_BODY) + ShireActionExprImpl(ACTION_EXPR) + ShireCaseBodyImpl(CASE_BODY) + PsiElement(ShireTokenType.case)('case') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.QUOTE_STRING)('"$0"') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.{)('{') + PsiElement(ShireTokenType.NEWLINE)('\n') + PsiWhiteSpace(' ') + ShireCasePatternActionImpl(CASE_PATTERN_ACTION) + ShireCaseConditionImpl(CASE_CONDITION) + PsiElement(ShireTokenType.QUOTE_STRING)('"error"') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.{)('{') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('grep') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"ERROR"') + PsiElement(ShireTokenType.))(')') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('sort') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('xargs') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"notify_admin"') + PsiElement(ShireTokenType.))(')') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.})('}') + PsiElement(ShireTokenType.NEWLINE)('\n') + PsiWhiteSpace(' ') + ShireCasePatternActionImpl(CASE_PATTERN_ACTION) + ShireCaseConditionImpl(CASE_CONDITION) + PsiElement(ShireTokenType.QUOTE_STRING)('"warn"') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.{)('{') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('grep') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"WARN"') + PsiElement(ShireTokenType.))(')') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('sort') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('xargs') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"notify_admin"') + PsiElement(ShireTokenType.))(')') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.})('}') + PsiElement(ShireTokenType.NEWLINE)('\n') + PsiWhiteSpace(' ') + ShireCasePatternActionImpl(CASE_PATTERN_ACTION) + ShireCaseConditionImpl(CASE_CONDITION) + PsiElement(ShireTokenType.QUOTE_STRING)('"info"') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.{)('{') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('grep') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"INFO"') + PsiElement(ShireTokenType.))(')') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('sort') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('xargs') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"notify_user"') + 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)('grep') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"ERROR"') + PsiElement(ShireTokenType.))(')') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('sort') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('xargs') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"notify_admin"') + PsiElement(ShireTokenType.))(')') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.})('}') + PsiElement(ShireTokenType.NEWLINE)('\n') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.})('}') + PsiElement(ShireTokenType.NEWLINE)('\n') PsiWhiteSpace(' ') - PsiElement(ShireTokenType.{)('{') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('grep') - PsiElement(ShireTokenType.()('(') - ShirePipelineArgsImpl(PIPELINE_ARGS) - ShirePipelineArgImpl(PIPELINE_ARG) - PsiElement(ShireTokenType.QUOTE_STRING)('"ERROR"') - PsiElement(ShireTokenType.))(')') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.|)('|') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('sort') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.|)('|') - PsiWhiteSpace(' ') - ShireActionExprImpl(ACTION_EXPR) - ShireFuncCallImpl(FUNC_CALL) - ShireFuncNameImpl(FUNC_NAME) - PsiElement(ShireTokenType.IDENTIFIER)('xargs') - PsiElement(ShireTokenType.()('(') - ShirePipelineArgsImpl(PIPELINE_ARGS) - ShirePipelineArgImpl(PIPELINE_ARG) - PsiElement(ShireTokenType.QUOTE_STRING)('"notify_admin"') - PsiElement(ShireTokenType.))(')') - PsiWhiteSpace(' ') PsiElement(ShireTokenType.})('}') PsiElement(ShireTokenType.NEWLINE)('\n') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.})('}') - PsiElement(ShireTokenType.NEWLINE)('\n') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.})('}') - PsiElement(ShireTokenType.NEWLINE)('\n') - PsiWhiteSpace(' ') - ShireFrontMatterEntryImpl(FRONT_MATTER_ENTRY) - ShireFrontMatterKeyImpl(FRONT_MATTER_KEY) - PsiElement(ShireTokenType.QUOTE_STRING)('"var4"') - PsiElement(ShireTokenType.COLON)(':') - PsiWhiteSpace(' ') - ShireFrontMatterValueImpl(FRONT_MATTER_VALUE) - PsiElement(ShireTokenType.NUMBER)('42') - PsiElement(ShireTokenType.NEWLINE)('\n') + PsiElement(ShireTokenType.INDENT)(' ') + ShireKeyValueImpl(KEY_VALUE) + ShireFrontMatterEntryImpl(FRONT_MATTER_ENTRY) + ShireFrontMatterKeyImpl(FRONT_MATTER_KEY) + PsiElement(ShireTokenType.QUOTE_STRING)('"var4"') + PsiElement(ShireTokenType.COLON)(':') + PsiWhiteSpace(' ') + ShireFrontMatterValueImpl(FRONT_MATTER_VALUE) + PsiElement(ShireTokenType.NUMBER)('42') + PsiElement(ShireTokenType.NEWLINE)('\n') PsiElement(ShireTokenType.FRONTMATTER_END)('---') PsiElement(ShireTokenType.NEWLINE)('\n') PsiElement(ShireTokenType.NEWLINE)('\n') diff --git a/shirelang/src/test/testData/parser/ShirePsiQueryExpression.txt b/shirelang/src/test/testData/parser/ShirePsiQueryExpression.txt index 6d05708e3..f733685d3 100644 --- a/shirelang/src/test/testData/parser/ShirePsiQueryExpression.txt +++ b/shirelang/src/test/testData/parser/ShirePsiQueryExpression.txt @@ -12,6 +12,138 @@ ShireFile PsiElement(ShireTokenType.NEWLINE)('\n') ShireObjectKeyValueImpl(OBJECT_KEY_VALUE) PsiElement(ShireTokenType.INDENT)(' ') + ShireKeyValueImpl(KEY_VALUE) + ShireFrontMatterEntryImpl(FRONT_MATTER_ENTRY) + ShireFrontMatterKeyImpl(FRONT_MATTER_KEY) + PsiElement(ShireTokenType.QUOTE_STRING)('"extContext"') + PsiElement(ShireTokenType.COLON)(':') + PsiWhiteSpace(' ') + ShirePatternActionImpl(PATTERN_ACTION) + PatternElement(PATTERN) + PsiElement(ShireTokenType.PATTERN_EXPR)('/build\.gradle\.kts/') + PsiWhiteSpace(' ') + ShireActionBlockImpl(ACTION_BLOCK) + PsiElement(ShireTokenType.{)('{') + PsiWhiteSpace(' ') + ShireActionBodyImpl(ACTION_BODY) + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('cat') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('grep') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"org.springframework.boot:spring-boot-starter-jdbc"') + PsiElement(ShireTokenType.))(')') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.|)('|') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('print') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('"This project use Spring Framework"') + PsiElement(ShireTokenType.))(')') + PsiElement(ShireTokenType.})('}') + PsiElement(ShireTokenType.NEWLINE)('\n') + PsiElement(ShireTokenType.INDENT)(' ') + ShireKeyValueImpl(KEY_VALUE) + ShireFrontMatterEntryImpl(FRONT_MATTER_ENTRY) + ShireFrontMatterKeyImpl(FRONT_MATTER_KEY) + PsiElement(ShireTokenType.QUOTE_STRING)('"testTemplate"') + PsiElement(ShireTokenType.COLON)(':') + PsiWhiteSpace(' ') + ShirePatternActionImpl(PATTERN_ACTION) + PatternElement(PATTERN) + PsiElement(ShireTokenType.PATTERN_EXPR)('/\(.*\).java/') + PsiWhiteSpace(' ') + ShireActionBlockImpl(ACTION_BLOCK) + PsiElement(ShireTokenType.{)('{') + PsiElement(ShireTokenType.NEWLINE)('\n') + PsiWhiteSpace(' ') + ShireActionBodyImpl(ACTION_BODY) + ShireActionExprImpl(ACTION_EXPR) + ShireCaseBodyImpl(CASE_BODY) + PsiElement(ShireTokenType.case)('case') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.QUOTE_STRING)('"$1"') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.{)('{') + PsiElement(ShireTokenType.NEWLINE)('\n') + PsiWhiteSpace(' ') + ShireCasePatternActionImpl(CASE_PATTERN_ACTION) + ShireCaseConditionImpl(CASE_CONDITION) + PsiElement(ShireTokenType.QUOTE_STRING)('"Controller"') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.{)('{') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('cat') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('".shire/templates/ControllerTest.java"') + PsiElement(ShireTokenType.))(')') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.})('}') + PsiElement(ShireTokenType.NEWLINE)('\n') + PsiWhiteSpace(' ') + ShireCasePatternActionImpl(CASE_PATTERN_ACTION) + ShireCaseConditionImpl(CASE_CONDITION) + PsiElement(ShireTokenType.QUOTE_STRING)('"Service"') + PsiWhiteSpace(' ') + PsiElement(ShireTokenType.{)('{') + PsiWhiteSpace(' ') + ShireActionExprImpl(ACTION_EXPR) + ShireFuncCallImpl(FUNC_CALL) + ShireFuncNameImpl(FUNC_NAME) + PsiElement(ShireTokenType.IDENTIFIER)('cat') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('".shire/templates/ServiceTest.java"') + 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)('cat') + PsiElement(ShireTokenType.()('(') + ShirePipelineArgsImpl(PIPELINE_ARGS) + ShirePipelineArgImpl(PIPELINE_ARG) + PsiElement(ShireTokenType.QUOTE_STRING)('".shire/templates/DefaultTest.java"') + 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.INDENT)(' ') ShireKeyValueImpl(KEY_VALUE) ShireFrontMatterEntryImpl(FRONT_MATTER_ENTRY) ShireFrontMatterKeyImpl(FRONT_MATTER_KEY) @@ -35,7 +167,7 @@ ShireFile PsiWhiteSpace(' ') PsiElement(ShireTokenType.IDENTIFIER)('clazz') PsiWhiteSpace(' ') - PsiComment(ShireTokenType.COMMENT)('// the class') + PsiComment(ShireTokenType.BLOCK_COMMENT)('/* sample */') PsiElement(ShireTokenType.NEWLINE)('\n') PsiWhiteSpace(' ') PsiElement(ShireTokenType.})('}') @@ -47,40 +179,24 @@ ShireFile PsiElement(ShireTokenType.{)('{') PsiElement(ShireTokenType.NEWLINE)('\n') PsiWhiteSpace(' ') - ShireLogicalAndExprImpl(LOGICAL_AND_EXPR) + ShireEqComparisonExprImpl(EQ_COMPARISON_EXPR) ShireCallExprImpl(CALL_EXPR) ShireRefExprImpl(REF_EXPR) ShireRefExprImpl(REF_EXPR) PsiElement(ShireTokenType.IDENTIFIER)('clazz') PsiElement(ShireTokenType..)('.') - PsiElement(ShireTokenType.IDENTIFIER)('extends') + PsiElement(ShireTokenType.IDENTIFIER)('getAnAnnotation') PsiElement(ShireTokenType.()('(') - ShireExpressionListImpl(EXPRESSION_LIST) - ShireLiteralExprImpl(LITERAL_EXPR) - PsiElement(ShireTokenType.QUOTE_STRING)('"org.springframework.web.bind.annotation.RestController"') PsiElement(ShireTokenType.))(')') PsiWhiteSpace(' ') - PsiElement(ShireTokenType.and)('and') + PsiElement(ShireTokenType.==)('==') PsiWhiteSpace(' ') - ShireEqComparisonExprImpl(EQ_COMPARISON_EXPR) - ShireCallExprImpl(CALL_EXPR) - ShireRefExprImpl(REF_EXPR) - ShireRefExprImpl(REF_EXPR) - PsiElement(ShireTokenType.IDENTIFIER)('clazz') - PsiElement(ShireTokenType..)('.') - PsiElement(ShireTokenType.IDENTIFIER)('getAnAnnotation') - PsiElement(ShireTokenType.()('(') - PsiElement(ShireTokenType.))(')') - PsiWhiteSpace(' ') - PsiElement(ShireTokenType.==)('==') - PsiWhiteSpace(' ') - ShireLiteralExprImpl(LITERAL_EXPR) - PsiElement(ShireTokenType.QUOTE_STRING)('"org.springframework.web.bind.annotation.RequestMapping"') + ShireLiteralExprImpl(LITERAL_EXPR) + PsiElement(ShireTokenType.QUOTE_STRING)('"org.springframework.web.bind.annotation.RequestMapping"') PsiElement(ShireTokenType.NEWLINE)('\n') PsiWhiteSpace(' ') PsiElement(ShireTokenType.})('}') PsiElement(ShireTokenType.NEWLINE)('\n') - PsiElement(ShireTokenType.NEWLINE)('\n') PsiWhiteSpace(' ') ShireSelectClauseImpl(SELECT_CLAUSE) PsiElement(ShireTokenType.select)('select') @@ -111,11 +227,4 @@ ShireFile PsiWhiteSpace(' ') PsiElement(ShireTokenType.})('}') PsiElement(ShireTokenType.NEWLINE)('\n') - PsiElement(ShireTokenType.FRONTMATTER_END)('---') - PsiElement(ShireTokenType.NEWLINE)('\n') - PsiElement(ShireTokenType.NEWLINE)('\n') - ShireUsedImpl(USED) - ShireVariableStartImpl(VARIABLE_START) - PsiElement(VARIABLE_START)('$') - ShireVariableIdImpl(VARIABLE_ID) - PsiElement(ShireTokenType.IDENTIFIER)('allController') \ No newline at end of file + PsiElement(ShireTokenType.FRONTMATTER_END)('---') \ No newline at end of file