hasseg.org

jEdit Syntax Highlighting Mode for the Peg/Leg Parser Generator 'Leg' Syntax

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"
       FILE="leg.xml"
       FILE_NAME_GLOB="*.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 Comments

Jeff June 5, 2012 at 9:27 PM

I know you posted this a while ago but what is the status on the parser that you are making? Would this parser be able to be used by jEdit? (Then we could use your mode to write our own parser generators that would run in this parsers?)

I’ve always wanted to create parsers for new languages in jEdit but I’m not quite heavily enough into Java or C to do so.

Thanks for any info?

Ali Rantakari June 7, 2012 at 6:03 PM

Hi Jeff,

The parser I was talking about can be found here: PEG Markdown Highlight. It’s pretty much finished, but I don’t think you can easily integrate that into jEdit, though. Just to clear any confusion: I was using jEdit to write PEG Markdown Highlight, but I didn’t write it to be integrated into jEdit. :)

Categories