@(next "match.c")
@(skip)
static void dir_tables_init(void)
{
@(collect)
  sethash(@nil, @{txr-sym}_s,@(skip)
@(until)
}
@(end)
@(bind tl-orig-sym
       @(append-each* ((entry (package-alist))
                       (pkg-name [mapcar car entry])
                       (pkg [mapcar cdr entry]))
          (append-each ((sym (package-symbols pkg)))
            (when (or (boundp sym) (fboundp sym)
                      (mboundp sym) (special-operator-p sym)
                      (constantp sym) (ffi-type-operator-p sym)
                      (ffi-type-p sym))
              (list sym)))))
@(bind tl-sym
       @(append-each ((sym tl-orig-sym))
           (let* ((pkg (symbol-package sym))
                  (pkg-name (package-name pkg))
                  (qualif (casequal pkg-name
                            ("keyword" ":")
                            ("usr" "")
                            (t `@{pkg-name}:`))))
              (list `@qualif@(symbol-name sym)`))))
@(do (set [txr-sym 0..0] '("end" "and" "or"
                           "catch" "finally"
                           "until" "last"
                           "if" "else" "elif"
                           "single" "first" "last" "empty" "mod" "modlast"
                           "include")))
@(set txr-sym @(sort (uniq txr-sym)))
@(set (tl-sym tl-orig-sym) @(multi-sort (list tl-sym tl-orig-sym)
                                        [list less]))
@(bind bs "\\\\")
@(bind hex "0-9A-Fa-f")
@(bind at "\\(@[ \\t]*\\)")
@(bind alpha "A-Za-z_")
@(bind alnum "A-Za-z_0-9")
@(bind dig "0-9")
@(bind oct "0-7")
@(bind chesc `abtnvfre@bs \\n`)
@(bind glyph `!$%&*+\\-<=>?@{bs}_~`)
@(bind lispwords @(append-each ((sym tl-orig-sym)
                                (text tl-sym))
                    (if (or (special-operator-p sym)
                            (mboundp sym)
                            (ffi-type-operator-p sym))
                      (unless (memq sym '(and dwim inc oand opip or pset
                                              qquote quote qref rotate set
                                              shift swap sys:l1-setq
                                              sys:lisp1-setq sys:qquote
                                              sys:quasi sys:quasilist sys:setq
                                              sys:setqf new lnew
                                              meth umeth usl))
                        (list text)))))
@(define generate (txr-p))
@  (output @(if txr-p "txr.vim" "tl.vim") :named out)
" VIM Syntax file for txr
" Kaz Kylheku <kaz@@kylheku.com>

" INSTALL-HOWTO:
"
" 1. Create the directory .vim/syntax in your home directory and
"    put the files txr.vim and tl.vim into this directory.
" 2. In your .vimrc, add this command to associate *.txr, *.tl and *.tlo
"    files with the txr and tl filetypes:
"    :au BufRead,BufNewFile *.txr set filetype=txr | set lisp
"    :au BufRead,BufNewFile *.tl,*.tlo set filetype=tl | set lisp
"
" If you want syntax highlighting to be on automatically (for any language)
" you need to add ":syntax on" in your .vimrc also. But you knew that already!
"
" This file is generated by the genvim.txr script in the TXR source tree.

syn case match
syn spell toplevel

