Skip to content

Commit

Permalink
feat: add source set support for highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 12, 2022
1 parent 2d49f9f commit 636f0df
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/grammars/FeakinLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import static com.feakin.intellij.parser.FkParserDefinition.*;
%type IElementType
%unicode


EOL=\R
WHITE_SPACE=\s+

Expand Down Expand Up @@ -67,7 +66,6 @@ INLINE_DOC = [\"][\"][^\"]*[\"]+([^\"]*[\"][\"]+)*
"Entity" { return ENTITY_KEYWORD; }
"ValueObject" { return VALUE_OBJECT_KEYWORD; }
"Struct" { return STRUCT_KEYWORD; }
"DomainEvent" { return DOMAIN_EVENT_KEYWORD; }
"impl" { return IMPL_KEYWORD; }
"endpoint" { return ENDPOINT_KEYWORD; }
"request" { return REQUEST_KEYWORD; }
Expand All @@ -92,6 +90,8 @@ INLINE_DOC = [\"][\"][^\"]*[\"]+([^\"]*[\"][\"]+)*
"layer" { return LAYER_KEYWORD; }
"dependency" { return DEPENDENCY_KEYWORD; }
"package" { return PACKAGE_KEYWORD; }
"DomainEvent" { return DOMAIN_EVENT_KEYWORD; }
"SourceSet" { return SOURCE_SET_KEYWORD; }

{COMMENT} { return COMMENT; }
{BLOCK_COMMENT} { return BLOCK_COMMENT; }
Expand Down
19 changes: 19 additions & 0 deletions src/main/grammars/FeakinParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
DEPENDENCY_KEYWORD = 'dependency'
PACKAGE_KEYWORD = 'package'
DOMAIN_EVENT_KEYWORD = 'DomainEvent'

SOURCE_SET_KEYWORD = 'SourceSet'
]
}

Expand All @@ -87,6 +89,7 @@ declaration ::= contextMapDeclaration
| structDeclaration
| implDeclaration
| layeredDeclaration
| sourceSetDeclaration

contextMapDeclaration ::= CONTEXT_MAP_KEYWORD IDENTIFIER contextMapBody
{
Expand Down Expand Up @@ -250,6 +253,22 @@ requestEntityName ::= IDENTIFIER

responseEntityName ::= IDENTIFIER

sourceSetDeclaration ::= SOURCE_SET_KEYWORD IDENTIFIER sourceSetDeclBody

sourceSetDeclBody ::= LBRACE (sourceSetItem)* RBRACE

sourceSetItem ::= IDENTIFIER sourceSetItemBody

sourceSetItemBody ::= LBRACE sourceSetEntry* RBRACE

sourceSetEntry ::= entryKey COLON entryValue SEMICOLON?

entryKey ::= IDENTIFIER

entryValue ::= value | '[' value* ']'

value ::= STRING_LITERAL | IDENTIFIER | NUMBER_LITERAL

contextName ::= IDENTIFIER
{
implements = [ "com.feakin.intellij.psi.ext.FkMandatoryReferenceElement" ]
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/com/feakin/intellij/edit/FkFoldingBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ class FkFoldingBuilder : CustomFoldingBuilder(), DumbAware {
override fun visitValueObjectBody(o: FkValueObjectBody) = fold(o)

override fun visitImplBody(o: FkImplBody) = fold(o)

override fun visitFlowBody(o: FkFlowBody) = fold(o)

override fun visitEndpointBody(o: FkEndpointBody) = fold(o)

override fun visitSourceSetDeclBody(o: FkSourceSetDeclBody) = fold(o)

override fun visitSourceSetItemBody(o: FkSourceSetItemBody) = fold(o)

private fun fold(element: PsiElement) {
descriptors += FoldingDescriptor(element.node, element.textRange)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ object FkTokenTypeSets {
FkElementTypes.DEPENDENCY_KEYWORD,
FkElementTypes.AGGREGATE_S_KEYWORD,
FkElementTypes.ENTITY_S_KEYWORD,

//sourceSet
FkElementTypes.SOURCE_SET_KEYWORD
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ class FeakinParsingTest : ParsingTestCase("parser", "fkl", FkParserDefinition())
fun testInlineDoc() {
doTest(true)
}

fun testSourceSet() {
doTest(true)
}
}
9 changes: 9 additions & 0 deletions src/test/testData/parser/SourceSet.fkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SourceSet sourceSet {
feakin {
srcDir: ["src/main/resources/uml"]
}
puml {
parser: "PlantUML"
srcDir: ["src/main/resources/uml"]
}
}
58 changes: 58 additions & 0 deletions src/test/testData/parser/SourceSet.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Feakin
FkDeclarationImpl(DECLARATION)
FkSourceSetDeclarationImpl(SOURCE_SET_DECLARATION)
PsiElement(FeakinTokenType.SourceSet)('SourceSet')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.IDENTIFIER)('sourceSet')
PsiWhiteSpace(' ')
FkSourceSetDeclBodyImpl(SOURCE_SET_DECL_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkSourceSetItemImpl(SOURCE_SET_ITEM)
PsiElement(FeakinTokenType.IDENTIFIER)('feakin')
PsiWhiteSpace(' ')
FkSourceSetItemBodyImpl(SOURCE_SET_ITEM_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkSourceSetEntryImpl(SOURCE_SET_ENTRY)
FkEntryKeyImpl(ENTRY_KEY)
PsiElement(FeakinTokenType.IDENTIFIER)('srcDir')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FkEntryValueImpl(ENTRY_VALUE)
PsiElement(BAD_CHARACTER)('[')
FkValueImpl(VALUE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"src/main/resources/uml"')
PsiElement(BAD_CHARACTER)(']')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n ')
FkSourceSetItemImpl(SOURCE_SET_ITEM)
PsiElement(FeakinTokenType.IDENTIFIER)('puml')
PsiWhiteSpace(' ')
FkSourceSetItemBodyImpl(SOURCE_SET_ITEM_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkSourceSetEntryImpl(SOURCE_SET_ENTRY)
FkEntryKeyImpl(ENTRY_KEY)
PsiElement(FeakinTokenType.IDENTIFIER)('parser')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FkEntryValueImpl(ENTRY_VALUE)
FkValueImpl(VALUE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"PlantUML"')
PsiWhiteSpace('\n ')
FkSourceSetEntryImpl(SOURCE_SET_ENTRY)
FkEntryKeyImpl(ENTRY_KEY)
PsiElement(FeakinTokenType.IDENTIFIER)('srcDir')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FkEntryValueImpl(ENTRY_VALUE)
PsiElement(BAD_CHARACTER)('[')
FkValueImpl(VALUE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"src/main/resources/uml"')
PsiElement(BAD_CHARACTER)(']')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n')
PsiElement(FeakinTokenType.})('}')

0 comments on commit 636f0df

Please sign in to comment.