Iniital checkin

This commit is contained in:
2017-09-12 12:48:21 +02:00
commit fd1e04fb62
270 changed files with 87560 additions and 0 deletions

View File

@ -0,0 +1,48 @@
module com.minres.rdl.GenerateRDL
import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*
var rootPath = ".."
Workflow {
component = XtextGenerator {
configuration = {
project = StandardProjectConfig {
baseName = "com.minres.rdl"
rootPath = rootPath
runtimeTest = {
enabled = true
}
eclipsePlugin = {
enabled = true
}
eclipsePluginTest = {
enabled = true
}
createEclipseMetaData = true
}
code = {
encoding = "UTF-8"
lineDelimiter = "\n"
fileHeader = "/*\n * generated by Xtext \${version}\n */"
}
}
language = StandardLanguage {
name = "com.minres.rdl.RDL"
fileExtensions = "rdl"
fragment = scoping.ImportNamespacesScopingFragment2 auto-inject {}
fragment = exporting.SimpleNamesFragment2 auto-inject {}
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
}
}
}

View File

@ -0,0 +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();
}
}

View File

@ -0,0 +1,405 @@
//grammar com.minres.rdl.RDL with org.eclipse.xtext.common.Terminals
grammar com.minres.rdl.RDL hidden(WS, ML_COMMENT, SL_COMMENT, ESCAPE_JSP, ESCAPE_ORDL)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate rdl "http://www.minres.com/rdl/RDL"
Root:
(
includes+=Include |
componentDefinitions+=ComponentDefinition |
enumDefinitions+=EnumDefinition |
namedInstantiations+=NamedInstantiation |
propertyAssignments+=PropertyAssignment |
propertyDefinitions+=PropertyDefinition
)*
;
Include:
'`include' importURI=STR
;
PropertyDefinition:
'property' name=ID '{'
(
"type" '=' type=PropertyTypeName ';' (usage=PropertyUsage default=PropertyDefault? | default=PropertyDefault usage=PropertyUsage) |
usage=PropertyUsage ("type" '=' type=PropertyTypeName ';' default=PropertyDefault? | default=PropertyDefault "type" '=' type=PropertyTypeName ';') |
default=PropertyDefault ("type" '=' type=PropertyTypeName ';' usage=PropertyUsage | usage=PropertyUsage "type" '=' type=PropertyTypeName ';')
) '}' ';'
;
enum PropertyTypeName:
STRING="string" | NUMBER="number" | BOOLEAN="boolean" | ADDRMAP="addrmap" | REG="reg" | REGFILE="regfile" | FIELD="field" | REF="ref"
;
PropertyDefault:
"default" '=' (string=STR | value=NUM | string="true" | string="false") ';'
;
PropertyUsage:
"component" '=' components+=PropertyComponent ('|' components+=PropertyComponent)* ';'
;
enum PropertyComponent:
SIGNAL="signal" | ADDRMAP="addrmap" | REG="reg" | REGFILE="regfile" | FIELD="field" | ALL="all"
;
ComponentDefinition:
type=ComponentDefinitionType name=ID?
'{'
( componentDefinitions+=ComponentDefinition
| namedInstantiations+=NamedInstantiation
| propertyAssignments+=PropertyAssignment
| enumDefinitions+=EnumDefinition
)* '}' immediateInstantiation=ImmediateInstantiation? ';'
;
enum ComponentDefinitionType:
SIGNAL="signal" | ADDRMAP="addrmap" | REGFILE="regfile" | REG="reg" | FIELD="field"
;
// Instantiation: NamedInstantiation|ImmediateInstantiation;
NamedInstantiation:
(external?="external")? (internal?="internal")? ("alias" alias=ID)? component=[ComponentDefinition] componentInstances+=ComponentInstance (',' componentInstances+=ComponentInstance)* ';'
;
ImmediateInstantiation:
(external?="external")? componentInstances+=ComponentInstance (',' componentInstances+=ComponentInstance)*
;
ComponentInstance:
name=ID (range=Range)?
//reset
('=' reset=NUM)?
//address
('@' address=NUM)?
//addr inc
('+=' addrInc=NUM)?
//addr mod
('%=' addrMod=NUM)?
;
Range:
'[' (start=NUM ':' end=NUM | size=NUM) ']'
;
PropertyAssignment:
DefaultProperyAssignment | ExplicitPropertyAssignment | PostPropertyAssignment
;
DefaultProperyAssignment:
"default" ExplicitPropertyAssignment
;
ExplicitPropertyAssignment :
modifier=PropertyModifier name=Property ';' |
name=Property ('=' rhs=PropertyAssignmentRhs)? ';'
;
PostPropertyAssignment:
(instance=HierInstanceRef '->' (propertyEnum=Property | property=[PropertyDefinition]) |
property=[PropertyDefinition] ) ('=' rhs=PropertyAssignmentRhs)? ';'
;
InstancePropertyRef:
instance=InstanceRef ('->' (propertyEnum=Property | property=[PropertyDefinition]))?
;
// unused rules to infer inheritance
Entity:
ComponentInstance|EnumDefinition|PropertyDefinition
;
InstanceRef:
instance=[Entity] ( "." tail=HierInstanceRef)?
;
HierInstanceRef returns InstanceRef:
instance=[ComponentInstance] ( "." tail=HierInstanceRef)?
;
PropertyAssignmentRhs:
value=PropertyRvalueConstant |
instPropRef=InstancePropertyRef |
enumRef= [EnumDefinition]
"enum" enums=EnumBody |
elements=Concat
;
Concat:
'{' elements+=ConcatElem (',' elements+=ConcatElem)* '}'
;
ConcatElem:
instPropRef=InstancePropertyRef | value=NUM
;
enum PropertyEnum:
UNSPECIFIED |
NAME="name" |
DESC="desc" |
ARBITER="arbiter" |
RSET="rset" |
RCLR="rclr" |
WOCLR="woclr" |
WOSET="woset" |
WE="we" |
WEL="wel" |
SWWE="swwe" |
SWWEL="swwel" |
HWSET="hwset" |
HWCLR="hwclr" |
SWMOD="swmod" |
SWACC="swacc" |
STICKY="sticky" |
STICKYBIT="stickybit" |
INTR="intr" |
ANDED="anded" |
ORED="ored" |
XORED="xored" |
COUNTER="counter" |
OVERFLOW="overflow" |
SHAREDEXTBUS="sharedextbus" |
ERREXTBUS="errextbus" |
RESET="reset" |
LITTLEENDIAN="littleendian" |
BIGENDIAN="bigendian" |
RSVDSET="rsvdset" |
RSVDSETX="rsvdsetX" |
BRIDGE="bridge" |
SHARED="shared" |
MSB0="msb0" |
LSB0="lsb0" |
SYNC="sync" |
ASYNC="async" |
CPUIF_RESET="cpuif_reset" |
FIELD_RESET="field_reset" |
ACTIVEHIGH="activehigh" |
ACTIVELOW="activelow" |
SINGLEPULSE="singlepulse" |
UNDERFLOW="underflow" |
INCR="incr" |
DECR="decr" |
INCRWIDTH="incrwidth" |
DECRWIDTH="decrwidth" |
INCRVALUE="incrvalue" |
DECRVALUE="decrvalue" |
SATURATE="saturate" |
DECRSATURATE="decrsaturate" |
THRESHOLD="threshold" |
DECRTHRESHOLD="decrthreshold" |
DONTCOMPARE="dontcompare" |
DONTTEST="donttest" |
INTERNAL="internal" |
ALIGNMENT="alignment" |
REGWIDTH="regwidth" |
FIELDWIDTH="fieldwidth" |
SIGNALWIDTH="signalwidth" |
ACCESSWIDTH="accesswidth" |
SW="sw" |
HW="hw" |
ADDRESSING="addressing" |
PRECEDENCE="precedence" |
ENCODE="encode" |
RESETSIGNAL="resetsignal" |
CLOCK="clock" |
MASK="mask" |
ENABLE="enable" |
HWENABLE="hwenable" |
HWMASK="hwmask" |
HALTMASK="haltmask" |
HALTENABLE="haltenable" |
HALT="halt" |
NEXT="next"
;
enum Property returns PropertyEnum:
NAME="name" |
DESC="desc" |
ARBITER="arbiter" |
RSET="rset" |
RCLR="rclr" |
WOCLR="woclr" |
WOSET="woset" |
WE="we" |
WEL="wel" |
SWWE="swwe" |
SWWEL="swwel" |
HWSET="hwset" |
HWCLR="hwclr" |
SWMOD="swmod" |
SWACC="swacc" |
STICKY="sticky" |
STICKYBIT="stickybit" |
INTR="intr" |
ANDED="anded" |
ORED="ored" |
XORED="xored" |
COUNTER="counter" |
OVERFLOW="overflow" |
SHAREDEXTBUS="sharedextbus" |
ERREXTBUS="errextbus" |
RESET="reset" |
LITTLEENDIAN="littleendian" |
BIGENDIAN="bigendian" |
RSVDSET="rsvdset" |
RSVDSETX="rsvdsetX" |
BRIDGE="bridge" |
SHARED="shared" |
MSB0="msb0" |
LSB0="lsb0" |
SYNC="sync" |
ASYNC="async" |
CPUIF_RESET="cpuif_reset" |
FIELD_RESET="field_reset" |
ACTIVEHIGH="activehigh" |
ACTIVELOW="activelow" |
SINGLEPULSE="singlepulse" |
UNDERFLOW="underflow" |
INCR="incr" |
DECR="decr" |
INCRWIDTH="incrwidth" |
DECRWIDTH="decrwidth" |
INCRVALUE="incrvalue" |
DECRVALUE="decrvalue" |
SATURATE="saturate" |
DECRSATURATE="decrsaturate" |
THRESHOLD="threshold" |
DECRTHRESHOLD="decrthreshold" |
DONTCOMPARE="dontcompare" |
DONTTEST="donttest" |
INTERNAL="internal" |
ALIGNMENT="alignment" |
REGWIDTH="regwidth" |
FIELDWIDTH="fieldwidth" |
SIGNALWIDTH="signalwidth" |
ACCESSWIDTH="accesswidth" |
SW="sw" |
HW="hw" |
ADDRESSING="addressing" |
PRECEDENCE="precedence" |
ENCODE="encode" |
RESETSIGNAL="resetsignal" |
CLOCK="clock" |
MASK="mask" |
ENABLE="enable" |
HWENABLE="hwenable" |
HWMASK="hwmask" |
HALTMASK="haltmask" |
HALTENABLE="haltenable" |
HALT="halt" |
NEXT="next"
;
PropertyRvalueConstant returns RValue:
val=RValueConstant | num=NUM | str=STR
;
enum RValueConstant:
UNDEFINED | TRUE="true" | FALSE="false" | RW="rw" | WR="wr" | R="r" | W="w" | NA="na" | COMPACT="compact" | REGALIGN="regalign" | FULLALIGN="fullalign" | HW="hw" | SW="sw"
;
enum PropertyModifier:
UNDEFINED | POSEDGE="posedge" | NEGEDGE="negedge" | BOTHEDGE="bothedge" | LEVEL="level" | NONSTICKY="nonsticky"
;
EnumDefinition:
"enum" name=ID body=EnumBody ';'
;
EnumBody:
'{' {EnumBody} entries+=EnumEntry* '}'
;
EnumEntry:
name=ID '=' index=NUM ('{' properties+=EnumProperty* '}')? ';'
;
EnumProperty:
( name='name' '=' value=STR | name='desc' '=' value=STR ) ';'
;
///////////////////////////////////////////////////////////////////////////////
// the terminals
///////////////////////////////////////////////////////////////////////////////
terminal ID:
'\\'? ('a'..'z'|'A'..'Z' | '_')('a'..'z'|'A'..'Z' | '_' | '0'..'9')*;
terminal WS : (' '|'\t'|'\r'|'\n')+;
terminal ML_COMMENT : '/*' -> '*/' ;
terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?;
terminal ESCAPE_JSP : '<%' -> '%>' ;
terminal ESCAPE_ORDL: '(' -> ')' ;
terminal NUM returns ecore::EJavaObject:
// <= verilog like numbers with size and base (16'123 'h1fff, ...====================================================================================> <= hexa decimal numbers =============> <numbers>
//'0'..'9'* '\'' ( 'b' ('0' | '1' | '_')+ | 'd'? ('0'..'9' | '_')+ | 'o' ('0'..'7' | '_')+ | 'h' ('0'..'9' | 'a'..'f' | 'A'..'F' | '_')+) | "0x" ('0'..'9' | 'a'..'f' | 'A'..'F')+ | '0'..'9'+;
'0'..'9'+ '\'b' ('0' | '1' | '_')+ |
'0'..'9'+ '\'o' ('0'..'7' | '_')+ |
'0'..'9'+ '\'h' ('0'..'9' | 'a'..'f' | 'A'..'F' | '_')+ |
'0'..'9'+ '\'d' ('0'..'9' | '_')+ |
'0x' ('0'..'9' | 'a'..'f' | 'A'..'F')+ |
'0'..'9'+
;
terminal STR:
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"' //|
// "'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
;

