diff --git a/io.typefox.xtext2langium.tests/src/io/typefox/xtext2langium/tests/Xtext2LangiumMultiLangTest.xtend b/io.typefox.xtext2langium.tests/src/io/typefox/xtext2langium/tests/Xtext2LangiumMultiLangTest.xtend index 774c5dc..ee5d4ea 100644 --- a/io.typefox.xtext2langium.tests/src/io/typefox/xtext2langium/tests/Xtext2LangiumMultiLangTest.xtend +++ b/io.typefox.xtext2langium.tests/src/io/typefox/xtext2langium/tests/Xtext2LangiumMultiLangTest.xtend @@ -40,6 +40,34 @@ class Xtext2LangiumMultiLangTest extends AbstractXtext2LangiumTest { terminal ID returns string:'^'? ('a' ..'z' | 'A' ..'Z' | '_' )('a' ..'z' | 'A' ..'Z' | '_' | '0' ..'9' )* ; terminal INT returns number:'0' ..'9' +; ''') + assertGeneratedFile('Terminals.langium', ''' + + terminal ID returns string:'^'? ('a' ..'z' | 'A' ..'Z' | '_' )('a' ..'z' | 'A' ..'Z' | '_' | '0' ..'9' )* ; + terminal INT returns number:'0' ..'9' +; + terminal STRING returns string:'"' ('\\' . | !('\\' | '"' ))*'"' | "'" ('\\' . | !('\\' | "'" ))*"'" ; + hidden terminal ML_COMMENT returns string:'/*' -> '*/' ; + hidden terminal SL_COMMENT returns string:'//' !('\n' | '\r' )('\r'? '\n' )? ; + hidden terminal WS returns string:(' ' | '\t' | '\r' | '\n' )+; + terminal ANY_OTHER returns string:.; + ''') + } + @Test + def void testTerminals_02() { + ''' + grammar io.typefox.xtext2langium.Test with org.eclipse.xtext.common.Terminals + generate xtext2langiumTest 'http://Xtext2LangiumTest' + import "http://www.eclipse.org/emf/2002/Ecore" as ecore + + @Override + terminal ID: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*; + @Override + terminal INT returns ecore::EInt: ('0'..'9')+; + '''.assertGeneratedLangium(''' + import 'Terminals' + + terminal ID returns string:'^'? ('a' ..'z' | 'A' ..'Z' | '_' )('a' ..'z' | 'A' ..'Z' | '_' | '0' ..'9' )* ; + terminal INT returns number:'0' ..'9' +; + ''', [removeOverridenRules = true]) assertGeneratedFile('Terminals.langium', ''' terminal STRING returns string:'"' ('\\' . | !('\\' | '"' ))*'"' | "'" ('\\' . | !('\\' | "'" ))*"'" ; @@ -85,7 +113,7 @@ class Xtext2LangiumMultiLangTest extends AbstractXtext2LangiumTest { greetings+=Greeting * ; - ''') + ''', [conf | conf.removeOverridenRules = true]) assertGeneratedFile('uddl.langium', ''' grammar Uddl import 'Terminals' diff --git a/io.typefox.xtext2langium/src/io/typefox/xtext2langium/Xtext2LangiumFragment.xtend b/io.typefox.xtext2langium/src/io/typefox/xtext2langium/Xtext2LangiumFragment.xtend index 139b83d..d164ec5 100644 --- a/io.typefox.xtext2langium/src/io/typefox/xtext2langium/Xtext2LangiumFragment.xtend +++ b/io.typefox.xtext2langium/src/io/typefox/xtext2langium/Xtext2LangiumFragment.xtend @@ -71,13 +71,20 @@ class Xtext2LangiumFragment extends AbstractXtextGeneratorFragment { boolean useStringAsEnumRuleType = false /** - * If true, types from the ecore metamodel will also be generated.
+ * If true, types from the ecore metamodel will also be generated.
* If false, ecore data types will be replaced with Langium data types. * Types that are not convertable to Langium built in types will be generated as string.
- * Default is false.
+ * Default is false.
*/ @Accessors(PUBLIC_SETTER) boolean generateEcoreTypes = false + /** + * In case a rule from the imported grammar was overriden, Langium will report a duplicate error. + * If true, the super grammar rules will be skipped in favor of the current grammar rules.
+ * Default is false.
+ */ + @Accessors(PUBLIC_SETTER) + boolean removeOverridenRules = false static val INDENT = ' ' @@ -117,7 +124,7 @@ class Xtext2LangiumFragment extends AbstractXtextGeneratorFragment { var entryRuleCreated = false for (rule : grammarToGenerate.rules.filter [ rule | /* Filter out rules that were overridden by the sub grammar */ - subGrammar === null || !subGrammar.rules.exists[name == rule.name] + subGrammar === null || !removeOverridenRules || !subGrammar.rules.exists[name == rule.name] ]) { if (rule.eClass === PARSER_RULE && !entryRuleCreated) { ctx.out.append('entry ')