use of org.erlide.engine.services.parsing.ScannerException in project erlide_eclipse by erlang.
the class ErlideScanner method lightScanString.
@Override
public List<ErlToken> lightScanString(final String string, final int offset) throws ScannerException {
OtpErlangObject r1 = null;
try {
r1 = backend.call("erlide_scanner", "light_scan_string", "ba", string, ErlideScanner.ENCODING);
} catch (final Exception e) {
throw new ScannerException("Could not parse string \"" + string + "\": " + e.getMessage());
}
if (r1 == null) {
return null;
}
if (!(r1 instanceof OtpErlangTuple)) {
throw new ScannerException("Could not parse string \"" + string + "\": weird return value " + r1);
}
final OtpErlangTuple t1 = (OtpErlangTuple) r1;
List<ErlToken> toks = null;
if (Util.isOk(t1)) {
if (t1.elementAt(1) instanceof OtpErlangBinary) {
final OtpErlangBinary b = (OtpErlangBinary) t1.elementAt(1);
final byte[] bytes = b.binaryValue();
toks = new ArrayList<>(bytes.length / 10);
for (int i = 0; i < bytes.length; i += 10) {
final ErlToken tk = new ErlToken(bytes, i, offset);
toks.add(tk);
}
return toks;
}
throw new ScannerException("unexpected token format");
}
throw new ScannerException("Could not parse string \"" + string + "\": " + t1.toString());
}
use of org.erlide.engine.services.parsing.ScannerException in project erlide_eclipse by erlang.
the class ErlangBracketInserter method getKindOfBracket.
private int getKindOfBracket(final IDocument document, final int offset, final int length) throws BadLocationException {
final IRegion endLine = document.getLineInformationOfOffset(offset + length);
List<ErlToken> tokens = null;
final int getOffset = offset + length;
final int getLength = endLine.getOffset() + endLine.getLength() - getOffset;
final String str = document.get(getOffset, getLength);
try {
tokens = ErlangEngine.getInstance().getSimpleScannerService().lightScanString(str, 0);
} catch (final ScannerException e) {
}
int kind = ErlToken.KIND_OTHER;
if (tokens != null && !tokens.isEmpty()) {
kind = tokens.get(0).getKind();
} else if (!str.isEmpty()) {
kind = str.charAt(0);
}
return kind;
}
Aggregations