From 981cf61ca77f969328ab4e0d32c17e7906e6789b Mon Sep 17 00:00:00 2001 From: cvette Date: Mon, 4 Sep 2017 21:03:02 +0200 Subject: [PATCH] TASK: Implement basic Fusion DSL support --- src/main/grammars/FusionLexer.flex | 21 +++++++++++++++++-- src/main/grammars/FusionParser.bnf | 8 ++++++- .../FusionHighlightingColors.java | 2 ++ .../highlighting/FusionSyntaxHighlighter.java | 1 + .../fusion/pages/FusionColorSettingsPage.java | 15 ++++++++++--- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/main/grammars/FusionLexer.flex b/src/main/grammars/FusionLexer.flex index 9c683eb4..09910744 100644 --- a/src/main/grammars/FusionLexer.flex +++ b/src/main/grammars/FusionLexer.flex @@ -54,6 +54,10 @@ VALUE_STRING_DOUBLE_QUOTE = [\"] ESCAPED_DOUBLE_QUOTE = "\\\\"* "\\\"" VALUE_STRING_IN_DOUBLE_QUOTE = [^\n\r\"\\]* +BACKTICK = "`" +ESCAPED_BACKTICK = "\\\\"* "\\\`" +VALUE_STRING_IN_BACKTICKS = [^\n\r\`\\]* + LEFT_BRACE = "{" RIGHT_BRACE = "}" LEFT_BRACKET = "[" @@ -103,9 +107,9 @@ IF_SEPARATOR = {COLON} // Value states %states VALUE_EXPECTED, -%states VALUE_STRING_EXPECTED_IN_SINGLE_QUOTE, VALUE_STRING_EXPECTED_IN_DOUBLE_QUOTE +%states VALUE_STRING_EXPECTED_IN_SINGLE_QUOTE, VALUE_STRING_EXPECTED_IN_DOUBLE_QUOTE, VALUE_STRING_EXPECTED_IN_BACKTICKS %states VALUE_STRING_EXPECTED_IN_SINGLE_QUOTE_PATH, VALUE_STRING_EXPECTED_IN_DOUBLE_QUOTE_PATH -%states OBJECT_TYPE_FOUND +%states OBJECT_TYPE_FOUND, DSL_IDENTIFIER_FOUND // Expression states %states EXPRESSION_FOUND @@ -167,6 +171,7 @@ IF_SEPARATOR = {COLON} {EXPRESSION_KEYWORD}/{LEFT_BRACE} { yybegin(EXPRESSION_FOUND); return FusionTypes.EXPRESSION_KEYWORD; } {OBJECT_TYPE_PART} { yybegin(CRLF_OR_LEFT_BRACE_EXPECTED); return FusionTypes.UNQUALIFIED_TYPE; } {OBJECT_TYPE_PART}/{COLON} { yybegin(OBJECT_TYPE_FOUND); return FusionTypes.OBJECT_TYPE_NAMESPACE; } + {OBJECT_TYPE_PART}/{BACKTICK} { yybegin(DSL_IDENTIFIER_FOUND); return FusionTypes.DSL_IDENTIFIER; } } { @@ -174,6 +179,10 @@ IF_SEPARATOR = {COLON} {OBJECT_TYPE_PART} { yybegin(CRLF_OR_LEFT_BRACE_EXPECTED); return FusionTypes.UNQUALIFIED_TYPE; } } + { + {BACKTICK} { yybegin(VALUE_STRING_EXPECTED_IN_BACKTICKS); return FusionTypes.BACKTICK; } +} + { {LEFT_BRACE} { yybegin(CRLF_OR_BLOCK_EXPECTED); return FusionTypes.LEFT_BRACE; } {CRLF} { yybegin(YYINITIAL); return FusionTypes.CRLF; } @@ -296,6 +305,14 @@ IF_SEPARATOR = {COLON} {VALUE_STRING_IN_DOUBLE_QUOTE} { return FusionTypes.VALUE_STRING; } } + { + {CRLF} { return FusionTypes.CRLF; } + {ESCAPED_BACKTICK}* { return FusionTypes.ESCAPED_BACKTICK; } + {BACKSLASH}* { return FusionTypes.VALUE_STRING; } + {VALUE_STRING_IN_BACKTICKS} { return FusionTypes.VALUE_STRING; } + {BACKTICK} { yybegin(CRLF_EXPECTED); return FusionTypes.BACKTICK; } +} + { {LEFT_BRACE} { eelNestingLevel++; if (eelNestingLevel == 1) { return FusionTypes.EEL_LEFT_BRACE; } else { return FusionTypes.EEL_OBJECT_LEFT_BRACE; } } {RIGHT_BRACE} { eelNestingLevel--; if (eelNestingLevel == 0) { yybegin(CRLF_EXPECTED); return FusionTypes.EEL_RIGHT_BRACE; } else { return FusionTypes.EEL_OBJECT_RIGHT_BRACE; }} diff --git a/src/main/grammars/FusionParser.bnf b/src/main/grammars/FusionParser.bnf index cb3447c1..34714617 100644 --- a/src/main/grammars/FusionParser.bnf +++ b/src/main/grammars/FusionParser.bnf @@ -43,7 +43,7 @@ resource ::= RESOURCE_KEYWORD RESOURCE_PATH {pin=1} private property ::= path (property_block|property_deletion|property_copy|property_assignment) left property_block ::= block left property_deletion ::= UNSET_OPERATOR -left property_assignment ::= ASSIGNMENT_OPERATOR (VALUE_BOOLEAN|VALUE_NULL|VALUE_NUMBER|value_string_line|expression|prototype_instance) {pin=1} +left property_assignment ::= ASSIGNMENT_OPERATOR (VALUE_BOOLEAN|VALUE_NULL|VALUE_NUMBER|value_dsl|value_string_line|expression|prototype_instance) {pin=1} left property_copy ::= COPY_OPERATOR (VALUE_BOOLEAN|VALUE_NULL|VALUE_NUMBER|value_string_line|prototype_instance|(prototype_signature [block])) { pin=1 implements = [ "de.vette.idea.neos.lang.fusion.psi.FusionCompositeElement"; "de.vette.idea.neos.lang.fusion.psi.ext.FusionPropertyCopyMixin"] @@ -72,6 +72,12 @@ prototype_signature ::= PROTOTYPE_KEYWORD LEFT_PAREN type RIGHT_PAREN { elementTypeFactory = "de.vette.idea.neos.lang.fusion.stubs.StubElementTypeFactory.factory" } +value_dsl ::= DSL_IDENTIFIER BACKTICK value_dsl_content BACKTICK { + pin=1 +} + +value_dsl_content ::= (VALUE_STRING | CRLF | ESCAPED_BACKTICK)* + value_string_line ::= VALUE_STRING_QUOTE value_string_line_content VALUE_STRING_QUOTE { pin=1 implements = [ "de.vette.idea.neos.lang.fusion.psi.FusionReferenceElement" ] diff --git a/src/main/java/de/vette/idea/neos/lang/fusion/highlighting/FusionHighlightingColors.java b/src/main/java/de/vette/idea/neos/lang/fusion/highlighting/FusionHighlightingColors.java index 70b0b61b..b8424b5b 100644 --- a/src/main/java/de/vette/idea/neos/lang/fusion/highlighting/FusionHighlightingColors.java +++ b/src/main/java/de/vette/idea/neos/lang/fusion/highlighting/FusionHighlightingColors.java @@ -66,4 +66,6 @@ public class FusionHighlightingColors { createTextAttributesKey("FUSION_EEL_OPERATOR", DefaultLanguageHighlighterColors.BRACES); public static final TextAttributesKey PARENTHESES = createTextAttributesKey("FUSION_PARENTHESES", DefaultLanguageHighlighterColors.PARENTHESES); + public static final TextAttributesKey DSL_IDENTIFIER = + createTextAttributesKey("FUSION_DSL_IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER); } diff --git a/src/main/java/de/vette/idea/neos/lang/fusion/highlighting/FusionSyntaxHighlighter.java b/src/main/java/de/vette/idea/neos/lang/fusion/highlighting/FusionSyntaxHighlighter.java index e6ec4930..29b5de61 100644 --- a/src/main/java/de/vette/idea/neos/lang/fusion/highlighting/FusionSyntaxHighlighter.java +++ b/src/main/java/de/vette/idea/neos/lang/fusion/highlighting/FusionSyntaxHighlighter.java @@ -80,6 +80,7 @@ public class FusionSyntaxHighlighter extends SyntaxHighlighterBase { ourMap1.put(FusionTypes.UNQUALIFIED_TYPE, FusionHighlightingColors.OBJECT_TYPE); ourMap1.put(FusionTypes.NAMESPACE_ALIAS, FusionHighlightingColors.OBJECT_TYPE); ourMap1.put(FusionTypes.PACKAGE_KEY, FusionHighlightingColors.OBJECT_TYPE); + ourMap1.put(FusionTypes.DSL_IDENTIFIER, FusionHighlightingColors.DSL_IDENTIFIER); ourMap1.put(FusionTypes.LEFT_BRACE, FusionHighlightingColors.BRACES); ourMap1.put(FusionTypes.RIGHT_BRACE, FusionHighlightingColors.BRACES); diff --git a/src/main/java/de/vette/idea/neos/lang/fusion/pages/FusionColorSettingsPage.java b/src/main/java/de/vette/idea/neos/lang/fusion/pages/FusionColorSettingsPage.java index 89934de7..f6853f97 100644 --- a/src/main/java/de/vette/idea/neos/lang/fusion/pages/FusionColorSettingsPage.java +++ b/src/main/java/de/vette/idea/neos/lang/fusion/pages/FusionColorSettingsPage.java @@ -57,7 +57,8 @@ public class FusionColorSettingsPage implements ColorSettingsPage, DisplayPriori new AttributesDescriptor("EEL Wrapper", FusionHighlightingColors.EEL_WRAPPER), new AttributesDescriptor("EEL Identifier", FusionHighlightingColors.EEL_IDENTIFIER), new AttributesDescriptor("EEL Function", FusionHighlightingColors.EEL_FUNCTION), - new AttributesDescriptor("EEL Operator", FusionHighlightingColors.EEL_OPERATOR) + new AttributesDescriptor("EEL Operator", FusionHighlightingColors.EEL_OPERATOR), + new AttributesDescriptor("DSL Identifier", FusionHighlightingColors.DSL_IDENTIFIER) }; @Nullable @@ -77,16 +78,24 @@ public SyntaxHighlighter getHighlighter() { @Override public String getDemoText() { return "include: NodeTypes/**/*\n" + - "namespace: ts=TYPO3.TypoScript\n" + + "namespace: neos=Neos.Fusion\n" + "\n" + "/**\n" + " * Change default page\n" + " **/\n" + "prototype(Neos.NodeTypes:Page.Document) < prototype(My.Package:DefaultPage) {\n" + " body {\n" + - " content = ts:Template {\n" + + " content = neos:Template {\n" + " templatePath = 'resource://My.Package/Private/Templates/TypoScript/PageContent.html'\n" + "\n" + + " renderer = afx`\n" + + "
\n" + + "

{props.title}

\n" + + "

{props.subtitle}

\n" + + " \n" + + "
\n" + + " `" + + "\n" + " // The default content section\n" + " main = PrimaryContent {\n" + " nodePath = 'main'\n" +