jEdit Syntax Highlighting Mode for the Peg/Leg Parser Generator ‘Leg’ Syntax

Posted on April 4, 2011
Filed under jEdit, Programming

jedit icon I’ve been working on a fast and embeddable Markdown parser that can be used for syntax highlighting in editors, based on the PEG grammar from John MacFarlane’s peg-markdown compiler project. The grammar is written in leg, a syntax for the peg/leg parser generator by Ian Piumarta, and to make my work with this new syntax a bit more pleasant I implemented a jEdit mode for it.

Download the mode here: leg.xml

Note that since the leg syntax uses curly brackets ({}) to delimit actions in the grammar, and those actions are written in C (which also uses curly brackets a lot), the mode has to somehow be able to match a certain number of balanced pairs of these brackets. As far as I know this is not directly supported in the jEdit syntax highlighting mode system but I was able to use the “delegates” mechanism to implement support for two levels of matched brackets, which should be enough for any reasonable use (in any case, it’s easy to add further levels of such support to the mode).

To install this mode, add the following to the modes/catalog file in your jEdit user settings directory (select Utilities → Settings Directory in jEdit to find this):

<MODE NAME="leg"

Then copy the leg.xml file into the same directory with this file. See the Installing Modes section of the jEdit users’ guide for more information.


2 Responses to “jEdit Syntax Highlighting Mode for the Peg/Leg Parser Generator ‘Leg’ Syntax”

Show/hide comments & reply form: