use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken in project scout.rt by eclipse.
the class SqlParser method tokenizeRaw.
@SuppressWarnings("squid:S1643")
private List<IToken> tokenizeRaw(List<IToken> list, Pattern p, Class<? extends IToken> tokenType, boolean transcodeDelimiters) {
ArrayList<IToken> newList = new ArrayList<IToken>(list.size());
for (IToken item : list) {
if (item instanceof Raw) {
String s = ((Raw) item).getText();
if (transcodeDelimiters) {
s = encodeDelimiters(s);
}
// extend s to start and end with an empty text (simpler regex can be used then)
s = " " + s + " ";
Matcher m = p.matcher(s);
int lastEnd = 0;
while (lastEnd < s.length() && m.find(lastEnd)) {
String r = s.substring(lastEnd, m.start(1));
if (transcodeDelimiters) {
r = decodeDelimiters(r);
}
newList.add(new Raw(r.trim()));
//
r = m.group(1);
if (transcodeDelimiters) {
r = decodeDelimiters(r);
}
IToken t;
try {
t = tokenType.newInstance();
} catch (Exception e) {
throw new ProcessingException("Could not create new instance of {}", tokenType, e);
}
t.setText(r);
newList.add(t);
//
lastEnd = m.end(1);
}
// remaining part
if (lastEnd < s.length()) {
String r = s.substring(lastEnd);
if (transcodeDelimiters) {
r = decodeDelimiters(r);
}
newList.add(new Raw(r.trim()));
}
} else {
newList.add(item);
}
}
return newList;
}
Aggregations