use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class DynamicChannelTest method testParseSimpleLanguage.
@Test
public void testParseSimpleLanguage() throws Exception {
IParseResult result = parse(model);
assertNotNull(result);
assertNotNull(result.getRootASTElement());
assertNotNull(result.getRootNode());
assertNotNull(result.getSyntaxErrors());
assertFalse(result.hasSyntaxErrors());
assertTrue(result.getSyntaxErrors().toString(), Iterables.isEmpty(result.getSyntaxErrors()));
}
use of org.eclipse.xtext.parser.IParseResult in project xtext-core by eclipse.
the class DynamicChannelTest method testNodeModelOfSimpleLanguage.
@Test
public void testNodeModelOfSimpleLanguage() throws Exception {
IParseResult result = parse(model);
List<ILeafNode> leafs = Lists.newArrayList(result.getRootNode().getLeafNodes());
assertEquals(23, leafs.size());
int i = 0;
checkLeaf(leafs.get(i++), grammar, false);
checkLeaf(leafs.get(i++), space, true);
checkLeaf(leafs.get(i++), a, false);
checkLeaf(leafs.get(i++), space, true);
checkLeaf(leafs.get(i++), ext, false);
checkLeaf(leafs.get(i++), space, true);
checkLeaf(leafs.get(i++), b, false);
checkLeaf(leafs.get(i++), dot, false);
checkLeaf(leafs.get(i++), space, true);
checkLeaf(leafs.get(i++), c, false);
checkLeaf(leafs.get(i++), lb, true);
checkLeaf(leafs.get(i++), comment, true);
checkLeaf(leafs.get(i++), rulename, false);
checkLeaf(leafs.get(i++), space + space, true);
checkLeaf(leafs.get(i++), returns, false);
checkLeaf(leafs.get(i++), space + lb, true);
checkLeaf(leafs.get(i++), d, false);
checkLeaf(leafs.get(i++), colon, false);
checkLeaf(leafs.get(i++), space, true);
checkLeaf(leafs.get(i++), name, false);
checkLeaf(leafs.get(i++), ass, false);
checkLeaf(leafs.get(i++), id, false);
checkLeaf(leafs.get(i++), sc, false);
}
use of org.eclipse.xtext.parser.IParseResult in project n4js by eclipse.
the class HighlightingParserTester method getTokens.
/**
* Parses the input and returns a list of lexer tokens. Asserts that the produced tokens are equal to the tokens
* that the production parser produced.
*
* @return the tokens for the highlighting.
*/
public List<Token> getTokens(CharSequence input) {
List<Token> result;
IParseResult parseResult = parser.parse(new StringReader(input.toString()));
if (!parseResult.hasSyntaxErrors()) {
result = throwingHighlightingParser.getTokens(input);
} else {
result = highlightingParser.getTokens(input);
}
// assert equal tokens
Iterator<Token> iter = result.iterator();
for (ILeafNode leaf : parseResult.getRootNode().getLeafNodes()) {
Assert.assertTrue("hasNext at index " + leaf.getTotalOffset() + " for leaf '" + leaf.getText() + "'", iter.hasNext());
Token token = iter.next();
// TODO: assert token type
Assert.assertEquals(leaf.getText(), token.getText());
}
return result;
}
use of org.eclipse.xtext.parser.IParseResult in project statecharts by Yakindu.
the class AbstractSGenTest method parseExpression.
protected EObject parseExpression(String expression, String ruleName) {
XtextResource resource = resourceProvider.get();
resource.setURI(URI.createPlatformPluginURI("path", true));
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setName(ruleName);
IParseResult result = parser.parse(parserRule, new StringReader(expression));
EObject rootASTElement = result.getRootASTElement();
resource.getContents().add(rootASTElement);
ListBasedDiagnosticConsumer diagnosticsConsumer = new ListBasedDiagnosticConsumer();
linker.linkModel(result.getRootASTElement(), diagnosticsConsumer);
if (result.hasSyntaxErrors()) {
StringBuilder errorMessages = new StringBuilder();
Iterable<INode> syntaxErrors = result.getSyntaxErrors();
for (INode iNode : syntaxErrors) {
errorMessages.append(iNode.getSyntaxErrorMessage());
errorMessages.append("\n");
}
throw new RuntimeException("Could not parse expression, syntax errors: " + errorMessages);
}
if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) {
throw new RuntimeException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR));
}
return rootASTElement;
}
use of org.eclipse.xtext.parser.IParseResult in project statecharts by Yakindu.
the class StextResource method parseStatechart.
protected void parseStatechart(Statechart statechart) {
IParseResult parseResult = parse(statechart, StatechartSpecification.class.getSimpleName());
StatechartSpecification rootASTElement = (StatechartSpecification) parseResult.getRootASTElement();
statechart.setNamespace(rootASTElement.getNamespace());
statechart.getScopes().clear();
EList<Scope> definitionScopes = rootASTElement.getScopes();
if (definitionScopes != null) {
statechart.getScopes().addAll(definitionScopes);
}
statechart.getAnnotations().clear();
EList<ArgumentedAnnotation> annotations = rootASTElement.getAnnotations();
if (annotations != null) {
statechart.getAnnotations().addAll(annotations);
}
}
Aggregations