Eu amo jEdit!
domingo, agosto 27th, 2006Pois afinal de contas, poucos são os editores que tem a coragem de fatorar o seu engine de Syntax Highlighting, permitindo que eu reuse (sob domínio público e/ou licença MIT), e gerar um Dump como este: package jEdit.Syntax;import java.io.CharArrayWriter;import java.io.FileInputStream;import java.io.IOException;import org.apache.commons.io.IOUtils;public class TestTokenMarker { public static void main(String[] args) { CharArrayWriter caw = new CharArrayWriter(); for (int i = 0; i < args.length; i++) { String file = args[i]; FileInputStream fis = null; try { fis = new FileInputStream(file); IOUtils.copy(fis, caw); } catch (IOException e) { ; } finally { IOUtils.closeQuietly(fis); } } IOUtils.closeQuietly(caw); char[] buf = caw.toCharArray(); highlight(buf); } private static void highlight(char[] buf) { String str = new String(buf); Segment sourceSegment = new Segment(buf, 0, buf.length); TokenMarker tk = new JavaTokenMarker(); String[] lines = str.split("\\n"); tk.insertLines(0, lines.length); Token rootToken = tk.markTokens(sourceSegment, 0); int pos = 0; while (null != rootToken) { System.out.println("id: " + rootToken.id + "; len=" + rootToken.length + ": " + new String(buf, pos, rootToken.length)); pos += rootToken.length; rootToken = rootToken.next; } }}