Skip to content

Commit

Permalink
feat: add support for struct with init
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 27, 2022
1 parent d6626d6 commit d5b3b04
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/grammars/FeakinLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ STRING_LITERAL=\"([^\\\"\r\n]|\\[^\r\n])*\"?
"'" { return QUOTA; }
"(" { return LPAREN; }
")" { return RPAREN; }
"<" { return LT; }
">" { return GT; }
"." { return DOT; }
"->" { return RARROW; }
"<-" { return LARROW; }
"<->" { return DARROW; }
Expand Down
13 changes: 10 additions & 3 deletions src/main/grammars/FeakinParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
QUOTA = "'"
LPAREN = '('
RPAREN = ')'

LT = '<'
GT = '>'
DOT = '.'
RARROW = "->"
LARROW = "<-"
DARROW = "<->"
Expand Down Expand Up @@ -93,7 +95,7 @@ contextDeclaration ::= CONTEXT_KEYWORD contextName LBRACE contextBody RBRACE

aggregateDeclaration ::= AGGREGATION_KEYWORD aggregateName LBRACE aggregateBody RBRACE

entityDeclaration ::= ENTITY_KEYWORD entityName LBRACE entityBody RBRACE
entityDeclaration ::= ENTITY_KEYWORD entityName LBRACE entityBody? RBRACE

valueObjectDeclaration ::= VALUE_OBJECT_KEYWORD valueObjectName LBRACE valueObjectBody RBRACE

Expand All @@ -114,7 +116,12 @@ structDeclaration ::= STRUCT_KEYWORD LBRACE structBody RBRACE

private structBody ::= structEntry*

private structEntry ::= IDENTIFIER COLON IDENTIFIER SEMICOLON?
private structEntry ::= IDENTIFIER COLON structType defaultValue? SEMICOLON?

structType ::= IDENTIFIER ('<' IDENTIFIER '>')?
;

private defaultValue ::= EQUAL IDENTIFIER ('.' IDENTIFIER )?

private useValueObject ::= VALUE_OBJECT_KEYWORD name_component (COMMA name_component)? SEMICOLON

Expand Down
10 changes: 9 additions & 1 deletion src/test/kotlin/com/feakin/intellij/parser/FeakinParsingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.feakin.intellij.parser

import com.intellij.testFramework.ParsingTestCase

class FeakinParsingTest: ParsingTestCase("parser", "fkl", FeakinParserDefinition()) {
class FeakinParsingTest : ParsingTestCase("parser", "fkl", FeakinParserDefinition()) {
override fun getTestDataPath(): String {
return "src/test/testData"
}
Expand All @@ -14,4 +14,12 @@ class FeakinParsingTest: ParsingTestCase("parser", "fkl", FeakinParserDefinition
fun testContextMapAggregate() {
doTest(true)
}

fun testEntityStructList() {
doTest(true)
}

fun testEmptyBody() {
doTest(true)
}
}
11 changes: 11 additions & 0 deletions src/test/testData/parser/EmptyBody.fkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ContextMap TicketBooking {
}

Context Reservation {
}

Aggregate Reservation {
}

Entity Reservation {
}
52 changes: 52 additions & 0 deletions src/test/testData/parser/EmptyBody.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Feakin
FeakinDeclarationImpl(DECLARATION)
FeakinContextMapDeclarationImpl(CONTEXT_MAP_DECLARATION)
PsiElement(FeakinTokenType.ContextMap)('ContextMap')
PsiWhiteSpace(' ')
FeakinContextMapNameImpl(CONTEXT_MAP_NAME)
FeakinNameComponentImpl(NAME_COMPONENT)
PsiElement(FeakinTokenType.IDENTIFIER)('TicketBooking')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n')
FeakinContextMapBodyImpl(CONTEXT_MAP_BODY)
<empty list>
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n\n')
FeakinDeclarationImpl(DECLARATION)
FeakinContextDeclarationImpl(CONTEXT_DECLARATION)
PsiElement(FeakinTokenType.Context)('Context')
PsiWhiteSpace(' ')
FeakinContextNameImpl(CONTEXT_NAME)
FeakinNameComponentImpl(NAME_COMPONENT)
PsiElement(FeakinTokenType.IDENTIFIER)('Reservation')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n')
FeakinContextBodyImpl(CONTEXT_BODY)
<empty list>
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n\n')
FeakinDeclarationImpl(DECLARATION)
FeakinAggregateDeclarationImpl(AGGREGATE_DECLARATION)
PsiElement(FeakinTokenType.Aggregate)('Aggregate')
PsiWhiteSpace(' ')
FeakinAggregateNameImpl(AGGREGATE_NAME)
FeakinNameComponentImpl(NAME_COMPONENT)
PsiElement(FeakinTokenType.IDENTIFIER)('Reservation')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n\n')
FeakinDeclarationImpl(DECLARATION)
FeakinEntityDeclarationImpl(ENTITY_DECLARATION)
PsiElement(FeakinTokenType.Entity)('Entity')
PsiWhiteSpace(' ')
FeakinEntityNameImpl(ENTITY_NAME)
FeakinNameComponentImpl(NAME_COMPONENT)
PsiElement(FeakinTokenType.IDENTIFIER)('Reservation')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n')
PsiElement(FeakinTokenType.})('}')
15 changes: 15 additions & 0 deletions src/test/testData/parser/EntityStructList.fkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Entity Reservation {
Struct {
id: String;
token: UUID;
status: ReservationStatus = ReservationStatus.OPEN;
expiresAt: LocalDateTime;
createdAt: LocalDateTime;
screeningId: String;
screeningStartTime: LocalDateTime;
name: String;
surname: String;
tickets: Set<Ticket>;
totalPrice: BigDecimal;
}
}
105 changes: 105 additions & 0 deletions src/test/testData/parser/EntityStructList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Feakin
FeakinDeclarationImpl(DECLARATION)
FeakinEntityDeclarationImpl(ENTITY_DECLARATION)
PsiElement(FeakinTokenType.Entity)('Entity')
PsiWhiteSpace(' ')
FeakinEntityNameImpl(ENTITY_NAME)
FeakinNameComponentImpl(NAME_COMPONENT)
PsiElement(FeakinTokenType.IDENTIFIER)('Reservation')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FeakinStructDeclarationImpl(STRUCT_DECLARATION)
PsiElement(FeakinTokenType.Struct)('Struct')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('id')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('String')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('token')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('UUID')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('status')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('ReservationStatus')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.=)('=')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.IDENTIFIER)('ReservationStatus')
PsiElement(FeakinTokenType..)('.')
PsiElement(FeakinTokenType.IDENTIFIER)('OPEN')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('expiresAt')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('LocalDateTime')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('createdAt')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('LocalDateTime')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('screeningId')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('String')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('screeningStartTime')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('LocalDateTime')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('name')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('String')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('surname')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('String')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('tickets')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('Set')
PsiElement(FeakinTokenType.<)('<')
PsiElement(FeakinTokenType.IDENTIFIER)('Ticket')
PsiElement(FeakinTokenType.>)('>')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.IDENTIFIER)('totalPrice')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FeakinStructTypeImpl(STRUCT_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('BigDecimal')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n')
PsiElement(FeakinTokenType.})('}')

0 comments on commit d5b3b04

Please sign in to comment.