[eclipse/xtext-eclipse#1547] enhance ecore2xtext generator & xtext2ecore transformer for reserved keywords in enums

Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
Christian Dietrich 2020-09-23 13:38:13 +02:00
parent e04efb9af6
commit 56de6162c0
16 changed files with 160 additions and 93 deletions

View file

@ -43,6 +43,9 @@ import org.eclipse.xtext.xtext.XtextLinker
import org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformerTest.MyErrorAcceptor
import org.junit.Test
import org.eclipse.xtext.xtext.XtextLinker.PackageRemover
import org.eclipse.xtext.EnumRule
import org.eclipse.xtext.EnumLiteralDeclaration
import org.eclipse.xtext.Alternatives
/**
* @author Jan Köhnlein - Initial contribution and API
@ -1562,6 +1565,26 @@ class Xtext2EcoreTransformerTest extends AbstractXtextTests {
createdType.feature("otherEnumFeature").
EType)
}
@Test def void testEclipseIssue1547() throws Exception {
var String grammarAsString = '''
grammar test with org.eclipse.xtext.common.Terminals
generate myDsl 'uri'
Model: element=Element;
enum Element : ^false='false' | true='true';
'''
var XtextResource resource = getResourceFromString(grammarAsString)
var Grammar g = (resource.getContents().get(0) as Grammar)
var EnumRule enumRule = (g.getRules().get(1) as EnumRule)
var EnumLiteralDeclaration eld1 = (((enumRule.getAlternatives() as Alternatives)).getElements().
get(0) as EnumLiteralDeclaration)
var EnumLiteralDeclaration eld2 = (((enumRule.getAlternatives() as Alternatives)).getElements().
get(1) as EnumLiteralDeclaration)
assertEquals("false", eld1.getEnumLiteral().getName())
assertEquals("true", eld2.getEnumLiteral().getName())
}
@Test def void testBug310122() throws Exception {
val grammarAsString = '''

View file

@ -25,8 +25,12 @@ import org.eclipse.emf.ecore.resource.ContentHandler;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.AbstractElement;
import org.eclipse.xtext.AbstractMetamodelDeclaration;
import org.eclipse.xtext.AbstractRule;
import org.eclipse.xtext.Alternatives;
import org.eclipse.xtext.EnumLiteralDeclaration;
import org.eclipse.xtext.EnumRule;
import org.eclipse.xtext.GeneratedMetamodel;
import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.GrammarUtil;
@ -2091,6 +2095,33 @@ public class Xtext2EcoreTransformerTest extends AbstractXtextTests {
this.<EStructuralFeature>feature(createdType, "otherEnumFeature").getEType());
}
@Test
public void testEclipseIssue1547() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate myDsl \'uri\'");
_builder.newLine();
_builder.append("Model: element=Element;");
_builder.newLine();
_builder.append("enum Element : ^false=\'false\' | true=\'true\';");
_builder.newLine();
String grammarAsString = _builder.toString();
XtextResource resource = this.getResourceFromString(grammarAsString);
EObject _get = resource.getContents().get(0);
Grammar g = ((Grammar) _get);
AbstractRule _get_1 = g.getRules().get(1);
EnumRule enumRule = ((EnumRule) _get_1);
AbstractElement _alternatives = enumRule.getAlternatives();
AbstractElement _get_2 = ((Alternatives) _alternatives).getElements().get(0);
EnumLiteralDeclaration eld1 = ((EnumLiteralDeclaration) _get_2);
AbstractElement _alternatives_1 = enumRule.getAlternatives();
AbstractElement _get_3 = ((Alternatives) _alternatives_1).getElements().get(1);
EnumLiteralDeclaration eld2 = ((EnumLiteralDeclaration) _get_3);
Assert.assertEquals("false", eld1.getEnumLiteral().getName());
Assert.assertEquals("true", eld2.getEnumLiteral().getName());
}
@Test
public void testBug310122() throws Exception {
StringConcatenation _builder = new StringConcatenation();

View file

@ -9874,9 +9874,9 @@ rule__EnumLiteralDeclaration__EnumLiteralAssignment_0
(
{ before(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralCrossReference_0_0()); }
(
{ before(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralIDTerminalRuleCall_0_0_1()); }
RULE_ID
{ after(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralIDTerminalRuleCall_0_0_1()); }
{ before(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralValidIDParserRuleCall_0_0_1()); }
ruleValidID
{ after(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralValidIDParserRuleCall_0_0_1()); }
)
{ after(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralCrossReference_0_0()); }
)

View file

@ -25048,7 +25048,7 @@ public class InternalXtextParser extends AbstractInternalContentAssistParser {
// InternalXtext.g:8036:1: ( rule__EnumRule__Group__4__Impl rule__EnumRule__Group__5 )
// InternalXtext.g:8037:2: rule__EnumRule__Group__4__Impl rule__EnumRule__Group__5
{
pushFollow(FollowSets000.FOLLOW_15);
pushFollow(FollowSets000.FOLLOW_3);
rule__EnumRule__Group__4__Impl();
state._fsp--;
@ -25801,7 +25801,7 @@ public class InternalXtextParser extends AbstractInternalContentAssistParser {
// InternalXtext.g:8286:1: ( rule__EnumLiterals__Group_1_1__0__Impl rule__EnumLiterals__Group_1_1__1 )
// InternalXtext.g:8287:2: rule__EnumLiterals__Group_1_1__0__Impl rule__EnumLiterals__Group_1_1__1
{
pushFollow(FollowSets000.FOLLOW_15);
pushFollow(FollowSets000.FOLLOW_3);
rule__EnumLiterals__Group_1_1__0__Impl();
state._fsp--;
@ -30009,25 +30009,29 @@ public class InternalXtextParser extends AbstractInternalContentAssistParser {
// $ANTLR start "rule__EnumLiteralDeclaration__EnumLiteralAssignment_0"
// InternalXtext.g:9869:1: rule__EnumLiteralDeclaration__EnumLiteralAssignment_0 : ( ( RULE_ID ) ) ;
// InternalXtext.g:9869:1: rule__EnumLiteralDeclaration__EnumLiteralAssignment_0 : ( ( ruleValidID ) ) ;
public final void rule__EnumLiteralDeclaration__EnumLiteralAssignment_0() throws RecognitionException {
int stackSize = keepStackSize();
try {
// InternalXtext.g:9873:1: ( ( ( RULE_ID ) ) )
// InternalXtext.g:9874:2: ( ( RULE_ID ) )
// InternalXtext.g:9873:1: ( ( ( ruleValidID ) ) )
// InternalXtext.g:9874:2: ( ( ruleValidID ) )
{
// InternalXtext.g:9874:2: ( ( RULE_ID ) )
// InternalXtext.g:9875:3: ( RULE_ID )
// InternalXtext.g:9874:2: ( ( ruleValidID ) )
// InternalXtext.g:9875:3: ( ruleValidID )
{
before(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralCrossReference_0_0());
// InternalXtext.g:9876:3: ( RULE_ID )
// InternalXtext.g:9877:4: RULE_ID
// InternalXtext.g:9876:3: ( ruleValidID )
// InternalXtext.g:9877:4: ruleValidID
{
before(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralIDTerminalRuleCall_0_0_1());
match(input,RULE_ID,FollowSets000.FOLLOW_2);
after(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralIDTerminalRuleCall_0_0_1());
before(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralValidIDParserRuleCall_0_0_1());
pushFollow(FollowSets000.FOLLOW_2);
ruleValidID();
state._fsp--;
after(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralValidIDParserRuleCall_0_0_1());
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
@ -211,7 +211,7 @@ class Ecore2XtextExtensions {
}
def static boolean needsAssignment(EStructuralFeature it) {
!derived && !transient && !((it instanceof EReference) && EReference.cast(it).container) &&
changeable && !derived && !transient && !((it instanceof EReference) && EReference.cast(it).container) &&
!((it.getEType instanceof EDataType) && !EDataType.cast(it.getEType).serializable);
}

View file

@ -130,7 +130,7 @@ import org.eclipse.xtext.xtext.wizard.WizardConfiguration
'''
EEnum:
'''enum «name.quoteIfNeccesary» returns «fqn»:
«it.ELiterals.map([name+" = '"+name+"'"]).join(' | ')»;'''
«it.ELiterals.map([name.quoteIfNeccesary+" = '"+name+"'"]).join(' | ')»;'''
EDataType:
if (it.serializable) {
'''

View file

@ -1,5 +1,5 @@
/**
* Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2015, 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
@ -394,7 +394,7 @@ public class Ecore2XtextExtensions {
}
public static boolean needsAssignment(final EStructuralFeature it) {
return ((((!it.isDerived()) && (!it.isTransient())) && (!((it instanceof EReference) && EReference.class.cast(it).isContainer()))) &&
return ((((it.isChangeable() && (!it.isDerived())) && (!it.isTransient())) && (!((it instanceof EReference) && EReference.class.cast(it).isContainer()))) &&
(!((it.getEType() instanceof EDataType) && (!EDataType.class.cast(it.getEType()).isSerializable()))));
}

View file

@ -378,10 +378,10 @@ public class Ecore2XtextGrammarCreator {
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t\t");
final Function1<EEnumLiteral, String> _function = (EEnumLiteral it_1) -> {
String _quoteIfNeccesary_1 = Ecore2XtextExtensions.quoteIfNeccesary(it_1.getName());
String _plus = (_quoteIfNeccesary_1 + " = \'");
String _name = it_1.getName();
String _plus = (_name + " = \'");
String _name_1 = it_1.getName();
String _plus_1 = (_plus + _name_1);
String _plus_1 = (_plus + _name);
return (_plus_1 + "\'");
};
String _join = IterableExtensions.join(ListExtensions.<EEnumLiteral, String>map(((EEnum)it).getELiterals(), _function), " | ");

View file

@ -3719,9 +3719,12 @@ ruleEnumLiteralDeclaration returns [EObject current=null]
$current = createModelElement(grammarAccess.getEnumLiteralDeclarationRule());
}
}
otherlv_0=RULE_ID
{
newLeafNode(otherlv_0, grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralCrossReference_0_0());
newCompositeNode(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralCrossReference_0_0());
}
ruleValidID
{
afterParserOrEnumRuleCall();
}
)
)

View file

@ -899,10 +899,10 @@ public class InternalXtextLexer extends Lexer {
try {
int _type = RULE_ID;
int _channel = DEFAULT_TOKEN_CHANNEL;
// InternalXtext.g:3756:9: ( ( '^' )? ( 'a' .. 'z' | 'A' .. 'Z' | '_' ) ( 'a' .. 'z' | 'A' .. 'Z' | '_' | '0' .. '9' )* )
// InternalXtext.g:3756:11: ( '^' )? ( 'a' .. 'z' | 'A' .. 'Z' | '_' ) ( 'a' .. 'z' | 'A' .. 'Z' | '_' | '0' .. '9' )*
// InternalXtext.g:3759:9: ( ( '^' )? ( 'a' .. 'z' | 'A' .. 'Z' | '_' ) ( 'a' .. 'z' | 'A' .. 'Z' | '_' | '0' .. '9' )* )
// InternalXtext.g:3759:11: ( '^' )? ( 'a' .. 'z' | 'A' .. 'Z' | '_' ) ( 'a' .. 'z' | 'A' .. 'Z' | '_' | '0' .. '9' )*
{
// InternalXtext.g:3756:11: ( '^' )?
// InternalXtext.g:3759:11: ( '^' )?
int alt1=2;
int LA1_0 = input.LA(1);
@ -911,7 +911,7 @@ public class InternalXtextLexer extends Lexer {
}
switch (alt1) {
case 1 :
// InternalXtext.g:3756:11: '^'
// InternalXtext.g:3759:11: '^'
{
match('^');
@ -929,7 +929,7 @@ public class InternalXtextLexer extends Lexer {
recover(mse);
throw mse;}
// InternalXtext.g:3756:40: ( 'a' .. 'z' | 'A' .. 'Z' | '_' | '0' .. '9' )*
// InternalXtext.g:3759:40: ( 'a' .. 'z' | 'A' .. 'Z' | '_' | '0' .. '9' )*
loop2:
do {
int alt2=2;
@ -978,10 +978,10 @@ public class InternalXtextLexer extends Lexer {
try {
int _type = RULE_INT;
int _channel = DEFAULT_TOKEN_CHANNEL;
// InternalXtext.g:3758:10: ( ( '0' .. '9' )+ )
// InternalXtext.g:3758:12: ( '0' .. '9' )+
// InternalXtext.g:3761:10: ( ( '0' .. '9' )+ )
// InternalXtext.g:3761:12: ( '0' .. '9' )+
{
// InternalXtext.g:3758:12: ( '0' .. '9' )+
// InternalXtext.g:3761:12: ( '0' .. '9' )+
int cnt3=0;
loop3:
do {
@ -995,7 +995,7 @@ public class InternalXtextLexer extends Lexer {
switch (alt3) {
case 1 :
// InternalXtext.g:3758:13: '0' .. '9'
// InternalXtext.g:3761:13: '0' .. '9'
{
matchRange('0','9');
@ -1027,10 +1027,10 @@ public class InternalXtextLexer extends Lexer {
try {
int _type = RULE_STRING;
int _channel = DEFAULT_TOKEN_CHANNEL;
// InternalXtext.g:3760:13: ( ( '\"' ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )* '\"' | '\\'' ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )* '\\'' ) )
// InternalXtext.g:3760:15: ( '\"' ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )* '\"' | '\\'' ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )* '\\'' )
// InternalXtext.g:3763:13: ( ( '\"' ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )* '\"' | '\\'' ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )* '\\'' ) )
// InternalXtext.g:3763:15: ( '\"' ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )* '\"' | '\\'' ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )* '\\'' )
{
// InternalXtext.g:3760:15: ( '\"' ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )* '\"' | '\\'' ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )* '\\'' )
// InternalXtext.g:3763:15: ( '\"' ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )* '\"' | '\\'' ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )* '\\'' )
int alt6=2;
int LA6_0 = input.LA(1);
@ -1048,10 +1048,10 @@ public class InternalXtextLexer extends Lexer {
}
switch (alt6) {
case 1 :
// InternalXtext.g:3760:16: '\"' ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )* '\"'
// InternalXtext.g:3763:16: '\"' ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )* '\"'
{
match('\"');
// InternalXtext.g:3760:20: ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )*
// InternalXtext.g:3763:20: ( '\\\\' . | ~ ( ( '\\\\' | '\"' ) ) )*
loop4:
do {
int alt4=3;
@ -1067,7 +1067,7 @@ public class InternalXtextLexer extends Lexer {
switch (alt4) {
case 1 :
// InternalXtext.g:3760:21: '\\\\' .
// InternalXtext.g:3763:21: '\\\\' .
{
match('\\');
matchAny();
@ -1075,7 +1075,7 @@ public class InternalXtextLexer extends Lexer {
}
break;
case 2 :
// InternalXtext.g:3760:28: ~ ( ( '\\\\' | '\"' ) )
// InternalXtext.g:3763:28: ~ ( ( '\\\\' | '\"' ) )
{
if ( (input.LA(1)>='\u0000' && input.LA(1)<='!')||(input.LA(1)>='#' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFF') ) {
input.consume();
@ -1100,10 +1100,10 @@ public class InternalXtextLexer extends Lexer {
}
break;
case 2 :
// InternalXtext.g:3760:48: '\\'' ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )* '\\''
// InternalXtext.g:3763:48: '\\'' ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )* '\\''
{
match('\'');
// InternalXtext.g:3760:53: ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )*
// InternalXtext.g:3763:53: ( '\\\\' . | ~ ( ( '\\\\' | '\\'' ) ) )*
loop5:
do {
int alt5=3;
@ -1119,7 +1119,7 @@ public class InternalXtextLexer extends Lexer {
switch (alt5) {
case 1 :
// InternalXtext.g:3760:54: '\\\\' .
// InternalXtext.g:3763:54: '\\\\' .
{
match('\\');
matchAny();
@ -1127,7 +1127,7 @@ public class InternalXtextLexer extends Lexer {
}
break;
case 2 :
// InternalXtext.g:3760:61: ~ ( ( '\\\\' | '\\'' ) )
// InternalXtext.g:3763:61: ~ ( ( '\\\\' | '\\'' ) )
{
if ( (input.LA(1)>='\u0000' && input.LA(1)<='&')||(input.LA(1)>='(' && input.LA(1)<='[')||(input.LA(1)>=']' && input.LA(1)<='\uFFFF') ) {
input.consume();
@ -1170,12 +1170,12 @@ public class InternalXtextLexer extends Lexer {
try {
int _type = RULE_ML_COMMENT;
int _channel = DEFAULT_TOKEN_CHANNEL;
// InternalXtext.g:3762:17: ( '/*' ( options {greedy=false; } : . )* '*/' )
// InternalXtext.g:3762:19: '/*' ( options {greedy=false; } : . )* '*/'
// InternalXtext.g:3765:17: ( '/*' ( options {greedy=false; } : . )* '*/' )
// InternalXtext.g:3765:19: '/*' ( options {greedy=false; } : . )* '*/'
{
match("/*");
// InternalXtext.g:3762:24: ( options {greedy=false; } : . )*
// InternalXtext.g:3765:24: ( options {greedy=false; } : . )*
loop7:
do {
int alt7=2;
@ -1200,7 +1200,7 @@ public class InternalXtextLexer extends Lexer {
switch (alt7) {
case 1 :
// InternalXtext.g:3762:52: .
// InternalXtext.g:3765:52: .
{
matchAny();
@ -1230,12 +1230,12 @@ public class InternalXtextLexer extends Lexer {
try {
int _type = RULE_SL_COMMENT;
int _channel = DEFAULT_TOKEN_CHANNEL;
// InternalXtext.g:3764:17: ( '//' (~ ( ( '\\n' | '\\r' ) ) )* ( ( '\\r' )? '\\n' )? )
// InternalXtext.g:3764:19: '//' (~ ( ( '\\n' | '\\r' ) ) )* ( ( '\\r' )? '\\n' )?
// InternalXtext.g:3767:17: ( '//' (~ ( ( '\\n' | '\\r' ) ) )* ( ( '\\r' )? '\\n' )? )
// InternalXtext.g:3767:19: '//' (~ ( ( '\\n' | '\\r' ) ) )* ( ( '\\r' )? '\\n' )?
{
match("//");
// InternalXtext.g:3764:24: (~ ( ( '\\n' | '\\r' ) ) )*
// InternalXtext.g:3767:24: (~ ( ( '\\n' | '\\r' ) ) )*
loop8:
do {
int alt8=2;
@ -1248,7 +1248,7 @@ public class InternalXtextLexer extends Lexer {
switch (alt8) {
case 1 :
// InternalXtext.g:3764:24: ~ ( ( '\\n' | '\\r' ) )
// InternalXtext.g:3767:24: ~ ( ( '\\n' | '\\r' ) )
{
if ( (input.LA(1)>='\u0000' && input.LA(1)<='\t')||(input.LA(1)>='\u000B' && input.LA(1)<='\f')||(input.LA(1)>='\u000E' && input.LA(1)<='\uFFFF') ) {
input.consume();
@ -1268,7 +1268,7 @@ public class InternalXtextLexer extends Lexer {
}
} while (true);
// InternalXtext.g:3764:40: ( ( '\\r' )? '\\n' )?
// InternalXtext.g:3767:40: ( ( '\\r' )? '\\n' )?
int alt10=2;
int LA10_0 = input.LA(1);
@ -1277,9 +1277,9 @@ public class InternalXtextLexer extends Lexer {
}
switch (alt10) {
case 1 :
// InternalXtext.g:3764:41: ( '\\r' )? '\\n'
// InternalXtext.g:3767:41: ( '\\r' )? '\\n'
{
// InternalXtext.g:3764:41: ( '\\r' )?
// InternalXtext.g:3767:41: ( '\\r' )?
int alt9=2;
int LA9_0 = input.LA(1);
@ -1288,7 +1288,7 @@ public class InternalXtextLexer extends Lexer {
}
switch (alt9) {
case 1 :
// InternalXtext.g:3764:41: '\\r'
// InternalXtext.g:3767:41: '\\r'
{
match('\r');
@ -1320,10 +1320,10 @@ public class InternalXtextLexer extends Lexer {
try {
int _type = RULE_WS;
int _channel = DEFAULT_TOKEN_CHANNEL;
// InternalXtext.g:3766:9: ( ( ' ' | '\\t' | '\\r' | '\\n' )+ )
// InternalXtext.g:3766:11: ( ' ' | '\\t' | '\\r' | '\\n' )+
// InternalXtext.g:3769:9: ( ( ' ' | '\\t' | '\\r' | '\\n' )+ )
// InternalXtext.g:3769:11: ( ' ' | '\\t' | '\\r' | '\\n' )+
{
// InternalXtext.g:3766:11: ( ' ' | '\\t' | '\\r' | '\\n' )+
// InternalXtext.g:3769:11: ( ' ' | '\\t' | '\\r' | '\\n' )+
int cnt11=0;
loop11:
do {
@ -1377,8 +1377,8 @@ public class InternalXtextLexer extends Lexer {
try {
int _type = RULE_ANY_OTHER;
int _channel = DEFAULT_TOKEN_CHANNEL;
// InternalXtext.g:3768:16: ( . )
// InternalXtext.g:3768:18: .
// InternalXtext.g:3771:16: ( . )
// InternalXtext.g:3771:18: .
{
matchAny();

View file

@ -9922,7 +9922,7 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
}
otherlv_5=(Token)match(input,25,FollowSets000.FOLLOW_13);
otherlv_5=(Token)match(input,25,FollowSets000.FOLLOW_3);
newLeafNode(otherlv_5, grammarAccess.getEnumRuleAccess().getColonKeyword_4());
@ -10090,7 +10090,7 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
case 1 :
// InternalXtext.g:3671:5: otherlv_2= '|' ( (lv_elements_3_0= ruleEnumLiteralDeclaration ) )
{
otherlv_2=(Token)match(input,30,FollowSets000.FOLLOW_13);
otherlv_2=(Token)match(input,30,FollowSets000.FOLLOW_3);
newLeafNode(otherlv_2, grammarAccess.getEnumLiteralsAccess().getVerticalLineKeyword_1_1_0());
@ -10203,11 +10203,10 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
// $ANTLR start "ruleEnumLiteralDeclaration"
// InternalXtext.g:3707:1: ruleEnumLiteralDeclaration returns [EObject current=null] : ( ( (otherlv_0= RULE_ID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )? ) ;
// InternalXtext.g:3707:1: ruleEnumLiteralDeclaration returns [EObject current=null] : ( ( ( ruleValidID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )? ) ;
public final EObject ruleEnumLiteralDeclaration() throws RecognitionException {
EObject current = null;
Token otherlv_0=null;
Token otherlv_1=null;
EObject lv_literal_2_0 = null;
@ -10216,26 +10215,33 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
enterRule();
try {
// InternalXtext.g:3713:2: ( ( ( (otherlv_0= RULE_ID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )? ) )
// InternalXtext.g:3714:2: ( ( (otherlv_0= RULE_ID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )? )
// InternalXtext.g:3713:2: ( ( ( ( ruleValidID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )? ) )
// InternalXtext.g:3714:2: ( ( ( ruleValidID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )? )
{
// InternalXtext.g:3714:2: ( ( (otherlv_0= RULE_ID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )? )
// InternalXtext.g:3715:3: ( (otherlv_0= RULE_ID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )?
// InternalXtext.g:3714:2: ( ( ( ruleValidID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )? )
// InternalXtext.g:3715:3: ( ( ruleValidID ) ) (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )?
{
// InternalXtext.g:3715:3: ( (otherlv_0= RULE_ID ) )
// InternalXtext.g:3716:4: (otherlv_0= RULE_ID )
// InternalXtext.g:3715:3: ( ( ruleValidID ) )
// InternalXtext.g:3716:4: ( ruleValidID )
{
// InternalXtext.g:3716:4: (otherlv_0= RULE_ID )
// InternalXtext.g:3717:5: otherlv_0= RULE_ID
// InternalXtext.g:3716:4: ( ruleValidID )
// InternalXtext.g:3717:5: ruleValidID
{
if (current==null) {
current = createModelElement(grammarAccess.getEnumLiteralDeclarationRule());
}
otherlv_0=(Token)match(input,RULE_ID,FollowSets000.FOLLOW_51);
newLeafNode(otherlv_0, grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralCrossReference_0_0());
newCompositeNode(grammarAccess.getEnumLiteralDeclarationAccess().getEnumLiteralEEnumLiteralCrossReference_0_0());
pushFollow(FollowSets000.FOLLOW_51);
ruleValidID();
state._fsp--;
afterParserOrEnumRuleCall();
}
@ -10243,7 +10249,7 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
}
// InternalXtext.g:3728:3: (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )?
// InternalXtext.g:3731:3: (otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) ) )?
int alt78=2;
int LA78_0 = input.LA(1);
@ -10252,17 +10258,17 @@ public class InternalXtextParser extends AbstractInternalAntlrParser {
}
switch (alt78) {
case 1 :
// InternalXtext.g:3729:4: otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) )
// InternalXtext.g:3732:4: otherlv_1= '=' ( (lv_literal_2_0= ruleKeyword ) )
{
otherlv_1=(Token)match(input,35,FollowSets000.FOLLOW_11);
newLeafNode(otherlv_1, grammarAccess.getEnumLiteralDeclarationAccess().getEqualsSignKeyword_1_0());
// InternalXtext.g:3733:4: ( (lv_literal_2_0= ruleKeyword ) )
// InternalXtext.g:3734:5: (lv_literal_2_0= ruleKeyword )
// InternalXtext.g:3736:4: ( (lv_literal_2_0= ruleKeyword ) )
// InternalXtext.g:3737:5: (lv_literal_2_0= ruleKeyword )
{
// InternalXtext.g:3734:5: (lv_literal_2_0= ruleKeyword )
// InternalXtext.g:3735:6: lv_literal_2_0= ruleKeyword
// InternalXtext.g:3737:5: (lv_literal_2_0= ruleKeyword )
// InternalXtext.g:3738:6: lv_literal_2_0= ruleKeyword
{
newCompositeNode(grammarAccess.getEnumLiteralDeclarationAccess().getLiteralKeywordParserRuleCall_1_1_0());

View file

@ -764,7 +764,7 @@ public class XtextSemanticSequencer extends AbstractDelegatingSemanticSequencer
* EnumLiteralDeclaration returns EnumLiteralDeclaration
*
* Constraint:
* (enumLiteral=[EEnumLiteral|ID] literal=Keyword?)
* (enumLiteral=[EEnumLiteral|ValidID] literal=Keyword?)
*/
protected void sequence_EnumLiteralDeclaration(ISerializationContext context, EnumLiteralDeclaration semanticObject) {
genericSequencer.createSequence(context, semanticObject);

View file

@ -2273,27 +2273,27 @@ public class XtextGrammarAccess extends AbstractElementFinder.AbstractGrammarEle
private final Group cGroup = (Group)rule.eContents().get(1);
private final Assignment cEnumLiteralAssignment_0 = (Assignment)cGroup.eContents().get(0);
private final CrossReference cEnumLiteralEEnumLiteralCrossReference_0_0 = (CrossReference)cEnumLiteralAssignment_0.eContents().get(0);
private final RuleCall cEnumLiteralEEnumLiteralIDTerminalRuleCall_0_0_1 = (RuleCall)cEnumLiteralEEnumLiteralCrossReference_0_0.eContents().get(1);
private final RuleCall cEnumLiteralEEnumLiteralValidIDParserRuleCall_0_0_1 = (RuleCall)cEnumLiteralEEnumLiteralCrossReference_0_0.eContents().get(1);
private final Group cGroup_1 = (Group)cGroup.eContents().get(1);
private final Keyword cEqualsSignKeyword_1_0 = (Keyword)cGroup_1.eContents().get(0);
private final Assignment cLiteralAssignment_1_1 = (Assignment)cGroup_1.eContents().get(1);
private final RuleCall cLiteralKeywordParserRuleCall_1_1_0 = (RuleCall)cLiteralAssignment_1_1.eContents().get(0);
//EnumLiteralDeclaration:
// enumLiteral=[ecore::EEnumLiteral] ('=' literal=Keyword)?;
// enumLiteral=[ecore::EEnumLiteral|ValidID] ('=' literal=Keyword)?;
@Override public ParserRule getRule() { return rule; }
//enumLiteral=[ecore::EEnumLiteral] ('=' literal=Keyword)?
//enumLiteral=[ecore::EEnumLiteral|ValidID] ('=' literal=Keyword)?
public Group getGroup() { return cGroup; }
//enumLiteral=[ecore::EEnumLiteral]
//enumLiteral=[ecore::EEnumLiteral|ValidID]
public Assignment getEnumLiteralAssignment_0() { return cEnumLiteralAssignment_0; }
//[ecore::EEnumLiteral]
//[ecore::EEnumLiteral|ValidID]
public CrossReference getEnumLiteralEEnumLiteralCrossReference_0_0() { return cEnumLiteralEEnumLiteralCrossReference_0_0; }
//ID
public RuleCall getEnumLiteralEEnumLiteralIDTerminalRuleCall_0_0_1() { return cEnumLiteralEEnumLiteralIDTerminalRuleCall_0_0_1; }
//ValidID
public RuleCall getEnumLiteralEEnumLiteralValidIDParserRuleCall_0_0_1() { return cEnumLiteralEEnumLiteralValidIDParserRuleCall_0_0_1; }
//('=' literal=Keyword)?
public Group getGroup_1() { return cGroup_1; }
@ -3049,7 +3049,7 @@ public class XtextGrammarAccess extends AbstractElementFinder.AbstractGrammarEle
}
//EnumLiteralDeclaration:
// enumLiteral=[ecore::EEnumLiteral] ('=' literal=Keyword)?;
// enumLiteral=[ecore::EEnumLiteral|ValidID] ('=' literal=Keyword)?;
public EnumLiteralDeclarationElements getEnumLiteralDeclarationAccess() {
return pEnumLiteralDeclaration;
}

View file

@ -269,5 +269,5 @@ EnumLiterals returns AbstractElement:
;
EnumLiteralDeclaration:
enumLiteral=[ecore::EEnumLiteral] ('=' literal=Keyword)?
enumLiteral=[ecore::EEnumLiteral|ValidID] ('=' literal=Keyword)?
;

View file

@ -343,7 +343,7 @@ public class Xtext2EcoreTransformer {
if (nodes.size() > 1)
throw new IllegalStateException("Unexpected nodes found: " + nodes);
INode node = nodes.get(0);
String text = node.getText();
String text = node.getText().trim().replace("^", "");
EEnumLiteral literal = null;
if (rule.getType().getMetamodel() instanceof ReferencedMetamodel) {
literal = returnType.getEEnumLiteral(text);