org.eclipse.xtext.TerminalRule Java Examples

The following examples show how to use org.eclipse.xtext.TerminalRule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Do not propose terminal fragments in hidden token sections.
 */
protected void completeHiddenTokens(Assignment assignment, final ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	CrossReference crossReference = (CrossReference) assignment.getTerminal();
	lookupCrossReference(crossReference, context, acceptor, new Predicate<IEObjectDescription>() {
		@Override
		public boolean apply(IEObjectDescription input) {
			if (input.getEClass() == XtextPackage.Literals.TERMINAL_RULE) {
				EObject object = resolve(input, context);
				if (object instanceof TerminalRule)
					return !((TerminalRule) object).isFragment();
			}
			return false;
		}
	});
}
 
Example #2
Source File: KeywordInspector.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public void inspectKeywordHidesTerminalRule(Keyword keyword) {
	AbstractRule container = GrammarUtil.containingRule(keyword);
	if (container instanceof TerminalRule)
		return;
	Grammar grammar = GrammarUtil.getGrammar(container);
	List<TerminalRule> rules = cache.get(KeywordInspector.class, grammar.eResource(), ()->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);
			}
		}
	}
}
 
Example #3
Source File: Bug303200TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Inject
public Bug303200TestLanguageGrammarAccess(GrammarProvider grammarProvider) {
	this.grammar = internalFindGrammar(grammarProvider);
	this.pProgram = new ProgramElements();
	this.pProgramDirective = new ProgramDirectiveElements();
	this.pFunctionDefinition = new FunctionDefinitionElements();
	this.pAttribute = new AttributeElements();
	this.pParameters = new ParametersElements();
	this.pBlock = new BlockElements();
	this.pStatement = new StatementElements();
	this.pPostfixExpression = new PostfixExpressionElements();
	this.pListExpression = new ListExpressionElements();
	this.pPropertyOperator = new PropertyOperatorElements();
	this.pPrimaryExpression = new PrimaryExpressionElements();
	this.tID = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.xtext.ui.tests.editor.contentassist.Bug303200TestLanguage.ID");
	this.tWS = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.xtext.ui.tests.editor.contentassist.Bug303200TestLanguage.WS");
	this.tLT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.xtext.ui.tests.editor.contentassist.Bug303200TestLanguage.LT");
}
 
Example #4
Source File: FlattenedGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public FlattenedGrammarAccess(RuleNames names, RuleFilter filter) {
	Grammar grammar = names.getContextGrammar();
	Grammar flattenedGrammar = copy(grammar);
	flattenedGrammar.setName(grammar.getName());
	Map<RuleWithParameterValues, AbstractRule> origToCopy = new LinkedHashMap<>();
	List<AbstractRule> copies = copyRuleStubs(names, origToCopy, filter.getRules(grammar),
			filter.isDiscardRuleTypeRef());
	addAll(flattenedGrammar.getRules(), copies);
	Multimap<TerminalRule, AbstractRule> calledFrom = copyRuleBodies(copies, origToCopy);
	setHiddenTokens(flattenedGrammar, grammar, origToCopy);
	markAsFragment(calledFrom);
	if (filter.isDiscardUnreachableRules()) {
		Set<AbstractRule> usedRules = new HashSet<>();
		if (!filter.isDiscardTerminalRules())
			usedRules.addAll(GrammarUtil.allTerminalRules(flattenedGrammar));
		UsedRulesFinder finder = new UsedRulesFinder(usedRules);
		finder.compute(flattenedGrammar);
		flattenedGrammar.getRules().retainAll(usedRules);
	}
	this.flattenedGrammar = flattenedGrammar;
	new OriginalGrammar(grammar).attachToEmfObject(flattenedGrammar);
}
 
Example #5
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testCheckRuleCallInUnorderedGroup_04() throws Exception {
	XtextValidator validator = get(XtextValidator.class);
	UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
	RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
	TerminalRule terminalRule = XtextFactory.eINSTANCE.createTerminalRule();
	ruleCall.setRule(terminalRule);
	unorderedGroup.getElements().add(ruleCall);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkRuleCallInUnorderedGroup(ruleCall);
	messageAcceptor.validate();
}
 
