Search in sources :

Example 1 with ErlToken

use of org.erlide.engine.services.parsing.ErlToken in project erlide_eclipse by erlang.

the class ErlCodeScanner method nextErlToken.

public ErlToken nextErlToken() {
    if (fTokens == null) {
        return ErlToken.EOF;
    }
    fCrtToken++;
    if (fCrtToken >= fTokens.size()) {
        return ErlToken.EOF;
    }
    final ErlToken tk = fTokens.get(fCrtToken);
    if (tk.getOffset() >= rangeOffset + rangeLength) {
        return ErlToken.EOF;
    }
    return fTokens.get(fCrtToken);
}
Also used : ErlToken(org.erlide.engine.services.parsing.ErlToken)

Example 2 with ErlToken

use of org.erlide.engine.services.parsing.ErlToken in project erlide_eclipse by erlang.

the class ErlangHyperlinkDetector method detectHyperlinks.

private IHyperlink[] detectHyperlinks(final IDocument doc, final int offset) {
    final AbstractErlangEditor editor = getAdapter(AbstractErlangEditor.class);
    if (editor == null) {
        return null;
    }
    final ErlToken token = editor.getScanner().getTokenAt(offset);
    if (token == null) {
        return null;
    }
    final int tokenKind = token.getKind();
    if (tokenKind != ErlToken.KIND_ATOM && tokenKind != ErlToken.KIND_STRING && tokenKind != ErlToken.KIND_MACRO && tokenKind != ErlToken.KIND_VAR) {
        return null;
    }
    try {
        final ITypedRegion partition = doc.getPartition(offset);
        final ErlRegion region = new ErlRegion(token.getOffset(), token.getLength(), partition.getType());
        if (!IDocument.DEFAULT_CONTENT_TYPE.equals(region.getType())) {
            return null;
        }
        return new IHyperlink[] { new ErlangHyperlink(editor, region) };
    } catch (final BadLocationException e) {
        return null;
    }
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) ITypedRegion(org.eclipse.jface.text.ITypedRegion) ErlToken(org.erlide.engine.services.parsing.ErlToken) BadLocationException(org.eclipse.jface.text.BadLocationException) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor)

Example 3 with ErlToken

use of org.erlide.engine.services.parsing.ErlToken in project erlide_eclipse by erlang.

the class ErlangWordFinder method findWord.

public static IRegion findWord(final IErlModule module, final AbstractErlangEditor editor, final int offset) {
    if (module == null) {
        return null;
    }
    if (editor != null) {
        editor.reconcileNow();
        final ErlToken token = editor.getScanner().getTokenAt(offset);
        if (token == null) {
            return null;
        }
        return new Region(token.getOffset(), token.getLength());
    }
    return null;
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) ErlToken(org.erlide.engine.services.parsing.ErlToken)

Example 4 with ErlToken

use of org.erlide.engine.services.parsing.ErlToken in project erlide_eclipse by erlang.

the class ErlideScanner method getTokenAt.

@SuppressWarnings("boxing")
public ErlToken getTokenAt(final String module, final int offset) {
    OtpErlangObject r1 = null;
    try {
        r1 = backend.call(ErlideScanner.ERLIDE_SCANNER, "get_token_at", "ai", module, offset);
    } catch (final Exception e) {
        return null;
    }
    if (!(r1 instanceof OtpErlangTuple)) {
        return null;
    }
    final OtpErlangTuple t1 = (OtpErlangTuple) r1;
    if (Util.isOk(t1)) {
        final OtpErlangObject ot = t1.elementAt(1);
        if (ot instanceof OtpErlangTuple) {
            final OtpErlangTuple tt = (OtpErlangTuple) ot;
            return new ErlToken(tt);
        }
    }
    return null;
}
Also used : 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)

Example 5 with ErlToken

use of org.erlide.engine.services.parsing.ErlToken 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)

Aggregations

ErlToken (org.erlide.engine.services.parsing.ErlToken)9 IRegion (org.eclipse.jface.text.IRegion)3 ScannerException (org.erlide.engine.services.parsing.ScannerException)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Region (org.eclipse.jface.text.Region)2 RpcException (org.erlide.runtime.rpc.RpcException)2 RpcTimeoutException (org.erlide.runtime.rpc.RpcTimeoutException)2 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)1 IDocument (org.eclipse.jface.text.IDocument)1 ITypedRegion (org.eclipse.jface.text.ITypedRegion)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 Point (org.eclipse.swt.graphics.Point)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IErlModule (org.erlide.engine.model.root.IErlModule)1 ScannerService (org.erlide.engine.services.parsing.ScannerService)1 AbstractErlangEditor (org.erlide.ui.editors.erl.AbstractErlangEditor)1 ErlangEditor (org.erlide.ui.editors.erl.ErlangEditor)1