use of org.antlr.runtime.ANTLRStringStream in project xtext-xtend by eclipse.
the class AbstractSmokeTest method testSkipTokensInBetween.
@Test
public void testSkipTokensInBetween() throws Exception {
for (String string : smokeTestModels) {
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);
doParseAndCheckForSmoke(string.substring(0, start) + string.substring(start + length));
}
}
}
use of org.antlr.runtime.ANTLRStringStream in project alfresco-remote-api by Alfresco.
the class WhereCompiler method compileWhereClause.
public static CommonTree compileWhereClause(String expression) throws RecognitionException {
// lexer splits input into tokens
ANTLRStringStream input = new ANTLRStringStream(expression);
TokenStream tokens = new CommonTokenStream(new WhereClauseLexer(input));
// parser generates abstract syntax tree
WhereClauseParser parser = new WhereClauseParser(tokens);
WhereClauseParser.whereclause_return ret = parser.whereclause();
// acquire parse result
CommonTree ast = (CommonTree) ret.getTree();
if (logger.isDebugEnabled())
print(ast, 0);
return ast;
}
use of org.antlr.runtime.ANTLRStringStream in project xtext-eclipse by eclipse.
the class AbstractTemplateProposalConflictHelper method initTokenSource.
@Override
protected void initTokenSource(String text, TokenSource tokenSource, ContentAssistContext context) {
EObject currentModel = context.getLastCompleteNode().getSemanticElement();
Variable variable = currentModel != null ? EcoreUtil2.getContainerOfType(currentModel, Variable.class) : null;
TemplateBody body = currentModel != null ? EcoreUtil2.getContainerOfType(currentModel, TemplateBody.class) : null;
Lexer lexer = (Lexer) tokenSource;
CharStream stream = new ANTLRStringStream(text);
lexer.setCharStream(stream);
initLexer(lexer, body != null, variable != null);
}
use of org.antlr.runtime.ANTLRStringStream in project xtext-eclipse by eclipse.
the class TemplateBodyHighlighter method doProvideHighlightingFor.
protected void doProvideHighlightingFor(String body, org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor acceptor) {
lexer.setCharStream(new ANTLRStringStream(body));
Token token = lexer.nextToken();
while (token != Token.EOF_TOKEN) {
String id = tokenIdMapper.getId(token.getType());
int offset = TokenTool.getOffset(token);
int length = TokenTool.getLength(token);
acceptor.addPosition(offset, length, id);
token = lexer.nextToken();
}
}
use of org.antlr.runtime.ANTLRStringStream in project xtext-eclipse by eclipse.
the class DocumentTokenSource method createLexer.
/**
* @deprecated use {@link #createTokenSource(String)} instead.
*/
@Deprecated
protected Lexer createLexer(String string) {
Lexer l = lexer.get();
l.setCharStream(new ANTLRStringStream(string));
return l;
}
Aggregations