use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class AbstractInternalContentAssistParser method createLookAheadTerminal.
@Override
public LookAheadTerminal createLookAheadTerminal(Token token) {
Grammar grammar = getGrammar();
String tokenName = getTokenNames()[token.getType()];
tokenName = getValueForTokenName(tokenName);
if (tokenName.charAt(0) == '\'') {
LookaheadKeyword result = new LookaheadKeyword();
result.setKeyword(tokenName.substring(1, tokenName.length() - 1));
result.setToken(token);
return result;
}
LookAheadTerminalRuleCall result = new LookAheadTerminalRuleCall();
result.setToken(token);
String ruleName = TokenTool.getLexerRuleName(tokenName);
if (terminalRules == null)
terminalRules = GrammarUtil.allTerminalRules(grammar);
for (TerminalRule rule : terminalRules) {
if (rule.getName().equalsIgnoreCase(ruleName)) {
result.setRule(rule);
return result;
}
}
throw new IllegalArgumentException("tokenType " + token.getType() + " seems to be invalid.");
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class KeywordInspector method inspectKeywordHidesTerminalRule.
public void inspectKeywordHidesTerminalRule(Keyword keyword) {
AbstractRule container = GrammarUtil.containingRule(keyword);
if (container instanceof TerminalRule)
return;
Grammar grammar = GrammarUtil.getGrammar(container);
List<TerminalRule> rules = GrammarUtil.allTerminalRules(grammar);
for (TerminalRule rule : rules) {
if (!rule.isFragment()) {
AbstractElement element = rule.getAlternatives();
if (element instanceof Keyword && Strings.isEmpty(element.getCardinality())) {
String value = ((Keyword) element).getValue();
if (value.equals(keyword.getValue()))
acceptor.acceptError("The keyword '" + value + "' hides the terminal rule " + rule.getName() + ".", keyword, XtextPackage.Literals.KEYWORD__VALUE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null);
}
}
}
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class SuperCallScope method getElements.
@Override
public Iterable<IEObjectDescription> getElements(EObject object) {
if (object instanceof AbstractRule) {
Grammar grammar = GrammarUtil.getGrammar(context);
AbstractRule rule = (AbstractRule) object;
if (GrammarUtil.getGrammar(rule) == grammar) {
return Lists.newArrayList(EObjectDescription.create(GrammarUtil.getSimpleName(grammar) + "." + rule.getName(), rule), EObjectDescription.create(grammar.getName() + "." + rule.getName(), rule));
}
List<IEObjectDescription> result = Lists.newArrayList(EObjectDescription.create(SUPER + "." + rule.getName(), rule), EObjectDescription.create(GrammarUtil.getSimpleName(grammar) + "." + rule.getName(), rule), EObjectDescription.create(grammar.getName() + "." + rule.getName(), rule));
AbstractRule contextRule = GrammarUtil.containingRule(context);
if (contextRule != null && contextRule.getName().equals(rule.getName())) {
result.add(0, EObjectDescription.create(SUPER, rule));
}
return result;
}
return Collections.emptyList();
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class XtextFragmentProvider method getEObject.
@Override
public EObject getEObject(Resource resource, String fragment, IFragmentProvider.Fallback fallback) {
if (!fragment.startsWith(PREFIX))
return fallback.getEObject(fragment);
String fragmentWithoutPrefix = fragment.substring(PREFIX.length());
List<String> splitted = Strings.split(fragmentWithoutPrefix, '/');
if (splitted.isEmpty()) {
return fallback.getEObject(fragment);
}
String firstPart = splitted.get(0);
Grammar grammar = null;
for (EObject content : resource.getContents()) {
if (content instanceof Grammar) {
Grammar g = (Grammar) content;
if (firstPart.equals(g.getName())) {
grammar = g;
if (splitted.size() == 1)
return grammar;
break;
}
}
}
if (splitted.size() == 2) {
return GrammarUtil.findRuleForName(grammar, splitted.get(1));
} else {
return fallback.getEObject(fragment);
}
}
use of org.eclipse.xtext.Grammar in project xtext-core by eclipse.
the class XtextLinker method linkModel.
@Override
public void linkModel(EObject model, IDiagnosticConsumer consumer) {
if (model instanceof Grammar) {
final Xtext2EcoreTransformer transformer = createTransformer((Grammar) model, consumer);
// TODO duplicate
transformer.removeGeneratedPackages();
super.linkModel(model, consumer);
updateOverriddenRules((Grammar) model);
try {
transformer.transform();
} catch (Exception e) {
log.error(e.getMessage(), e);
consumer.consume(new ExceptionDiagnostic(e), Severity.ERROR);
}
if (!model.eResource().eAdapters().contains(packageRemover))
model.eResource().eAdapters().add(packageRemover);
} else {
super.linkModel(model, consumer);
}
}
Aggregations