在哪里可以找到 Java 的语法高亮库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/864688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where can I find a syntax highlighting library for Java?
提问by
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?
我正在用 Java 编写源代码编辑器(用于 Java 源代码),我想添加简单的语法突出显示(关键字的独特着色就足够了)。有什么建议?
回答by Michael Myers
Something like JSyntaxPane
, perhaps?
类似的东西JSyntaxPane
,也许?
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.
一个非常易于使用和扩展的 JEditorKit,支持几种语言。主要目标是通过对语法突出显示的支持,使具有美观的 Java Swing 编辑器变得容易。
回答by newfie_coder
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...
可能想查看现有的编辑器(例如 Notepad++ - http://notepad-plus.sourceforge.net/uk/site.htm)并查看如何完成用户定义的语法突出显示(要检查的插件之一 - Gmod 10 Lua 语法荧光笔)。我敢打赌 Java(和其他语言)的实现方式类似......
回答by ivmos
What about RSyntaxTextArea? It uses a modified BSD license.
RSyntaxTextArea怎么样?它使用修改后的 BSD 许可证。
回答by GEOCHET
You should check Google's prettify.jsout. Some pretty neat tricks in there, and you might get a more robust feel for syntax highlighting.
您应该查看 Google 的prettify.js。那里有一些非常巧妙的技巧,你可能会对语法高亮有更强大的感觉。
回答by Andreas Dolk
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.
您首先应该考虑使用通用解析器从源创建 AST(抽象语法树)。周围有一些工具,首先我发现谷歌搜索互联网是javaparser。看起来这个解析器也记录行号和列,所以来自 javaparser 的 AST 可以成为编辑器的一个很好的模型。
Just process the tree, define colors for the AST node types and print it.
只需处理树,为 AST 节点类型定义颜色并打印它。
回答by Andreas Dolk
http://www.neathighlighter.com/is a good JavaScript highlighter
http://www.neathighlighter.com/是一个很好的 JavaScript 荧光笔