use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class AssignmentFinder method findValidAssignmentsForContainmentRef.
protected Set<AbstractElement> findValidAssignmentsForContainmentRef(EObject semanticObj, Multimap<AbstractElement, ISerializationContext> assignments, EObject value) {
Multimap<ISerializationContext, AbstractElement> children = ArrayListMultimap.create();
for (Entry<AbstractElement, Collection<ISerializationContext>> e : assignments.asMap().entrySet()) {
AbstractElement ele = e.getKey();
if (ele instanceof RuleCall) {
EClassifier classifier = ((RuleCall) ele).getRule().getType().getClassifier();
if (!classifier.isInstance(value))
continue;
}
for (ISerializationContext container : e.getValue()) {
ISerializationContext child = SerializationContext.forChild(container, ele, value);
children.put(child, ele);
}
}
if (children.size() < 2)
return Sets.newHashSet(children.values());
Set<ISerializationContext> found = contextFinder.findByContents(value, children.keySet());
Set<AbstractElement> result = Sets.newLinkedHashSet();
for (ISerializationContext ctx : children.keySet()) if (found.contains(ctx))
result.addAll(children.get(ctx));
return result;
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class NodeModelSemanticSequencer method acceptSemantic.
protected boolean acceptSemantic(EObject semanticObject, AbstractElement ele, Object value, INode node) {
Assignment ass = GrammarUtil.containingAssignment(ele);
int index = -2;
if (ass != null) {
EStructuralFeature feat = semanticObject.eClass().getEStructuralFeature(ass.getFeature());
if (feat != null) {
if (feat.isMany())
index = ((List<?>) semanticObject.eGet(feat)).indexOf(value);
else
index = -1;
}
}
String token = node.getText().trim();
if (ele instanceof Action) {
if (((Action) ele).getFeature() != null) {
if (sequenceAcceptor.enterAssignedAction((Action) ele, (EObject) value, (ICompositeNode) node)) {
createSequence(ele, (EObject) value);
sequenceAcceptor.leaveAssignedAction((Action) ele, (EObject) value);
}
return true;
}
} else if (GrammarUtil.containingCrossReference(ele) != null) {
if (ele instanceof RuleCall) {
RuleCall rc = (RuleCall) ele;
if (rc.getRule() instanceof ParserRule) {
sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index, (ICompositeNode) node);
return true;
}
if (rc.getRule() instanceof TerminalRule) {
sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, (ILeafNode) node);
return true;
}
if (rc.getRule() instanceof EnumRule) {
sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, (ICompositeNode) node);
return true;
}
// } else if (ele instanceof Keyword) {
// acceptor.acceptAssignedCrossRefKeyword((Keyword) ele, token, (EObject) value, index,(ILeafNode) node);
// return true;
}
} else if (ass != null) {
if (ele instanceof RuleCall) {
RuleCall rc = (RuleCall) ele;
if (rc.getRule() instanceof ParserRule) {
if (rc.getRule().getType().getClassifier() instanceof EClass) {
if (sequenceAcceptor.enterAssignedParserRuleCall(rc, (EObject) value, (ICompositeNode) node)) {
createSequence(rc.getRule(), (EObject) value);
sequenceAcceptor.leaveAssignedParserRuleCall(rc, (EObject) value);
}
} else
sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, (ICompositeNode) node);
return true;
}
if (rc.getRule() instanceof TerminalRule) {
sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, (ILeafNode) node);
return true;
}
if (rc.getRule() instanceof EnumRule) {
sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, (ICompositeNode) node);
return true;
}
} else if (ele instanceof Keyword) {
if (GrammarUtil.isBooleanAssignment(ass))
sequenceAcceptor.acceptAssignedKeyword((Keyword) ele, token, true, index, (ILeafNode) node);
else
sequenceAcceptor.acceptAssignedKeyword((Keyword) ele, token, (String) value, index, (ILeafNode) node);
return true;
}
}
return false;
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class DebugGraphGenerator method generateDebugGraphs.
public Iterable<Pair<String, String>> generateDebugGraphs() {
final ArrayList<Pair<String, String>> result = CollectionLiterals.<Pair<String, String>>newArrayList();
@Extension final NamedSerializationContextProvider names = new NamedSerializationContextProvider(this.grammar);
final String dir_context = this.directory("context");
final String dir_context_type = this.directory("context_type");
final String dir_syntactic_sequencer = this.directory("syntactic_sequencer");
final String dir_semantic_sequencer = this.directory("semantic_sequencer");
List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextPDAProvider.getContextPDAs(this.grammar));
for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e : _namedContexts) {
{
String _name = e.getName();
String _plus = (dir_context + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.pdaToDot, e.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e.getName();
String _plus_2 = (dir_context + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts_1 = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextTypePDAProvider.getContextTypePDAs(this.grammar));
for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e_1 : _namedContexts_1) {
{
String _name = e_1.getName();
String _plus = (dir_context_type + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.pdaToDot, e_1.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_1.getName();
String _plus_2 = (dir_context_type + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_1.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState>> _namedContexts_2 = names.<ISyntacticSequencerPDAProvider.ISynAbsorberState>getNamedContexts(this.syntacticSequencerPDAProvider.getSyntacticSequencerPDAs(this.grammar));
for (final NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState> e_2 : _namedContexts_2) {
{
String _name = e_2.getName();
String _plus = (dir_syntactic_sequencer + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.syntacticSequencerPDA2Dot, e_2.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_2.getName();
String _plus_2 = (dir_syntactic_sequencer + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_2.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>>> _namedContexts_3 = names.<Nfa<ISemanticSequencerNfaProvider.ISemState>>getNamedContexts(this.semanticSequencerNFAProvider.getSemanticSequencerNFAs(this.grammar));
for (final NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>> e_3 : _namedContexts_3) {
{
String _name = e_3.getName();
String _plus = (dir_semantic_sequencer + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.nfaToDot, e_3.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_3.getName();
String _plus_2 = (dir_semantic_sequencer + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_3.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
try {
int i = 0;
final HashMap<ISyntacticSequencerPDAProvider.ISynTransition, String> trans2id = CollectionLiterals.<ISyntacticSequencerPDAProvider.ISynTransition, String>newHashMap();
Set<ISyntacticSequencerPDAProvider.ISynTransition> _allAmbiguousTransitions = this.syntacticSequencerUtil.getAllAmbiguousTransitions();
for (final ISyntacticSequencerPDAProvider.ISynTransition transition : _allAmbiguousTransitions) {
{
final String name = ("ambiguity_" + Integer.valueOf(i));
String _directory = this.directory("syntactic_sequencer");
String _plus = (_directory + name);
String _plus_1 = (_plus + ".dot");
String _draw = this.nfaToDot.draw(transition.getAmbiguousNfa());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _draw);
result.add(_mappedTo);
trans2id.put(transition, name);
i = (i + 1);
}
}
final StringBuffer ambiguities = new StringBuffer();
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax = this.syntacticSequencerUtil.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group : _allAmbiguousTransitionsBySyntax) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("id: ");
String _identifier = group.getIdentifier();
_builder.append(_identifier);
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("Ambiguous syntax:�:");
_builder.newLine();
_builder.append(" ");
String _replace = group.getElementAlias().toString().replace("\n", "\n ");
_builder.append(_replace, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("This ambiguous syntax occurs at:");
_builder.newLine();
{
List<ISyntacticSequencerPDAProvider.ISynTransition> _transitions = group.getTransitions();
for (final ISyntacticSequencerPDAProvider.ISynTransition trans : _transitions) {
_builder.append("\t");
String _get = trans2id.get(trans);
_builder.append(_get, "\t");
_builder.append(":");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(" ");
String _replace_1 = group.ambiguityInsideTransition(trans).replace("\n", "\n ");
_builder.append(_replace_1, "\t ");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.newLine();
ambiguities.append(_builder);
}
String _directory = this.directory("syntactic_sequencer");
String _plus = (_directory + "ambiguities.txt");
String _string = ambiguities.toString();
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus, _string);
result.add(_mappedTo);
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e_4 = (Exception) _t;
e_4.printStackTrace();
} else {
throw Exceptions.sneakyThrow(_t);
}
}
return result;
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class FlattenedGrammarAccess method copyRuleBodies.
private Multimap<TerminalRule, AbstractRule> copyRuleBodies(final List<AbstractRule> copies, final Map<RuleWithParameterValues, AbstractRule> origToCopy) {
abstract class __FlattenedGrammarAccess_1 extends EcoreUtil.Copier {
final __FlattenedGrammarAccess_1 _this__FlattenedGrammarAccess_1 = this;
abstract Set<Parameter> getParameterConfig(final RuleCall origRuleCall, final RuleCall copyRuleCall);
abstract void mergePredicates(final AbstractElement into, final AbstractElement from);
abstract void mergeCardinalities(final AbstractElement into, final AbstractElement from);
abstract boolean evaluate(final Condition condition);
}
final HashMultimap<TerminalRule, AbstractRule> calledFrom = HashMultimap.<TerminalRule, AbstractRule>create();
for (final AbstractRule copy : copies) {
{
AbstractRule orig = RuleWithParameterValues.getOriginalRule(copy);
final Set<Parameter> paramValues = RuleWithParameterValues.getParamValues(copy);
EcoreUtil.Copier copier = new __FlattenedGrammarAccess_1() {
@Override
protected void copyReference(final EReference eReference, final EObject eObject, final EObject copyEObject) {
if ((eReference == XtextPackage.Literals.RULE_CALL__RULE)) {
RuleCall origRuleCall = ((RuleCall) eObject);
RuleCall copyRuleCall = ((RuleCall) copyEObject);
AbstractRule _rule = origRuleCall.getRule();
Set<Parameter> _parameterConfig = this.getParameterConfig(origRuleCall, copyRuleCall);
RuleWithParameterValues _ruleWithParameterValues = new RuleWithParameterValues(_rule, _parameterConfig);
AbstractRule calledCopy = origToCopy.get(_ruleWithParameterValues);
copyRuleCall.setRule(calledCopy);
if ((calledCopy instanceof TerminalRule)) {
calledFrom.put(((TerminalRule) calledCopy), copy);
}
} else {
super.copyReference(eReference, eObject, copyEObject);
}
}
Set<Parameter> getParameterConfig(final RuleCall origRuleCall, final RuleCall copyRuleCall) {
boolean _isEmpty = origRuleCall.getArguments().isEmpty();
if (_isEmpty) {
return Collections.<Parameter>emptySet();
}
final Function1<NamedArgument, Boolean> _function = (NamedArgument it) -> {
return Boolean.valueOf(this.evaluate(it.getValue()));
};
final Function1<NamedArgument, Parameter> _function_1 = (NamedArgument it) -> {
return it.getParameter();
};
Set<Parameter> result = IterableExtensions.<Parameter>toSet(IterableExtensions.<NamedArgument, Parameter>map(IterableExtensions.<NamedArgument>filter(origRuleCall.getArguments(), _function), _function_1));
return result;
}
@Override
protected void copyContainment(final EReference eReference, final EObject eObject, final EObject copyEObject) {
boolean _matched = false;
if (Objects.equal(eReference, XtextPackage.Literals.RULE_CALL__ARGUMENTS)) {
_matched = true;
}
if (!_matched) {
if (Objects.equal(eReference, XtextPackage.Literals.GROUP__GUARD_CONDITION)) {
_matched = true;
}
}
if (_matched) {
return;
}
super.copyContainment(eReference, eObject, copyEObject);
}
@Override
public EObject copy(final EObject eObject) {
if ((eObject instanceof Group)) {
Group group = ((Group) eObject);
Condition _guardCondition = group.getGuardCondition();
boolean _tripleNotEquals = (_guardCondition != null);
if (_tripleNotEquals) {
boolean _evaluate = this.evaluate(group.getGuardCondition());
boolean _not = (!_evaluate);
if (_not) {
return null;
}
}
}
EObject result = super.copy(eObject);
if ((result instanceof CompoundElement)) {
List<AbstractElement> elements = ((CompoundElement) result).getElements();
int _size = elements.size();
boolean _tripleEquals = (_size == 1);
if (_tripleEquals) {
if (((!((CompoundElement) result).isFirstSetPredicated()) && (!((CompoundElement) result).isPredicated()))) {
AbstractElement element = elements.get(0);
this.mergeCardinalities(element, ((AbstractElement) result));
this.mergePredicates(element, ((AbstractElement) result));
return element;
} else {
AbstractElement element_1 = elements.get(0);
this.mergePredicates(((AbstractElement) result), element_1);
element_1.setFirstSetPredicated(false);
element_1.setPredicated(false);
}
}
}
if ((eObject instanceof AbstractElement)) {
OriginalElement original = new OriginalElement(((AbstractElement) eObject));
EClass _eClass = ((AbstractElement) eObject).eClass();
EClass _eClass_1 = result.eClass();
boolean _notEquals = (!Objects.equal(_eClass, _eClass_1));
if (_notEquals) {
String _name = result.eClass().getName();
String _plus = ("copy is: \'" + _name);
String _plus_1 = (_plus + "\' but original was: \'");
String _name_1 = ((AbstractElement) eObject).eClass().getName();
String _plus_2 = (_plus_1 + _name_1);
String _plus_3 = (_plus_2 + "\'");
throw new IllegalStateException(_plus_3);
}
original.attachToEmfObject(result);
}
return result;
}
void mergePredicates(final AbstractElement into, final AbstractElement from) {
boolean _isPredicated = from.isPredicated();
if (_isPredicated) {
into.setPredicated(true);
into.setFirstSetPredicated(false);
} else {
if (((!into.isPredicated()) && from.isFirstSetPredicated())) {
into.setFirstSetPredicated(true);
}
}
}
void mergeCardinalities(final AbstractElement into, final AbstractElement from) {
String c1 = into.getCardinality();
String c2 = from.getCardinality();
String _switchResult = null;
boolean _matched = false;
if ((Objects.equal(c1, "*") || Objects.equal(c2, "*"))) {
_matched = true;
}
if (!_matched) {
if ((Objects.equal(c1, "+") && Objects.equal(c2, "?"))) {
_matched = true;
}
}
if (!_matched) {
if ((Objects.equal(c1, "?") && Objects.equal(c2, "+"))) {
_matched = true;
}
}
if (_matched) {
_switchResult = "*";
}
if (!_matched) {
if (Objects.equal(c1, null)) {
_matched = true;
_switchResult = c2;
}
}
if (!_matched) {
_switchResult = c1;
}
into.setCardinality(_switchResult);
}
boolean evaluate(final Condition condition) {
boolean result = new ConditionEvaluator(paramValues).evaluate(condition);
return result;
}
};
EObject _copy = copier.copy(orig.getAlternatives());
AbstractElement copiedBody = ((AbstractElement) _copy);
copier.copyReferences();
copy.setAlternatives(copiedBody);
if ((orig instanceof ParserRule)) {
ParserRule castedCopy = ((ParserRule) copy);
boolean _isDefinesHiddenTokens = ((ParserRule) orig).isDefinesHiddenTokens();
if (_isDefinesHiddenTokens) {
castedCopy.setDefinesHiddenTokens(true);
EList<AbstractRule> _hiddenTokens = ((ParserRule) orig).getHiddenTokens();
for (final AbstractRule rule : _hiddenTokens) {
{
RuleWithParameterValues _ruleWithParameterValues = new RuleWithParameterValues(rule);
final AbstractRule copiedTerminalRule = origToCopy.get(_ruleWithParameterValues);
EList<AbstractRule> _hiddenTokens_1 = castedCopy.getHiddenTokens();
_hiddenTokens_1.add(copiedTerminalRule);
calledFrom.put(((TerminalRule) copiedTerminalRule), castedCopy);
}
}
}
}
}
}
return calledFrom;
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class LazyLinkerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
with(new AbstractModule() {
@Override
protected void configure() {
bind(EPackage.Registry.class).toInstance(EPackage.Registry.INSTANCE);
bind(IGrammarAccess.class).toInstance(new IGrammarAccess() {
@Override
public List<Pair<Keyword, Keyword>> findKeywordPairs(String leftKw, String rightKw) {
return Collections.emptyList();
}
@Override
public List<Keyword> findKeywords(String... keywords) {
return Collections.emptyList();
}
@Override
public List<RuleCall> findRuleCalls(AbstractRule... rules) {
return Collections.emptyList();
}
@Override
public Grammar getGrammar() {
return XtextFactory.eINSTANCE.createGrammar();
}
});
}
});
linker = get(LazyLinker.class);
resourceSet = get(XtextResourceSet.class);
resourceSet.setClasspathURIContext(getClass());
lazyLinkingPackage = (EPackage) resourceSet.getResource(URI.createURI("classpath:/org/eclipse/xtext/linking/lazy/LazyLinking.ecore"), true).getContents().get(0);
}
Aggregations