Pygments Highlighting for Kappa

11 views
Skip to first unread message

Héctor F

unread,
Apr 17, 2019, 8:00:10 PM4/17/19
to kappa-users
Hi all,

I've created a lexer for our favorite simulation language for the Pygments package. The main advantage is that Overleaf can use the Minted package for code highlighting in LaTeX, and Minted uses Pygments. This means one will be able to highlight Kappa code in LaTeX documents fairly easy, without having to carry around a Kappa style file, or deal with LaTeX installations...

The lexer and demo script are currently at https://github.com/hmedina/KappaPygmentsLexer
$ ./demo.py --help

The lexer currently can parse the entire KaSim test suite correctly (or at least the valid Kappa4 files in it...); that said, I would appreciate the trial-by-fire that is user-testing. Moreover, if people have STYLES they would like to see in an official distro, I'm happy to add them to the list (currently, there's one that mimics the GUI's highlighting, one that highlights edit-notation operations, and one that just serves to spot nuances in the lexer). Minted allows one to define styles for Pygments, so those are easily customizable, specially given the large number of tokens I created.

Best,
Hector

Héctor F

unread,
May 7, 2019, 10:31:00 AM5/7/19
to kappa-users
Hi all,
The pull request has been submitted to the Pygments package. However, it seems development suffers from lack of dev-time.In the mean time, you can check out my branch at https://bitbucket.org/hectorfmedinaa/pygments-main/src/default/ Installation instructions are located in the readme (i.e. just $ ./setup.py install or $ ./setup.py develop --user if you want to edit the source & create styles)

As the lexer structure used is similar to that used by CodeMirror, we may be enhancing the Kappaapp & the GUI's lexer down the line. So users are encouraged to use & abuse it (and then complain to me, and maybe "the maintainer of the KaSim documentation" ;)

As for the pygments tokens, I deconstructed Kappa to the bones, so there is a LOT of customization about how stuff is rendered. See the pygments-main/pygments/tokens_for_kappa.py file to see the token tree / hierarchy. In my use case, I highlight edit notation operations (e.g. bonds in red, internal states in blue, counter stuff in green, agent creation/deletion in bold with red background), and put agent names in bold (checkout the styles folder). The lexer can distinguish agent names from variables (duh), and even the difference between a counter declaration and a counter edit operation (which the GUI can't... just sayin'...).

All the best,
Hector
Reply all
Reply to author
Forward
0 new messages