org.eclipse.xtext.NegatedToken Java Examples

The following examples show how to use org.eclipse.xtext.NegatedToken. 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: TerminalRuleInterpreter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Boolean caseNegatedToken(NegatedToken object) {
	boolean result = false;
	OUTER: do {
		if (eof())
			break OUTER;
		IMarker marker = markerFactory.mark();
		if (!doSwitch(object.getTerminal())) {
			result = true;
			input.incOffset();
			continue OUTER;
		}
		marker.rollback();
		break OUTER;
	} while(GrammarUtil.isMultipleCardinality(object));
	return result || GrammarUtil.isOptionalCardinality(object);
}
 
Example #2
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testNegatedTokenNotEOF() throws Exception {
	String grammarAsText =
			"grammar test with org.eclipse.xtext.common.Terminals\n" +
			"generate test 'http://test'\n" +
			"A: foo=DUMMY;\n" +
			"terminal DUMMY: !EOF;";
	Grammar grammar = (Grammar) getModel(grammarAsText);
	XtextValidator validator = get(XtextValidator.class);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
	TerminalRule terminal = (TerminalRule) grammar.getRules().get(1);
	NegatedToken token = (NegatedToken)terminal.getAlternatives();
	messageAcceptor.expectedContext(token.getTerminal());
	configureValidator(validator, messageAcceptor, token);
	validator.checkNegatedTokenNotEOF(token);
	messageAcceptor.validate();
}
 
Example #3
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testNegatedTokenNotEOF_2() throws Exception {
	String grammarAsText =
			"grammar test with org.eclipse.xtext.common.Terminals\n" +
					"generate test 'http://test'\n" +
					"A: foo=DUMMY;\n" +
					"terminal DUMMY: !(EOF | ID);";
	Grammar grammar = (Grammar) getModel(grammarAsText);
	XtextValidator validator = get(XtextValidator.class);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
	TerminalRule terminal = (TerminalRule) grammar.getRules().get(1);
	NegatedToken token = (NegatedToken)terminal.getAlternatives();
	messageAcceptor.expectedContext(((Alternatives)token.getTerminal()).getElements().get(0));
	configureValidator(validator, messageAcceptor, token);
	validator.checkNegatedTokenNotEOF(token);
	messageAcceptor.validate();
}
 
Example #4
Source File: TerminalRuleToLexerBody.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String caseNegatedToken(NegatedToken object) {
	result.append("~(");
	doSwitch(object.getTerminal());
	result.append(")").append(Strings.emptyIfNull(object.getCardinality()));
	return "";
}
 
Example #5
Source File: XtextSemanticSequencer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Contexts:
 *     AbstractNegatedToken returns NegatedToken
 *     NegatedToken returns NegatedToken
 *
 * Constraint:
 *     terminal=TerminalTokenElement
 */
protected void sequence_NegatedToken(ISerializationContext context, NegatedToken semanticObject) {
	if (errorAcceptor != null) {
		if (transientValues.isValueTransient(semanticObject, XtextPackage.Literals.ABSTRACT_NEGATED_TOKEN__TERMINAL) == ValueTransient.YES)
			errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XtextPackage.Literals.ABSTRACT_NEGATED_TOKEN__TERMINAL));
	}
	SequenceFeeder feeder = createSequencerFeeder(context, semanticObject);
	feeder.accept(grammarAccess.getNegatedTokenAccess().getTerminalTerminalTokenElementParserRuleCall_1_0(), semanticObject.getTerminal());
	feeder.finish();
}
 
Example #6
Source File: TerminalRuleToLexerBody.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String caseNegatedToken(NegatedToken object) {
	result.append("~(");
	doSwitch(object.getTerminal());
	result.append(")").append(Strings.emptyIfNull(object.getCardinality()));
	return "";
}
 
Example #7
Source File: XtextLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
String text(NegatedToken object) {
	return "!";
}
 
Example #8
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Check
public void checkNegatedTokenNotEOF(NegatedToken token) {
	for (EOF eof : EcoreUtil2.getAllContentsOfType(token, EOF.class)) {
		error("It is not possible to negate EOF", eof, null);
	}
}
 
Example #9
Source File: XtextSemanticSequencer.java    From xtext-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Contexts:
 *     TerminalAlternatives returns NegatedToken
 *     TerminalAlternatives.Alternatives_1_0 returns NegatedToken
 *     TerminalGroup returns NegatedToken
 *     TerminalGroup.Group_1_0 returns NegatedToken
 *     TerminalToken returns NegatedToken
 *     TerminalTokenElement returns NegatedToken
 *     ParenthesizedTerminalElement returns NegatedToken
 *
 * Constraint:
 *     (terminal=TerminalTokenElement (cardinality='?' | cardinality='*' | cardinality='+')*)
 */
protected void sequence_NegatedToken_TerminalToken(ISerializationContext context, NegatedToken semanticObject) {
	genericSequencer.createSequence(context, semanticObject);
}