use of org.eclipse.xtext.Keyword 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.Keyword in project xtext-core by eclipse.
the class AbstractElementFinder method findKeywords.
public List<Keyword> findKeywords(String... keywords) {
Set<String> kwds = new HashSet<String>(Arrays.asList(keywords));
ArrayList<Keyword> r = new ArrayList<Keyword>();
for (AbstractRule ar : getRules()) {
TreeIterator<EObject> i = ar.eAllContents();
while (i.hasNext()) {
EObject o = i.next();
if (o instanceof Keyword) {
Keyword k = (Keyword) o;
if (kwds.contains(k.getValue()))
r.add(k);
}
}
}
return r;
}
use of org.eclipse.xtext.Keyword 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);
}
use of org.eclipse.xtext.Keyword in project xtext-core by eclipse.
the class NodeModelTest method testKeywordInAlternative.
@Test
public void testKeywordInAlternative() throws Exception {
with(SimpleExpressionsTestLanguageStandaloneSetup.class);
EObject object = getModel("d / e");
ICompositeNode root = NodeModelUtils.getNode(object).getRootNode();
List<ILeafNode> nodes = Lists.newArrayList(root.getLeafNodes());
assertTrue(nodes.get(2).getGrammarElement() instanceof Keyword);
}
use of org.eclipse.xtext.Keyword in project n4js by eclipse.
the class N4JSSyntaxValidator method doFindLeafWithKeyword.
/**
* Returns the first keyword with the given value, or null if no such keyword is found.
*/
private ILeafNode doFindLeafWithKeyword(EObject semanticElement, String stopAtKeyword, ICompositeNode node, String keyWord, boolean commaAlternative, int hitNumber) {
EObject grammarElement;
int foundHits = 0;
for (BidiTreeIterator<INode> iter = node.getAsTreeIterable().iterator(); iter.hasNext(); ) {
INode child = iter.next();
EObject childSemElement = child.getSemanticElement();
if (child != node && childSemElement != null && childSemElement != semanticElement) {
iter.prune();
} else if (child instanceof ILeafNode) {
ILeafNode leaf = (ILeafNode) child;
grammarElement = leaf.getGrammarElement();
if (grammarElement instanceof Keyword) {
String value = ((Keyword) grammarElement).getValue();
if (stopAtKeyword.equals(value)) {
return null;
}
if (keyWord.equals(value)) {
if (grammarElement.eContainer() instanceof Alternatives) {
AbstractElement first = ((Alternatives) (grammarElement.eContainer())).getElements().get(0);
boolean inCommaAlternative = (first instanceof Keyword && ",".equals(((Keyword) first).getValue()));
if (inCommaAlternative == commaAlternative) {
foundHits++;
if (foundHits >= hitNumber) {
return leaf;
}
}
} else {
if (!commaAlternative) {
foundHits++;
if (foundHits >= hitNumber) {
return leaf;
}
}
}
}
}
}
}
return null;
}
Aggregations