Migrated to XText 2.14 and Photon for RDL Editor RCP

This commit is contained in:
2018-06-02 23:41:27 +02:00
parent cc6d106838
commit 9a55dd5a21
165 changed files with 2419 additions and 662 deletions

View File

@ -21,6 +21,9 @@ Workflow {
eclipsePluginTest = {
enabled = true
}
web = {
enabled = true
}
createEclipseMetaData = true
}
code = {
@ -33,7 +36,6 @@ Workflow {
name = "com.minres.rdl.RDL"
fileExtensions = "rdl"
fragment = scoping.ImportNamespacesScopingFragment2 auto-inject {}
fragment = exporting.SimpleNamesFragment2 auto-inject {}
parserGenerator = {
@ -41,13 +43,18 @@ Workflow {
backtrack = true
}
}
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
generator = {
generateXtendMain = true
}
newProjectWizardForEclipse = {
generate = true
}
}
}
}

View File

@ -1,121 +1,121 @@
package com.minres.rdl;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class IntegerWithRadix {
private static final Pattern bin = Pattern.compile("([0-9]+)?'b([01_]+)");
private static final Pattern oct = Pattern.compile("([0-9]+)?'o([0-7_]+)");
private static final Pattern dec = Pattern.compile("([0-9]+)?'d([0-9_]+)");
private static final Pattern hex = Pattern.compile("([0-9]+)?'h([0-9a-fA-F_]+)");
public long value;
public int length;
public int radix;
public IntegerWithRadix(Integer valueOf) {
this.value=valueOf;
this.radix=10;
this.length=0;
}
public IntegerWithRadix(Integer valueOf, int radix) {
this.value=valueOf;
this.radix=radix;
this.length=0;
}
public IntegerWithRadix(Integer valueOf, int radix, int len) {
this.value=valueOf;
this.radix=radix;
this.length=len;
}
public IntegerWithRadix(String string) {
radix=10;
if(string.contains("'")){
Matcher matcher=hex.matcher(string);
if(matcher.matches()){
radix = 16;
if(matcher.groupCount()==2){
length=Integer.valueOf(matcher.group(1));
string=matcher.group(2).replaceAll("_", "");
} else
string=matcher.group(1).replaceAll("_", "");
value=Long.parseLong(string, radix);
}
matcher =bin.matcher(string);
if(matcher.matches()){
radix = 2;
if(matcher.groupCount()==2){
length=Integer.valueOf(matcher.group(1));
string=matcher.group(2).replaceAll("_", "");
} else
string=matcher.group(1).replaceAll("_", "");
value=Long.parseLong(string, radix);
}
matcher =dec.matcher(string);
if(matcher.matches()){
radix = 10;
if(matcher.groupCount()==2){
length=Integer.valueOf(matcher.group(1));
string=matcher.group(2).replaceAll("_", "");
} else
string=matcher.group(1).replaceAll("_", "");
value=Long.parseLong(string, radix);
}
matcher =oct.matcher(string);
if(matcher.matches()){
radix = 8;
if(matcher.groupCount()==2){
length=Integer.valueOf(matcher.group(1));
string=matcher.group(2).replaceAll("_", "");
} else
string=matcher.group(1).replaceAll("_", "");
value=Long.parseLong(string, radix);
}
} else if(string.startsWith("0x") || string.startsWith("0X")) {
radix = 16;
string = string.substring(2);
} else if(string.startsWith("0") && string.length()>1) {
radix=8;
}
value=Long.parseLong(string, radix);
}
public String toString(){
StringBuilder sb = new StringBuilder();
if(length>0){
sb.append(length);
switch(radix){
case 16:
sb.append("'h").append(Long.toHexString(value));
break;
case 8:
sb.append("'o").append(Long.toOctalString(value));
break;
case 2:
sb.append("'b").append(Long.toBinaryString(value));
break;
default:
sb.append("'d").append(value);
break;
}
} else{
switch(radix){
case 16:
sb.append("0x").append(Long.toHexString(value));
break;
case 8:
sb.append("0").append(Long.toOctalString(value));
break;
default:
sb.append(value);
break;
}
}
return sb.toString();
}
}
package com.minres.rdl;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class IntegerWithRadix {
private static final Pattern bin = Pattern.compile("([0-9]+)?'b([01_]+)");
private static final Pattern oct = Pattern.compile("([0-9]+)?'o([0-7_]+)");
private static final Pattern dec = Pattern.compile("([0-9]+)?'d([0-9_]+)");
private static final Pattern hex = Pattern.compile("([0-9]+)?'h([0-9a-fA-F_]+)");
public long value;
public int length;
public int radix;
public IntegerWithRadix(Integer valueOf) {
this.value=valueOf;
this.radix=10;
this.length=0;
}
public IntegerWithRadix(Integer valueOf, int radix) {
this.value=valueOf;
this.radix=radix;
this.length=0;
}
public IntegerWithRadix(Integer valueOf, int radix, int len) {
this.value=valueOf;
this.radix=radix;
this.length=len;
}
public IntegerWithRadix(String string) {
radix=10;
if(string.contains("'")){
Matcher matcher=hex.matcher(string);
if(matcher.matches()){
radix = 16;
if(matcher.groupCount()==2){
length=Integer.valueOf(matcher.group(1));
string=matcher.group(2).replaceAll("_", "");
} else
string=matcher.group(1).replaceAll("_", "");
value=Long.parseLong(string, radix);
}
matcher =bin.matcher(string);
if(matcher.matches()){
radix = 2;
if(matcher.groupCount()==2){
length=Integer.valueOf(matcher.group(1));
string=matcher.group(2).replaceAll("_", "");
} else
string=matcher.group(1).replaceAll("_", "");
value=Long.parseLong(string, radix);
}
matcher =dec.matcher(string);
if(matcher.matches()){
radix = 10;
if(matcher.groupCount()==2){
length=Integer.valueOf(matcher.group(1));
string=matcher.group(2).replaceAll("_", "");
} else
string=matcher.group(1).replaceAll("_", "");
value=Long.parseLong(string, radix);
}
matcher =oct.matcher(string);
if(matcher.matches()){
radix = 8;
if(matcher.groupCount()==2){
length=Integer.valueOf(matcher.group(1));
string=matcher.group(2).replaceAll("_", "");
} else
string=matcher.group(1).replaceAll("_", "");
value=Long.parseLong(string, radix);
}
} else if(string.startsWith("0x") || string.startsWith("0X")) {
radix = 16;
string = string.substring(2);
} else if(string.startsWith("0") && string.length()>1) {
radix=8;
}
value=Long.parseLong(string, radix);
}
public String toString(){
StringBuilder sb = new StringBuilder();
if(length>0){
sb.append(length);
switch(radix){
case 16:
sb.append("'h").append(Long.toHexString(value));
break;
case 8:
sb.append("'o").append(Long.toOctalString(value));
break;
case 2:
sb.append("'b").append(Long.toBinaryString(value));
break;
default:
sb.append("'d").append(value);
break;
}
} else{
switch(radix){
case 16:
sb.append("0x").append(Long.toHexString(value));
break;
case 8:
sb.append("0").append(Long.toOctalString(value));
break;
default:
sb.append(value);
break;
}
}
return sb.toString();
}
}

