Skip to content

Commit

Permalink
Merge branch 'task/cv-dsl-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
cvette committed Jan 15, 2018
2 parents 9669bda + 8f06690 commit 8c33422
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ def pluginsForIdeaVersion = [
// Branch Number: 172
'com.jetbrains.php:172.3317.83',
'yaml',
'IntelliLang',

// test dependencies
'CSS',
'java-i18n',
'properties',
// DEV dependencies: UNCOMMENT the following lines during development
// to install additional plugins for development
// 'PsiViewer:3.28.93'
'PsiViewer:3.28.93'
],
'2017.1.3': [
// Branch Number: 171
Expand Down
1 change: 1 addition & 0 deletions src/main/grammars/FusionLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ IF_SEPARATOR = {COLON}
{LEFT_BRACE} { yybegin(YYINITIAL); return FusionTypes.LEFT_BRACE; }
}


<PROTOTYPE_FOUND> {
{OBJECT_TYPE_PART} { return FusionTypes.UNQUALIFIED_TYPE; }
{OBJECT_TYPE_PART}/{COLON} { yybegin(OBJECT_TYPE_IN_PROTOTYPE_FOUND); return FusionTypes.OBJECT_TYPE_NAMESPACE; }
Expand Down
6 changes: 5 additions & 1 deletion src/main/grammars/FusionParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ value_dsl ::= DSL_IDENTIFIER BACKTICK value_dsl_content BACKTICK {
pin=1
}

value_dsl_content ::= (VALUE_STRING | CRLF | ESCAPED_BACKTICK)*
value_dsl_content ::= (VALUE_STRING | CRLF | ESCAPED_BACKTICK)* {
implements = [ "com.intellij.psi.PsiLanguageInjectionHost" ]
mixin = "de.vette.idea.neos.lang.fusion.psi.impl.ext.FusionValueDslContentImplMixin"
}

value_string_line ::= VALUE_STRING_QUOTE value_string_line_content VALUE_STRING_QUOTE {
pin=1
implements = [ "de.vette.idea.neos.lang.fusion.psi.FusionReferenceElement" ]
mixin = "de.vette.idea.neos.lang.fusion.psi.impl.ext.FusionValueStringLineImplMixin"
}

value_string_line_content ::= (VALUE_STRING | CRLF | VALUE_STRING_ESCAPED_QUOTE)*

value_string_single_line ::= VALUE_STRING_QUOTE (VALUE_STRING | VALUE_STRING_ESCAPED_QUOTE)* VALUE_STRING_QUOTE {pin=1}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* IntelliJ IDEA plugin to support the Neos CMS.
* Copyright (C) 2016 Christian Vette
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.vette.idea.neos.lang.fusion.injection;

import com.intellij.openapi.util.TextRange;
import com.intellij.psi.LiteralTextEscaper;
import de.vette.idea.neos.lang.fusion.psi.FusionValueDslContent;
import org.jetbrains.annotations.NotNull;

public class FusionDslTextEscaper extends LiteralTextEscaper<FusionValueDslContent> {

public FusionDslTextEscaper(@NotNull FusionValueDslContent host) {
super(host);
}

@Override
public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
outChars.append(myHost.getText(), rangeInsideHost.getStartOffset(), rangeInsideHost.getEndOffset());
return true;
}

@Override
public int getOffsetInHost(int offsetInDecoded, @NotNull TextRange rangeInsideHost) {
int offset = offsetInDecoded + rangeInsideHost.getStartOffset();
if (offset < rangeInsideHost.getStartOffset()) offset = rangeInsideHost.getStartOffset();
if (offset > rangeInsideHost.getEndOffset()) offset = rangeInsideHost.getEndOffset();
return offset;
}

@Override
public boolean isOneLine() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* IntelliJ IDEA plugin to support the Neos CMS.
* Copyright (C) 2016 Christian Vette
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.vette.idea.neos.lang.fusion.injection;

import com.intellij.psi.PsiLanguageInjectionHost;
import de.vette.idea.neos.lang.fusion.patterns.FusionPatterns;
import org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport;
import org.jetbrains.annotations.NotNull;

public class FusionLanguageInjectionSupport extends AbstractLanguageInjectionSupport {
private final String SUPPORT_ID = "fusion";

@NotNull
@Override
public String getId() {
return SUPPORT_ID;
}

@NotNull
@Override
public Class[] getPatternClasses() {
return new Class[]{FusionPatterns.class};
}

@Override
public boolean useDefaultInjector(PsiLanguageInjectionHost host) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* IntelliJ IDEA plugin to support the Neos CMS.
* Copyright (C) 2016 Christian Vette
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.eadzc
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.vette.idea.neos.lang.fusion.injection;

import com.intellij.lang.Language;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.InjectedLanguagePlaces;
import com.intellij.psi.LanguageInjector;
import com.intellij.psi.PsiLanguageInjectionHost;
import org.intellij.plugins.intelliLang.Configuration;
import org.intellij.plugins.intelliLang.inject.InjectedLanguage;
import org.intellij.plugins.intelliLang.inject.config.BaseInjection;
import org.jetbrains.annotations.NotNull;

import java.util.*;

public class FusionLanguageInjector implements LanguageInjector {

private final Configuration myInjectionConfiguration;

public FusionLanguageInjector(Configuration configuration) {
myInjectionConfiguration = configuration;
}

@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {
Iterator it = myInjectionConfiguration.getInjections("fusion").iterator();
while(it.hasNext()) {
BaseInjection injection = (BaseInjection) it.next();
if (injection.acceptsPsiElement(host)) {
Language language = InjectedLanguage.findLanguageById(injection.getInjectedLanguageId());
if (language != null) {
injectionPlacesRegistrar.addPlace(language, new TextRange(0, host.getTextLength()), "", "");
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* IntelliJ IDEA plugin to support the Neos CMS.
* Copyright (C) 2016 Christian Vette
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.vette.idea.neos.lang.fusion.patterns;

import com.intellij.patterns.InitialPatternCondition;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;

public class FusionElementPattern<T extends PsiElement,Self extends FusionElementPattern<T,Self>> extends PsiElementPattern<T,Self> {

public FusionElementPattern(Class<T> aClass) {
super(aClass);
}

public FusionElementPattern(@NotNull InitialPatternCondition<T> condition) {
super(condition);
}

public static class Capture<T extends PsiElement> extends FusionElementPattern<T, FusionElementPattern.Capture<T>> {
public Capture(Class<T> aClass) {
super(aClass);
}

public Capture(@NotNull InitialPatternCondition<T> condition) {
super(condition);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* IntelliJ IDEA plugin to support the Neos CMS.
* Copyright (C) 2016 Christian Vette
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.vette.idea.neos.lang.fusion.patterns;

import com.intellij.patterns.InitialPatternCondition;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.util.ProcessingContext;
import de.vette.idea.neos.lang.fusion.psi.FusionValueDsl;
import de.vette.idea.neos.lang.fusion.patterns.FusionElementPattern.Capture;
import de.vette.idea.neos.lang.fusion.psi.FusionValueDslContent;
import org.jetbrains.annotations.Nullable;

public class FusionPatterns extends PlatformPatterns {

public static FusionElementPattern fusionValueDsl(final String identifier) {
return new Capture(new InitialPatternCondition<FusionValueDslContent>(FusionValueDslContent.class) {
public boolean accepts(@Nullable Object o, ProcessingContext context) {
if (o instanceof FusionValueDslContent) {
FusionValueDsl s = (FusionValueDsl) ((FusionValueDslContent) o).getParent();
return s.getDslIdentifier().getText().equals(identifier);
}

return false;
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* IntelliJ IDEA plugin to support the Neos CMS.
* Copyright (C) 2016 Christian Vette
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.vette.idea.neos.lang.fusion.psi.impl.ext;

import com.intellij.lang.ASTNode;
import com.intellij.psi.LiteralTextEscaper;
import com.intellij.psi.PsiLanguageInjectionHost;
import de.vette.idea.neos.lang.fusion.injection.FusionDslTextEscaper;
import de.vette.idea.neos.lang.fusion.psi.FusionValueDslContent;
import de.vette.idea.neos.lang.fusion.psi.impl.FusionCompositeElementImpl;
import org.jetbrains.annotations.NotNull;

public class FusionValueDslContentImplMixin extends FusionCompositeElementImpl implements FusionValueDslContent {

public FusionValueDslContentImplMixin(@NotNull ASTNode astNode) {
super(astNode);
}

@Override
public boolean isValidHost() {
return true;
}

@Override
public PsiLanguageInjectionHost updateText(@NotNull String text) {
return null;
}

@NotNull
@Override
public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextEscaper() {
return new FusionDslTextEscaper(this);
}
}
8 changes: 8 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<depends>com.jetbrains.php</depends>
<depends>org.jetbrains.plugins.yaml</depends>

<extensions defaultExtensionNs="org.intellij.intelliLang">
<languageSupport implementation="de.vette.idea.neos.lang.fusion.injection.FusionLanguageInjectionSupport"/>
<injectionConfig config="de/vette/idea/neos/lang/fusion/injection/fusionInjections.xml"/>
</extensions>

<extensions defaultExtensionNs="com.intellij">
<projectService serviceImplementation="de.vette.idea.neos.Settings"/>
<projectConfigurable instance="de.vette.idea.neos.SettingsForm"
Expand Down Expand Up @@ -83,6 +88,9 @@
<!-- Indices -->
<stubIndex implementation="de.vette.idea.neos.lang.fusion.stubs.index.FusionNamespaceDeclarationIndex"/>
<stubIndex implementation="de.vette.idea.neos.lang.fusion.stubs.index.FusionPrototypeDeclarationIndex"/>

<patterns.patternClass className="de.vette.idea.neos.lang.fusion.patterns.FusionPatterns" alias="fusion"/>
<languageInjector implementation="de.vette.idea.neos.lang.fusion.injection.FusionLanguageInjector" />
</extensions>

<project-components>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<component name="LanguageInjectionConfiguration">
<injection language="HTML" injector-id="fusion">
<display-name>AFX</display-name>
<place><![CDATA[fusionValueDsl("afx")]]></place>
</injection>
</component>

0 comments on commit 8c33422

Please sign in to comment.