Skip to content

Commit

Permalink
feat(syntax): add support for var and typedef
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 13, 2022
1 parent 0947624 commit ab9bb12
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/grammars/FeakinParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ whenEntryBody ::= LBRACE stepDeclaration* RBRACE

variableDeclaration ::= VAR_KEYWORD IDENTIFIER COLON fieldType variableBody

variableBody ::= LBRACE structEntry* RBRACE
variableBody ::= LBRACE variableEntry* RBRACE

variableEntry ::= variableKey COLON entryValue SEMICOLON?

variableKey ::= IDENTIFIER | PACKAGE_KEYWORD

value ::= STRING_LITERAL | IDENTIFIER | NUMBER_LITERAL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ class FeakinParsingTest : ParsingTestCase("parser", "fkl", FkParserDefinition())
fun testSourceSet() {
doTest(true)
}

fun testTypeDef() {
doTest(true)
}
}
8 changes: 8 additions & 0 deletions src/test/testData/parser/TypeDef.fkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var source: JavaSource {
language: "Java";
package: "com.phodal.coco";
}

def ContextMap {
// todo: parser generator
}
46 changes: 46 additions & 0 deletions src/test/testData/parser/TypeDef.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Feakin
FkDeclarationImpl(DECLARATION)
FkVariableDeclarationImpl(VARIABLE_DECLARATION)
PsiElement(FeakinTokenType.var)('var')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.IDENTIFIER)('source')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FkFieldTypeImpl(FIELD_TYPE)
PsiElement(FeakinTokenType.IDENTIFIER)('JavaSource')
PsiWhiteSpace(' ')
FkVariableBodyImpl(VARIABLE_BODY)
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
FkVariableEntryImpl(VARIABLE_ENTRY)
FkVariableKeyImpl(VARIABLE_KEY)
PsiElement(FeakinTokenType.IDENTIFIER)('language')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FkEntryValueImpl(ENTRY_VALUE)
FkValueImpl(VALUE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"Java"')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n ')
FkVariableEntryImpl(VARIABLE_ENTRY)
FkVariableKeyImpl(VARIABLE_KEY)
PsiElement(FeakinTokenType.package)('package')
PsiElement(FeakinTokenType.:)(':')
PsiWhiteSpace(' ')
FkEntryValueImpl(ENTRY_VALUE)
FkValueImpl(VALUE)
PsiElement(FeakinTokenType.STRING_LITERAL)('"com.phodal.coco"')
PsiElement(FeakinTokenType.;)(';')
PsiWhiteSpace('\n')
PsiElement(FeakinTokenType.})('}')
PsiWhiteSpace('\n\n')
PsiErrorElement:<declaration> expected, got 'def'
PsiElement(FeakinTokenType.def)('def')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.ContextMap)('ContextMap')
PsiWhiteSpace(' ')
PsiElement(FeakinTokenType.{)('{')
PsiWhiteSpace('\n ')
PsiComment(FeakinTokenType.COMMENT)('// todo: parser generator')
PsiWhiteSpace('\n')
PsiElement(FeakinTokenType.})('}')

0 comments on commit ab9bb12

Please sign in to comment.