I wrote GitHub - ralsina/tartrazine: A Crystal reimplementation of the Pygments/Chroma syntax highlighters to highlight code, and because crystal has its own highlighter, I connected both things.
HOWEVER it fails with some files which are valid crystal. In particular it failed with crycco/src/crycco.cr at main · ralsina/crycco · GitHub
I have reduced the failing input to this:
/#{l[""]}/
"\n"
It fails trying to parse the \n
> bin/tartrazine -f html crycco.cr
Unhandled exception: unknown token: 'n' (Crystal::SyntaxException)
from /usr/lib/crystal/compiler/crystal/syntax/lexer.cr:2949:7 in 'raise'
from /usr/lib/crystal/compiler/crystal/syntax/lexer.cr:2948:5 in 'raise'
from /usr/lib/crystal/compiler/crystal/syntax/lexer.cr:2941:7 in 'unknown_token'
from /usr/lib/crystal/compiler/crystal/syntax/lexer.cr:158:14 in 'next_token'
from /usr/lib/crystal/crystal/syntax_highlighter.cr:87:7 in 'highlight_normal_state'
from /usr/lib/crystal/crystal/syntax_highlighter.cr:80:11 in 'highlight_normal_state'
from /usr/lib/crystal/crystal/syntax_highlighter.cr:14:5 in 'highlight'
from src/lexer.cr:412:7 in 'initialize'
from src/lexer.cr:406:5 in 'new'
from src/lexer.cr:423:7 in 'tokenizer'
from src/lexer.cr:422:5 in 'tokenizer'
from src/formatters/html.cr:79:19 in 'format_text'
from src/formatters/html.cr:57:7 in 'format'
from src/main.cr:112:3 in '__crystal_main'
from /usr/lib/crystal/crystal/main.cr:118:5 in 'main_user_code'
from /usr/lib/crystal/crystal/main.cr:104:7 in 'main'
from /usr/lib/crystal/crystal/main.cr:130:3 in 'main'
from /usr/lib/libc.so.6 in '??'
from /usr/lib/libc.so.6 in '__libc_start_main'
from bin/tartrazine in '_start'
from ???
I can produce a minimal program calling the syntax highlighter for a self-contained test if needed
You can also see it in the interpreter, notice how it doesn’t highlight the bad lines: