use of org.eclipse.xtext.TerminalRule in project xtext-core by eclipse.
the class XtextLinkerTest method testQualifiedRuleCall_02.
@Test
public void testQualifiedRuleCall_02() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate test \'http://test\'");
_builder.newLine();
_builder.append("Rule: name=ID;");
_builder.newLine();
_builder.append("terminal STRING: super;");
_builder.newLine();
final String grammarAsString = _builder.toString();
final XtextResource resource = this.getResourceFromString(grammarAsString);
EObject _get = resource.getContents().get(0);
Grammar grammar = ((Grammar) _get);
AbstractRule _get_1 = grammar.getRules().get(1);
final TerminalRule string = ((TerminalRule) _get_1);
AbstractElement _alternatives = string.getAlternatives();
final RuleCall callToSuper = ((RuleCall) _alternatives);
Assert.assertEquals(GrammarUtil.findRuleForName(IterableExtensions.<Grammar>head(grammar.getUsedGrammars()), "STRING"), callToSuper.getRule());
}
use of org.eclipse.xtext.TerminalRule in project xtext-core by eclipse.
the class CommentTest method testSingleLineComment.
@Test
public void testSingleLineComment() throws Exception {
String model = "// comment\n/*element foo;\nelement bar;*/";
INode node = getRootNode(model);
List<ILeafNode> leafNodes = Lists.newArrayList(node.getLeafNodes());
assertEquals(2, leafNodes.size());
assertTrue(leafNodes.get(0).getGrammarElement() instanceof TerminalRule);
assertTrue(leafNodes.get(1).getGrammarElement() instanceof TerminalRule);
}
use of org.eclipse.xtext.TerminalRule in project xtext-core by eclipse.
the class XtextValidationTest method testTerminalRuleNamingConventions.
@Test
public void testTerminalRuleNamingConventions() throws Exception {
String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "A : someFeature=New_Line;\n" + "terminal New_Line : '\n';";
Grammar grammar = (Grammar) getModel(grammarAsText);
TerminalRule rule = (TerminalRule) grammar.getRules().get(1);
XtextValidator validator = get(XtextValidator.class);
ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(rule, false, true);
configureValidator(validator, messageAcceptor, rule);
validator.checkTerminalRuleNamingConventions(rule);
messageAcceptor.validate();
}
use of org.eclipse.xtext.TerminalRule in project xtext-core by eclipse.
the class XtextValidationTest method testNegatedTokenNotEOF_2.
@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();
}
use of org.eclipse.xtext.TerminalRule in project xtext-core by eclipse.
the class PsiAntlrGrammarGenerator method _dataTypeEbnf2.
@Override
protected String _dataTypeEbnf2(final RuleCall it, final boolean supportActions) {
String _xifexpression = null;
if (supportActions) {
String _switchResult = null;
AbstractRule _rule = it.getRule();
boolean _matched = false;
if (_rule instanceof EnumRule) {
boolean _isAssigned = GrammarUtil.isAssigned(it);
if (_isAssigned) {
_matched = true;
}
}
if (!_matched) {
if (_rule instanceof ParserRule) {
boolean _isAssigned = GrammarUtil.isAssigned(it);
if (_isAssigned) {
_matched = true;
}
}
}
if (_matched) {
_switchResult = super._dataTypeEbnf2(it, supportActions);
}
if (!_matched) {
if (_rule instanceof EnumRule) {
_matched = true;
}
if (!_matched) {
if (_rule instanceof ParserRule) {
_matched = true;
}
}
if (_matched) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{");
_builder.newLine();
_builder.append("\t");
CharSequence _markComposite = this.markComposite(it);
_builder.append(_markComposite, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
String __dataTypeEbnf2 = super._dataTypeEbnf2(it, supportActions);
_builder.append(__dataTypeEbnf2);
_builder.newLineIfNotEmpty();
_builder.append("{");
_builder.newLine();
_builder.append("\t");
CharSequence _doneComposite = this.doneComposite(it);
_builder.append(_doneComposite, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
_switchResult = _builder.toString();
}
}
if (!_matched) {
if (_rule instanceof TerminalRule) {
_matched = true;
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("{");
_builder_1.newLine();
_builder_1.append("\t");
CharSequence _markLeaf = this.markLeaf(it);
_builder_1.append(_markLeaf, "\t");
_builder_1.newLineIfNotEmpty();
_builder_1.append("}");
_builder_1.newLine();
String _localVar = this._grammarAccessExtensions.localVar(it);
_builder_1.append(_localVar);
_builder_1.append("=");
String __dataTypeEbnf2_1 = super._dataTypeEbnf2(it, supportActions);
_builder_1.append(__dataTypeEbnf2_1);
_builder_1.newLineIfNotEmpty();
_builder_1.append("{");
_builder_1.newLine();
_builder_1.append("\t");
CharSequence _doneLeaf = this.doneLeaf(it, this._grammarAccessExtensions.localVar(it));
_builder_1.append(_doneLeaf, "\t");
_builder_1.newLineIfNotEmpty();
_builder_1.append("}");
_builder_1.newLine();
_switchResult = _builder_1.toString();
}
}
if (!_matched) {
_switchResult = super._dataTypeEbnf2(it, supportActions);
}
_xifexpression = _switchResult;
} else {
_xifexpression = super._dataTypeEbnf2(it, supportActions);
}
return _xifexpression;
}
Aggregations