andre-simon / highlight

Source code to formatted text converter
GNU General Public License v3.0
206 stars 58 forks source link

Help Needed Understanding "PreProcessor" Syntax Element #45

Closed tajmone closed 6 years ago

tajmone commented 6 years ago

Ciao André,

I've just realized that in the template.lang I created for the "extras" folder I've forgot to cover the PreProcessor element! (it slipped through! I thought I had them all covered...)

Since I've already opened a pull request (PR #44) to update the template, it would be a right time to add the missing element; but I'll need to understand better how it works.

The documentation states:

PreProcessor = { Prefix, Continuation? }

  Prefix:        String, regular expression which describes open delimiter
  Continuation:  String, contains line continuation character (optional).

And the example I've found (I think from Python) is:

PreProcessor = {
  Prefix=[[#]],
  Continuation="\\",
}

How does this element actually work? Does the parser assume that from the Prefix match onward (until end of line) the Prefix and all that follows it is part of the PreProcessor element? (ie: like with single line comments)

And is the Continuation meant to be a RegEx that, if matched, will carry on over the next line the PreProcessor element? ie: it can occur only at the end of the line?

Sorry to bother you with this, but I've trouble coming to grips with this element. (haven't had a chance to use it so far!)

andre-simon commented 6 years ago

Hi Tristano,

your assumptions are correct, except Continuation which is a character and no regular expression. If the preprocessort line ends with this character the mode just continues.

andre-simon commented 6 years ago

The preprocessor state is aware of comments or strings, as you have noticed in the PR comments.

tajmone commented 6 years ago

Added to Wiki:

https://github.com/tajmone/highlight/wiki/LanDefs#preprocessor