Skip to content

Commit

Permalink
some syntax coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbohne committed Jun 11, 2017
1 parent ae9b3ef commit 47331b5
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 5 deletions.
7 changes: 4 additions & 3 deletions org.bynar.versailles.xtext.ui/META-INF/MANIFEST.MF
Expand Up @@ -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
Expand Up @@ -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<? extends AbstractAntlrTokenToAttributeIdMapper> bindAbstractAntlrTokenToAttributeIdMapper() {
return VersaillesAntlrTokenToAttributeIdMapper
}
def Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration() {
return VersaillesHighlightingConfiguration;
}
def Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() {
return VersaillesSemanticHighlightingCalculator;
}
}
@@ -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
}

}
16 changes: 16 additions & 0 deletions org.bynar.xtext.ui/src/org/bynar/xtext/ui/BynarLangUiModule.xtend
Expand Up @@ -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<? extends AbstractAntlrTokenToAttributeIdMapper> bindAbstractAntlrTokenToAttributeIdMapper() {
return VersaillesAntlrTokenToAttributeIdMapper
}
def Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration() {
return VersaillesHighlightingConfiguration;
}
def Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() {
return VersaillesSemanticHighlightingCalculator;
}
}
4 changes: 2 additions & 2 deletions org.bynar.xtext/src/org/bynar/xtext/BynarLang.xtext
Expand Up @@ -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
Expand Down Expand Up @@ -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" |
Expand Down

0 comments on commit 47331b5

Please sign in to comment.