use of org.fife.ui.rsyntaxtextarea.Token in project knime-core by knime.
the class AbstractRuleParser method parse.
/**
* {@inheritDoc}
*/
@Override
public ParseResult parse(final RSyntaxDocument doc, final String style) {
if (isNotApplicable(style)) {
return new DefaultParseResult(this);
}
DefaultParseResult res = new DefaultParseResult(this);
Element rootElement = doc.getDefaultRootElement();
boolean wasCatchAllRule = false;
for (int line = 0; line < rootElement.getElementCount(); ++line) {
String lastString = null;
StringBuilder sb = new StringBuilder();
// Go through the tokens
Token token = doc.getTokenListForLine(line);
while (token != null && token.isPaintable()) {
String lexeme = token.getLexeme();
// If it is an operator, make it a reserved word.
if (getOperators().contains(lexeme)) {
token.setType(TokenTypes.RESERVED_WORD);
token.setLanguageIndex(0);
}
sb.append(lexeme);
if (lexeme.length() > 0 && lexeme.charAt(0) == '"' && lexeme.charAt(lexeme.length() - 1) == '"') {
lastString = lexeme;
}
token = token.getNextToken();
}
try {
String lineText = sb.toString();
// Check for potential error in outcomes.
if (lineText.trim().endsWith("\"") && m_warnOnColRefsInStrings) {
String lastContent = lastString != null && lastString.length() > 2 ? lastString.substring(1, lastString.length() - 1) : lastString;
// ENH better check
if (lastContent != null && lastContent.endsWith("$") && lastContent.charAt(0) == '$') {
DefaultParserNotice notice = new DefaultParserNotice(this, "You might be referring to a column or flow variable, although no String " + "interpolation is implemented, you might want to " + "remove the quotes around the reference.", line, doc.getTokenListForLine(line).getOffset() + lineText.lastIndexOf(lastContent), lastContent.length());
notice.setLevel(ParserNotice.Level.WARNING);
res.addNotice(notice);
}
}
if (!lineText.isEmpty()) {
wasCatchAllRule |= parseAndWarn(doc, res, wasCatchAllRule, line, lineText);
}
} catch (ParseException e) {
DefaultParserNotice notice;
if (e.getErrorOffset() >= sb.length()) {
notice = new DefaultParserNotice(this, e.getMessage(), line);
} else {
notice = new DefaultParserNotice(this, e.getMessage(), line, doc.getTokenListForLine(line).getOffset() + e.getErrorOffset(), sb.length() - e.getErrorOffset());
}
res.addNotice(notice);
}
}
return res;
}
Aggregations