use of org.eclipse.xtext.TerminalRule in project xtext-core by eclipse.
the class CommentOnEofBug_234135_Test method testCommentOnEof.
@Test
public void testCommentOnEof() throws Exception {
with(ReferenceGrammarTestLanguageStandaloneSetup.class);
String model = "//comment";
List<ILeafNode> leafNodes = Lists.newArrayList(getRootNode(model).getLeafNodes());
assertEquals(1, leafNodes.size());
EObject grammarElement = leafNodes.get(0).getGrammarElement();
assertNotNull(grammarElement);
assertTrue(grammarElement instanceof TerminalRule);
}
use of org.eclipse.xtext.TerminalRule in project xtext-core by eclipse.
the class SyntacticSequencerPDAProvider method getType.
protected SynStateType getType(ISerState state) {
switch(state.getType()) {
case ELEMENT:
AbstractElement ele = state.getGrammarElement();
Assignment ass;
if (ele instanceof Action) {
if (((Action) ele).getFeature() == null)
return SynStateType.UNASSIGEND_ACTION_CALL;
else
return SynStateType.ASSIGNED_ACTION_CALL;
} else if (GrammarUtil.containingCrossReference(ele) != null) {
if (ele instanceof RuleCall) {
RuleCall rc = (RuleCall) ele;
if (rc.getRule() instanceof ParserRule)
return SynStateType.ASSIGNED_CROSSREF_DATATYPE_RULE_CALL;
if (rc.getRule() instanceof TerminalRule)
return SynStateType.ASSIGNED_CROSSREF_TERMINAL_RULE_CALL;
if (rc.getRule() instanceof EnumRule)
return SynStateType.ASSIGNED_CROSSREF_ENUM_RULE_CALL;
} else if (ele instanceof Keyword)
return SynStateType.ASSIGNED_CROSSREF_KEYWORD;
} else if ((ass = GrammarUtil.containingAssignment(ele)) != null) {
if (ele instanceof RuleCall) {
RuleCall rc = (RuleCall) ele;
if (rc.getRule() instanceof ParserRule) {
if (rc.getRule().getType().getClassifier() instanceof EClass)
return SynStateType.ASSIGNED_PARSER_RULE_CALL;
return SynStateType.ASSIGNED_DATATYPE_RULE_CALL;
}
if (rc.getRule() instanceof TerminalRule)
return SynStateType.ASSIGNED_TERMINAL_RULE_CALL;
if (rc.getRule() instanceof EnumRule)
return SynStateType.ASSIGNED_ENUM_RULE_CALL;
} else if (ele instanceof Keyword) {
if (GrammarUtil.isBooleanAssignment(ass))
return SynStateType.ASSIGNED_BOOLEAN_KEYWORD;
else
return SynStateType.ASSIGNED_KEYWORD;
}
} else {
if (ele instanceof RuleCall) {
RuleCall rc = (RuleCall) ele;
if (rc.getRule() instanceof ParserRule)
return SynStateType.UNASSIGNED_DATATYPE_RULE_CALL;
if (rc.getRule() instanceof TerminalRule)
return SynStateType.UNASSIGNED_TERMINAL_RULE_CALL;
} else if (ele instanceof Keyword)
return SynStateType.UNASSIGEND_KEYWORD;
}
break;
case PUSH:
return SynStateType.UNASSIGNED_PARSER_RULE_ENTER;
case POP:
return SynStateType.UNASSIGNED_PARSER_RULE_EXIT;
case START:
return SynStateType.START;
case STOP:
return SynStateType.STOP;
}
throw new RuntimeException("no type found for " + state);
}
use of org.eclipse.xtext.TerminalRule in project xtext-core by eclipse.
the class AbstractSyntacticSequencer method acceptNode.
protected void acceptNode(INode node) {
Object ge = node.getGrammarElement();
if (ge instanceof Keyword)
acceptUnassignedKeyword((Keyword) ge, node.getText(), (ILeafNode) node);
else if (ge instanceof RuleCall) {
RuleCall rc = (RuleCall) ge;
if (rc.getRule() instanceof TerminalRule)
acceptUnassignedTerminal(rc, node.getText(), (ILeafNode) node);
else if (rc.getRule() instanceof ParserRule) {
StringBuilder text = new StringBuilder();
for (ILeafNode leaf : node.getLeafNodes()) if (text.length() > 0 || !leaf.isHidden())
text.append(leaf.getText());
acceptUnassignedDatatype(rc, text.toString(), (ICompositeNode) node);
} else if (rc.getRule() instanceof EnumRule)
acceptUnassignedEnum(rc, node.getText(), (ICompositeNode) node);
} else if (ge instanceof Action)
acceptUnassignedAction((Action) ge);
else
throw new RuntimeException("Unexpected grammar element: " + node.getGrammarElement());
}
use of org.eclipse.xtext.TerminalRule 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.TerminalRule in project xtext-core by eclipse.
the class XtextAntlrGeneratorFragment2 method generateContentAssistTokenSource.
public JavaFileAccess generateContentAssistTokenSource() {
JavaFileAccess _xblockexpression = null;
{
@Extension final ContentAssistGrammarNaming naming = this.contentAssistNaming;
final JavaFileAccess file = this.fileFactory.createJavaFile(naming.getTokenSourceClass(this.getGrammar()));
final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("BEGIN", "INDENT", "OPEN")).contains(it.getName().toUpperCase()));
};
final Iterable<TerminalRule> open = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function);
final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("END", "DEDENT", "CLOSE")).contains(it.getName().toUpperCase()));
};
final Iterable<TerminalRule> close = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function_1);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(AbstractIndentationTokenSource.class);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
String _simpleName_1 = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append("(");
_builder.append(TokenSource.class, "\t");
_builder.append(" delegate) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super(delegate);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected boolean shouldSplitTokenImpl(");
_builder.append(Token.class, "\t");
_builder.append(" token) {");
_builder.newLineIfNotEmpty();
{
final Function1<TerminalRule, TerminalRule> _function = (TerminalRule it) -> {
return AntlrGrammarGenUtil.<TerminalRule>getOriginalElement(it);
};
final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
String _upperCase = it.getName().toUpperCase();
return Boolean.valueOf(Objects.equal(_upperCase, "WS"));
};
boolean _exists = IterableExtensions.<TerminalRule>exists(ListExtensions.<TerminalRule, TerminalRule>map(GrammarUtil.allTerminalRules(XtextAntlrGeneratorFragment2.this.getGrammar()), _function), _function_1);
if (_exists) {
_builder.append("\t\t");
_builder.append("// TODO Review assumption");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return token.getType() == ");
TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass, "\t\t");
_builder.append(".RULE_WS;");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t\t");
_builder.append("// TODO Implement me");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw new UnsupportedOperationException(\"Implement me\");");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected int getBeginTokenType() {");
_builder.newLine();
{
int _size = IterableExtensions.size(open);
boolean _equals = (_size == 1);
if (_equals) {
_builder.append("\t\t");
_builder.append("// TODO Review assumption");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return ");
TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass_1, "\t\t");
_builder.append(".");
String _ruleName = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(open));
_builder.append(_ruleName, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t\t");
_builder.append("// TODO Implement me");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw new UnsupportedOperationException(\"Implement me\");");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected int getEndTokenType() {");
_builder.newLine();
{
int _size_1 = IterableExtensions.size(close);
boolean _equals_1 = (_size_1 == 1);
if (_equals_1) {
_builder.append("\t\t");
_builder.append("// TODO Review assumption");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return ");
TypeReference _internalParserClass_2 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass_2, "\t\t");
_builder.append(".");
String _ruleName_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(close));
_builder.append(_ruleName_1, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t\t");
_builder.append("// TODO Implement me");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw new UnsupportedOperationException(\"Implement me\");");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected boolean shouldEmitPendingEndTokens() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return false;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
_xblockexpression = file;
}
return _xblockexpression;
}
Aggregations