Skip to content

Commit

Permalink
feat: add endpoint impl support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 4, 2022
1 parent 291dd60 commit 91785e7
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/grammars/FeakinLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ STRING_LITERAL=\"([^\\\"\r\n]|\\[^\r\n])*\"?
"Entity" { return ENTITY_KEYWORD; }
"ValueObject" { return VALUE_OBJECT_KEYWORD; }
"Struct" { return STRUCT_KEYWORD; }
"impl" { return IMPL_KEYWORD; }
"endpoint" { return ENDPOINT_KEYWORD; }
"request" { return REQUEST_KEYWORD; }
"response" { return RESPONSE_KEYWORD; }
"GET" { return GET_KEYWORD; }
"POST" { return POST_KEYWORD; }
"PUT" { return PUT_KEYWORD; }
"DELETE" { return DELETE_KEYWORD; }
"PATCH" { return PATCH_KEYWORD; }
"HEAD" { return HEAD_KEYWORD; }
"OPTIONS" { return OPTIONS_KEYWORD; }
"authorization" { return AUTH_KEYWORD; }

{COMMENT} { return COMMENT; }
{BLOCK_COMMENT} { return BLOCK_COMMENT; }
Expand Down
53 changes: 53 additions & 0 deletions src/main/grammars/FeakinParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@
ENTITY_KEYWORD = 'Entity'
VALUE_OBJECT_KEYWORD = 'ValueObject'
STRUCT_KEYWORD = 'Struct'
IMPL_KEYWORD = 'impl'
ENDPOINT_KEYWORD = 'endpoint'
REQUEST_KEYWORD = 'request'
RESPONSE_KEYWORD = 'response'

GET_KEYWORD = 'GET'
POST_KEYWORD = 'POST'
PUT_KEYWORD = 'PUT'
DELETE_KEYWORD = 'DELETE'
PATCH_KEYWORD = 'PATCH'
HEAD_KEYWORD = 'HEAD'
OPTIONS_KEYWORD = 'OPTIONS'
AUTH_KEYWORD = 'authorization'
]
}

Expand All @@ -59,6 +72,7 @@ declaration ::= contextMapDeclaration
| entityDeclaration
| valueObjectDeclaration
| structDeclaration
| implDeclaration

contextMapDeclaration ::= CONTEXT_MAP_KEYWORD contextMapName LBRACE contextMapBody? RBRACE
{
Expand Down Expand Up @@ -131,6 +145,43 @@ private useStruct ::= STRUCT_KEYWORD name_component (COMMA name_component)?
private valueObjectBody ::= structDeclaration
| useStruct

implDeclaration ::= IMPL_KEYWORD implName LBRACE implBody? RBRACE

implBody ::= endpointDeclaration*

endpointDeclaration ::= ENDPOINT_KEYWORD LBRACE endpointBody RBRACE

endpointBody ::= requestDeclaration authorizationDecl? responseDeclaration?

private authorizationDecl ::= AUTH_KEYWORD authorizationType? authorizationValue*

private authorizationValue ::= IDENTIFIER
private authorizationType ::= IDENTIFIER COLON

requestDeclaration ::= httpRequestDeclaration
// | grpcRequestDeclaration

private httpRequestDeclaration ::= httpMethod uri requestBody? SEMICOLON

httpMethod ::= GET_KEYWORD
| POST_KEYWORD
| PUT_KEYWORD
| DELETE_KEYWORD
| PATCH_KEYWORD
| HEAD_KEYWORD
| OPTIONS_KEYWORD
;

uri ::= STRING_LITERAL

requestBody ::= REQUEST_KEYWORD COLON (requestEntityName | structDeclaration) SEMICOLON;

responseDeclaration ::= RESPONSE_KEYWORD COLON responseEntityName SEMICOLON;

requestEntityName ::= name_component

responseEntityName ::= name_component

contextMapName ::= name_component

contextName ::= name_component
Expand All @@ -143,6 +194,8 @@ valueObjectName ::= name_component

contextNodeName ::= name_component

implName ::= name_component

name_component ::= IDENTIFIER
{
mixin="com.feakin.intellij.psi.impl.FeakinNamedElementImpl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ class FeakinParsingTest : ParsingTestCase("parser", "fkl", FeakinParserDefinitio
fun testEmptyBody() {
doTest(true)
}

fun testRequestImpl() {
doTest(true)
}
}
6 changes: 6 additions & 0 deletions src/test/testData/parser/RequestImpl.fkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
impl CinemaCreated {
endpoint {
GET "/book/{id}";
response: Cinema;
}
}
38 changes: 38 additions & 0 deletions src/test/testData/parser/RequestImpl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feakin
FeakinDeclarationImpl(DECLARATION)
FeakinImplDeclarationImpl(IMPL_DECLARATION)
PsiElement(FeakinTokenType.impl)('impl')
PsiWhiteSpace(' ')
FeakinImplNameImpl(IMPL_NAME)
FeakinNameComponentImpl(NAME_COMPONENT)
PsiElement(FeakinTokenType.IDENTIFIER)('CinemaCreated')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FeakinImplBodyImpl(IMPL_BODY)
FeakinEndpointDeclarationImpl(ENDPOINT_DECLARATION)
PsiElement(FeakinTokenType.endpoint)('endpoint')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FeakinEndpointBodyImpl(ENDPOINT_BODY)
FeakinRequestDeclarationImpl(REQUEST_DECLARATION)
FeakinHttpMethodImpl(HTTP_METHOD)
PsiElement(FeakinTokenType.GET)('GET')
PsiWhiteSpace(' ')
FeakinUriImpl(URI)
PsiElement(FeakinTokenType.STRING_LITERAL)('"/book/{id}"')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
FeakinResponseDeclarationImpl(RESPONSE_DECLARATION)
PsiElement(FeakinTokenType.response)('response')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinResponseEntityNameImpl(RESPONSE_ENTITY_NAME)
FeakinNameComponentImpl(NAME_COMPONENT)
PsiElement(FeakinTokenType.IDENTIFIER)('Cinema')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n')
PsiElement(FeakinTokenType.})('}')

0 comments on commit 91785e7

Please sign in to comment.