Where can I find a syntax highlighting library for

2019-01-10 19:27发布

I'm writing a source-code editor in Java (for Java source code), and I'd like to add simple syntax highlighting (distinctive coloring for keywords would suffice). Any suggestions?

6条回答
祖国的老花朵
2楼-- · 2019-01-10 19:34

You first should think about using a common parser to create an AST (abstract syntax tree) from the sources. There are some tools around, first I find googling the internet was javaparser. It looks like this parser also records line numbers and columns, so the AST from javaparser can be a nice model for the editor.

Just process the tree, define colors for the AST node types and print it.

查看更多
够拽才男人
3楼-- · 2019-01-10 19:35

http://www.neathighlighter.com/ is a good JavaScript highlighter

查看更多
该账号已被封号
4楼-- · 2019-01-10 19:47
祖国的老花朵
5楼-- · 2019-01-10 19:57

Something like JSyntaxPane, perhaps?

A very simple to use and extend JEditorKit that supports few languages. The main goal is to make it easy to have nice looking Java Swing Editors with support for Syntax Highlighting.

查看更多
对你真心纯属浪费
6楼-- · 2019-01-10 19:57

You should check Google's prettify.js out. Some pretty neat tricks in there, and you might get a more robust feel for syntax highlighting.

查看更多
聊天终结者
7楼-- · 2019-01-10 19:58

Might want to look at an existing editor (Notepad++ for example - http://notepad-plus.sourceforge.net/uk/site.htm) and see how user-defined syntax highlighting is done (oneo of the plugins to check - Gmod 10 Lua Syntax Highlighter). I'd wager that the Java (and other languages) are done similarly...

查看更多
登录 后发表回答