Open johannphilippe opened 2 years ago
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 !
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.
- Edit : also Ctrl+left or Ctrl+right to move caret from one word if possible
Option+left/right already moves caret by words. Shift+Option+left/right extends the selection by words.
Because of course, tab as a "space * 3" is mostly used in code editor.
The tab number of spaces needs to be configurable.
For example, in Flutter, the basic TextField uses tab like elements basic_input_box uses it -> to pass focus. But in a multiline text editor like in the elements example, you probably want it to add a few spaces. (modifié)
Same with element input text boxes. Code editors should behave differently.
I would let basic_text_box for generic editing, then inherit it to a styled_text_box with advanced features like syntax highlighting, eventually more advanced editing can inherit from the latter
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.
One last thing : if text elements are mainly based on std::u32string and std::u32string_view, like it seems to be, it makes it hard to work with regex (I don't think there is u32 regex in std). Could we template it to let used decide on it ? Of course, I can always write a function to convert, but with a lot of text elements (I will use a lot of basic input in my soft), I think it will cost a little bit to CPU.
There is: std::wregex
and std::wsmatch
The right tool is actually a recursive descent parser
Doesn't it require tokenizing first ? I will take a look at RDP !
The right tool is actually a recursive descent parser
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: https://github.com/boostorg/quickbook/blob/develop/src/syntax_highlight.cpp
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)
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.
After reading the code, I think I need a bit of time to understand it :smile: I found that today, that seems to explain the syntax used to describe grammars : https://en.wikipedia.org/wiki/Spirit_Parser_Framework
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.