How Is Syntax Highlighting Built?

陌路散爱 提交于 2019-11-30 00:13:30

问题


I'm now building a developers editor using Lazarus and as every good developers editor, it needs to have a syntax highlighting, because of this that I want to know some things:

  • How is syntax highlight normally built(using many ifs to change the font on a TextField?
  • TSynEdit is very nice to do this?
  • How to use TSynEdit(links and resources)?

回答1:


You can actually see an excellent example for yourself if you look at the editor for SharpDevelop. It's implemented in C# but uses great OOP that should be readily portable to other platforms or languages.

Most home-brewed syntax highlighters tend to use the MS Windows RichText control but they're usually slow and clunky and really slow down when a lot of code is added.




回答2:


You could read the source code of Eclipse or VIM. In Eclipse you will find an Abstract Syntax Tree base. On top of it are parsers that are carefully written to be tolerant of errors, since code in progress often does not satisfy the full grammar of the language. The highlighting uses the information in the syntax tree.



来源:https://stackoverflow.com/questions/2031154/how-is-syntax-highlighting-built

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