View File

@ -1,37 +1,29 @@
/*
* generated by Xtext 2.12.0
* generated by Xtext 2.14.0
*/
package com.minres.rdl
import org.eclipse.xtext.conversion.IValueConverterService
import com.minres.rdl.converter.RdlTerminalConverters
import org.eclipse.xtext.scoping.IGlobalScopeProvider
import org.eclipse.xtext.naming.IQualifiedNameProvider
/**
* Use this class to register components to be used at runtime / without the Equinox extension registry.
*/
class RDLRuntimeModule extends AbstractRDLRuntimeModule {
override Class<? extends IValueConverterService> bindIValueConverterService() {
return typeof(RdlTerminalConverters);
}
// the following two are used to allow URI based include mechanism
// contributed by org.eclipse.xtext.generator.scoping.AbstractScopingFragment
override void configureIScopeProviderDelegate(com.google.inject.Binder binder) {
binder.bind(typeof(org.eclipse.xtext.scoping.IScopeProvider)).
annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).
to(typeof(org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider));
}
// the following two are used to allow URI based include mechanism
// contributed by org.eclipse.xtext.xtext.generator.scoping.ImportNamespacesScopingFragment2
override Class<? extends IGlobalScopeProvider> bindIGlobalScopeProvider() {
//return typeof(ResourceSetGlobalScopeProvider)
return typeof(org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider)
}
// contributed by org.eclipse.xtext.generator.exporting.SimpleNamesFragment
override Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
//return typeof(ResourceSetGlobalScopeProvider)
return typeof(org.eclipse.xtext.naming.SimpleNameProvider)
}
}

View File

@ -1,5 +1,5 @@
/*
* generated by Xtext 2.12.0
* generated by Xtext 2.14.0
*/
package com.minres.rdl

View File

@ -0,0 +1,58 @@
/*
* generated by Xtext 2.14.0
*/
package com.minres.rdl.generator
import com.google.inject.Inject
import com.google.inject.Provider
import com.minres.rdl.RDLStandaloneSetup
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.xtext.generator.GeneratorContext
import org.eclipse.xtext.generator.GeneratorDelegate
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
import org.eclipse.xtext.util.CancelIndicator
import org.eclipse.xtext.validation.CheckMode
import org.eclipse.xtext.validation.IResourceValidator
class Main {
def static main(String[] args) {
if (args.empty) {
System::err.println('Aborting: no path to EMF resource provided!')
return
}
val injector = new RDLStandaloneSetup().createInjectorAndDoEMFRegistration
val main = injector.getInstance(Main)
main.runGenerator(args.get(0))
}
@Inject Provider<ResourceSet> resourceSetProvider
@Inject IResourceValidator validator
@Inject GeneratorDelegate generator
@Inject JavaIoFileSystemAccess fileAccess
def protected runGenerator(String string) {
// Load the resource
val set = resourceSetProvider.get
val resource = set.getResource(URI.createFileURI(string), true)
// Validate the resource
val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
if (!issues.empty) {
issues.forEach[System.err.println(it)]
return
}
// Configure and start the generator
fileAccess.outputPath = 'src-gen/'
val context = new GeneratorContext => [
cancelIndicator = CancelIndicator.NullImpl
]
generator.generate(resource, fileAccess, context)
System.out.println('Code generation finished.')
}
}

View File

@ -1,5 +1,5 @@
/*
* generated by Xtext 2.12.0
* generated by Xtext 2.14.0
*/
package com.minres.rdl.validation