Example #6
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkKeywordNoSpaces(final Keyword keyword) {
	if (keyword.getValue() != null && !(keyword.eContainer() instanceof EnumLiteralDeclaration) 
			&& !(GrammarUtil.containingRule(keyword) instanceof TerminalRule)) {
		if (keyword.getValue().contains(" ") || keyword.getValue().contains("\t")) {
			addIssue("A keyword should not contain spaces.", 
					keyword, 
					null,
					SPACES_IN_KEYWORD);
		}
	}
}
 
Example #7
Source File: SemverGrammarAccess.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public TerminalRule getDIGITSRule() {
	return tDIGITS;
}
 
Example #8
Source File: SingleCodetemplateGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getIDRule() {
	return gaCodetemplates.getIDRule();
}
 
Example #9
Source File: FormatterTestLanguage2GrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getINTRule() {
	return gaTerminals.getINTRule();
}
 
Example #10
Source File: Bug291022TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getANY_OTHERRule() {
	return gaTerminals.getANY_OTHERRule();
}
 
Example #11
Source File: ActionTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getSL_COMMENTRule() {
	return gaTerminals.getSL_COMMENTRule();
}
 
Example #12
Source File: ConcreteSyntaxValidationTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getINTRule() {
	return gaTerminals.getINTRule();
}
 
Example #13
Source File: UnorderedGroupsTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getIDRule() {
	return gaTerminals.getIDRule();
}
 
Example #14
Source File: Bug287988TestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getINTRule() {
	return gaTerminals.getINTRule();
}
 
Example #15
Source File: InheritanceTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getWSRule() {
	return gaTerminals.getWSRule();
}
 
Example #16
Source File: Bug377311TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getWSRule() {
	return tWS;
}
 
Example #17
Source File: MultiRuleEnumTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getSL_COMMENTRule() {
	return gaTerminals.getSL_COMMENTRule();
}
 
Example #18
Source File: Bug289187TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getSTRINGRule() {
	return gaTerminals.getSTRINGRule();
}
 
Example #19
Source File: CommentAssociationTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getSL_COMMENTRule() {
	return gaTerminals.getSL_COMMENTRule();
}
 
Example #20
Source File: LangATestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getML_COMMENTRule() {
	return gaTerminals.getML_COMMENTRule();
}
 
Example #21
Source File: LookaheadTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getSL_COMMENTRule() {
	return gaTerminals.getSL_COMMENTRule();
}
 
Example #22
Source File: RefactoringTestLanguage1GrammarAccess.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getIDRule() {
	return gaTerminals.getIDRule();
}
 
Example #23
Source File: MultiValueFeatureTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getML_COMMENTRule() {
	return gaTerminals.getML_COMMENTRule();
}
 
Example #24
Source File: RegularExpressionGrammarAccess.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public TerminalRule getUNICODE_DIGITRule() {
	return tUNICODE_DIGIT;
}
 
Example #25
Source File: TypeExpressionsGrammarAccess.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public TerminalRule getZWJRule() {
	return gaUnicode.getZWJRule();
}
 
Example #26
Source File: RegionAccessTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getANY_OTHERRule() {
	return gaTerminals.getANY_OTHERRule();
}
 
Example #27
Source File: FileAwareTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getANY_OTHERRule() {
	return gaTerminals.getANY_OTHERRule();
}
 
Example #28
Source File: PartialContentAssistTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getSTRINGRule() {
	return gaTerminals.getSTRINGRule();
}
 
Example #29
Source File: SuperTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TerminalRule getSL_COMMENTRule() {
	return gaTerminals.getSL_COMMENTRule();
}
 
Example #30
Source File: TypeExpressionsGrammarAccess.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public TerminalRule getDOT_DOTRule() {
	return tDOT_DOT;
}