-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a code editor with syntax highlighting #291
Comments
I dissuade you from using a lexer. 1. It's not the right tool. 2. It is an unnecessary dependency, and 3. It is easy to implement without it. The right tool is actually a recursive descent parser because parsing syntax is recursive WRT elements such as braces, parentheses and even comments in some languages (e.g. pascal). It is easy to hand-code an RDP for this purpose. I can offer guidance or write code if needed. |
Option+left/right already moves caret by words. Shift+Option+left/right extends the selection by words. |
The tab number of spaces needs to be configurable. |
Same with element input text boxes. Code editors should behave differently. |
A (styled) rich-text editor and a code-editor are two separate things that have very specific requirements. While it may seem intuitive to have a code-editor inherit from a rich-text editor, it is best to simply have these as totally separate classes. There's not much code-reuse advantage. |
There is: |
Doesn't it require tokenizing first ? I will take a look at RDP ! |
No. Not really. Boost.Spirit for example does not require a lexer. |
I wrote a syntax highlighter a long time ago, using spirit, for syntax highlighting c++. It might be possible to 1. Extract the parser proper and rewrite it using pure c++ (no dependencies) 2. make it generic to allow other languages. Here's the github page: BoostBook It's still being used by Boost documentation. Many Boost docs use it. Here's the actual syntax highlighting code: The advantage there is that the grammar is formalized and can be lifted. (edit: reading the code again, I realize there's also a python parser) |
After reading the code, I think I need a bit of time to understand it 😄 |
I would like to contribute to development of a code editor element with syntax highlighting.
It could probably be derived from
basic_text_box
, though it would require a dynamic syntax analyzer allowing user configuration for support of - almost - any language (perheaps brainf*ck is not a major target :D ), at least common syntax.I quickly modified lexertk here, so it doesn't dismisses spaces, tabs and comments. I could also "highlight" an ugly custom static text box (no edit). This tiny library lexertk can still bring a few ideas on how we could do that !
Discord discussion below about text editor and related.
The text was updated successfully, but these errors were encountered: