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);
}
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;
}
}
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;
}
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;
}
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());
}
Aggregations