Skip to content

Commit

Permalink
Integrate identifier assignment with existing statements
Browse files Browse the repository at this point in the history
This makes it more straightforward to generate blocks for auto
formatting.
  • Loading branch information
dirkgroot committed Mar 31, 2023
1 parent 458a208 commit db76d07
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 135 deletions.
44 changes: 29 additions & 15 deletions src/main/gen/nl/dirkgroot/structurizr/dsl/StructurizrDSLParser.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDTypes.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDVisitor.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/main/grammar/StructurizrDSL.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@

structurizrDSLFile ::= statement*

private statement ::= identifierAssignment | elementDefinition | scriptBlock | explicitRelationship | implicitRelationship

identifierAssignment ::= identifierName '=' elementDefinition
identifierName ::= IDENTIFIER
private statement ::= elementDefinition | scriptBlock | explicitRelationship | implicitRelationship

private elementDefinition ::= singleLineStatement | blockStatement | propertyBlockStatement | CRLF

singleLineStatement ::= keywordWithArguments lf_eof
blockStatement ::= keywordWithArguments '{' CRLF statement* '}' lf_eof
singleLineStatement ::= identifierAssignment? keywordWithArguments lf_eof
blockStatement ::= identifierAssignment? keywordWithArguments '{' CRLF statement* '}' lf_eof

private identifierAssignment ::= identifierName '='

propertyBlockStatement ::= keywordWithPropertyBlock '{' CRLF keyValuePair* '}'
keyValuePair ::= key value CRLF
key ::= text
Expand All @@ -138,6 +138,7 @@ keyword ::= '!adrs' | 'animation' | 'autoLayout' | 'background' | 'border' | 'co
keywordWithPropertyBlock ::= 'branding' | 'configuration' | 'properties' | 'terminology' | 'users'

argument ::= text
identifierName ::= IDENTIFIER

private text ::= QUOTED_TEXT | UNQUOTED_TEXT
private lf_eof ::= CRLF | <<eof>>
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ class IdentifierAssignmentTest : StructurizrDSLParserTest() {
assertPsiTree(
"""identifier = softwareSystem blaat""",
"""
IdentifierAssignment
SingleLineStatement
IdentifierName identifier
SingleLineStatement
Keyword softwareSystem
Argument blaat
Keyword softwareSystem
Argument blaat
""".trimIndent()
)
}
Expand All @@ -32,15 +31,14 @@ class IdentifierAssignmentTest : StructurizrDSLParserTest() {
}
""".trimIndent(),
"""
IdentifierAssignment
BlockStatement
IdentifierName identifier
BlockStatement
Keyword softwareSystem
Argument blaat
SingleLineStatement
Keyword container
Argument containerName
""".trimIndent()
Keyword softwareSystem
Argument blaat
SingleLineStatement
Keyword container
Argument containerName
""".trimIndent()
)
}
}
Expand All @@ -57,11 +55,10 @@ class IdentifierAssignmentTest : StructurizrDSLParserTest() {
"""
BlockStatement
Keyword model
IdentifierAssignment
SingleLineStatement
IdentifierName identifier
SingleLineStatement
Keyword softwareSystem
Argument name
Keyword softwareSystem
Argument name
""".trimIndent()
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,37 @@
package nl.dirkgroot.structurizr.dsl.support

import assertk.assertThat
import assertk.assertions.isEmpty
import assertk.assertions.isNotEmpty
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiErrorElement
import com.intellij.psi.PsiFileFactory
import com.intellij.psi.tree.TokenSet
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import com.intellij.testFramework.junit5.RunInEdt
import nl.dirkgroot.structurizr.dsl.StructurizrDSLFileType
import nl.dirkgroot.structurizr.dsl.psi.StructurizrDSLFile
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach

@RunInEdt
abstract class StructurizrDSLParserTest {
private lateinit var project: Project
protected lateinit var fixture: CodeInsightTestFixture
protected lateinit var project: Project

@BeforeEach
fun setUp() {
val fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory()
val fixture = fixtureFactory.createLightFixtureBuilder("test").fixture
fixture = fixtureFactory.createCodeInsightFixture(fixtureFactory.createLightFixtureBuilder("test").fixture)
fixture.setUp()
project = fixture.project
}

protected fun parse(text: String) = PsiFileFactory.getInstance(project)
@AfterEach
fun tearDown() {
fixture.tearDown()
}

private fun parse(text: String) = PsiFileFactory.getInstance(project)
.createFileFromText("test.dsl", StructurizrDSLFileType, text)

protected fun assertPsiTree(source: String, expected: String) {
val file = parse(source)
assertPsiTree(file, expected)
}

protected fun assertParseSucceeds(source: String): StructurizrDSLFile {
val psiFile = parse(source)
val root = psiFile.viewProvider.allFiles.first()

assertThat(
root.node.getChildren(TokenSet.ANY)
.filterIsInstance<PsiErrorElement>()
).isEmpty()

return root as StructurizrDSLFile
}

protected fun assertParseFails(source: String) {
val psiFile = parse(source)
val root = psiFile.viewProvider.allFiles.first()

assertThat(
root.node.getChildren(TokenSet.ANY)
.filterIsInstance<PsiErrorElement>()
).isNotEmpty()
}
}

0 comments on commit db76d07

Please sign in to comment.