Skip to content

Commit

Permalink
feat: add support for aggregate/entity binding by impl
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 10, 2022
1 parent 6da0957 commit 81d44e2
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/grammars/FeakinLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ STRING_LITERAL=\"([^\\\"\r\n]|\\[^\r\n])*\"?
"endpoint" { return ENDPOINT_KEYWORD; }
"request" { return REQUEST_KEYWORD; }
"response" { return RESPONSE_KEYWORD; }
"aggregate" { return AGGREGATE_S_KEYWORD; }
"entity" { return ENTITY_S_KEYWORD; }
"GET" { return GET_KEYWORD; }
"POST" { return POST_KEYWORD; }
"PUT" { return PUT_KEYWORD; }
Expand Down
14 changes: 11 additions & 3 deletions src/main/grammars/FeakinParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
ENDPOINT_KEYWORD = 'endpoint'
REQUEST_KEYWORD = 'request'
RESPONSE_KEYWORD = 'response'
AGGREGATE_S_KEYWORD = 'aggregate'
ENTITY_S_KEYWORD = 'entity'

GET_KEYWORD = 'GET'
POST_KEYWORD = 'POST'
Expand Down Expand Up @@ -159,9 +161,9 @@ private useStruct ::= STRUCT_KEYWORD IDENTIFIER (COMMA IDENTIFIER)? SEMICOL

valueObjectBody ::= LBRACE (structDeclaration | useStruct)? RBRACE

implDeclaration ::= IMPL_KEYWORD IDENTIFIER implBody {}
implDeclaration ::= IMPL_KEYWORD IDENTIFIER implBody

implBody ::= LBRACE (endpointDeclaration flowDeclaration?)? RBRACE
implBody ::= LBRACE (set_target_object? endpointDeclaration flowDeclaration?)? RBRACE

endpointDeclaration ::= ENDPOINT_KEYWORD endpointBody

Expand Down Expand Up @@ -214,7 +216,13 @@ private passObject ::= objectName (COLON viaMethodName)?

layeredDeclaration ::= LAYERED_KEYWORD IDENTIFIER layeredBody

layeredBody ::= LBRACE dependency? layerDeclaration* RBRACE
layeredBody ::= LBRACE dependency? layerDeclaration* RBRACE

set_target_object ::= AGGREGATE_S_KEYWORD COLON setAggregateName SEMICOLON?
| ENTITY_S_KEYWORD COLON setEntityName SEMICOLON?

setAggregateName ::= IDENTIFIER
setEntityName ::= IDENTIFIER

dependency ::= DEPENDENCY_KEYWORD LBRACE dependencyBody RBRACE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ object FkTokenTypeSets {
FkElementTypes.LAYER_KEYWORD,
FkElementTypes.PACKAGE_KEYWORD,
FkElementTypes.DEPENDENCY_KEYWORD,
FkElementTypes.AGGREGATE_S_KEYWORD,
FkElementTypes.ENTITY_S_KEYWORD,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ class FeakinParsingTest : ParsingTestCase("parser", "fkl", FkParserDefinition())
fun testLayered() {
doTest(true)
}

fun testLayeredWithImpl() {
doTest(true)
}
}
31 changes: 31 additions & 0 deletions src/test/testData/parser/LayeredWithImpl.fkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// Hello Got event ?
impl HelloGot {
aggregate: Hello;
endpoint {
GET "/hello";
response: String;
}
}

