Re: LPeg for multiple line constructs (was: Re: [code] A small addition to the textadept Wiki)

From: Mitchell <>
Date: Sun, 18 Feb 2018 10:50:02 -0500 (EST)


On Sat, 17 Feb 2018, wrote:

> Let me ask a followup--one of the important things my lexer / folder needs to
> recognize is the multiline mbox header (with a variable number of lines).
> A minimum mbox header (constrained by the applications I plan to use--kmail,
> recoll, nmail, some others is 3 lines, like this:
> From "poor man's lobster" Fri Feb 16 09:22:39 2018
> Date: 02/16/18 09:22 am
> Subject: poor man's lobster
> It can include an arbitrary number of additional lines after the From line of
> the form:
> <keyword>: <whatever>
> (In other words, just like what can be included in a real mbox header.)
> When a valid mbox header is recognized, the From line would become a fold
> point, and, the lines (and parts of lines) would be highlighted to make it
> easy to read.
> I think I finally have some insight into how to to that in a C++ lexer
> (handling the multiple lines is the problem).
> Would that be fairly easy to do in LPeg?

The highlighting should be pretty straightforward. You'd be writing a lexer that lexes by lines and you would look for lines that start with "From " and lines that start with "[keyword]: " (where keyword would probably be `lexer.word`), and process them accordingly.

As for folding, that's more difficult and you'd probably need to write a custom folder.

You can look at examples of line lexers via `grep -i lex_by_line lexers/*`. Custom folders are outside the scope of the documentation, but `lexers/lexer.lua` has an `M.fold()` function that you can reference when writing your own folding function (e.g. `function lex:fold(...) ... end`).


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Sun 18 Feb 2018 - 10:50:02 EST

This archive was generated by hypermail 2.2.0 : Mon 19 Feb 2018 - 06:28:06 EST