ENB: Status report: delegated syntax coloring

33 views
Skip to first unread message

Edward K. Ream

unread,
Nov 22, 2024, 5:26:38 AM11/22/24
to leo-editor

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

jkn

unread,
Nov 22, 2024, 7:03:57 AM11/22/24
to leo-editor
Always nice to be able to brag in a report ;-)

Edward K. Ream

unread,
Nov 22, 2024, 9:24:08 AM11/22/24
to leo-e...@googlegroups.com
On Fri, Nov 22, 2024 at 6:04 AM jkn <jkn...@nicorp.f9.co.uk> wrote:
Always nice to be able to brag in a report ;-)

You betcha!

Edward

Edward K. Ream

unread,
Nov 23, 2024, 8:23:35 AM11/23/24
to leo-editor
On Friday, November 22, 2024 at 4:26:38 AM UTC-6 Edward K. Ream wrote:

> 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

Reply all
Reply to author
Forward
0 new messages