5

Scintilla is a text editor. Scintillua adds dynamic Lua LPeg lexers to Scintilla for multiple languages. According to the documentation, Scintillua can be used as a library:

Using Scintillua as a Lua Library

In order to use Scintillua as a Lua library, simply place the lexers/ directory in your Lua path (or modify Lua’s package.path accordingly), require() the library and load() a lexer, and call that lexer’s lex() function. Here is an example interactive Lua session doing this:

$> lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> lexer_path = '/home/mitchell/code/scintillua/lexers/?.lua'
> package.path = package.path..';'..lexer_path
> c = require('lexer').load('ansi_c')
> tokens = c:lex('int void main() { return 0; }')
> for i = 1, #tokens, 2 do print(tokens[i], tokens[i+1]) end
type    4
ansi_c_whitespace   5
type    9
ansi_c_whitespace   10
identifier  14
operator    15
operator    16
ansi_c_whitespace   17
operator    18
ansi_c_whitespace   19
keyword 25
ansi_c_whitespace   26
number  27
operator    28
ansi_c_whitespace   29
operator    30

I was wondering if it would be possible to use those lexers as a lua replacement for minted or listings? In addition, it seems that Scintillua supports code folding that could be used to underline code structure as in an old question of mine. What would be the basic code for interacting between TeX and lua (catcodes, etc.)?

cjorssen
  • 10,032
  • 4
  • 36
  • 126
  • This isn’t trivially possible, because neither minted nor listings accept such a lexer input. You’ll need to write your own package that accepts lexer input and formats the tokens. – Konrad Rudolph Aug 16 '16 at 09:13
  • @KonradRudolph Indeed. I'd like to have a skeleton showing how it is possible to work on lua side, including the verbatim part. Then I can work on and elaborate. – cjorssen Aug 16 '16 at 11:17
  • 1
    @cjorssen: In ConTeXt, passing the verbatim part to lua is trivial. See manipulating verbatim text on the ConTeXt wiki. Something similar should also exist for You will need to write a function that takes the lua table returned by lex() and generates the appropriate TeX code. – Aditya Aug 17 '16 at 17:21
  • I took this as an exercice to learn how to do TeX without TeX in luatex (I don't want to deal with verbatim at TeX level). Development is here, really early stage... – cjorssen Oct 11 '16 at 10:05

0 Answers0