diff --git a/org.bynar.versailles.xtext.ui/META-INF/MANIFEST.MF b/org.bynar.versailles.xtext.ui/META-INF/MANIFEST.MF index f1c53db..c528302 100644 --- a/org.bynar.versailles.xtext.ui/META-INF/MANIFEST.MF +++ b/org.bynar.versailles.xtext.ui/META-INF/MANIFEST.MF @@ -19,7 +19,8 @@ Require-Bundle: org.bynar.versailles.xtext, org.eclipse.xtext.xbase.lib Import-Package: org.apache.log4j Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Export-Package: org.bynar.versailles.xtext.ui.quickfix, - org.bynar.versailles.xtext.ui.contentassist, - org.bynar.versailles.xtext.ui.internal +Export-Package: org.bynar.versailles.xtext.ui.contentassist, + org.bynar.versailles.xtext.ui.internal, + org.bynar.versailles.xtext.ui.quickfix, + org.bynar.versailles.xtext.ui.syntaxcoloring Bundle-Activator: org.bynar.versailles.xtext.ui.internal.XtextActivator diff --git a/org.bynar.versailles.xtext.ui/src/org/bynar/versailles/xtext/ui/VersaillesLangUiModule.xtend b/org.bynar.versailles.xtext.ui/src/org/bynar/versailles/xtext/ui/VersaillesLangUiModule.xtend index 975352e..bd94e86 100644 --- a/org.bynar.versailles.xtext.ui/src/org/bynar/versailles/xtext/ui/VersaillesLangUiModule.xtend +++ b/org.bynar.versailles.xtext.ui/src/org/bynar/versailles/xtext/ui/VersaillesLangUiModule.xtend @@ -4,10 +4,25 @@ package org.bynar.versailles.xtext.ui import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor +import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator +import org.bynar.versailles.xtext.ui.syntaxcoloring.VersaillesSemanticHighlightingCalculator +import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration +import org.bynar.versailles.xtext.ui.syntaxcoloring.VersaillesHighlightingConfiguration +import org.eclipse.xtext.ide.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper +import org.bynar.versailles.xtext.ui.syntaxcoloring.VersaillesAntlrTokenToAttributeIdMapper /** * Use this class to register components to be used within the Eclipse IDE. */ @FinalFieldsConstructor class VersaillesLangUiModule extends AbstractVersaillesLangUiModule { + def Class bindAbstractAntlrTokenToAttributeIdMapper() { + return VersaillesAntlrTokenToAttributeIdMapper + } + def Class bindIHighlightingConfiguration() { + return VersaillesHighlightingConfiguration; + } + def Class bindISemanticHighlightingCalculator() { + return VersaillesSemanticHighlightingCalculator; + } } diff --git a/org.bynar.versailles.xtext.ui/src/org/bynar/versailles/xtext/ui/syntaxcoloring/SyntaxColoring.xtend b/org.bynar.versailles.xtext.ui/src/org/bynar/versailles/xtext/ui/syntaxcoloring/SyntaxColoring.xtend new file mode 100644 index 0000000..aef367d --- /dev/null +++ b/org.bynar.versailles.xtext.ui/src/org/bynar/versailles/xtext/ui/syntaxcoloring/SyntaxColoring.xtend @@ -0,0 +1,80 @@ +package org.bynar.versailles.xtext.ui.syntaxcoloring + +import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator +import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor +import org.eclipse.xtext.util.CancelIndicator +import org.eclipse.emf.ecore.EObject +import org.bynar.versailles.xtext.versaillesLang.Variable +import org.bynar.versailles.xtext.versaillesLang.VersaillesLangPackage +import org.eclipse.xtext.ide.editor.syntaxcoloring.HighlightingStyles +import org.bynar.versailles.xtext.versaillesLang.DefStmt +import org.bynar.versailles.xtext.versaillesLang.TypeStmt +import org.bynar.versailles.xtext.versaillesLang.MemberAccessExpr +import org.bynar.versailles.xtext.versaillesLang.MemberAccessType +import org.bynar.versailles.xtext.versaillesLang.TupleComponent +import org.bynar.versailles.xtext.versaillesLang.JanusClassVariable +import org.bynar.versailles.xtext.versaillesLang.TypeVariable +import org.bynar.versailles.xtext.versaillesLang.TupleTypeComponent +import org.bynar.versailles.xtext.versaillesLang.NamePath +import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration +import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfigurationAcceptor +import org.eclipse.xtext.ui.editor.utils.TextStyle +import org.eclipse.xtext.ide.editor.syntaxcoloring.DefaultAntlrTokenToAttributeIdMapper +import org.eclipse.swt.SWT + +public class VersaillesAntlrTokenToAttributeIdMapper extends DefaultAntlrTokenToAttributeIdMapper { + override protected String calculateId(String tokenName, int tokenType) { + if (tokenName.startsWith("RULE_INTERPOL_")) + return HighlightingStyles.STRING_ID + return super.calculateId(tokenName, tokenType) + } +} + +public class VersaillesHighlightingConfiguration extends DefaultHighlightingConfiguration { + public static final String TYPE_ID = "type" + + override public void configure(IHighlightingConfigurationAcceptor acceptor) { + super.configure(acceptor) + acceptor.acceptDefaultHighlighting(TYPE_ID, "Type", typeTextStyle()); + } + + def TextStyle typeTextStyle() { + val textStyle = defaultTextStyle().copy(); + textStyle.style = SWT.ITALIC + return textStyle; + } + +} + +public class VersaillesSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator { + + override protected boolean highlightElement(EObject object, IHighlightedPositionAcceptor acceptor, + CancelIndicator cancelIndicator) { + switch object { + NamePath: + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.NAME_PATH__STEPS), HighlightingStyles.DEFAULT_ID) + Variable: + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.VARIABLE__NAME), HighlightingStyles.DEFAULT_ID) + TupleComponent: + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.TUPLE_COMPONENT__NAME), HighlightingStyles.DEFAULT_ID) + MemberAccessExpr: + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.MEMBER_ACCESS_EXPR__MEMBER_NAME), HighlightingStyles.DEFAULT_ID) + DefStmt: { + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.DEF_STMT__NAME), HighlightingStyles.DEFAULT_ID) + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.DEF_STMT__NAME2), HighlightingStyles.DEFAULT_ID) + } + TypeStmt: + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.TYPE_STMT__NAME), VersaillesHighlightingConfiguration.TYPE_ID) + MemberAccessType: + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.MEMBER_ACCESS_TYPE__MEMBER_NAME), VersaillesHighlightingConfiguration.TYPE_ID) + TypeVariable: + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.TYPE_VARIABLE__NAME), VersaillesHighlightingConfiguration.TYPE_ID) + TupleTypeComponent: + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.TUPLE_TYPE_COMPONENT__NAME), VersaillesHighlightingConfiguration.TYPE_ID) + JanusClassVariable: + highlightFeature(acceptor, object, object.eClass.getEStructuralFeature(VersaillesLangPackage.JANUS_CLASS_VARIABLE__NAME), VersaillesHighlightingConfiguration.TYPE_ID) + } + return false + } + +} \ No newline at end of file diff --git a/org.bynar.xtext.ui/src/org/bynar/xtext/ui/BynarLangUiModule.xtend b/org.bynar.xtext.ui/src/org/bynar/xtext/ui/BynarLangUiModule.xtend index 2e319af..cfe62ef 100644 --- a/org.bynar.xtext.ui/src/org/bynar/xtext/ui/BynarLangUiModule.xtend +++ b/org.bynar.xtext.ui/src/org/bynar/xtext/ui/BynarLangUiModule.xtend @@ -4,10 +4,26 @@ package org.bynar.xtext.ui import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor +import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration +import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator +import org.bynar.versailles.xtext.ui.syntaxcoloring.VersaillesHighlightingConfiguration +import org.bynar.versailles.xtext.ui.syntaxcoloring.VersaillesSemanticHighlightingCalculator +import org.eclipse.xtext.ide.editor.syntaxcoloring.AbstractAntlrTokenToAttributeIdMapper +import org.bynar.versailles.xtext.ui.syntaxcoloring.VersaillesAntlrTokenToAttributeIdMapper /** * Use this class to register components to be used within the Eclipse IDE. */ @FinalFieldsConstructor class BynarLangUiModule extends AbstractBynarLangUiModule { + + def Class bindAbstractAntlrTokenToAttributeIdMapper() { + return VersaillesAntlrTokenToAttributeIdMapper + } + def Class bindIHighlightingConfiguration() { + return VersaillesHighlightingConfiguration; + } + def Class bindISemanticHighlightingCalculator() { + return VersaillesSemanticHighlightingCalculator; + } } diff --git a/org.bynar.xtext/src/org/bynar/xtext/BynarLang.xtext b/org.bynar.xtext/src/org/bynar/xtext/BynarLang.xtext index 4b9c73d..325efbc 100644 --- a/org.bynar.xtext/src/org/bynar/xtext/BynarLang.xtext +++ b/org.bynar.xtext/src/org/bynar/xtext/BynarLang.xtext @@ -8,7 +8,7 @@ generate bynarLang "http://www.bynar.org/xtext/BynarLang" CompilationUnit returns versailles::CompilationUnit: super; @Override -Statement returns versailles::Statement: +SimpleStatement returns versailles::Statement: super | "component" ({RegisterComponent} bitPosition=IndexExpr | {RecordComponent}) name=Name (title=STRING)? (description=InterpolatedString)? ":" type=TypeExpression | {RecordAlign} "align" "at" alignment=Expression unit=BitUnit @@ -57,7 +57,7 @@ BitUnit: @Override Name: - super + super | "align" | "at" | "array" | "bit" |"bits" | "by" | "byte" | "bytes" | "component" | "containing" | "converted" | "fixed" | "kB" | "gigabyte" | "gigabytes" | "gibibyte" | "gibibytes" |