View File

@ -0,0 +1,37 @@
/*
* generated by Xtext 2.12.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);
}
// 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

@ -0,0 +1,15 @@
/*
* generated by Xtext 2.12.0
*/
package com.minres.rdl
/**
* Initialization support for running Xtext languages without Equinox extension registry.
*/
class RDLStandaloneSetup extends RDLStandaloneSetupGenerated {
def static void doSetup() {
new RDLStandaloneSetup().createInjectorAndDoEMFRegistration()
}
}

View File

@ -0,0 +1,21 @@
package com.minres.rdl;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.scoping.impl.ImportUriResolver;
public class RdlImportUriResolver extends ImportUriResolver {
private static final Logger LOGGER = Logger.getLogger(RdlImportUriResolver.class);
public RdlImportUriResolver() {
super();
LOGGER.setLevel(Level.INFO);
}
@Override
public String resolve(EObject object) {
return super.resolve(object);
}
}

View File

@ -0,0 +1,18 @@
package com.minres.rdl.converter
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter
import org.eclipse.xtext.nodemodel.INode
class IDValueConverter extends AbstractLexerBasedConverter<String> {
override protected String toEscapedString(String value) {
return value
}
override String toValue(String string, INode node) {
if(string.startsWith('\\'))
return string.substring(1)
else
return string
}
}

