This Engineering Notebook post brags about progress in improving Leo's syntax coloring. This thread discussed my first thoughts.
PR #4204 contains the code. It:
- Generalizes the syntax (code pattern) established by @language jupytext.
- Adds two semantics methods to the jedit class.
- Adds new rules (functions) for html elements in three mode files:
html.py, css.py, and javascript.py.
This excellent strategy appeared after many happy hours of experimentation.
Semantics
The PR adds two new semantic methods: jedit.push_delegate and jedit.pop_delegate and modifies an existing semantic method, jedit.match_at_language.
These methods are tricky because they must alter the (complex!) state of the jedit class.
These methods hide all such complexity from the rule functions in the mode files.
Rule functions
The PR adds new rules for html elements to the three mode files. Rules for:
<script>, </script>, <style>, </style>
replace the corresponding delegated rule sets in each mode file! In other words, the PR greatly reduces the scale of delegation.
These new rules follow a straightforward pattern:
- Rules for <style> and <script> color the element and call push_delegate.
- Rules for </style> and </script> color the element and call pop_delegate.
- Rules for @language color the directive and call match_at_language.
This is how it is written in The Book.
Summary
New html rules replace entire rule sets in html.py, css.py, and javascript.py. These mode files now use the "delegate" kwarg only to colorize single html elements!
The semantics methods hide all the heavy lifting from the rule methods.
The PR must still fix all semantic edge cases. In the end, everything will look effortless.
Edward
Always nice to be able to brag in a report ;-)
> The PR must still fix all semantic edge cases. In the end, everything will look effortless.
Recent revs have seen further collapses in complexity:
For the first time in Leo's history, the all-important html_rule4 now correctly colorizes all html elements.
The delegation code in jedit.colorRangeWithTag is now:
self.push_delegate(delegate)
state = self.currentState()
self.mainLoop(state, s, i, j)
self.pop_delegate()
This is how it is written in the book.
Summary
The new delegation patterns continue to simplify Leo's colorizers. Afaik, no ugly code remains.
At 75 years old, I'm beginning to hit my stride. As the cricket players say, 75 not out.
Edward