diff --git a/CHANGELOG.md b/CHANGELOG.md index c9f73cd..86c5429 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## [Unreleased] +### Added + +- Very simple parser, which should provide just enough of a basis to add basic editor functionality like code + formatting and auto indentation. + ## [0.1.3-alpha] - 2023-03-30 ### Changed diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/StructurizrDSLParser.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/StructurizrDSLParser.java index 64678ae..5363ffd 100644 --- a/src/main/gen/nl/dirkgroot/structurizr/dsl/StructurizrDSLParser.java +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/StructurizrDSLParser.java @@ -36,20 +36,460 @@ static boolean parse_root_(IElementType t, PsiBuilder b, int l) { } /* ********************************************************** */ - // !<> - public static boolean rootElement(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "rootElement")) return false; + // text + public static boolean argument(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "argument")) return false; + if (!nextTokenIs(b, "", QUOTED_TEXT, UNQUOTED_TEXT)) return false; boolean r; - Marker m = enter_section_(b, l, _NOT_, ROOT_ELEMENT, ""); - r = !eof(b, l + 1); + Marker m = enter_section_(b, l, _NONE_, ARGUMENT, ""); + r = text(b, l + 1); exit_section_(b, l, m, r, false, null); return r; } /* ********************************************************** */ - // rootElement + // identifierAssignment? keywordWithArguments '{' CRLF statement* '}' lf_eof + public static boolean blockStatement(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "blockStatement")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, BLOCK_STATEMENT, ""); + r = blockStatement_0(b, l + 1); + r = r && keywordWithArguments(b, l + 1); + r = r && consumeTokens(b, 0, BRACE1, CRLF); + r = r && blockStatement_4(b, l + 1); + r = r && consumeToken(b, BRACE2); + r = r && lf_eof(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; + } + + // identifierAssignment? + private static boolean blockStatement_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "blockStatement_0")) return false; + identifierAssignment(b, l + 1); + return true; + } + + // statement* + private static boolean blockStatement_4(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "blockStatement_4")) return false; + while (true) { + int c = current_position_(b); + if (!statement(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "blockStatement_4", c)) break; + } + return true; + } + + /* ********************************************************** */ + // singleLineStatement | blockStatement | propertyBlockStatement | CRLF + static boolean elementDefinition(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "elementDefinition")) return false; + boolean r; + r = singleLineStatement(b, l + 1); + if (!r) r = blockStatement(b, l + 1); + if (!r) r = propertyBlockStatement(b, l + 1); + if (!r) r = consumeToken(b, CRLF); + return r; + } + + /* ********************************************************** */ + // identifierName '->' identifierName argument* + public static boolean explicitRelationship(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "explicitRelationship")) return false; + if (!nextTokenIs(b, IDENTIFIER)) return false; + boolean r; + Marker m = enter_section_(b); + r = identifierName(b, l + 1); + r = r && consumeToken(b, RELATIONSHIP_KEYWORD); + r = r && identifierName(b, l + 1); + r = r && explicitRelationship_3(b, l + 1); + exit_section_(b, m, EXPLICIT_RELATIONSHIP, r); + return r; + } + + // argument* + private static boolean explicitRelationship_3(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "explicitRelationship_3")) return false; + while (true) { + int c = current_position_(b); + if (!argument(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "explicitRelationship_3", c)) break; + } + return true; + } + + /* ********************************************************** */ + // identifierName '=' + static boolean identifierAssignment(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "identifierAssignment")) return false; + if (!nextTokenIs(b, IDENTIFIER)) return false; + boolean r; + Marker m = enter_section_(b); + r = identifierName(b, l + 1); + r = r && consumeToken(b, EQUALS); + exit_section_(b, m, null, r); + return r; + } + + /* ********************************************************** */ + // IDENTIFIER + public static boolean identifierName(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "identifierName")) return false; + if (!nextTokenIs(b, IDENTIFIER)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, IDENTIFIER); + exit_section_(b, m, IDENTIFIER_NAME, r); + return r; + } + + /* ********************************************************** */ + // identifierName+ lf_eof + public static boolean identifierReferences(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "identifierReferences")) return false; + if (!nextTokenIs(b, IDENTIFIER)) return false; + boolean r; + Marker m = enter_section_(b); + r = identifierReferences_0(b, l + 1); + r = r && lf_eof(b, l + 1); + exit_section_(b, m, IDENTIFIER_REFERENCES, r); + return r; + } + + // identifierName+ + private static boolean identifierReferences_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "identifierReferences_0")) return false; + boolean r; + Marker m = enter_section_(b); + r = identifierName(b, l + 1); + while (r) { + int c = current_position_(b); + if (!identifierName(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "identifierReferences_0", c)) break; + } + exit_section_(b, m, null, r); + return r; + } + + /* ********************************************************** */ + // '->' identifierName argument* + public static boolean implicitRelationship(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "implicitRelationship")) return false; + if (!nextTokenIs(b, RELATIONSHIP_KEYWORD)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, RELATIONSHIP_KEYWORD); + r = r && identifierName(b, l + 1); + r = r && implicitRelationship_2(b, l + 1); + exit_section_(b, m, IMPLICIT_RELATIONSHIP, r); + return r; + } + + // argument* + private static boolean implicitRelationship_2(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "implicitRelationship_2")) return false; + while (true) { + int c = current_position_(b); + if (!argument(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "implicitRelationship_2", c)) break; + } + return true; + } + + /* ********************************************************** */ + // text + public static boolean key(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "key")) return false; + if (!nextTokenIs(b, "", QUOTED_TEXT, UNQUOTED_TEXT)) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, KEY, ""); + r = text(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // key value CRLF + public static boolean keyValuePair(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "keyValuePair")) return false; + if (!nextTokenIs(b, "", QUOTED_TEXT, UNQUOTED_TEXT)) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, KEY_VALUE_PAIR, ""); + r = key(b, l + 1); + r = r && value(b, l + 1); + r = r && consumeToken(b, CRLF); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // '!adrs' | 'animation' | 'autoLayout' | 'background' | 'border' | 'color' | 'colour' | 'component' | + // '!constant' | 'containerInstance' | 'container' | 'custom' | 'deploymentEnvironment' | 'deploymentGroup' | + // 'deployment' | 'deploymentNode' | 'description' | '!docs' | 'dynamic' | 'element' | 'enterprise' | + // 'exclude' | 'extends' | 'filtered' | 'fontSize' | 'group' | 'healthCheck' | 'height' | 'icon' | + // '!identifiers' | '!impliedRelationships' | 'include' | '!include' | 'infrastructureNode' | 'instances' | + // 'metadata' | 'model' | 'opacity' | 'person' | 'perspectives' | '!plugin' | 'position' | '!ref' | '->' | + // 'routing' | '!script' | 'shape' | 'softwareSystemInstance' | 'softwareSystem' | 'stroke' | 'strokeWidth' | + // 'style' | 'styles' | 'systemContext' | 'systemLandscape' | 'tags' | 'technology' | 'theme' | 'thickness' | + // 'title' | 'url' | 'views' | 'width' | 'workspace' + public static boolean keyword(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "keyword")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, KEYWORD, ""); + r = consumeToken(b, ADRS_KEYWORD); + if (!r) r = consumeToken(b, ANIMATION_KEYWORD); + if (!r) r = consumeToken(b, AUTO_LAYOUT_KEYWORD); + if (!r) r = consumeToken(b, BACKGROUND_KEYWORD); + if (!r) r = consumeToken(b, BORDER_KEYWORD); + if (!r) r = consumeToken(b, COLOR_KEYWORD); + if (!r) r = consumeToken(b, COLOUR_KEYWORD); + if (!r) r = consumeToken(b, COMPONENT_KEYWORD); + if (!r) r = consumeToken(b, CONSTANT_KEYWORD); + if (!r) r = consumeToken(b, CONTAINER_INSTANCE); + if (!r) r = consumeToken(b, CONTAINER_KEYWORD); + if (!r) r = consumeToken(b, CUSTOM_KEYWORD); + if (!r) r = consumeToken(b, DEPLOYMENT_ENVIRONMENT_KEYWORD); + if (!r) r = consumeToken(b, DEPLOYMENT_GROUP_KEYWORD); + if (!r) r = consumeToken(b, DEPLOYMENT_KEYWORD); + if (!r) r = consumeToken(b, DEPLOYMENT_NODE_KEYWORD); + if (!r) r = consumeToken(b, DESCRIPTION_KEYWORD); + if (!r) r = consumeToken(b, DOCS_KEYWORD); + if (!r) r = consumeToken(b, DYNAMIC_KEYWORD); + if (!r) r = consumeToken(b, ELEMENT_KEYWORD); + if (!r) r = consumeToken(b, ENTERPRISE_KEYWORD); + if (!r) r = consumeToken(b, EXCLUDE_ELEMENT_KEYWORD); + if (!r) r = consumeToken(b, EXTENDS_KEYWORD); + if (!r) r = consumeToken(b, FILTERED_KEYWORD); + if (!r) r = consumeToken(b, FONTSIZE_KEYWORD); + if (!r) r = consumeToken(b, GROUP_KEYWORD); + if (!r) r = consumeToken(b, HEALTH_CHECK_KEYWORD); + if (!r) r = consumeToken(b, HEIGHT_KEYWORD); + if (!r) r = consumeToken(b, ICON_KEYWORD); + if (!r) r = consumeToken(b, IDENTIFIERS_KEYWORD); + if (!r) r = consumeToken(b, IMPLIED_RELATIONSHIPS_KEYWORD); + if (!r) r = consumeToken(b, INCLUDE_ELEMENT_KEYWORD); + if (!r) r = consumeToken(b, INCLUDE_FILE_KEYWORD); + if (!r) r = consumeToken(b, INFRASTRUCTURE_NODE_KEYWORD); + if (!r) r = consumeToken(b, INSTANCES_KEYWORD); + if (!r) r = consumeToken(b, METADATA_KEYWORD); + if (!r) r = consumeToken(b, MODEL_KEYWORD); + if (!r) r = consumeToken(b, OPACITY_KEYWORD); + if (!r) r = consumeToken(b, PERSON_KEYWORD); + if (!r) r = consumeToken(b, PERSPECTIVES_KEYWORD); + if (!r) r = consumeToken(b, PLUGIN_KEYWORD); + if (!r) r = consumeToken(b, POSITION_KEYWORD); + if (!r) r = consumeToken(b, REF_KEYWORD); + if (!r) r = consumeToken(b, RELATIONSHIP_KEYWORD); + if (!r) r = consumeToken(b, ROUTING_KEYWORD); + if (!r) r = consumeToken(b, SCRIPT_KEYWORD); + if (!r) r = consumeToken(b, SHAPE_KEYWORD); + if (!r) r = consumeToken(b, SOFTWARE_SYSTEM_INSTANCE_KEYWORD); + if (!r) r = consumeToken(b, SOFTWARE_SYSTEM_KEYWORD); + if (!r) r = consumeToken(b, STROKE_KEYWORD); + if (!r) r = consumeToken(b, STROKEWIDTH_KEYWORD); + if (!r) r = consumeToken(b, STYLE_KEYWORD); + if (!r) r = consumeToken(b, STYLES_KEYWORD); + if (!r) r = consumeToken(b, SYSTEM_CONTEXT_KEYWORD); + if (!r) r = consumeToken(b, SYSTEM_LANDSCAPE_KEYWORD); + if (!r) r = consumeToken(b, TAGS_KEYWORD); + if (!r) r = consumeToken(b, TECHNOLOGY_KEYWORD); + if (!r) r = consumeToken(b, THEME_KEYWORD); + if (!r) r = consumeToken(b, THICKNESS_KEYWORD); + if (!r) r = consumeToken(b, TITLE_KEYWORD); + if (!r) r = consumeToken(b, URL_KEYWORD); + if (!r) r = consumeToken(b, VIEWS_KEYWORD); + if (!r) r = consumeToken(b, WIDTH_KEYWORD); + if (!r) r = consumeToken(b, WORKSPACE_KEYWORD); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // keyword argument* + static boolean keywordWithArguments(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "keywordWithArguments")) return false; + boolean r; + Marker m = enter_section_(b); + r = keyword(b, l + 1); + r = r && keywordWithArguments_1(b, l + 1); + exit_section_(b, m, null, r); + return r; + } + + // argument* + private static boolean keywordWithArguments_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "keywordWithArguments_1")) return false; + while (true) { + int c = current_position_(b); + if (!argument(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "keywordWithArguments_1", c)) break; + } + return true; + } + + /* ********************************************************** */ + // 'branding' | 'configuration' | 'properties' | 'terminology' | 'users' + public static boolean keywordWithPropertyBlock(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "keywordWithPropertyBlock")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, KEYWORD_WITH_PROPERTY_BLOCK, ""); + r = consumeToken(b, BRANDING_KEYWORD); + if (!r) r = consumeToken(b, CONFIGURATION_KEYWORD); + if (!r) r = consumeToken(b, PROPERTIES_KEYWORD); + if (!r) r = consumeToken(b, TERMINOLOGY_KEYWORD); + if (!r) r = consumeToken(b, USERS_KEYWORD); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // CRLF | <> + static boolean lf_eof(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "lf_eof")) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, CRLF); + if (!r) r = eof(b, l + 1); + exit_section_(b, m, null, r); + return r; + } + + /* ********************************************************** */ + // keywordWithPropertyBlock '{' CRLF keyValuePair* '}' + public static boolean propertyBlockStatement(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "propertyBlockStatement")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, PROPERTY_BLOCK_STATEMENT, ""); + r = keywordWithPropertyBlock(b, l + 1); + r = r && consumeTokens(b, 0, BRACE1, CRLF); + r = r && propertyBlockStatement_3(b, l + 1); + r = r && consumeToken(b, BRACE2); + exit_section_(b, l, m, r, false, null); + return r; + } + + // keyValuePair* + private static boolean propertyBlockStatement_3(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "propertyBlockStatement_3")) return false; + while (true) { + int c = current_position_(b); + if (!keyValuePair(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "propertyBlockStatement_3", c)) break; + } + return true; + } + + /* ********************************************************** */ + // '!script' argument* '{' scriptContents '}' + public static boolean scriptBlock(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "scriptBlock")) return false; + if (!nextTokenIs(b, SCRIPT_KEYWORD)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, SCRIPT_KEYWORD); + r = r && scriptBlock_1(b, l + 1); + r = r && consumeToken(b, BRACE1); + r = r && scriptContents(b, l + 1); + r = r && consumeToken(b, BRACE2); + exit_section_(b, m, SCRIPT_BLOCK, r); + return r; + } + + // argument* + private static boolean scriptBlock_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "scriptBlock_1")) return false; + while (true) { + int c = current_position_(b); + if (!argument(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "scriptBlock_1", c)) break; + } + return true; + } + + /* ********************************************************** */ + // SCRIPT_TEXT+ + public static boolean scriptContents(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "scriptContents")) return false; + if (!nextTokenIs(b, SCRIPT_TEXT)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, SCRIPT_TEXT); + while (r) { + int c = current_position_(b); + if (!consumeToken(b, SCRIPT_TEXT)) break; + if (!empty_element_parsed_guard_(b, "scriptContents", c)) break; + } + exit_section_(b, m, SCRIPT_CONTENTS, r); + return r; + } + + /* ********************************************************** */ + // identifierAssignment? keywordWithArguments lf_eof + public static boolean singleLineStatement(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "singleLineStatement")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, SINGLE_LINE_STATEMENT, ""); + r = singleLineStatement_0(b, l + 1); + r = r && keywordWithArguments(b, l + 1); + r = r && lf_eof(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; + } + + // identifierAssignment? + private static boolean singleLineStatement_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "singleLineStatement_0")) return false; + identifierAssignment(b, l + 1); + return true; + } + + /* ********************************************************** */ + // elementDefinition | scriptBlock | explicitRelationship | implicitRelationship | identifierReferences + static boolean statement(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "statement")) return false; + boolean r; + r = elementDefinition(b, l + 1); + if (!r) r = scriptBlock(b, l + 1); + if (!r) r = explicitRelationship(b, l + 1); + if (!r) r = implicitRelationship(b, l + 1); + if (!r) r = identifierReferences(b, l + 1); + return r; + } + + /* ********************************************************** */ + // statement* static boolean structurizrDSLFile(PsiBuilder b, int l) { - return rootElement(b, l + 1); + if (!recursion_guard_(b, l, "structurizrDSLFile")) return false; + while (true) { + int c = current_position_(b); + if (!statement(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "structurizrDSLFile", c)) break; + } + return true; + } + + /* ********************************************************** */ + // QUOTED_TEXT | UNQUOTED_TEXT + static boolean text(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "text")) return false; + if (!nextTokenIs(b, "", QUOTED_TEXT, UNQUOTED_TEXT)) return false; + boolean r; + r = consumeToken(b, QUOTED_TEXT); + if (!r) r = consumeToken(b, UNQUOTED_TEXT); + return r; + } + + /* ********************************************************** */ + // text + public static boolean value(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "value")) return false; + if (!nextTokenIs(b, "", QUOTED_TEXT, UNQUOTED_TEXT)) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, VALUE, ""); + r = text(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; } } diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDArgument.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDArgument.java new file mode 100644 index 0000000..689962d --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDArgument.java @@ -0,0 +1,10 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDArgument extends PsiElement { + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDBlockStatement.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDBlockStatement.java new file mode 100644 index 0000000..0e9fb18 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDBlockStatement.java @@ -0,0 +1,40 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDBlockStatement extends PsiElement { + + @NotNull + List getArgumentList(); + + @NotNull + List getBlockStatementList(); + + @NotNull + List getExplicitRelationshipList(); + + @Nullable + SDIdentifierName getIdentifierName(); + + @NotNull + List getIdentifierReferencesList(); + + @NotNull + List getImplicitRelationshipList(); + + @NotNull + SDKeyword getKeyword(); + + @NotNull + List getPropertyBlockStatementList(); + + @NotNull + List getScriptBlockList(); + + @NotNull + List getSingleLineStatementList(); + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDExplicitRelationship.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDExplicitRelationship.java new file mode 100644 index 0000000..8e3686f --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDExplicitRelationship.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDExplicitRelationship extends PsiElement { + + @NotNull + List getArgumentList(); + + @NotNull + List getIdentifierNameList(); + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDIdentifierAssignment.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDIdentifierAssignment.java new file mode 100644 index 0000000..28e783c --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDIdentifierAssignment.java @@ -0,0 +1,22 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDIdentifierAssignment extends PsiElement { + + @Nullable + SDBlockStatement getBlockStatement(); + + @NotNull + SDIdentifierName getIdentifierName(); + + @Nullable + SDPropertyBlockStatement getPropertyBlockStatement(); + + @Nullable + SDSingleLineStatement getSingleLineStatement(); + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDIdentifierName.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDIdentifierName.java new file mode 100644 index 0000000..1a58f56 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDIdentifierName.java @@ -0,0 +1,10 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDIdentifierName extends PsiElement { + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDIdentifierReferences.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDIdentifierReferences.java new file mode 100644 index 0000000..199b07d --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDIdentifierReferences.java @@ -0,0 +1,13 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDIdentifierReferences extends PsiElement { + + @NotNull + List getIdentifierNameList(); + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDImplicitRelationship.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDImplicitRelationship.java new file mode 100644 index 0000000..0724fed --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDImplicitRelationship.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDImplicitRelationship extends PsiElement { + + @NotNull + List getArgumentList(); + + @NotNull + SDIdentifierName getIdentifierName(); + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKey.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKey.java new file mode 100644 index 0000000..3d2ff27 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKey.java @@ -0,0 +1,10 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDKey extends PsiElement { + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKeyValuePair.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKeyValuePair.java new file mode 100644 index 0000000..381a749 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKeyValuePair.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDKeyValuePair extends PsiElement { + + @NotNull + SDKey getKey(); + + @NotNull + SDValue getValue(); + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKeyword.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKeyword.java new file mode 100644 index 0000000..6529f1b --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKeyword.java @@ -0,0 +1,10 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDKeyword extends PsiElement { + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKeywordWithPropertyBlock.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKeywordWithPropertyBlock.java new file mode 100644 index 0000000..41ac6de --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDKeywordWithPropertyBlock.java @@ -0,0 +1,10 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDKeywordWithPropertyBlock extends PsiElement { + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDPropertyBlockStatement.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDPropertyBlockStatement.java new file mode 100644 index 0000000..95576b6 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDPropertyBlockStatement.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDPropertyBlockStatement extends PsiElement { + + @NotNull + List getKeyValuePairList(); + + @NotNull + SDKeywordWithPropertyBlock getKeywordWithPropertyBlock(); + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDScriptBlock.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDScriptBlock.java new file mode 100644 index 0000000..6b2590c --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDScriptBlock.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDScriptBlock extends PsiElement { + + @NotNull + List getArgumentList(); + + @NotNull + SDScriptContents getScriptContents(); + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDScriptContents.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDScriptContents.java new file mode 100644 index 0000000..3fb79c5 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDScriptContents.java @@ -0,0 +1,10 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDScriptContents extends PsiElement { + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDSingleLineStatement.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDSingleLineStatement.java new file mode 100644 index 0000000..4a85eca --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDSingleLineStatement.java @@ -0,0 +1,19 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDSingleLineStatement extends PsiElement { + + @NotNull + List getArgumentList(); + + @Nullable + SDIdentifierName getIdentifierName(); + + @NotNull + SDKeyword getKeyword(); + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDTypes.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDTypes.java index 8a3976c..ba0a91d 100644 --- a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDTypes.java +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDTypes.java @@ -8,7 +8,21 @@ public interface SDTypes { - IElementType ROOT_ELEMENT = new SDElement("ROOT_ELEMENT"); + IElementType ARGUMENT = new SDElement("ARGUMENT"); + IElementType BLOCK_STATEMENT = new SDElement("BLOCK_STATEMENT"); + IElementType EXPLICIT_RELATIONSHIP = new SDElement("EXPLICIT_RELATIONSHIP"); + IElementType IDENTIFIER_NAME = new SDElement("IDENTIFIER_NAME"); + IElementType IDENTIFIER_REFERENCES = new SDElement("IDENTIFIER_REFERENCES"); + IElementType IMPLICIT_RELATIONSHIP = new SDElement("IMPLICIT_RELATIONSHIP"); + IElementType KEY = new SDElement("KEY"); + IElementType KEYWORD = new SDElement("KEYWORD"); + IElementType KEYWORD_WITH_PROPERTY_BLOCK = new SDElement("KEYWORD_WITH_PROPERTY_BLOCK"); + IElementType KEY_VALUE_PAIR = new SDElement("KEY_VALUE_PAIR"); + IElementType PROPERTY_BLOCK_STATEMENT = new SDElement("PROPERTY_BLOCK_STATEMENT"); + IElementType SCRIPT_BLOCK = new SDElement("SCRIPT_BLOCK"); + IElementType SCRIPT_CONTENTS = new SDElement("SCRIPT_CONTENTS"); + IElementType SINGLE_LINE_STATEMENT = new SDElement("SINGLE_LINE_STATEMENT"); + IElementType VALUE = new SDElement("VALUE"); IElementType ADRS_KEYWORD = new SDToken("!adrs"); IElementType ANIMATION_KEYWORD = new SDToken("animation"); @@ -26,7 +40,7 @@ public interface SDTypes { IElementType CONSTANT_KEYWORD = new SDToken("!constant"); IElementType CONTAINER_INSTANCE = new SDToken("containerInstance"); IElementType CONTAINER_KEYWORD = new SDToken("container"); - IElementType CRLF = new SDToken("crlf"); + IElementType CRLF = new SDToken("CRLF"); IElementType CUSTOM_KEYWORD = new SDToken("custom"); IElementType DEPLOYMENT_ENVIRONMENT_KEYWORD = new SDToken("deploymentEnvironment"); IElementType DEPLOYMENT_GROUP_KEYWORD = new SDToken("deploymentGroup"); @@ -46,7 +60,7 @@ public interface SDTypes { IElementType HEALTH_CHECK_KEYWORD = new SDToken("healthCheck"); IElementType HEIGHT_KEYWORD = new SDToken("height"); IElementType ICON_KEYWORD = new SDToken("icon"); - IElementType IDENTIFIER = new SDToken("identifier"); + IElementType IDENTIFIER = new SDToken("IDENTIFIER"); IElementType IDENTIFIERS_KEYWORD = new SDToken("!identifiers"); IElementType IMPLIED_RELATIONSHIPS_KEYWORD = new SDToken("!impliedRelationships"); IElementType INCLUDE_ELEMENT_KEYWORD = new SDToken("include"); @@ -62,12 +76,12 @@ public interface SDTypes { IElementType PLUGIN_KEYWORD = new SDToken("!plugin"); IElementType POSITION_KEYWORD = new SDToken("position"); IElementType PROPERTIES_KEYWORD = new SDToken("properties"); - IElementType QUOTED_TEXT = new SDToken("quoted_text"); + IElementType QUOTED_TEXT = new SDToken("QUOTED_TEXT"); IElementType REF_KEYWORD = new SDToken("!ref"); IElementType RELATIONSHIP_KEYWORD = new SDToken("->"); IElementType ROUTING_KEYWORD = new SDToken("routing"); IElementType SCRIPT_KEYWORD = new SDToken("!script"); - IElementType SCRIPT_TEXT = new SDToken("script_text"); + IElementType SCRIPT_TEXT = new SDToken("SCRIPT_TEXT"); IElementType SHAPE_KEYWORD = new SDToken("shape"); IElementType SOFTWARE_SYSTEM_INSTANCE_KEYWORD = new SDToken("softwareSystemInstance"); IElementType SOFTWARE_SYSTEM_KEYWORD = new SDToken("softwareSystem"); @@ -83,7 +97,7 @@ public interface SDTypes { IElementType THEME_KEYWORD = new SDToken("theme"); IElementType THICKNESS_KEYWORD = new SDToken("thickness"); IElementType TITLE_KEYWORD = new SDToken("title"); - IElementType UNQUOTED_TEXT = new SDToken("unquoted_text"); + IElementType UNQUOTED_TEXT = new SDToken("UNQUOTED_TEXT"); IElementType URL_KEYWORD = new SDToken("url"); IElementType USERS_KEYWORD = new SDToken("users"); IElementType VIEWS_KEYWORD = new SDToken("views"); @@ -93,8 +107,50 @@ public interface SDTypes { class Factory { public static PsiElement createElement(ASTNode node) { IElementType type = node.getElementType(); - if (type == ROOT_ELEMENT) { - return new SDRootElementImpl(node); + if (type == ARGUMENT) { + return new SDArgumentImpl(node); + } + else if (type == BLOCK_STATEMENT) { + return new SDBlockStatementImpl(node); + } + else if (type == EXPLICIT_RELATIONSHIP) { + return new SDExplicitRelationshipImpl(node); + } + else if (type == IDENTIFIER_NAME) { + return new SDIdentifierNameImpl(node); + } + else if (type == IDENTIFIER_REFERENCES) { + return new SDIdentifierReferencesImpl(node); + } + else if (type == IMPLICIT_RELATIONSHIP) { + return new SDImplicitRelationshipImpl(node); + } + else if (type == KEY) { + return new SDKeyImpl(node); + } + else if (type == KEYWORD) { + return new SDKeywordImpl(node); + } + else if (type == KEYWORD_WITH_PROPERTY_BLOCK) { + return new SDKeywordWithPropertyBlockImpl(node); + } + else if (type == KEY_VALUE_PAIR) { + return new SDKeyValuePairImpl(node); + } + else if (type == PROPERTY_BLOCK_STATEMENT) { + return new SDPropertyBlockStatementImpl(node); + } + else if (type == SCRIPT_BLOCK) { + return new SDScriptBlockImpl(node); + } + else if (type == SCRIPT_CONTENTS) { + return new SDScriptContentsImpl(node); + } + else if (type == SINGLE_LINE_STATEMENT) { + return new SDSingleLineStatementImpl(node); + } + else if (type == VALUE) { + return new SDValueImpl(node); } throw new AssertionError("Unknown element type: " + type); } diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDValue.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDValue.java new file mode 100644 index 0000000..87d6d5b --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDValue.java @@ -0,0 +1,10 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface SDValue extends PsiElement { + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDVisitor.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDVisitor.java index a3556e9..f86882f 100644 --- a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDVisitor.java +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/SDVisitor.java @@ -7,7 +7,63 @@ public class SDVisitor extends PsiElementVisitor { - public void visitRootElement(@NotNull SDRootElement o) { + public void visitArgument(@NotNull SDArgument o) { + visitPsiElement(o); + } + + public void visitBlockStatement(@NotNull SDBlockStatement o) { + visitPsiElement(o); + } + + public void visitExplicitRelationship(@NotNull SDExplicitRelationship o) { + visitPsiElement(o); + } + + public void visitIdentifierName(@NotNull SDIdentifierName o) { + visitPsiElement(o); + } + + public void visitIdentifierReferences(@NotNull SDIdentifierReferences o) { + visitPsiElement(o); + } + + public void visitImplicitRelationship(@NotNull SDImplicitRelationship o) { + visitPsiElement(o); + } + + public void visitKey(@NotNull SDKey o) { + visitPsiElement(o); + } + + public void visitKeyValuePair(@NotNull SDKeyValuePair o) { + visitPsiElement(o); + } + + public void visitKeyword(@NotNull SDKeyword o) { + visitPsiElement(o); + } + + public void visitKeywordWithPropertyBlock(@NotNull SDKeywordWithPropertyBlock o) { + visitPsiElement(o); + } + + public void visitPropertyBlockStatement(@NotNull SDPropertyBlockStatement o) { + visitPsiElement(o); + } + + public void visitScriptBlock(@NotNull SDScriptBlock o) { + visitPsiElement(o); + } + + public void visitScriptContents(@NotNull SDScriptContents o) { + visitPsiElement(o); + } + + public void visitSingleLineStatement(@NotNull SDSingleLineStatement o) { + visitPsiElement(o); + } + + public void visitValue(@NotNull SDValue o) { visitPsiElement(o); } diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDRootElementImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDArgumentImpl.java similarity index 80% rename from src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDRootElementImpl.java rename to src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDArgumentImpl.java index 8dafba4..5cd6138 100644 --- a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDRootElementImpl.java +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDArgumentImpl.java @@ -11,14 +11,14 @@ import com.intellij.extapi.psi.ASTWrapperPsiElement; import nl.dirkgroot.structurizr.dsl.psi.*; -public class SDRootElementImpl extends ASTWrapperPsiElement implements SDRootElement { +public class SDArgumentImpl extends ASTWrapperPsiElement implements SDArgument { - public SDRootElementImpl(@NotNull ASTNode node) { + public SDArgumentImpl(@NotNull ASTNode node) { super(node); } public void accept(@NotNull SDVisitor visitor) { - visitor.visitRootElement(this); + visitor.visitArgument(this); } @Override diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDBlockStatementImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDBlockStatementImpl.java new file mode 100644 index 0000000..985ce61 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDBlockStatementImpl.java @@ -0,0 +1,90 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDBlockStatementImpl extends ASTWrapperPsiElement implements SDBlockStatement { + + public SDBlockStatementImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitBlockStatement(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getArgumentList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDArgument.class); + } + + @Override + @NotNull + public List getBlockStatementList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDBlockStatement.class); + } + + @Override + @NotNull + public List getExplicitRelationshipList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDExplicitRelationship.class); + } + + @Override + @Nullable + public SDIdentifierName getIdentifierName() { + return findChildByClass(SDIdentifierName.class); + } + + @Override + @NotNull + public List getIdentifierReferencesList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDIdentifierReferences.class); + } + + @Override + @NotNull + public List getImplicitRelationshipList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDImplicitRelationship.class); + } + + @Override + @NotNull + public SDKeyword getKeyword() { + return findNotNullChildByClass(SDKeyword.class); + } + + @Override + @NotNull + public List getPropertyBlockStatementList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDPropertyBlockStatement.class); + } + + @Override + @NotNull + public List getScriptBlockList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDScriptBlock.class); + } + + @Override + @NotNull + public List getSingleLineStatementList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDSingleLineStatement.class); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDExplicitRelationshipImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDExplicitRelationshipImpl.java new file mode 100644 index 0000000..142fc54 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDExplicitRelationshipImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDExplicitRelationshipImpl extends ASTWrapperPsiElement implements SDExplicitRelationship { + + public SDExplicitRelationshipImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitExplicitRelationship(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getArgumentList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDArgument.class); + } + + @Override + @NotNull + public List getIdentifierNameList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDIdentifierName.class); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDIdentifierNameImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDIdentifierNameImpl.java new file mode 100644 index 0000000..6063834 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDIdentifierNameImpl.java @@ -0,0 +1,30 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDIdentifierNameImpl extends ASTWrapperPsiElement implements SDIdentifierName { + + public SDIdentifierNameImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitIdentifierName(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDIdentifierReferencesImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDIdentifierReferencesImpl.java new file mode 100644 index 0000000..0e24d5f --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDIdentifierReferencesImpl.java @@ -0,0 +1,36 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDIdentifierReferencesImpl extends ASTWrapperPsiElement implements SDIdentifierReferences { + + public SDIdentifierReferencesImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitIdentifierReferences(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getIdentifierNameList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDIdentifierName.class); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDImplicitRelationshipImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDImplicitRelationshipImpl.java new file mode 100644 index 0000000..077cd41 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDImplicitRelationshipImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDImplicitRelationshipImpl extends ASTWrapperPsiElement implements SDImplicitRelationship { + + public SDImplicitRelationshipImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitImplicitRelationship(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getArgumentList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDArgument.class); + } + + @Override + @NotNull + public SDIdentifierName getIdentifierName() { + return findNotNullChildByClass(SDIdentifierName.class); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeyImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeyImpl.java new file mode 100644 index 0000000..10f6c99 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeyImpl.java @@ -0,0 +1,30 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDKeyImpl extends ASTWrapperPsiElement implements SDKey { + + public SDKeyImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitKey(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeyValuePairImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeyValuePairImpl.java new file mode 100644 index 0000000..f835594 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeyValuePairImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDKeyValuePairImpl extends ASTWrapperPsiElement implements SDKeyValuePair { + + public SDKeyValuePairImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitKeyValuePair(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public SDKey getKey() { + return findNotNullChildByClass(SDKey.class); + } + + @Override + @NotNull + public SDValue getValue() { + return findNotNullChildByClass(SDValue.class); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeywordImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeywordImpl.java new file mode 100644 index 0000000..2491b05 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeywordImpl.java @@ -0,0 +1,30 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDKeywordImpl extends ASTWrapperPsiElement implements SDKeyword { + + public SDKeywordImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitKeyword(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeywordWithPropertyBlockImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeywordWithPropertyBlockImpl.java new file mode 100644 index 0000000..45476da --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDKeywordWithPropertyBlockImpl.java @@ -0,0 +1,30 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDKeywordWithPropertyBlockImpl extends ASTWrapperPsiElement implements SDKeywordWithPropertyBlock { + + public SDKeywordWithPropertyBlockImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitKeywordWithPropertyBlock(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDPropertyBlockStatementImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDPropertyBlockStatementImpl.java new file mode 100644 index 0000000..66644e3 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDPropertyBlockStatementImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDPropertyBlockStatementImpl extends ASTWrapperPsiElement implements SDPropertyBlockStatement { + + public SDPropertyBlockStatementImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitPropertyBlockStatement(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getKeyValuePairList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDKeyValuePair.class); + } + + @Override + @NotNull + public SDKeywordWithPropertyBlock getKeywordWithPropertyBlock() { + return findNotNullChildByClass(SDKeywordWithPropertyBlock.class); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDScriptBlockImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDScriptBlockImpl.java new file mode 100644 index 0000000..8cd28a3 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDScriptBlockImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDScriptBlockImpl extends ASTWrapperPsiElement implements SDScriptBlock { + + public SDScriptBlockImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitScriptBlock(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getArgumentList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDArgument.class); + } + + @Override + @NotNull + public SDScriptContents getScriptContents() { + return findNotNullChildByClass(SDScriptContents.class); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDScriptContentsImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDScriptContentsImpl.java new file mode 100644 index 0000000..ea4db26 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDScriptContentsImpl.java @@ -0,0 +1,30 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDScriptContentsImpl extends ASTWrapperPsiElement implements SDScriptContents { + + public SDScriptContentsImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitScriptContents(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDSingleLineStatementImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDSingleLineStatementImpl.java new file mode 100644 index 0000000..1c7e233 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDSingleLineStatementImpl.java @@ -0,0 +1,48 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDSingleLineStatementImpl extends ASTWrapperPsiElement implements SDSingleLineStatement { + + public SDSingleLineStatementImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitSingleLineStatement(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getArgumentList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, SDArgument.class); + } + + @Override + @Nullable + public SDIdentifierName getIdentifierName() { + return findChildByClass(SDIdentifierName.class); + } + + @Override + @NotNull + public SDKeyword getKeyword() { + return findNotNullChildByClass(SDKeyword.class); + } + +} diff --git a/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDValueImpl.java b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDValueImpl.java new file mode 100644 index 0000000..de39d40 --- /dev/null +++ b/src/main/gen/nl/dirkgroot/structurizr/dsl/psi/impl/SDValueImpl.java @@ -0,0 +1,30 @@ +// This is a generated file. Not intended for manual editing. +package nl.dirkgroot.structurizr.dsl.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static nl.dirkgroot.structurizr.dsl.psi.SDTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import nl.dirkgroot.structurizr.dsl.psi.*; + +public class SDValueImpl extends ASTWrapperPsiElement implements SDValue { + + public SDValueImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull SDVisitor visitor) { + visitor.visitValue(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof SDVisitor) accept((SDVisitor)visitor); + else super.accept(visitor); + } + +} diff --git a/src/main/grammar/StructurizrDSL.bnf b/src/main/grammar/StructurizrDSL.bnf index c94a0ad..92e483a 100644 --- a/src/main/grammar/StructurizrDSL.bnf +++ b/src/main/grammar/StructurizrDSL.bnf @@ -92,8 +92,8 @@ width_keyword='width' workspace_keyword='workspace' - quoted_text='regexp:\"[^\"\r\n]*\"' - unquoted_text='regexp:[^\s\"\r\n]+' + quoted_text='regexp:"[^"\r\n]*"' + unquoted_text='regexp:[^\s"\r\n]+' identifier='regexp:[a-zA-Z_0-9]+' @@ -101,6 +101,46 @@ ] } -structurizrDSLFile ::= rootElement +structurizrDSLFile ::= statement* -rootElement ::= !<> +private statement ::= elementDefinition | scriptBlock | explicitRelationship | implicitRelationship | identifierReferences + +private elementDefinition ::= singleLineStatement | blockStatement | propertyBlockStatement | CRLF + +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 +value ::= text + +scriptBlock ::= '!script' argument* '{' scriptContents '}' +scriptContents ::= SCRIPT_TEXT+ + +explicitRelationship ::= identifierName '->' identifierName argument* +implicitRelationship ::= '->' identifierName argument* + +identifierReferences ::= identifierName+ lf_eof + +private keywordWithArguments ::= keyword argument* + +keyword ::= '!adrs' | 'animation' | 'autoLayout' | 'background' | 'border' | 'color' | 'colour' | 'component' | + '!constant' | 'containerInstance' | 'container' | 'custom' | 'deploymentEnvironment' | 'deploymentGroup' | + 'deployment' | 'deploymentNode' | 'description' | '!docs' | 'dynamic' | 'element' | 'enterprise' | + 'exclude' | 'extends' | 'filtered' | 'fontSize' | 'group' | 'healthCheck' | 'height' | 'icon' | + '!identifiers' | '!impliedRelationships' | 'include' | '!include' | 'infrastructureNode' | 'instances' | + 'metadata' | 'model' | 'opacity' | 'person' | 'perspectives' | '!plugin' | 'position' | '!ref' | '->' | + 'routing' | '!script' | 'shape' | 'softwareSystemInstance' | 'softwareSystem' | 'stroke' | 'strokeWidth' | + 'style' | 'styles' | 'systemContext' | 'systemLandscape' | 'tags' | 'technology' | 'theme' | 'thickness' | + 'title' | 'url' | 'views' | 'width' | 'workspace' + +keywordWithPropertyBlock ::= 'branding' | 'configuration' | 'properties' | 'terminology' | 'users' + +argument ::= text +identifierName ::= IDENTIFIER + +private text ::= QUOTED_TEXT | UNQUOTED_TEXT +private lf_eof ::= CRLF | <> diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 975e279..32b311f 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -13,6 +13,8 @@ extensions="dsl"/> + diff --git a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/ElementsWithBlocksOfElementsTest.kt b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/ElementsWithBlocksOfElementsTest.kt new file mode 100644 index 0000000..4dcacef --- /dev/null +++ b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/ElementsWithBlocksOfElementsTest.kt @@ -0,0 +1,120 @@ +package nl.dirkgroot.structurizr.dsl.parser + +import nl.dirkgroot.structurizr.dsl.lexer.KEYWORDS_WITH_BLOCKS +import nl.dirkgroot.structurizr.dsl.support.StructurizrDSLParserTest +import org.junit.jupiter.api.DynamicTest.dynamicTest +import org.junit.jupiter.api.TestFactory + +class ElementsWithBlocksOfElementsTest : StructurizrDSLParserTest() { + @TestFactory + fun `empty block`() = KEYWORDS_WITH_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """ + $keyword { + } + """.trimIndent(), + """ + BlockStatement + Keyword $keyword + """.trimIndent() + ) + } + } + + @TestFactory + fun `block with only empty lines inside`() = KEYWORDS_WITH_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """ + $keyword { + + + } + """.trimIndent(), + """ + BlockStatement + Keyword $keyword + """.trimIndent() + ) + } + } + + @TestFactory + fun `block with single line element inside`() = KEYWORDS_WITH_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + val (elementKeyword, _) = KEYWORDS_WITH_BLOCKS.random() + assertPsiTree( + """ + $keyword { + $elementKeyword arg1 + } + """.trimIndent(), + """ + BlockStatement + Keyword $keyword + SingleLineStatement + Keyword $elementKeyword + Argument arg1 + """.trimIndent() + ) + } + } + + @TestFactory + fun `block with multiple single line elements inside`() = KEYWORDS_WITH_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + val (elementKeyword, _) = KEYWORDS_WITH_BLOCKS.random() + assertPsiTree( + """ + $keyword { + $elementKeyword arg1 + $elementKeyword arg2 + + $elementKeyword arg3 + } + """.trimIndent(), + """ + BlockStatement + Keyword $keyword + SingleLineStatement + Keyword $elementKeyword + Argument arg1 + SingleLineStatement + Keyword $elementKeyword + Argument arg2 + SingleLineStatement + Keyword $elementKeyword + Argument arg3 + """.trimIndent() + ) + } + } + + @TestFactory + fun `nested blocks`() = KEYWORDS_WITH_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + val (elementKeyword, _) = KEYWORDS_WITH_BLOCKS.random() + assertPsiTree( + """ + $keyword { + $elementKeyword arg1 { + } + $elementKeyword arg2 { + } + } + """.trimIndent(), + """ + BlockStatement + Keyword $keyword + BlockStatement + Keyword $elementKeyword + Argument arg1 + BlockStatement + Keyword $elementKeyword + Argument arg2 + """.trimIndent() + ) + } + } +} diff --git a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/ElementsWithPropertyBlocksTest.kt b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/ElementsWithPropertyBlocksTest.kt new file mode 100644 index 0000000..5c92cac --- /dev/null +++ b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/ElementsWithPropertyBlocksTest.kt @@ -0,0 +1,95 @@ +package nl.dirkgroot.structurizr.dsl.parser + +import nl.dirkgroot.structurizr.dsl.lexer.KEYWORDS_WITH_PROPERTY_BLOCKS +import nl.dirkgroot.structurizr.dsl.support.StructurizrDSLParserTest +import org.junit.jupiter.api.DynamicTest.dynamicTest +import org.junit.jupiter.api.TestFactory + +class ElementsWithPropertyBlocksTest : StructurizrDSLParserTest() { + @TestFactory + fun `empty block`() = KEYWORDS_WITH_PROPERTY_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """ + $keyword { + } + """.trimIndent(), + """ + PropertyBlockStatement + KeywordWithPropertyBlock $keyword + """.trimIndent() + ) + } + } + + @TestFactory + fun `block with only empty lines inside`() = KEYWORDS_WITH_PROPERTY_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """ + $keyword { + + + + } + """.trimIndent(), + """ + PropertyBlockStatement + KeywordWithPropertyBlock $keyword + """.trimIndent() + ) + } + } + + @TestFactory + fun `block with single property inside`() = KEYWORDS_WITH_PROPERTY_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """ + $keyword { + key value + } + """.trimIndent(), + """ + PropertyBlockStatement + KeywordWithPropertyBlock $keyword + KeyValuePair + Key key + Value value + """.trimIndent() + ) + } + } + + @TestFactory + fun `block with multiple properties inside`() = KEYWORDS_WITH_PROPERTY_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """ + $keyword { + key1 value1 + key2 "value 2" + "key 3" value3 + "key 4" "value 4" + } + """.trimIndent(), + """ + PropertyBlockStatement + KeywordWithPropertyBlock $keyword + KeyValuePair + Key key1 + Value value1 + KeyValuePair + Key key2 + Value "value 2" + KeyValuePair + Key "key 3" + Value value3 + KeyValuePair + Key "key 4" + Value "value 4" + """.trimIndent() + ) + } + } +} diff --git a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/IdentifierAssignmentTest.kt b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/IdentifierAssignmentTest.kt new file mode 100644 index 0000000..71fe186 --- /dev/null +++ b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/IdentifierAssignmentTest.kt @@ -0,0 +1,66 @@ +package nl.dirkgroot.structurizr.dsl.parser + +import nl.dirkgroot.structurizr.dsl.lexer.KEYWORDS +import nl.dirkgroot.structurizr.dsl.support.StructurizrDSLParserTest +import org.junit.jupiter.api.DynamicTest.dynamicTest +import org.junit.jupiter.api.TestFactory + +class IdentifierAssignmentTest : StructurizrDSLParserTest() { + @TestFactory + fun `identifier assignment to single line element`() = KEYWORDS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """identifier = softwareSystem blaat""", + """ + SingleLineStatement + IdentifierName identifier + Keyword softwareSystem + Argument blaat + """.trimIndent() + ) + } + } + + @TestFactory + fun `identifier assignment to block element`() = KEYWORDS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """ + identifier = softwareSystem blaat { + container containerName + } + """.trimIndent(), + """ + BlockStatement + IdentifierName identifier + Keyword softwareSystem + Argument blaat + SingleLineStatement + Keyword container + Argument containerName + """.trimIndent() + ) + } + } + + @TestFactory + fun `identifier assignment inside block`() = KEYWORDS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """ + model { + identifier = softwareSystem name + } + """.trimIndent(), + """ + BlockStatement + Keyword model + SingleLineStatement + IdentifierName identifier + Keyword softwareSystem + Argument name + """.trimIndent() + ) + } + } +} diff --git a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/LineWithIdentifierReferencesTest.kt b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/LineWithIdentifierReferencesTest.kt new file mode 100644 index 0000000..a51c397 --- /dev/null +++ b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/LineWithIdentifierReferencesTest.kt @@ -0,0 +1,53 @@ +package nl.dirkgroot.structurizr.dsl.parser + +import nl.dirkgroot.structurizr.dsl.support.StructurizrDSLParserTest +import org.junit.jupiter.api.Test + +class LineWithIdentifierReferencesTest : StructurizrDSLParserTest() { + @Test + fun `single identifier reference on one line`() { + assertPsiTree( + """ + someIdentifier + """.trimIndent(), + """ + IdentifierReferences + IdentifierName someIdentifier + """.trimIndent() + ) + } + + @Test + fun `multiple identifier references on one line`() { + assertPsiTree( + """ + someIdentifier1 someIdentifier2 + """.trimIndent(), + """ + IdentifierReferences + IdentifierName someIdentifier1 + IdentifierName someIdentifier2 + """.trimIndent() + ) + } + + @Test + fun `multiple lines with identifier references`() { + assertPsiTree( + """ + someIdentifier1 someIdentifier2 + someIdentifier3 + someIdentifier4 + """.trimIndent(), + """ + IdentifierReferences + IdentifierName someIdentifier1 + IdentifierName someIdentifier2 + IdentifierReferences + IdentifierName someIdentifier3 + IdentifierReferences + IdentifierName someIdentifier4 + """.trimIndent() + ) + } +} diff --git a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/NonCodeElementsTest.kt b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/NonCodeElementsTest.kt new file mode 100644 index 0000000..efc1c2e --- /dev/null +++ b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/NonCodeElementsTest.kt @@ -0,0 +1,72 @@ +package nl.dirkgroot.structurizr.dsl.parser + +import nl.dirkgroot.structurizr.dsl.support.StructurizrDSLParserTest +import org.junit.jupiter.api.Test + +class NonCodeElementsTest : StructurizrDSLParserTest() { + @Test + fun `empty line`() { + assertPsiTree("\n", """PsiWhiteSpace \n""") + } + + @Test + fun `empty lines`() { + assertPsiTree( + "\n\n", + """ + PsiWhiteSpace \n + PsiWhiteSpace \n + """.trimIndent() + ) + } + + @Test + fun `line comment`() { + assertPsiTree("// comment", "PsiComment // comment") + } + + @Test + fun `line comments`() { + assertPsiTree( + """ + // comment + // another comment + """.trimIndent(), + """ + PsiComment // comment + LeafPsiElement \n + PsiComment // another comment + """.trimIndent() + ) + } + + @Test + fun `line comment with trailing newline`() { + assertPsiTree( + "// comment\n", + """ + PsiComment // comment + LeafPsiElement \n + """.trimIndent() + ) + } + + @Test + fun `block comment single line`() { + assertPsiTree( + "/* block comment */", + "PsiComment /* block comment */" + ) + } + + @Test + fun `block comment multiple lines`() { + assertPsiTree( + """ + /* block + comment */ + """.trimIndent(), + """PsiComment /* block\n comment */""" + ) + } +} diff --git a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/RelationshipTest.kt b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/RelationshipTest.kt new file mode 100644 index 0000000..56e9ca0 --- /dev/null +++ b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/RelationshipTest.kt @@ -0,0 +1,56 @@ +package nl.dirkgroot.structurizr.dsl.parser + +import nl.dirkgroot.structurizr.dsl.support.StructurizrDSLParserTest +import org.junit.jupiter.api.Test + +class RelationshipTest : StructurizrDSLParserTest() { + @Test + fun `explicit without arguments`() { + assertPsiTree( + """a -> b""", + """ + ExplicitRelationship + IdentifierName a + IdentifierName b + """.trimIndent() + ) + } + + @Test + fun `implicit without arguments`() { + assertPsiTree( + """-> b""", + """ + ImplicitRelationship + IdentifierName b + """.trimIndent() + ) + } + + @Test + fun `explicit with arguments`() { + assertPsiTree( + """a -> b arg1 arg2""", + """ + ExplicitRelationship + IdentifierName a + IdentifierName b + Argument arg1 + Argument arg2 + """.trimIndent() + ) + } + + @Test + fun `implicit with arguments`() { + assertPsiTree( + """-> b arg1 arg2""", + """ + ImplicitRelationship + IdentifierName b + Argument arg1 + Argument arg2 + """.trimIndent() + ) + } +} diff --git a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/ScriptBlockTest.kt b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/ScriptBlockTest.kt new file mode 100644 index 0000000..dbe202a --- /dev/null +++ b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/ScriptBlockTest.kt @@ -0,0 +1,53 @@ +package nl.dirkgroot.structurizr.dsl.parser + +import nl.dirkgroot.structurizr.dsl.support.StructurizrDSLParserTest +import org.junit.jupiter.api.Test + +class ScriptBlockTest : StructurizrDSLParserTest() { + @Test + fun `empty script block`() { + assertPsiTree( + """ + !script { + } + """.trimIndent(), + """ + ScriptBlock + ScriptContents \n + """.trimIndent() + ) + } + + @Test + fun `empty script block with arguments`() { + assertPsiTree( + """ + !script kotlin arg2 { + } + """.trimIndent(), + """ + ScriptBlock + Argument kotlin + Argument arg2 + ScriptContents \n + """.trimIndent() + ) + } + + @Test + fun `script block with content`() { + assertPsiTree( + """ + !script kotlin { + println("Hello World...") + println("...from a script block") + } + """.trimIndent(), + """ + ScriptBlock + Argument kotlin + ScriptContents \n println("Hello World...")\n println("...from a script block")\n + """.trimIndent() + ) + } +} diff --git a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/SingleLineElementsTest.kt b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/SingleLineElementsTest.kt new file mode 100644 index 0000000..77ec34c --- /dev/null +++ b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/parser/SingleLineElementsTest.kt @@ -0,0 +1,70 @@ +package nl.dirkgroot.structurizr.dsl.parser + +import nl.dirkgroot.structurizr.dsl.lexer.KEYWORDS_WITH_BLOCKS +import nl.dirkgroot.structurizr.dsl.support.StructurizrDSLParserTest +import org.junit.jupiter.api.DynamicTest.dynamicTest +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestFactory + +class SingleLineElementsTest : StructurizrDSLParserTest() { + @TestFactory + fun `without argument`() = KEYWORDS_WITH_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + keyword, + """ + SingleLineStatement + Keyword $keyword + """.trimIndent() + ) + } + } + + @TestFactory + fun `with one argument`() = KEYWORDS_WITH_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + "$keyword arg1", + """ + SingleLineStatement + Keyword $keyword + Argument arg1 + """.trimIndent() + ) + } + } + + @TestFactory + fun `with many arguments`() = KEYWORDS_WITH_BLOCKS.map { (keyword, _) -> + dynamicTest(keyword) { + assertPsiTree( + """$keyword arg1 "arg 2" arg3""", + """ + SingleLineStatement + Keyword $keyword + Argument arg1 + Argument "arg 2" + Argument arg3 + """.trimIndent() + ) + } + } + + @Test + fun `multiple single line elements`() { + assertPsiTree( + """ + !adrs docs/adrs + !adrs other/stuff + """.trimIndent(), + """ + SingleLineStatement + Keyword !adrs + Argument docs/adrs + SingleLineStatement + Keyword !adrs + Argument other/stuff + """.trimIndent() + ) + } +} diff --git a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/support/StructurizrDSLParserTest.kt b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/support/StructurizrDSLParserTest.kt index e37272a..54817b0 100644 --- a/src/test/kotlin/nl/dirkgroot/structurizr/dsl/support/StructurizrDSLParserTest.kt +++ b/src/test/kotlin/nl/dirkgroot/structurizr/dsl/support/StructurizrDSLParserTest.kt @@ -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() - ).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() - ).isNotEmpty() - } }