setlocal iskeyword=a-z,A-Z,48-57,!,$,%,&,*,+,-,:,<,=,>,?,\\,_,~,/,^
@  (rep) @{tl-sym}@(mod 0 4)@\nsyn keyword tl_keyword contained @{tl-sym}@(end)
@  (end)
@  (if txr-p)
@    (output :continue out)
@      (rep) @{txr-sym}@(mod 0 4)@\nsyn keyword txr_keyword contained @{txr-sym}@(end)
syn match txr_error "@at[*]\?[\t ]*."
syn match txr_atat "@at@@"
syn match txr_comment "@at[#;].*"
syn match txr_contin "@at\\$"
syn match txr_char "@at\\."
syn match txr_error "@at\\[xo]"
syn match txr_char "@at\\x[@hex]\+;\?"
syn match txr_char "@at\\[@oct]\+;\?"
syn match txr_regdir "@at/\(\\/\|[^/]\|\\\n\)*/"
@    (end)
@  (end)
@  (output :continue out)
syn match txr_nested_error "[^\t ]\+" contained
syn match txr_variable "@at[*]\?[ \t]*[@alpha][@alnum]*"
syn match txr_splicevar "@@[ \t,*@@]*[@alpha][@alnum]*" contained
syn match txr_metanum "@@\+[0-9]\+"@(if txr-p " contained")
syn match txr_badesc "\\." contained
syn match txr_escat "\\@@" contained
syn match txr_stresc "\\[@chesc"`']" contained
syn match txr_numesc "\\x[@hex]\+;\?" contained
syn match txr_numesc "\\[@oct]\+;\?" contained
syn match txr_regesc "\\[@chesc/sSdDwW()\|.*?+~&%\[\]\-]" contained

syn match txr_error "#[^HSR]"@(if txr-p " contained")

syn match txr_chr "#\\x[@hex]\+"@(if txr-p " contained")
syn match txr_chr "#\\o[@oct]\+"@(if txr-p " contained")
syn match txr_chr "#\\[^ \t\n@alnum]"@(if txr-p " contained")
syn match txr_chr "#\\[@alnum]\+"@(if txr-p " contained")
syn match txr_ncomment ";.*"@(if txr-p " contained")

syn match txr_hashbang "\%^#!.*"

syn match txr_dot "\." contained
syn match txr_ident "[@alnum@glyph]*[@alpha@glyph^][@alnum@glyph^]*" contained
syn match tl_ident "[:@@][@alnum@glyph^/]\+"@(if txr-p " contained")
syn match txr_braced_ident "[:][@alnum@glyph^/]\+" contained
syn match tl_ident "[@alnum@glyph/]\+[@alnum@glyph^/#]*"@(if txr-p " contained")
syn match txr_pnum "#[xob][+\-]\?[@alnum]\+" contains=txr_xnum,txr_bnum,txr_onum@(if txr-p " contained")
syn match txr_xnum "#x[+\-]\?[@hex]\+" containedin=txr_pnum contained
syn match txr_onum "#o[+\-]\?[@oct]\+" containedin=txr_pnum contained
syn match txr_bnum "#b[+\-]\?[01]\+" containedin=txr_pnum contained
syn match txr_num "[+\-]\?[@dig]\+\([^@alnum@glyph^/#]\|\n\)"me=e-1@(if txr-p " contained")
syn match txr_badnum "[+\-]\?[@dig]*[.][@dig]\+\([eE][+\-]\?[@dig]\+\)\?[@alpha@glyph^/#]\+"@(if txr-p " contained")
syn match txr_num "[+\-]\?[@dig]*[.][@dig]\+\([eE][+\-]\?[@dig]\+\)\?\([^@alnum@glyph^/#]\|\n\)"me=e-1@(if txr-p " contained")
syn match txr_num "[+\-]\?[@dig]\+\([eE][+\-]\?[@dig]\+\)\([^@alnum@glyph^/#]\|\n\)"me=e-1@(if txr-p " contained")
syn match tl_ident ":"@(if txr-p " contained")
syn match tl_splice "[ \t,]\|,[*]"@(if txr-p " contained")

syn match txr_unquote "," contained
syn match txr_splice ",\*" contained
syn match txr_quote "'" contained
syn match txr_quote "\^" contained
syn match txr_dotdot "\.\." contained
syn match txr_metaat "@@" contained
syn match txr_circ "#[0-9]\+[#=]"

syn match txr_buf_error "[^']" contained
syn match txr_buf_interior "\([@hex][\n\t ]*[@hex]\|[\n\t ]\+\)" contained

syn region txr_bracevar matchgroup=Delimiter start="@@[ \t]*[*]\?{" matchgroup=Delimiter end="}" contains=txr_num,txr_pnum,tl_ident,tl_splice,tl_metanum,txr_metaat,txr_circ,txr_braced_ident,txr_dot,txr_dotdot,txr_string,txr_list,txr_bracket,txr_mlist,txr_mbracket,txr_regex,txr_quasilit,txr_chr,txr_nested_error
@  (end)
@  (if txr-p)
@    (output :continue out)
syn region txr_directive matchgroup=Delimiter start="@@[ \t]*(" matchgroup=Delimiter end=")" contains=txr_keyword,txr_string,txr_list,txr_bracket,txr_mlist,txr_mbracket,txr_quasilit,txr_num,txr_pnum,txr_badnum,tl_ident,tl_regex,txr_string,txr_chr,txr_quote,txr_unquote,txr_splice,txr_dot,txr_dotdot,txr_metaat,txr_circ,txr_ncomment,txr_nested_error
@    (end)
@  (end)
@  (output :continue out)
syn region txr_list @(if txr-p "contained ")matchgroup=Delimiter start="\(#[HSR]\?\)\?(" matchgroup=Delimiter end=")" contains=tl_keyword,txr_string,tl_regex,txr_num,txr_pnum,txr_badnum,tl_ident,txr_metanum,txr_ign_par,txr_ign_bkt,txr_list,txr_bracket,txr_mlist,txr_mbracket,txr_quasilit,txr_chr,txr_buf,txr_quote,txr_unquote,txr_splice,txr_dot,txr_dotdot,txr_metaat,txr_circ,txr_ncomment,txr_nested_error
syn region txr_bracket @(if txr-p "contained ")matchgroup=Delimiter start="\[" matchgroup=Delimiter end="\]" contains=tl_keyword,txr_string,tl_regex,txr_num,txr_pnum,txr_badnum,tl_ident,txr_metanum,txr_ign_par,txr_ign_bkt,txr_list,txr_bracket,txr_mlist,txr_mbracket,txr_quasilit,txr_chr,txr_buf,txr_quote,txr_unquote,txr_splice,txr_dot,txr_dotdot,txr_metaat,txr_circ,txr_ncomment,txr_nested_error
syn region txr_mlist @(if txr-p "contained ")matchgroup=Delimiter start="@@[ \t^',]*(" matchgroup=Delimiter end=")" contains=tl_keyword,txr_string,tl_regex,txr_num,txr_pnum,txr_badnum,tl_ident,txr_metanum,txr_ign_par,txr_ign_bkt,txr_list,txr_bracket,txr_mlist,txr_mbracket,txr_quasilit,txr_chr,txr_buf,txr_quote,txr_unquote,txr_splice,txr_dot,txr_dotdot,txr_metaat,txr_circ,txr_ncomment,txr_nested_error
syn region txr_mbracket matchgroup=Delimiter start="@@[ \t^',]*\[" matchgroup=Delimiter end="\]" contains=tl_keyword,txr_string,tl_regex,txr_num,txr_pnum,txr_badnum,tl_ident,txr_metanum,txr_ign_par,txr_ign_bkt,txr_list,txr_bracket,txr_mlist,txr_mbracket,txr_quasilit,txr_chr,txr_buf,txr_quote,txr_unquote,txr_splice,txr_dot,txr_dotdot,txr_metaat,txr_circ,txr_ncomment,txr_nested_error
syn region txr_string @(if txr-p "contained ")start=+#\?\*\?"+ end=+["\n]+ contains=txr_stresc,txr_numesc,txr_badesc
syn region txr_quasilit @(if txr-p "contained ")start=+#\?\*\?`+ end=+[`\n]+ contains=txr_splicevar,txr_metanum,txr_bracevar,txr_mlist,txr_mbracket,txr_escat,txr_stresc,txr_numesc,txr_badesc
syn region txr_regex @(if txr-p "contained ")start="/" end="[/\n]" contains=txr_regesc,txr_numesc,txr_badesc
syn region tl_regex @(if txr-p "contained ")start="#/" end="[/\n]" contains=txr_regesc,txr_numesc,txr_badesc
syn region txr_buf @(if txr-p "contained ")matchgroup=txr_buf start="#b'" end="'" contains=txr_buf_interior,txr_buf_error
syn region txr_ign_par @(if txr-p "contained ")matchgroup=Comment start="#;[ \t',]*\(#[HSR]\?\)\?(" matchgroup=Comment end=")" contains=txr_ign_par_interior,txr_ign_bkt_interior
syn region txr_ign_bkt @(if txr-p "contained ")matchgroup=Comment start="#;[ \t',]*\(#[HSR]\?\)\?\[" matchgroup=Comment end="\]" contains=txr_ign_par_interior,txr_ign_bkt_interior
syn region txr_ign_par_interior contained matchgroup=Comment start="(" matchgroup=Comment end=")" contains=txr_ign_par_interior,txr_ign_bkt_interior
syn region txr_ign_bkt_interior contained matchgroup=Comment start="\[" matchgroup=Comment end="\]" contains=txr_ign_par_interior,txr_ign_bkt_interior

hi def link txr_at Special
hi def link txr_atstar Special
hi def link txr_atat Special
hi def link txr_comment Comment
hi def link txr_ncomment Comment
hi def link txr_hashbang Preproc
hi def link txr_contin Preproc
hi def link txr_char String
hi def link txr_keyword Keyword
hi def link tl_keyword Type
hi def link txr_string String
hi def link txr_chr String
hi def link txr_quasilit String
hi def link txr_regex String
hi def link tl_regex String
hi def link txr_regdir String
hi def link txr_variable Identifier
hi def link txr_splicevar Identifier
hi def link txr_metanum Identifier
hi def link txr_escat Special
hi def link txr_stresc Special
hi def link txr_numesc Special
hi def link txr_regesc Special
hi def link txr_badesc Error
hi def link txr_ident Identifier
hi def link tl_ident Identifier
hi def link txr_num Number
hi def link txr_xnum Number
hi def link txr_bnum Number
hi def link txr_onum Number
hi def link txr_badnum Error
hi def link txr_pnum Error
hi def link txr_quote Special
hi def link txr_unquote Special
hi def link txr_splice Special
hi def link txr_dot Special
hi def link txr_dotdot Special
hi def link txr_metaat Special
hi def link txr_circ Special
hi def link txr_munqspl Special
hi def link tl_splice Special
hi def link txr_error Error
hi def link txr_nested_error Error
hi def link txr_buf String
hi def link txr_buf_interior String
hi def link txr_buf_error Error
hi def link txr_ign_par Comment
hi def link txr_ign_bkt_interior Comment
hi def link txr_ign_par_interior Comment
hi def link txr_ign_bkt Comment

let b:current_syntax = "lisp"

set lispwords=@{lispwords ","},:method,:function,:init,:postinit,:fini
@  (end)
@(end)
@(generate t)
@(generate nil)