View File

@ -0,0 +1,29 @@
package com.minres.rdl.converter
import org.eclipse.xtext.conversion.ValueConverterException
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter
import org.eclipse.xtext.nodemodel.INode
import org.eclipse.xtext.util.Strings
import com.minres.rdl.IntegerWithRadix
package class NUMValueConverter extends AbstractLexerBasedConverter<IntegerWithRadix> {
override protected String toEscapedString(IntegerWithRadix value) {
return value.toString()
}
override protected void assertValidValue(IntegerWithRadix value) {
super.assertValidValue(value)
}
override IntegerWithRadix toValue(String string, INode node) throws ValueConverterException {
if(Strings.isEmpty(string)) throw new ValueConverterException(
"Couldn't convert empty string to an integer value.", node, null);
try {
return new IntegerWithRadix(string)
} catch (NumberFormatException e) {
throw new ValueConverterException('''Couldn't convert '«»«string»' to an integer value.''', node, e)
}
}
}

View File

@ -0,0 +1,27 @@
package com.minres.rdl.converter
import org.eclipse.xtext.common.services.DefaultTerminalConverters
import org.eclipse.xtext.conversion.IValueConverter
import org.eclipse.xtext.conversion.ValueConverter
import com.google.inject.Inject
import com.minres.rdl.IntegerWithRadix
class RdlTerminalConverters extends DefaultTerminalConverters {
@Inject NUMValueConverter numValueConverter
@Inject STRValueConverter stringConverter
@Inject IDValueConverter idConverter
@ValueConverter(rule="NUM") def IValueConverter<IntegerWithRadix> getNumValueConverter() {
return numValueConverter
}
@ValueConverter(rule = "STR") def IValueConverter<String> getStrValueConverter() {
return stringConverter;
}
@ValueConverter(rule = "ID") def IValueConverter<String> getIdValueConverter() {
return idConverter;
}
}

