Search in sources :

Example 1 with ScannerException

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());
}
Also used : ScannerException(org.erlide.engine.services.parsing.ScannerException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) ErlToken(org.erlide.engine.services.parsing.ErlToken) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) ScannerException(org.erlide.engine.services.parsing.ScannerException) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary)

Example 2 with ScannerException

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;
}
Also used : ScannerException(org.erlide.engine.services.parsing.ScannerException) ErlToken(org.erlide.engine.services.parsing.ErlToken) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point)

Aggregations

ErlToken (org.erlide.engine.services.parsing.ErlToken)2 ScannerException (org.erlide.engine.services.parsing.ScannerException)2 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 IRegion (org.eclipse.jface.text.IRegion)1 Point (org.eclipse.swt.graphics.Point)1 RpcException (org.erlide.runtime.rpc.RpcException)1 RpcTimeoutException (org.erlide.runtime.rpc.RpcTimeoutException)1