Skip to content

Commit

Permalink
TASK: Implement basic Fusion DSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
cvette committed Sep 4, 2017
1 parent ce00da9 commit 981cf61
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
21 changes: 19 additions & 2 deletions src/main/grammars/FusionLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "["
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -167,13 +171,18 @@ 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; }
}

<OBJECT_TYPE_FOUND> {
{COLON} { return FusionTypes.OBJECT_TYPE_SEPARATOR; }
{OBJECT_TYPE_PART} { yybegin(CRLF_OR_LEFT_BRACE_EXPECTED); return FusionTypes.UNQUALIFIED_TYPE; }
}

<DSL_IDENTIFIER_FOUND> {
{BACKTICK} { yybegin(VALUE_STRING_EXPECTED_IN_BACKTICKS); return FusionTypes.BACKTICK; }
}

<CRLF_OR_LEFT_BRACE_EXPECTED> {
{LEFT_BRACE} { yybegin(CRLF_OR_BLOCK_EXPECTED); return FusionTypes.LEFT_BRACE; }
{CRLF} { yybegin(YYINITIAL); return FusionTypes.CRLF; }
Expand Down Expand Up @@ -296,6 +305,14 @@ IF_SEPARATOR = {COLON}
{VALUE_STRING_IN_DOUBLE_QUOTE} { return FusionTypes.VALUE_STRING; }
}

<VALUE_STRING_EXPECTED_IN_BACKTICKS> {
{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; }
}

<EXPRESSION_FOUND> {
{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; }}
Expand Down
8 changes: 7 additions & 1 deletion src/main/grammars/FusionParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" +
" <div>\n" +
" <h1 @key=\"headline\" class=\"headline\">{props.title}</h1>\n" +
" <h2 @key=\"subheadline\" class=\"subheadline\" @if.hasSubtitle={props.subtitle ? true : false}>{props.subtitle}</h2>\n" +
" <PackageFactory.AtomicFusion.AFX:Image @key=\"image\" uri={props.imageUri} />\n" +
" </div>\n" +
" `" +
"\n" +
" // The default content section\n" +
" main = PrimaryContent {\n" +
" nodePath = 'main'\n" +
Expand Down

0 comments on commit 981cf61

Please sign in to comment.