View File

@ -0,0 +1,15 @@
package com.minres.rdl.converter
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter
import org.eclipse.xtext.nodemodel.INode
class STRValueConverter extends AbstractLexerBasedConverter<String> {
override protected String toEscapedString(String value) {
return "\""+value+"\""
}
override String toValue(String string, INode node) {
return string.substring(1, string.length-1)
}
}

View File

@ -0,0 +1,30 @@
/*
* generated by Xtext
*/
package com.minres.rdl.formatting
import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter
import org.eclipse.xtext.formatting.impl.FormattingConfig
import com.google.inject.Inject;
import com.minres.rdl.services.RDLGrammarAccess
/**
* This class contains custom formatting description.
*
* see : http://www.eclipse.org/Xtext/documentation.html#formatting
* on how and when to use it
*
* Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example
*/
class RDLFormatter extends AbstractDeclarativeFormatter {
@Inject extension RDLGrammarAccess
override protected void configureFormatting(FormattingConfig c) {
// It's usually a good idea to activate the following three statements.
// They will add and preserve newlines around comments
c.setLinewrap(0, 1, 2).before(SL_COMMENTRule)
c.setLinewrap(0, 1, 2).before(ML_COMMENTRule)
c.setLinewrap(0, 1, 1).after(ML_COMMENTRule)
}
}

