ScintillaOrg / lexilla

A library of language lexers for use with Scintilla
https://www.scintilla.org/Lexilla.html
Other
179 stars 64 forks source link

Added troff/nroff lexer #264

Closed rhaberkorn closed 1 month ago

rhaberkorn commented 1 month ago

Among many other things, this allows lexing of manpage source documents. The lexer is macro-package agnostic, though. Troff is also used as a typesetting package.

This lexer goes further than most Troff lexers by actually trying to parse its syntax instead of only applying heuristics. Unfortunately, the language is strictly speaking unparseable even with intimate knowledge of the syntax of all of its requests as its parsing behavior often depends on runtime state (and we all know that the halting problem is undecidable). Any Troff lexer is therefore necessarily a compromise. This implementation tries hard to guarantee at least the following:

Currently there are the following restrictions:

SciTECO already added support for this lexer..

Here's a proper SciTE properties file for supporting the Lexer. It was only tested with SciTE 5.13, but I don't think that much has changed in the properties syntax. I can also send it to the Scintilla mailing list once this gets merged, unless @nyamatongwe just takes it from here.

nyamatongwe commented 1 month ago

I will look at this after 5.4.0 is released in a few days.

nyamatongwe commented 1 month ago

There are some shadowed variables which produces warnings. Shadowed variables can make it easier for maintainers to add new bugs so its best to rename either the inner or outer variables. This is best done by the original author as they are more likely to see problems in behaviour. This log is from Visual C++ Code Analysis and similar results are produced by cppcheck.

G:\u\hg\pull\lexilla\lexers\LexTroff.cxx(850): warning C6246: 
Local declaration of 'i' hides declaration of the same name in outer scope. 
For additional information, see previous declaration at line '793' of 'g:\u\hg\pull\lexilla\lexers\lextroff.cxx'.
G:\u\hg\pull\lexilla\lexers\LexTroff.cxx(851): warning C6246: 
Local declaration of 'style' hides declaration of the same name in outer scope. 
For additional information, see previous declaration at line '796' of 'g:\u\hg\pull\lexilla\lexers\lextroff.cxx'.
rhaberkorn commented 1 month ago

cppcheck doesn't warn about anything by default for some strange reason. Even more strangely, adding -Wshadow to CXXFLAGS/WARNINGS does not produce any warnings about the shadowed variables.

Anyway, I refactored my code and also renamed a few variables, to conform to the camel case style of lexilla.

The troff branch is rebased on top of master.

nyamatongwe commented 1 month ago

Squashed then committed with some minor changes.

Changed header inclusion order to match scripts\HeaderOrder.txt. Fixed a couple of misspellings 'similiar' and 'supportin'. Added to LexillaHistory.html and cppcheck.suppress.

nyamatongwe commented 1 month ago

cppcheck doesn't warn about anything by default

The command line used (from the directory above lexilla is:

cppcheck -j 8 --enable=all --suppressions-list=lexilla/cppcheck.suppress --max-configs=120 -I lexilla/include -I lexilla/access -I lexilla/lexlib -I scintilla/include --template=gcc --quiet lexilla
rhaberkorn commented 1 month ago

Thank you! Will you add Troff support to the upcoming SciTE release?

IMHO you can close this PR.

nyamatongwe commented 1 month ago

The troff.properties file includes *.mm in file.patterns.troff which conflicts with its use in file.patterns.cpp in cpp.properties for Objective C++ for Apple development.

I couldn't find *.mm associated with troff on the popular file extension sites.

rhaberkorn commented 1 month ago

I couldn't find *.mm associated with troff on the popular file extension sites.

It's for the Memorandum Macros, a classic macro package. See man groff_mm and here.

Still, as Troff is generally little used nowadays, you should probably give precedence to Objective C++ and leave the *.mm extension in troff.properties commented out.

Even the Groff repository contains only a single letter.mm file. I used the Memorandum Macros here, so it was obvious I had to give precedence to Troff in my SciTECO lexer config. ;-)

nyamatongwe commented 1 month ago

Added troff.properties to SciTE but to avoid long menus it is inactive until user enables it by changing imports.exclude.

https://sourceforge.net/p/scintilla/scite/ci/dcaf189779c4ab8408e40e0b98b61f44a1ffa02c/

rhaberkorn commented 1 month ago

Great, thanks! I will drop a note on the Groff mailing list once it gets into the next SciTE release.

PS: Why did you remove all of the comments in troff.properties?

nyamatongwe commented 1 month ago

PS: Why did you remove all of the comments in troff.properties?

That's the version embedded into the single file executable which doesn't have any comments since you can't read inside the executable and comments could muck up its slightly different format.

I'd actually forgotten to add the main copy of troff.properties so committing that: https://sourceforge.net/p/scintilla/scite/ci/1726b0201bc43b76c15bb68e8242f62d8543ff2b/