How can I get syntax highlighting for my format in an Eclipse text editor?

橙三吉。 提交于 2019-12-25 04:58:45

问题


I need syntax highlighting for text with a specific structure in an Eclipse text editor. The scheme is simple; basically each line has six words separated by white-space, and lines starting with # are comments. Most important is to highlight the comments, but it would be useful to individually color the six elements in the non-commented lines.

If it is too complicated to obtain, perhaps I could use an existing plugin meant for something with a similar syntax. Any suggestions?


回答1:


If you want to write your own editor, you could try XText. With XText you can write editors for your own DSL (Domain Specific Language), which i suspect is what you have. The editors also support auto completion and other nice features. I haven't tried XText so far, but i heard that it's pretty easy to learn.

If highlighting of the comments is enough, you can also try to assign your file endings like the configuration for properties files, sincec comments in properties files are also a #. You can edit the configuration in Window -> Preferences -> Editors -> File Associations and then choose the Properties File Editor for your file type.




回答2:


This is exactly one of the targets of LiClipse (http://brainwy.github.io/liclipse/): easily doing an editor with syntax highlighting, basic code-completion, outline, etc targeting Eclipse.

No java skills are required to add a new language (mostly creating a new .liclipse -- which is a YAML -- file in the proper place and creating some basic rules to say how to partition your language -- i.e.: usually just separating code from comments from strings -- and specifying the keywords you have in the partition would already give you proper syntax highlighting).

If you download it, there are a number of examples at plugins\com.brainwy.liclipse.editor\languages and there's some basic documentation at http://brainwy.github.io/liclipse/supported_languages.html and http://brainwy.github.io/liclipse/scope_definition.html on how to do it.



来源:https://stackoverflow.com/questions/11501419/how-can-i-get-syntax-highlighting-for-my-format-in-an-eclipse-text-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!