layered DDD {
// by default
dependency {
"interface" -> "application"
"interface" -> "domain"
"domain" -> "application"
"application" -> "infrastructure"
"interface" -> "infrastructure"
}
layer interface {
package: "com.feakin.demo.rest";
}
layer domain {
package: "com.feakin.demo.domain";
}
layer application {
package: "com.feakin.demo.application";
}
layer infrastructure {
package: "com.feakin.demo.infrastructure";
}
}
179 changes: 179 additions & 0 deletions src/test/testData/parser/LayeredWithImpl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
Feakin
PsiComment(FeakinTokenType.COMMENT)('/// Hello Got event ?')
PsiWhiteSpace('\n')
FkDeclarationImpl(DECLARATION)
FkImplDeclarationImpl(IMPL_DECLARATION)
PsiElement(FeakinTokenType.impl)('impl')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.IDENTIFIER)('HelloGot')
PsiWhiteSpace(' ')
FkImplBodyImpl(IMPL_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkSetTargetObjectImpl(SET_TARGET_OBJECT)
PsiElement(FeakinTokenType.aggregate)('aggregate')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FkSetAggregateNameImpl(SET_AGGREGATE_NAME)
PsiElement(FeakinTokenType.IDENTIFIER)('Hello')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
FkEndpointDeclarationImpl(ENDPOINT_DECLARATION)
PsiElement(FeakinTokenType.endpoint)('endpoint')
PsiWhiteSpace(' ')
FkEndpointBodyImpl(ENDPOINT_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkRequestDeclarationImpl(REQUEST_DECLARATION)
FkHttpMethodImpl(HTTP_METHOD)
PsiElement(FeakinTokenType.GET)('GET')
PsiWhiteSpace(' ')
FkUriImpl(URI)
PsiElement(FeakinTokenType.STRING_LITERAL)('"/hello"')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
FkResponseDeclarationImpl(RESPONSE_DECLARATION)
PsiElement(FeakinTokenType.response)('response')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FkResponseEntityNameImpl(RESPONSE_ENTITY_NAME)
PsiElement(FeakinTokenType.IDENTIFIER)('String')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n\n')
FkDeclarationImpl(DECLARATION)
FkLayeredDeclarationImpl(LAYERED_DECLARATION)
PsiElement(FeakinTokenType.layered)('layered')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.IDENTIFIER)('DDD')
PsiWhiteSpace(' ')
FkLayeredBodyImpl(LAYERED_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
PsiComment(FeakinTokenType.COMMENT)('// by default')
PsiWhiteSpace('\n ')
FkDependencyImpl(DEPENDENCY)
PsiElement(FeakinTokenType.dependency)('dependency')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkDependencyBodyImpl(DEPENDENCY_BODY)
FkDependencyRuleImpl(DEPENDENCY_RULE)
FkDepSourceImpl(DEP_SOURCE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"interface"')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.->)('->')
PsiWhiteSpace(' ')
FkDepTargetImpl(DEP_TARGET)
PsiElement(FeakinTokenType.STRING_LITERAL)('"application"')
PsiWhiteSpace('\n ')
FkDependencyRuleImpl(DEPENDENCY_RULE)
FkDepSourceImpl(DEP_SOURCE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"interface"')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.->)('->')
PsiWhiteSpace(' ')
FkDepTargetImpl(DEP_TARGET)
PsiElement(FeakinTokenType.STRING_LITERAL)('"domain"')
PsiWhiteSpace('\n ')
FkDependencyRuleImpl(DEPENDENCY_RULE)
FkDepSourceImpl(DEP_SOURCE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"domain"')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.->)('->')
PsiWhiteSpace(' ')
FkDepTargetImpl(DEP_TARGET)
PsiElement(FeakinTokenType.STRING_LITERAL)('"application"')
PsiWhiteSpace('\n ')
FkDependencyRuleImpl(DEPENDENCY_RULE)
FkDepSourceImpl(DEP_SOURCE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"application"')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.->)('->')
PsiWhiteSpace(' ')
FkDepTargetImpl(DEP_TARGET)
PsiElement(FeakinTokenType.STRING_LITERAL)('"infrastructure"')
PsiWhiteSpace('\n ')
FkDependencyRuleImpl(DEPENDENCY_RULE)
FkDepSourceImpl(DEP_SOURCE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"interface"')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.->)('->')
PsiWhiteSpace(' ')
FkDepTargetImpl(DEP_TARGET)
PsiElement(FeakinTokenType.STRING_LITERAL)('"infrastructure"')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n ')
FkLayerDeclarationImpl(LAYER_DECLARATION)
PsiElement(FeakinTokenType.layer)('layer')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.IDENTIFIER)('interface')
PsiWhiteSpace(' ')
FkLayerBodyImpl(LAYER_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkPackageNameImpl(PACKAGE_NAME)
PsiElement(FeakinTokenType.package)('package')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.STRING_LITERAL)('"com.feakin.demo.rest"')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n ')
FkLayerDeclarationImpl(LAYER_DECLARATION)
PsiElement(FeakinTokenType.layer)('layer')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.IDENTIFIER)('domain')
PsiWhiteSpace(' ')
FkLayerBodyImpl(LAYER_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkPackageNameImpl(PACKAGE_NAME)
PsiElement(FeakinTokenType.package)('package')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.STRING_LITERAL)('"com.feakin.demo.domain"')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n ')
FkLayerDeclarationImpl(LAYER_DECLARATION)
PsiElement(FeakinTokenType.layer)('layer')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.IDENTIFIER)('application')
PsiWhiteSpace(' ')
FkLayerBodyImpl(LAYER_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkPackageNameImpl(PACKAGE_NAME)
PsiElement(FeakinTokenType.package)('package')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.STRING_LITERAL)('"com.feakin.demo.application"')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n ')
FkLayerDeclarationImpl(LAYER_DECLARATION)
PsiElement(FeakinTokenType.layer)('layer')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.IDENTIFIER)('infrastructure')
PsiWhiteSpace(' ')
FkLayerBodyImpl(LAYER_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkPackageNameImpl(PACKAGE_NAME)
PsiElement(FeakinTokenType.package)('package')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.STRING_LITERAL)('"com.feakin.demo.infrastructure"')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n')
PsiElement(FeakinTokenType.})('}')

0 comments on commit 81d44e2

Please sign in to comment.