在哪里可以找到用于Java的语法高亮库?

时间:2022-08-03 15:05:14

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源代码),我想添加简单的语法突出显示(关键字的独特着色就足够了)。有什么建议?

6 个解决方案

#1


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编辑器变得简单,并支持Syntax Highlighting。

#2


What about RSyntaxTextArea? It uses a modified BSD license.

那么RSyntaxTextArea呢?它使用修改后的BSD许可证。

#3


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节点类型的颜色并打印它。

#4


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 Syntax荧光笔)。我敢打赌Java(和其他语言)也是这样做的......

#5


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.

您应该检查Google的prettify.js。那里有一些非常巧妙的技巧,你可能会对语法高亮有一种更强大的感觉。

#6


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

http://www.neathighlighter.com/是一款优秀的JavaScript荧光笔

#1


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编辑器变得简单,并支持Syntax Highlighting。

#2


What about RSyntaxTextArea? It uses a modified BSD license.

那么RSyntaxTextArea呢?它使用修改后的BSD许可证。

#3


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节点类型的颜色并打印它。

#4


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 Syntax荧光笔)。我敢打赌Java(和其他语言)也是这样做的......

#5


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.

您应该检查Google的prettify.js。那里有一些非常巧妙的技巧,你可能会对语法高亮有一种更强大的感觉。

#6


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

http://www.neathighlighter.com/是一款优秀的JavaScript荧光笔