View File

@ -0,0 +1,25 @@
/*
* generated by Xtext 2.12.0
*/
package com.minres.rdl.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
/**
* Generates code from your model files on save.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
*/
class RDLGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// fsa.generateFile('greetings.txt', 'People to greet: ' +
// resource.allContents
// .filter(Greeting)
// .map[name]
// .join(', '))
}
}

View File

@ -0,0 +1,29 @@
package com.minres.rdl.messages;
import com.google.inject.Inject
import org.eclipse.xtext.GrammarUtil
import org.eclipse.xtext.IGrammarAccess
import org.eclipse.xtext.nodemodel.SyntaxErrorMessage
import org.eclipse.xtext.parser.antlr.SyntaxErrorMessageProvider
class RDLSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider {
public static val String USED_RESERVED_KEYWORD = "USED_RESERVED_KEYWORD"
@Inject IGrammarAccess grammarAccess
/**
* Customized error message for reserved keywords
*/
override getSyntaxErrorMessage(IParserErrorContext context) {
println context?.recognitionException?.class
val unexpectedText = context?.recognitionException?.token?.text
if (GrammarUtil::getAllKeywords(grammarAccess.getGrammar()).contains(unexpectedText)) {
println(context.defaultMessage)
return new SyntaxErrorMessage('''
"«unexpectedText»" is a reserved keyword which is not allowed as Identifier.
Please choose another word or alternatively confuse your co-workers by escaping it with the caret (^) character like this: "^«unexpectedText»".''',
USED_RESERVED_KEYWORD)
}
super.getSyntaxErrorMessage(context)
}
}

View File

@ -0,0 +1,12 @@
package com.minres.rdl.preferences;
/**
* Constant definitions for plug-in preferences
*/
public class PreferenceConstants {
public static final String P_GENERATE_CSV = "booleanCsvPreference";
public static final String P_ADDRESSUNIT = "choiceAddrunitPreference";
}

View File

@ -0,0 +1,41 @@
package com.minres.rdl.preferences;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
/**
* Class used to initialize default preference values.
*/
public class PreferenceInitializer extends AbstractPreferenceInitializer {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#
* initializeDefaultPreferences()
*/
public void initializeDefaultPreferences() {
IEclipsePreferences store = getPreferenceStore();
store.putBoolean(PreferenceConstants.P_GENERATE_CSV, true);
String value = System.getProperty("com.minres.rdl.rdl.addrunit");
if(value!=null){
if("byte".equals(value)){
store.put(PreferenceConstants.P_ADDRESSUNIT, "byte");
} else if("word".equals(value)){
store.put(PreferenceConstants.P_ADDRESSUNIT, "word");
} else if("dword".equals(value)){
store.put(PreferenceConstants.P_ADDRESSUNIT, "dword");
} else {
System.err.println("Unknown configuration value: '"+value+"', using 'byte'");
store.put(PreferenceConstants.P_ADDRESSUNIT, "byte");
}
} else
store.put(PreferenceConstants.P_ADDRESSUNIT, "byte");
}
public static IEclipsePreferences getPreferenceStore() {
return DefaultScope.INSTANCE.getNode("com.minres.rdl.rdl");
}
}

