local info = { version = 1.400, comment = "basics for scintilla lpeg lexer for context/metafun", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", copyright = "PRAGMA ADE / ConTeXt Development Team", license = "see context related readme files", comment = "contains copyrighted code from mitchell.att.foicica.com", } -- We need a copy of this file to lexer.lua in the same path. This was not needed -- before version 10 but I can't figure out what else to do. It looks like there -- is some loading of lexer.lua but I can't see where. -- For a while it looked like we're stuck with scite 3 because there would be no -- update of scintillua for the newer versions (c++ changes) but now it looks that -- there will be updates (2021). There is a dll for scite >= 5 but it doesn't -- work (yet). In version 5.20+ the scintillua dll makes scite crash (alsl when I -- use the recommended import). In an early 5.02 loading the (shipped) lpeg lexer -- does nothing at all. There have been changes in the lua interface too but I need -- to compare the old and new lib. For now I gave up and got back to version 3+. It -- would be nice if error messages would go to the log pane so that wget an idea -- what happens. After all the code involved (below) is not that much and not that -- complex either. -- -- Actually, scite 5.22 also crashed when a program was launched so better wait -- for a while. (In the worst case, when it all stops working, we need to migrate -- to visual code, which is out backup/fallback plan.) I didn't test if the latest -- textadept still works with our lexer variant. In the meantime that editor has -- grown to some 30 MB so it is no longer a lightweight option (scite with scintilla -- is still quite small). if lpeg.setmaxstack then lpeg.setmaxstack(1000) end local log = false local trace = false local detail = false local show = false -- nice for tracing (also for later) local collapse = false -- can save some 15% (maybe easier on scintilla) local inspect = false -- can save some 15% (maybe easier on scintilla) -- local log = true -- local trace = true -- GET GOING -- -- You need to copy this file over lexer.lua. In principle other lexers could work -- too but not now. Maybe some day. All patterns will move into the patterns name -- space. I might do the same with styles. If you run an older version of SciTE you -- can take one of the archives. Pre 3.41 versions can just be copied to the right -- path, as there we still use part of the normal lexer. Below we mention some -- issues with different versions of SciTE. We try to keep up with changes but best -- check careful if the version that yuou install works as expected because SciTE -- and the scintillua dll need to be in sync. -- -- REMARK -- -- We started using lpeg lexing as soon as it came available. Because we had rather -- demanding files and also wanted to use nested lexers, we ended up with our own -- variant. At least at that time this was more robust and also much faster (as we -- have some pretty large Lua data files and also work with large xml files). As a -- consequence successive versions had to be adapted to changes in the (at that time -- still unstable) api. In addition to lexing we also have spell checking and such. -- Around version 3.60 things became more stable so I don't expect to change much. -- -- LEXING -- -- When pc's showed up we wrote our own editor (texedit) in MODULA 2. It was fast, -- had multiple overlapping (text) windows, could run in the at most 1M memory at -- that time, etc. The realtime file browsing with lexing that we had at that time -- is still on my current wish list. The color scheme and logic that we used related -- to the logic behind the ConTeXt user interface that evolved. -- -- Later I rewrote the editor in perl/tk. I don't like the perl syntax but tk -- widgets are very powerful and hard to beat. In fact, TextAdept reminds me of -- that: wrap your own interface around a framework (tk had an edit control that one -- could control completely not that different from scintilla). Last time I checked -- it still ran fine so I might try to implement something like its file handling in -- TextAdept. -- -- In the end I settled for SciTE for which I wrote TeX and MetaPost lexers that -- could handle keyword sets. With respect to lexing (syntax highlighting) ConTeXt -- has a long history, if only because we need it for manuals. Anyway, in the end we -- arrived at lpeg based lexing (which is quite natural as we have lots of lpeg -- usage in ConTeXt). The basic color schemes haven't changed much. The most -- prominent differences are the nested lexers. -- -- In the meantime I made the lexer suitable for typesetting sources which was no -- big deal as we already had that in place (ConTeXt used lpeg from the day it -- showed up so we have several lexing options there too). -- -- Keep in mind that in ConTeXt (typesetting) lexing can follow several approaches: -- line based (which is handy for verbatim mode), syntax mode (which is nice for -- tutorials), and tolerant mode (so that one can also show bad examples or errors). -- These demands can clash. -- -- HISTORY -- -- The remarks below are more for myself so that I keep track of changes in the -- way we adapt to the changes in the scintillua and scite. -- -- The fold and lex functions are copied and patched from original code by Mitchell -- (see lexer.lua) in the scintillua distribution. So whatever I say below, assume -- that all errors are mine. The ability to use lpeg in scintilla is a real nice -- addition and a brilliant move. The code is a byproduct of the (mainly Lua based) -- TextAdept which at the time I ran into it was a rapidly moving target so I -- decided to stick ot SciTE. When I played with it, it had no realtime output pane -- although that seems to be dealt with now (2017). I need to have a look at it in -- more detail but a first test again made the output hang and it was a bit slow too -- (and I also want the log pane as SciTE has it, on the right, in view). So, for -- now I stick to SciTE even when it's somewhat crippled by the fact that we cannot -- hook our own (language dependent) lexer into the output pane (somehow the -- errorlist lexer is hard coded into the editor). Hopefully that will change some -- day. The ConTeXt distribution has cmd runner for textdept that will plug in the -- lexers discussed here as well as a dedicated runner. Considere it an experiment. -- -- The basic code hasn't changed much but we had to adapt a few times to changes in -- the api and/or work around bugs. Starting with SciTE version 3.20 there was an -- issue with coloring. We still lacked a connection with SciTE itself (properties -- as well as printing to the log pane) and we could not trace this (on windows). -- However on unix we can see messages! As far as I can see, there are no -- fundamental changes in lexer.lua or LexLPeg.cxx so it must be/have been in -- Scintilla itself. So we went back to 3.10. Indicators of issues are: no lexing of -- 'next' and 'goto