mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
moved 'FlattenedGrammarAccess' to o.e.xtext.xtext
This makes it accessible for the serializer Signed-off-by: Moritz Eysholdt <moritz.eysholdt@itemis.de>
This commit is contained in:
parent
71c030d1f9
commit
23a90dc931
8 changed files with 41 additions and 45 deletions
|
@ -32,7 +32,6 @@ Export-Package: org.eclipse.xtext.xtext.generator,
|
|||
org.eclipse.xtext.xtext.generator.idea,
|
||||
org.eclipse.xtext.xtext.generator.idea.parser.antlr,
|
||||
org.eclipse.xtext.xtext.generator.model,
|
||||
org.eclipse.xtext.xtext.generator.normalization;x-friends:="org.eclipse.xtext.tests,org.eclipse.xtext.idea.generator,org.eclipse.xtext.generator",
|
||||
org.eclipse.xtext.xtext.generator.parser.antlr,
|
||||
org.eclipse.xtext.xtext.generator.parser.antlr.splitting;x-friends:="org.eclipse.xtext.generator,org.eclipse.xtext.tests",
|
||||
org.eclipse.xtext.xtext.generator.parser.antlr.splitting.internal;x-friends:="org.eclipse.xtext.tests",
|
||||
|
|
|
@ -23,14 +23,14 @@ import org.eclipse.xtext.ParserRule
|
|||
import org.eclipse.xtext.RuleCall
|
||||
import org.eclipse.xtext.TerminalRule
|
||||
import org.eclipse.xtext.UnorderedGroup
|
||||
import org.eclipse.xtext.xtext.FlattenedGrammarAccess
|
||||
import org.eclipse.xtext.xtext.RuleFilter
|
||||
import org.eclipse.xtext.xtext.RuleNames
|
||||
import org.eclipse.xtext.xtext.generator.CodeConfig
|
||||
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming
|
||||
import org.eclipse.xtext.xtext.generator.grammarAccess.GrammarAccessExtensions
|
||||
import org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference
|
||||
import org.eclipse.xtext.xtext.generator.normalization.FlattenedGrammarAccess
|
||||
import org.eclipse.xtext.xtext.generator.normalization.RuleFilter
|
||||
|
||||
import static extension org.eclipse.xtext.GrammarUtil.*
|
||||
import static extension org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.*
|
||||
|
|
|
@ -35,10 +35,10 @@ import org.eclipse.xtext.util.Strings;
|
|||
import org.eclipse.xtext.util.XtextSwitch;
|
||||
import org.eclipse.xtext.xbase.lib.Functions;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xtext.OriginalElement;
|
||||
import org.eclipse.xtext.xtext.OriginalGrammar;
|
||||
import org.eclipse.xtext.xtext.RuleNames;
|
||||
import org.eclipse.xtext.xtext.generator.normalization.OriginalElement;
|
||||
import org.eclipse.xtext.xtext.generator.normalization.OriginalGrammar;
|
||||
import org.eclipse.xtext.xtext.generator.normalization.RuleWithParameterValues;
|
||||
import org.eclipse.xtext.xtext.RuleWithParameterValues;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.generator.normalization
|
||||
package org.eclipse.xtext.xtext
|
||||
|
||||
import com.google.common.collect.HashMultimap
|
||||
import com.google.common.collect.ImmutableSet
|
||||
|
@ -35,11 +35,8 @@ import org.eclipse.xtext.RuleCall
|
|||
import org.eclipse.xtext.TerminalRule
|
||||
import org.eclipse.xtext.XtextPackage
|
||||
import org.eclipse.xtext.util.internal.EmfAdaptable
|
||||
import org.eclipse.xtext.xtext.ConditionEvaluator
|
||||
import org.eclipse.xtext.xtext.RuleNames
|
||||
import org.eclipse.xtext.xtext.UsedRulesFinder
|
||||
|
||||
import static extension org.eclipse.xtext.xtext.generator.normalization.RuleWithParameterValues.*
|
||||
import static extension org.eclipse.xtext.xtext.RuleWithParameterValues.*
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
|
@ -74,8 +71,9 @@ class FlattenedGrammarAccess {
|
|||
}
|
||||
|
||||
def private void setHiddenTokens(
|
||||
Grammar copy, Grammar orig,
|
||||
Map<RuleWithParameterValues, AbstractRule> origToCopy
|
||||
Grammar copy,
|
||||
Grammar orig,
|
||||
Map<RuleWithParameterValues, AbstractRule> origToCopy
|
||||
) {
|
||||
if (orig === null) {
|
||||
copy.definesHiddenTokens = true
|
||||
|
@ -84,26 +82,26 @@ class FlattenedGrammarAccess {
|
|||
} else {
|
||||
copy.definesHiddenTokens = true
|
||||
copy.hiddenTokens += orig.hiddenTokens.map [ hidden |
|
||||
origToCopy.get(new RuleWithParameterValues(hidden))
|
||||
origToCopy.get(new RuleWithParameterValues(hidden))
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
def private void markAsFragment(Multimap<TerminalRule, AbstractRule> calledFrom) {
|
||||
calledFrom.keySet.filter[
|
||||
calledFrom.keySet.filter [
|
||||
!isFragment
|
||||
].filter[
|
||||
].filter [
|
||||
allAreTerminalRules(calledFrom.get(it))
|
||||
].filter[
|
||||
].filter [
|
||||
!(it.eContainer as Grammar).hiddenTokens.contains(it)
|
||||
].forEach[
|
||||
fragment=true
|
||||
].forEach [
|
||||
fragment = true
|
||||
]
|
||||
}
|
||||
|
||||
def private Multimap<TerminalRule, AbstractRule> copyRuleBodies(
|
||||
List<AbstractRule> copies,
|
||||
Map<RuleWithParameterValues, AbstractRule> origToCopy
|
||||
List<AbstractRule> copies,
|
||||
Map<RuleWithParameterValues, AbstractRule> origToCopy
|
||||
) {
|
||||
val calledFrom = HashMultimap.create()
|
||||
for (copy : copies) {
|
||||
|
@ -115,7 +113,8 @@ class FlattenedGrammarAccess {
|
|||
var origRuleCall = eObject as RuleCall
|
||||
var copyRuleCall = copyEObject as RuleCall
|
||||
var calledCopy = origToCopy.get(
|
||||
new RuleWithParameterValues(origRuleCall.getRule(), getParameterConfig(origRuleCall, copyRuleCall)))
|
||||
new RuleWithParameterValues(origRuleCall.getRule(),
|
||||
getParameterConfig(origRuleCall, copyRuleCall)))
|
||||
copyRuleCall.rule = calledCopy
|
||||
if (calledCopy instanceof TerminalRule) {
|
||||
calledFrom.put(calledCopy, copy)
|
||||
|
@ -126,17 +125,17 @@ class FlattenedGrammarAccess {
|
|||
}
|
||||
|
||||
def private Set<Parameter> getParameterConfig(RuleCall origRuleCall, RuleCall copyRuleCall) {
|
||||
if(origRuleCall.getArguments().isEmpty())
|
||||
if (origRuleCall.getArguments().isEmpty())
|
||||
return Collections.emptySet()
|
||||
var result = origRuleCall.arguments.filter [ value.evaluate ].map[ parameter ].toSet
|
||||
var result = origRuleCall.arguments.filter[value.evaluate].map[parameter].toSet
|
||||
return result
|
||||
}
|
||||
|
||||
override protected void copyContainment(EReference eReference, EObject eObject, EObject copyEObject) {
|
||||
switch(eReference) {
|
||||
switch (eReference) {
|
||||
case XtextPackage.Literals.RULE_CALL__ARGUMENTS,
|
||||
case XtextPackage.Literals.GROUP__GUARD_CONDITION: return
|
||||
default: super.copyContainment(eReference, eObject, copyEObject)
|
||||
default: super.copyContainment(eReference, eObject, copyEObject)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +170,8 @@ class FlattenedGrammarAccess {
|
|||
if (eObject instanceof AbstractElement) {
|
||||
var original = new OriginalElement(eObject)
|
||||
if (eObject.eClass != result.eClass) {
|
||||
throw new IllegalStateException("copy is: '" + result.eClass.name + "' but original was: '" + eObject.eClass.name + "'")
|
||||
throw new IllegalStateException(
|
||||
"copy is: '" + result.eClass.name + "' but original was: '" + eObject.eClass.name + "'")
|
||||
}
|
||||
original.attachToEmfObject(result)
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ class FlattenedGrammarAccess {
|
|||
case c1 == '+' && c2 == '?',
|
||||
case c1 == '?' && c2 == '+': '*'
|
||||
case null: c2
|
||||
default: c1
|
||||
default: c1
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ class FlattenedGrammarAccess {
|
|||
copy.attachTo(rule, origToCopy)
|
||||
result += copy
|
||||
} else {
|
||||
Sets.powerSet(ImmutableSet.copyOf(params)).forEach[ parameterConfig, i |
|
||||
Sets.powerSet(ImmutableSet.copyOf(params)).forEach [ parameterConfig, i |
|
||||
var parameterValues = new RuleWithParameterValues(rule, parameterConfig)
|
||||
var copy = copy(rule)
|
||||
copy.name = names.getAntlrRuleName(rule, i)
|
||||
|
@ -271,7 +271,7 @@ class FlattenedGrammarAccess {
|
|||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
def private attachTo(AbstractRule copy, AbstractRule orig, Map<RuleWithParameterValues, AbstractRule> origToCopy) {
|
||||
var parameterValues = new RuleWithParameterValues(orig)
|
||||
parameterValues.attachToEmfObject(copy)
|
||||
|
@ -279,7 +279,7 @@ class FlattenedGrammarAccess {
|
|||
}
|
||||
|
||||
def private boolean allAreTerminalRules(Collection<AbstractRule> callers) {
|
||||
return callers.forall[ it instanceof TerminalRule ]
|
||||
return callers.forall[it instanceof TerminalRule]
|
||||
}
|
||||
|
||||
def private <T extends EObject> T copy(T t) {
|
|
@ -5,12 +5,12 @@
|
|||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator.normalization
|
||||
package org.eclipse.xtext.xtext
|
||||
|
||||
import org.eclipse.xtext.util.internal.EmfAdaptable
|
||||
import org.eclipse.xtend.lib.annotations.Data
|
||||
import org.eclipse.xtext.AbstractElement
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.util.internal.EmfAdaptable
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
|
@ -5,7 +5,7 @@
|
|||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator.normalization;
|
||||
package org.eclipse.xtext.xtext;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.generator.normalization
|
||||
package org.eclipse.xtext.xtext
|
||||
|
||||
import java.util.Collections
|
||||
import java.util.Set
|
||||
|
@ -15,7 +15,6 @@ import org.eclipse.xtext.AbstractRule
|
|||
import org.eclipse.xtext.Parameter
|
||||
import org.eclipse.xtext.ParserRule
|
||||
import org.eclipse.xtext.util.internal.EmfAdaptable
|
||||
import org.eclipse.xtext.xtext.ParameterConfigHelper
|
||||
|
||||
/**
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
|
@ -27,16 +26,17 @@ class RuleWithParameterValues {
|
|||
val Set<Parameter> paramValues
|
||||
|
||||
@FinalFieldsConstructor
|
||||
new() {}
|
||||
|
||||
new() {
|
||||
}
|
||||
|
||||
package new(AbstractRule original) {
|
||||
this(original, Collections.<Parameter>emptySet())
|
||||
}
|
||||
|
||||
|
||||
def static AbstractRule getOriginalRule(AbstractRule copy) {
|
||||
return findInEmfObject(copy).getOriginal()
|
||||
}
|
||||
|
||||
|
||||
def static AbstractRule tryGetOriginalRule(AbstractRule copy) {
|
||||
return findInEmfObject(copy)?.getOriginal()
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class RuleWithParameterValues {
|
|||
def static Set<Parameter> getParamValues(AbstractRule copy) {
|
||||
return findInEmfObject(copy).getParamValues()
|
||||
}
|
||||
|
||||
|
||||
def static int getParamConfig(AbstractRule copy) {
|
||||
val values = findInEmfObject(copy)
|
||||
return ParameterConfigHelper.getParameterConfig(values.paramValues, values.original as ParserRule)
|
|
@ -5,16 +5,13 @@
|
|||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.generator
|
||||
package org.eclipse.xtext.xtext
|
||||
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.XtextStandaloneSetup
|
||||
import org.eclipse.xtext.junit4.AbstractXtextTests
|
||||
import org.eclipse.xtext.resource.XtextResource
|
||||
import org.eclipse.xtext.xtext.RuleNames
|
||||
import org.eclipse.xtext.xtext.generator.normalization.FlattenedGrammarAccess
|
||||
import org.eclipse.xtext.xtext.generator.normalization.RuleFilter
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
Loading…
Reference in a new issue