View File

@ -0,0 +1,19 @@
package com.minres.rdl.preferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
public class RdlPreferences {
public static boolean getGenerateCsv() {
return getPreferenceStore().getBoolean(PreferenceConstants.P_GENERATE_CSV, true);
}
public static String getAddrUnit() {
return getPreferenceStore().get(PreferenceConstants.P_ADDRESSUNIT, System.getProperty("com.minres.rdl.rdl.addrunit"));
}
public static IEclipsePreferences getPreferenceStore() {
return InstanceScope.INSTANCE.getNode("com.minres.rdl.rdl");
}
}

View File

@ -0,0 +1,162 @@
/*
* generated by Xtext 2.12.0
*/
package com.minres.rdl.scoping
import com.minres.rdl.rdl.ComponentDefinition
import com.minres.rdl.rdl.ComponentInstance
import com.minres.rdl.rdl.EnumDefinition
import com.minres.rdl.rdl.InstanceRef
import com.minres.rdl.rdl.NamedInstantiation
import com.minres.rdl.rdl.Root
import java.util.ArrayList
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.EcoreUtil2
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.Scopes
import org.eclipse.emf.ecore.resource.Resource
import java.util.List
/**
* This class contains custom scoping description.
*
* see : http://www.eclipse.org/Xtext/documentation.html#scoping
* on how and when to use it
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping
* on how and when to use it.
*
*/
class RDLScopeProvider extends AbstractRDLScopeProvider { //AbstractDeclarativeScopeProvider {
// override IScope getScope(EObject context, EReference reference){
//// println("scope_"+reference.EContainingClass.name+"_"+reference.name+"("+context.eClass.name+",..)")
// switch(context){
// InstanceRef:{
// var definition = context.componentDefinition
// val parent = context.eContainer()
// if (parent instanceof InstanceRef)
// definition = parent.instance.componentDefinition
// if (definition !== null)
// return getScopeWithInstancesAndEnums(definition)
// return IScope.NULLSCOPE
// }
// NamedInstantiation:{
// val componentDef = context.componentDefinition
// if(componentDef!==null)
// return getScopeWithComponentDefinition(componentDef)
// else
// return getScopeWithComponentDefinition(context.root)
// }
// }
// super.getScope(context, reference)
// }
dispatch def IScope getScopeWithComponentDefinition(ComponentDefinition componentDef){
return Scopes.scopeFor(componentDef.componentDefinitions, getScopeWithComponentDefinition(componentDef.eContainer))
}
dispatch def IScope getScopeWithComponentDefinition(Root root){
var compDefs = root.componentDefinitions
for (incl : root.includes) {
var resource = EcoreUtil2.getResource(root.eResource, incl.importURI);
val r = resource.contents.head as Root
compDefs+=r.componentDefinitions
}
return Scopes.scopeFor(compDefs)
}
dispatch def IScope getScopeWithInstancesAndEnums(ComponentDefinition componentDef){
var res = new ArrayList<ComponentInstance>()
for(NamedInstantiation inst:componentDef.namedInstantiations)
if(inst.componentInstances.size>0) res.addAll(inst.componentInstances)
for(ComponentDefinition definition:componentDef.componentDefinitions)
if(definition.immediateInstantiation!==null && definition.immediateInstantiation.componentInstances.size>0)
res.addAll(definition.immediateInstantiation.componentInstances)
return Scopes.scopeFor(res+componentDef.enumDefinitions, getScopeWithInstancesAndEnums(componentDef.eContainer))
}
dispatch def IScope getScopeWithInstancesAndEnums(Root root){
var res = new ArrayList<ComponentInstance>()
for(instantiation: root.namedInstantiations)
if(instantiation.componentInstances.size>0)
res.addAll(instantiation.componentInstances)
for(ComponentDefinition definition:root.componentDefinitions)
if(definition.immediateInstantiation!==null && definition.immediateInstantiation.componentInstances.size>0)
res.addAll(definition.immediateInstantiation.componentInstances)
var enums = EcoreUtil2.getAllContentsOfType(root, EnumDefinition)
for (incl : root.includes) {
val resource = EcoreUtil2.getResource(root.eResource, incl.importURI);
enums+=EcoreUtil2.getAllContentsOfType(resource.contents.head as Root, EnumDefinition)
}
return Scopes.scopeFor(res+enums)
}
private def Root root(EObject definition){
var container = definition.eContainer
while(!(container instanceof Root)) container=container.eContainer
return container as Root
}
private def ComponentDefinition componentDefinition(EObject obj){
var container = obj.eContainer
while(!(container instanceof Root)){
if(container instanceof NamedInstantiation) return container.component
if(container instanceof ComponentDefinition) return container
container=container.eContainer
}
return null
}
// dispatch def Iterable<ComponentDefinition> allComponentDefinitions(ComponentDefinition definition){
// return definition.componentDefinitions + definition.eContainer.allComponentDefinitions
// }
//
// dispatch def Iterable<? extends ComponentDefinition> allComponentDefinitions(Root root){
// var compDefs = root.componentDefinitions
// for (incl : root.includes) {
// var resource = EcoreUtil2.getResource(root.eResource, incl.importURI);
// val r = resource.contents.head as Root
// compDefs+=r.allComponentDefinitions
// }
// return compDefs
// }
// dispatch def Iterable<EnumDefinition> allEnumDefinitions(ComponentDefinition componentDefinition){
// return componentDefinition.enumDefinitions + componentDefinition.eContainer.allEnumDefinitions
// }
//
// dispatch def Iterable<EnumDefinition> allEnumDefinitions(Root root){
// var List<Resource> res1=newArrayList()
// res1+=root.eResource
// var enums = EcoreUtil2.getAllContentsOfType(root, EnumDefinition)
// for (incl : root.includes) {
// val resource = EcoreUtil2.getResource(root.eResource, incl.importURI);
// enums+=(resource.contents.head as Root).allEnumDefinitions
// }
// return enums
// }
//
// private def Iterable<ComponentInstance> allInstances(ComponentDefinition componentDefinition){
// var res = new ArrayList<ComponentInstance>()
// for(NamedInstantiation inst:componentDefinition.namedInstantiations)
// if(inst.componentInstances.size>0) res.addAll(inst.componentInstances)
// for(ComponentDefinition definition:componentDefinition.componentDefinitions)
// if(definition.immediateInstantiation!==null && definition.immediateInstantiation.componentInstances.size>0)
// res.addAll(definition.immediateInstantiation.componentInstances)
// if(componentDefinition.eContainer instanceof ComponentDefinition) {
// res.addAll((componentDefinition.eContainer as ComponentDefinition).allInstances)
// } else if(componentDefinition.eContainer instanceof Root){
// var root = componentDefinition.eContainer as Root
// for(instantiation: root.namedInstantiations)
// if(instantiation.componentInstances.size>0)
// res.addAll(instantiation.componentInstances)
// for(ComponentDefinition definition:root.componentDefinitions)
// if(definition.immediateInstantiation!==null && definition.immediateInstantiation.componentInstances.size>0)
// res.addAll(definition.immediateInstantiation.componentInstances)
// }
// return res
// }
}

View File

@ -0,0 +1,25 @@
/*
* generated by Xtext 2.12.0
*/
package com.minres.rdl.validation
/**
* This class contains custom validation rules.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
*/
class RDLValidator extends AbstractRDLValidator {
// public static val INVALID_NAME = 'invalidName'
//
// @Check
// def checkGreetingStartsWithCapital(Greeting greeting) {
// if (!Character.isUpperCase(greeting.name.charAt(0))) {
// warning('Name should start with a capital',
// RDLPackage.Literals.GREETING__NAME,
// INVALID_NAME)
// }
// }
}