use of org.antlr.runtime.ANTLRStringStream in project xtext-core by eclipse.
the class AbstractSmokeTest method testSkipTokensInBetween.
@Test
public void testSkipTokensInBetween() throws Exception {
for (String string : getSmokeTestModels()) {
List<CommonToken> tokenList = Lists.newArrayList();
{
Lexer lexer = lexerProvider.get();
lexer.setCharStream(new ANTLRStringStream(string));
Token token = lexer.nextToken();
while (token != Token.EOF_TOKEN) {
tokenList.add((CommonToken) token);
token = lexer.nextToken();
}
}
for (CommonToken token : tokenList) {
int start = token.getStartIndex();
int length = token.getText().length();
logProgress(token);
processModel(string.substring(0, start) + string.substring(start + length));
}
}
}
use of org.antlr.runtime.ANTLRStringStream in project xtext-core by eclipse.
the class AbstractSmokeTest method testSkipTokensInBetweenWithoutResourceSet.
@Test
public void testSkipTokensInBetweenWithoutResourceSet() throws Exception {
for (String string : getSmokeTestModels()) {
List<CommonToken> tokenList = Lists.newArrayList();
{
Lexer lexer = lexerProvider.get();
lexer.setCharStream(new ANTLRStringStream(string));
Token token = lexer.nextToken();
while (token != Token.EOF_TOKEN) {
tokenList.add((CommonToken) token);
token = lexer.nextToken();
}
}
for (CommonToken token : tokenList) {
int start = token.getStartIndex();
int length = token.getText().length();
logProgress(token);
processModelWithoutResourceSet(string.substring(0, start) + string.substring(start + length));
}
}
}
use of org.antlr.runtime.ANTLRStringStream in project xtext-core by eclipse.
the class ContentAssistContextFactory method createContextsForLastCompleteNode.
protected void createContextsForLastCompleteNode(EObject previousModel, boolean strict) {
String currentNodePrefix = getPrefix(currentNode);
if (!Strings.isEmpty(currentNodePrefix) && !currentNode.getText().equals(currentNodePrefix)) {
lexer.setCharStream(new ANTLRStringStream(currentNodePrefix));
Token token = lexer.nextToken();
if (token == Token.EOF_TOKEN) {
// error case - nothing could be parsed
return;
}
while (token != Token.EOF_TOKEN) {
if (isErrorToken(token))
return;
token = lexer.nextToken();
}
}
String prefix = "";
String completeInput = getInputToParse(document, completionOffset);
Collection<FollowElement> followElements = parser.getFollowElements(completeInput, strict);
doCreateContexts(lastCompleteNode, currentNode, prefix, previousModel, followElements);
}
use of org.antlr.runtime.ANTLRStringStream in project xtext-core by eclipse.
the class AntlrProposalConflictHelper method initTokenSource.
protected void initTokenSource(String text, TokenSource tokenSource, ContentAssistContext context) {
Lexer lexer = (Lexer) tokenSource;
CharStream stream = new ANTLRStringStream(text);
lexer.setCharStream(stream);
}
use of org.antlr.runtime.ANTLRStringStream in project xtext-core by eclipse.
the class InternalParserTest method createParser.
protected InternalXtextGrammarTestLanguageParser createParser(String input) {
CharStream stream = new ANTLRStringStream(input);
InternalXtextGrammarTestLanguageLexer lexer = new InternalXtextGrammarTestLanguageLexer(stream);
InternalXtextGrammarTestLanguageParser result = new InternalXtextGrammarTestLanguageParser(null);
ObservableXtextTokenStream tokenStream = new ObservableXtextTokenStream(lexer, result);
tokenStream.setInitialHiddenTokens("RULE_WS", "RULE_ML_COMMENT", "RULE_SL_COMMENT");
tokenStream.setListener(result);
result.setGrammarAccess(grammarAccess);
result.setTokenStream(tokenStream);
return result;
}
Aggregations