Difference between revisions of "Verbatim with LuaTeX"

From Wiki
Jump to navigation Jump to search
m
 
Line 900: Line 900:
 
</texcode>
 
</texcode>
  
[[Category:LuaTeX]]
+
[[Category:Basics]]

Latest revision as of 17:12, 8 June 2020

Here are some verb-*.lua files for syntax highlighting source code or configuration files. The provided files are based on the tex/context/base/verb-*.lua from the ConTeXt distribution and he verb-cpp.lua files posted by Shen Chen in [1]

Python

The verb-py.lua file distinguishes between the following five states:

  • all statements, repeats, conditionals and operators
  • strings (multi line comment with ' ' ' or """ are supported)
  • preconditions (import, from, as)
  • comments
  • builtins
-- filename : verb-py.lua
-- comment  : Syntax highlighting for Python files.
--            Used original tex/context/base/verb-*.lua files,
--            verb-cpp.lua posted by Shen Chen to the NTG-context
--            list (http://archive.contextgarden.net/message/20081002.173802.460c46fe.en.html)
--            and vim syntax files as starting points.
-- author   : Dražen Baić
if not buffers                  then buffers                  = { } end
if not buffers.visualizers      then buffers.visualizers      = { } end
if not buffers.visualizers.py   then buffers.visualizers.py   = { } end

buffers.visualizers.py.in_py_raw_string = false

buffers.visualizers.py.categories = {}

buffers.visualizers.py.delimiters = {
    '@', '%', '^', '&', '*', '(', ')', '-', '+', 
    '=', '|', '\\', '/', '{', '}', '[', ']', ':', ';', '"', 
    '\'', '<', '>', ',', '.', '?', ' ', '#' 
}

buffers.visualizers.py.colors = {
    "prettyone",   -- statements, repeats, conditionals and operators
    "prettytwo",   -- strings
    "prettythree", -- preconditions
    "prettyfour",  -- comments
    "prettyfive"   -- builtins
}

buffers.visualizers.py.categories.statements = {
    'assert',
    'break',
    'continue',
    'del',
    'except', 'exec',
    'finally',
    'global',
    'lambda',
    'pass', 'print',
    'raise', 'return',
    'try',
    'with',
    'yield',
    'def', 'class'
}

buffers.visualizers.py.categories.repeats = {
    'for', 'while'
}

buffers.visualizers.py.categories.conditionals = {
    'if', 'elif', 'else',
}

buffers.visualizers.py.categories.operators = {
    'and', 'in', 'is', 'not', 'or'
}

buffers.visualizers.py.categories.precondits = {
    'import', 'from', 'as'
}

buffers.visualizers.py.categories.builtins = {
     '__import__', 
     'abs', 'apply', 
     'bool', 'buffer', 
     'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 
     'delattr', 'dict', 'dir', 'divmod', 
     'enumerate', 'Ellipsis', 'eval', 'execfile', 
     'False', 'file', 'filter', 'float', 'frozenset', 
     'getattr', 'globals', 
     'hasattr', 'hash', 'help', 'hex', 
     'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 
     'len', 'list', 'locals', 'long', 
     'map', 'max', 'min', 
     'None', 'NotImplemented', 
     'object', 'oct', 'open', 'ord', 
     'pow', 'property', 
     'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 
     'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super',
     'True', 'tuple', 'type', 
     'unichr', 'unicode', 
     'vars', 
     'xrange', 
     'zip'
}

buffers.visualizers.py.words = { }

for k,v in pairs(buffers.visualizers.py.categories) do
    for _,w in pairs(v) do
        buffers.visualizers.py.words[w] = k
    end
end

buffers.visualizers.py.styles = { }
-- Uncomment the following lines to enable different
-- styles for each state
-- buffers.visualizers.py.styles.statements = "\\bf "
-- buffers.visualizers.py.styles.repeats = "\\bi "
-- buffers.visualizers.py.styles.conditionals = "\\bi "
-- buffers.visualizers.py.styles.operators = "\\bi "
-- buffers.visualizers.py.styles.precondits = "\\bf "
-- buffers.visualizers.py.styles.comments = "\\it "
-- buffers.visualizers.py.styles.strings = "\\bi "

function buffers.flush_py_word(state, word, result)
    if #word>0 then
        local id = buffers.visualizers.py.words[word]
        if id == 'precondits' then
            state = buffers.change_state(3,state,result)
            if buffers.visualizers.py.styles[id] then
                result[#result+1] = buffers.visualizers.py.styles[id] .. buffers.escaped(word)
            else
                result[#result+1] = buffers.escaped(word)
            end
            state = buffers.finish_state(state,result)
            return state
        elseif id == 'builtins' then
            state = buffers.change_state(5,state,result)
            result[#result+1] = buffers.escaped(word)
            state = buffers.finish_state(state,result)
            return state
        elseif id then
          state = buffers.change_state(1,state,result)
          if buffers.visualizers.py.styles[id] then
              result[#result+1] = buffers.visualizers.py.styles[id] .. buffers.escaped(word)
          else
              result[#result+1] = buffers.escaped(word)
          end
            state = buffers.finish_state(state,result)
            return state
        else
            result[#result+1] = buffers.escaped(word)
            return state
        end
    else
        state = buffers.finish_state(state,result)
        return state
    end
end


function buffers.visualizers.py.flush_line(str,nested)
    local i, result , word = 1, { }, ""
    local state = 0
    local delimiters=buffers.visualizers.py.delimiters
    local is_delimiter = false
    local in_string = false
  
    buffers.currentcolors = buffers.visualizers.py.colors
  
    while i <= #str do
        c=string.sub(str,i,i)
        if buffers.visualizers.py.in_py_raw_string then
            if c=="\'" and string.sub(str,i,i+2)=="\'\'\'" then
                -- without the next line the triple quotes won't be colored
                -- correctly if they appear in the beginning of a line
                state = buffers.change_state(2,state,result)
                result[#result+1] = buffers.escaped(string.sub(str,i,i+2))
                i=i+2
                buffers.visualizers.py.in_py_raw_string=false
                state = buffers.finish_state(state,result)
            elseif c=="\"" and string.sub(str,i,i+2)=="\"\"\"" then
                -- without the next line the triple quotes won't be colored
                -- correctly if they appear in the beginning of a line
                state = buffers.change_state(2,state,result)
                result[#result+1] = buffers.escaped(string.sub(str,i,i+2))
                i=i+2
                buffers.visualizers.py.in_py_raw_string=false
                state = buffers.finish_state(state,result)
            else
                state = buffers.change_state(2,state,result)
                result[#result+1] = buffers.escaped_chr(c)
            end
        elseif in_string then
            if c=="\\" then
                result[#result+1] = buffers.escaped(string.sub(str,i,i+1))
                i=i+1
            elseif c=="\"" then
                result[#result+1] = buffers.escaped_chr(c)
                in_string=false
                state = buffers.finish_state(state,result)
            elseif c=="\'" then
                result[#result+1] = buffers.escaped_chr(c)
                in_string=false
                state = buffers.finish_state(state,result)
            else
                result[#result+1] = buffers.escaped_chr(c)
            end
        else
            for _,v in ipairs(delimiters) do
                if  c==v then
                    is_delimiter = true
                end
            end
            if is_delimiter then
                if c==" " then
                    state = buffers.flush_py_word(state,word,result)
                    result[#result+1] = "\\obs "
                elseif (c=="\'") and string.sub(str,i,i+2)=="\'\'\'" then
                    state = buffers.flush_py_word(state,word,result)
                    buffers.visualizers.py.in_py_raw_string = true
                    state = buffers.change_state(2,state,result)
                    result[#result+1] = buffers.escaped(string.sub(str,i,i+1))
                    i=i+1
                elseif (c=="\"") and string.sub(str,i,i+2)=="\"\"\"" then
                    state = buffers.flush_py_word(state,word,result)
                    buffers.visualizers.py.in_py_raw_string = true
                    state = buffers.change_state(2,state,result)
                    result[#result+1] = buffers.escaped(string.sub(str,i,i+1))
                    i=i+1
                elseif (c=="#") then
                    state = buffers.flush_py_word(state,word,result)
                    state = buffers.change_state(4,state,result)
                    result[#result+1] = buffers.escaped(string.sub(str,i))
                    i=#str
                elseif (c=="\"") and not in_string then
                    state = buffers.flush_py_word(state,word,result)
                    in_string = true
                    state = buffers.change_state(2,state,result)
                    result[#result+1] = buffers.escaped_chr(c)
                elseif (c=="\'") and not in_string then
                    state = buffers.flush_py_word(state,word,result)
                    in_string = true
                    state = buffers.change_state(2,state,result)
                    result[#result+1] = buffers.escaped_chr(c)
                elseif (c==".") and (#word==0 or string.find(string.sub(word,1,1),'%d')) then
                   word = word .. c
                    is_delimiter=false
                else
                    state = buffers.flush_py_word(state,word,result)
                    result[#result+1] = buffers.escaped_chr(c)
                end
                if is_delimiter then
                    word = ""
                    is_delimiter=false
                end
            else
              word = word .. c
            end
        end
        i=i+1
    end
    state = buffers.flush_py_word(state,word,result)
    buffers.flush_result(result,false)
end


Apache httpd.conf

The verb-apa.lua file distinguishes between the following five states:

  • declarations
  • strings
  • sections (like <Directory> and </Directory>)
  • comments
  • options
-- filename : verb-apa.lua
-- comment  : Syntax highlighting for Apache config files.
--            Used original tex/context/base/verb-*.lua files,
--            verb-cpp.lua posted by Shen Chen to the NTG-context
--            list (http://archive.contextgarden.net/message/20081002.173802.460c46fe.en.html)
--            and vim syntax files as starting points.
-- author   : Dražen Baić
if not buffers                  then buffers                  = { } end
if not buffers.visualizers      then buffers.visualizers      = { } end
if not buffers.visualizers.apa  then buffers.visualizers.apa  = { } end

buffers.visualizers.apa.categories = {}

buffers.visualizers.apa.delimiters = {
    '"', '\'', ',', '.', '?', ' ', '#', '*', '>' 
}

buffers.visualizers.apa.colors = {
    "prettyone",   -- declarations
    "prettytwo",   -- strings
    "prettythree", -- sections
    "prettyfour",  -- comments
    "prettyfive"   -- options
}

buffers.visualizers.apa.categories.declarations_core = {
    'AcceptFilter', 'AcceptMutex', 'AcceptPathInfo', 'AccessFileName', 'AddDefaultCharset', 'AllowEncodedSlashes',
    'AllowOverride', 'AssignUserId', 'AuthName', 'AuthType', 
    'CGIMapExtension', 'ChildPerUserId', 'ContentDigest', 'CoreDumpDirectory', 
    'DefaultType', 'DocumentRoot', 
    'EnableExceptionHook', 'EnableMMAP', 'EnableSendfile', 'ErrorDocument', 'ErrorLog', 
    'FileETag', 'ForceType', 
    'GracefulShutdownTimeout', 'Group', 
    'HostNameLookups', 
    'IdentityCheck', 'Include', 
    'KeepAlive', 'KeepAliveTimeout', 
    'LimitInternalRecursion', 'LimitRequestBody', 'LimitRequestFields', 'LimitRequestFieldsize', 'LimitRequestLine', 
    'LimitXMLRequestBody', 'Listen', 'ListenBacklog', 'LockFile',
    'LogLevel', 
    'MaxClients', 'MaxKeepAliveRequests', 'MaxMemFree', 'MaxRequestsPerChild', 'MaxSpareServers', 'MaxSpareThreads',
    'MaxSpareThreadsPerChild', 'MaxThreads', 'MinSpareServers',
    'MinSpareThreads', 
    'NameVirtualHost', 'NumServers', 
    'Options', 
    'PidFile', 
    'Require', 'RLimitCPU', 'RLimitMEM', 'RLimitNPROC', 
    'Satisfy', 'ScoreBoardFile', 'ScriptInterpreterSource', 'SendBufferSize', 'ServerAdmin', 'ServerAlias', 'ServerLimit',
    'ServerName', 'ServerPath', 'ServerRoot', 'ServerSignature', 'ServerTokens',
    'SetHandler', 'SetInputFilter', 'SetOutputFilter', 'StartServers', 'StartThreads', 
    'ThreadLimit', 'ThreadsPerChild', 'ThreadStackSize', 'TimeOut', 'TraceEnable', 
    'UseCanonicalName', 'User', 
    'Win32DisableAcceptEx'
}

buffers.visualizers.apa.categories.declarations_mod = {
    -- mod_actions
    'Action', 'Script',
    -- mod_alias
    'Alias', 'AliasMatch', 'Redirect', 'RedirectMatch', 'RedirectTemp', 'RedirectPermanent', 'ScriptAlias', 'ScriptAliasMatch',
    -- mod_auth_basic
    'AuthBasicAuthoritative', 'AuthBasicProvider',
    -- mod_auth_digest
    'AuthDigestAlgorithm', 'AuthDigestDomain', 'AuthDigestNcCheck', 'AuthDigestNonceFormat', 'AuthDigestNonceLifetime',
    'AuthDigestProvider', 'AuthDigestQop', 'AuthDigestShmemSize',
    -- mod_authn_anon
    'Anonymous', 'Anonymous_Authoritative', 'Anonymous_LogEmail', 'Anonymous_MustGiveEmail', 'Anonymous_NoUserID',
    'Anonymous_VerifyEmail',
    -- mod_authn_dbd
    'AuthDBDUserPWQuery', 'AuthDBDUserRealmQuery',
    -- mod_authn_dbm
    'AuthDBMType', 'AuthDBMUserFile',
    -- mod_authn_default
    'AuthDefaultAuthoritative',
    -- mod_authn_file
    'AuthUserFile',
    -- mod_authnz_ldap
    'AuthLDAPBindDN', 'AuthLDAPBindPassword', 'AuthLDAPCharsetConfig', 'AuthLDAPCompareDNOnServer',
    'AuthLDAPDereferenceAliases', 'AuthLDAPGroupAttribute',
    'AuthLDAPGroupAttributeIsDN', 'AuthLDAPRemoteUserAttribute', 'AuthLDAPRemoteUserIsDN', 'AuthLDAPUrl',
    'AuthzLDAPAuthoritative',
    -- mod_authz_dbm
    'AuthDBMGroupFile', 'AuthzDBMAuthoritative', 'AuthzDBMType',
    -- mod_authz_default
    'AuthzDefaultAuthoritative',
    -- mod_authz_groupfile
    'AuthGroupFile', 'AuthzGroupFileAuthoritative',
    -- mod_authz_host
    'Allow', 'Deny', 'Order',
    -- mod_authz_owner
    'AuthzOwnerAuthoritative',
    -- mod_authz_user
    'AuthzUserAuthoritative',
    -- mod_autoindex
    'AddAlt', 'AddAltByEncoding', 'AddAltByType', 'AddDescription', 'AddIcon', 'AddIconByEncoding', 'AddIconByType',
    'DefaultIcon', 'HeaderName', 'IndexHeadInsert', 'IndexIgnore',
    'IndexOptions', 'IndexOrderDefault', 'IndexStyleSheet', 'ReadmeName',
    -- mod_cache
    'CacheDefaultExpire', 'CacheDisable', 'CacheEnable', 'CacheIgnoreCacheControl', 'CacheIgnoreHeaders',
    'CacheIgnoreNoLastMod', 'CacheIgnoreQueryString', 'CacheLastModifiedFactor',
    'CacheMaxExpire', 'CacheStoreNoStore', 'CacheStorePrivate',
    -- mod_cern_meta
    'MetaDir', 'MetaFiles', 'MetaSuffix',
    -- mod_cgi and mod_cgid
    'ScriptLog', 'ScriptLogBuffer', 'ScriptLogLength', 'ScriptSock',
    -- mod_charset_lite
    'CharsetDefault', 'CharsetOptions', 'CharsetSourceEnc',
    -- mod_dav
    'Dav', 'DavDepthInfinity', 'DavMinTimeout',
    -- mod_dav_fs
    'DavLockDB',
    -- mod_dav_lock
    'DavGenericLockDB',
    -- mod_dbd
    'DBDExptime', 'DBDKeep', 'DBDMax', 'DBDMin', 'DBDParams', 'DBDPersist', 'DBDPrepareSQL', 'DBDriver',
    -- mod_deflate
    'DeflateBufferSize', 'DeflateCompressionLevel', 'DeflateFilterNote', 'DeflateMemLevel', 'DeflateWindowSize',
    -- mod_dir
    'DirectoryIndex', 'DirectorySlash',
    -- mod_disk_cache
    'CacheDirLength', 'CacheDirLevels', 'CacheMaxFileSize', 'CacheMinFileSize', 'CacheRoot',
    -- mod_dumpio
    'DumpIOInput', 'DumpIOLogLevel', 'DumpIOOutput',
    -- mod_echo
    'ProtocolEcho',
    -- mod_env
    'PassEnv', 'SetEnv', 'UnsetEnv',
    -- mod_example
    'Example',
    -- mod_expires
    'ExpiresActive', 'ExpiresByType', 'ExpiresDefault',
    -- mod_ext_filter
    'ExtFilterDefine', 'ExtFilterOptions',
    -- mod_file_cache
    'CacheFile', 'MMapFile',
    -- mod_filter
    'FilterChain', 'FilterDeclare', 'FilterProtocol', 'FilterProvider', 'FilterTrace',
    -- mod_headers
    'Header', 'RequestHeader',
    -- mod_ident
    'IdentityCheck', 'IdentityCheckTimeout',
    -- mod_imagemap
    'ImapMenu', 'ImapDefault', 'ImapBase',
    -- mod_include
    'SSIEnableAccess', 'SSIEndTag', 'SSIErrorMsg', 'SSIStartTag', 'SSITimeFormat', 'SSIUndefinedEcho', 'XBitHack',
    -- mod_info
    'AddModuleInfo',
    -- mod_isapi
    'ISAPIAppendLogToErrors', 'ISAPIAppendLogToQuery', 'ISAPICacheFile', 'ISAIPFakeAsync', 'ISAPILogNotSupported', 'ISAPIReadAheadBuffer',
    -- mod_ldap
    'LDAPCacheEntries', 'LDAPCacheTTL', 'LDAPConnectionTimeout', 'LDAPOpCacheEntries', 'LDAPOpCacheTTL',
    'LDAPSharedCacheFile', 'LDAPSharedCacheSize', 'LDAPTrustedClientCert',
    'LDAPTrustedGlobalCert', 'LDAPTrustedMode', 'LDAPVerifyServerCert',
    -- mod_log_config
    'BufferedLogs', 'CookieLog', 'CustomLog', 'LogFormat', 'TransferLog',
    -- mod_log_forensic
    'ForensicLog',
    -- mod_mem_cache
    'MCacheMaxObjectCount', 'MCacheMaxObjectSize', 'MCacheMaxStreamingBuffer', 'MCacheMinObjectSize',
    'MCacheRemovalAlgorithm', 'MCacheSize',
    -- mod_mime
    'AddCharset', 'AddEncoding', 'AddHandler', 'AddInputFilter', 'AddLanguage', 'AddOutputFilter', 'AddType', 'DefaultLanguage',
    'ModMimeUsePathInfo', 'MultiviewsMatch', 'RemoveCharset',
    'RemoveEncoding', 'RemoveHandler', 'RemoveInputFilter', 'RemoveLanguage', 'RemoveOutputFilter', 'RemoveType', 'TypesConfig',
    -- mod_mime_magic
    'MimeMagicFile',
    -- mod_negotiation
    'CacheNegotiatedDocs', 'ForceLanguagePriority', 'LanguagePriority',
    -- mod_nw_ssl
    '', 'NWSSLTrustedCerts', 'NWSSLUpgradeable', 'SecureListen',
    -- mod_proxy
    'AllowCONNECT', 'BalancerMember', 'NoProxy', 'ProxyBadHeader', 'ProxyBlock', 'ProxyDomain', 'ProxyErrorOverride',
    'ProxyFtpDirCharset', 'ProxyIOBufferSize', 'ProxyMaxForwards', 'ProxyPass',
    'ProxyPassInterpolateEnv', 'ProxyPassMatch', 'ProxyPassReverse', 'ProxyPassReverseCookieDomain', 'ProxyPassReverseCookiePath',
    'ProxyPreserveHost', 'ProxyReceiveBufferSize', 'ProxyRemote',
    'ProxyRemoteMatch', 'ProxyRequests', 'ProxySet', 'ProxyStatus', 'ProxyTimeout', 'ProxyVia',
    -- mod_rewrite
    'RewriteBase', 'RewriteCond', 'RewriteEngine', 'RewriteLock', 'RewriteLog', 'RewriteLogLevel', 'RewriteMap', 'RewriteOptions', 'RewriteRule',
    -- mod_setenvif
    'BrowserMatch', 'BrowserMatchNoCase', 'SetEnvIf', 'SetEnvIfNoCase',
    -- mod_so
    'LoadFile', 'LoadModule',
    -- mod_speling
    'CheckCaseOnly', 'CheckSpelling',
    -- mod_ssl
    'SSLCACertificateFile', 'SSLCACertificatePath', 'SSLCADNRequestFile', 'SSLCADNRequestPath', 'SSLCARevocationFile',
    'SSLCARevocationPath', 'SSLCertificateChainFile', 'SSLCertificateFile',
    'SSLCertificateKeyFile', 'SSLCipherSuite', 'SSLCryptoDevice', 'SSLEngine', 'SSLHonorCipherOrder', 'SSLMutex', 'SSLOptions',
    'SSLPassPhraseDialog', 'SSLProtocol', 'SSLProxyCACertificateFile', 'SSLProxyCACertificatePath', 'SSLProxyCARevocationFile',
    'SSLProxyCARevocationPath', 'SSLProxyCipherSuite', 'SSLProxyEngine',
    'SSLProxyMachineCertificateFile', 'SSLProxyMachineCertificatePath',
    'SSLProxyProtocol', 'SSLProxyVerify', 'SSLProxyVerifyDepth', 'SSLRandomSeed', 'SSLRenegBufferSize', 'SSLRequire',
    'SSLRequireSSL', 'SSLSessionCache', 'SSLSessionCacheTimeout', 'SSLUserName',
    'SSLVerifyClient', 'SSLVerifyDepth',
    -- mod_status
    'ExtendedStatus', 'SeeRequestTail',
    -- mod_substitute
    'Substitute',
    -- mod_suexec
    'SuexecUserGroup',
    -- mod_userdir
    'UserDir',
    -- mod_usertrack
    'CookieDomain', 'CookieExpires', 'CookieName', 'CookieStyle', 'CookieTracking',
    -- mod_vhost_alias
    'VirtualDocumentRoot', 'VirtualDocumentRootIP', 'VirtualScriptAlias', 'VirtualScriptAliasIP'
}

buffers.visualizers.apa.categories.options = {
    -- core
    'INode', 'MTime', 'Size',
    'Any', 'All', 'On', 'Off', 'Double', 'EMail', 'DNS', 'Min', 'Minimal', 'OS', 'Prod', 'ProductOnly', 'Full',
    'emerg', 'alert', 'crit', 'error', 'warn', 'notice', 'info', 'debug',
    'registry', 'script', 'inetd', 'standalone',
    'user', 'group',
    'flock', 'fcntl', 'sysvsem', 'pthread',
    -- mod_alias
    'permanent', 'temp', 'seeother', 'gone',
    -- mod_auth_digest
    'none', 'auth', 'auth-int', 'MD5-sess',
    -- mod_auth_dbm
    'default', 'SDBM', 'GDBM', 'NDBM', 'DB',
    -- mod_authz_host
    'from',
    -- mod_authnz_ldap
    'always', 'never', 'searching', 'finding',
    'ldap-user', 'ldap-group', 'ldap-dn', 'ldap-attribute', 'ldap-filter',
    -- mod_autoindex
    'DescriptionWidth', 'FancyIndexing', 'FoldersFirst', 'IconHeight', 'IconsAreLinks', 'IconWidth', 'NameWidth',
    'ScanHTMLTitles', 'SuppressColumnSorting', 'SuppressDescription',
    'SuppressHTMLPreamble', 'SuppressLastModified', 'SuppressSize', 'TrackModified',
    'Ascending', 'Descending', 'Name', 'Date', 'Description',
    'IgnoreClient', 'IgnoreCase', 'ShowForbidden', 'SuppresRules',
    -- mod_charset_lite
    'DebugLevel', 'ImplicitAdd', 'NoImplicitAdd',
    -- mod_ext_filter
    'PreservesContentLength', 'LogStderr', 'NoLogStderr',
    -- mod_headers
    'set', 'unset', 'append', 'add',
    -- mod_imagemap
    'formatted', 'semiformatted', 'unformatted',
    'nocontent', 'referer', 'map',
    -- mod_ldap
    'CA_DER', 'CA_BASE64', 'CA_CERT7_DB', 'CA_SECMOD', 'CERT_DER', 'CERT_BASE64', 'CERT_KEY3_DB',
    'CERT_NICKNAME', 'CERT_PFX', 'KEY_DER', 'KEY_BASE64', 'KEY_PFX',
    -- mod_mime
    'NegotiatedOnly', 'Filters', 'Handlers',
    -- mod_rewrite
    'inherit',
    -- mod_ssl
    'builtin', 'sem',
    'optional', 'optional_no_ca',
    'file', 'exec', 'egd', 'dbm', 'shm',
    'SSLv2', 'SSLv3', 'TLSv1', 'kRSA', 'kHDr', 'kDHd', 'kEDH', 'aNULL', 'aRSA', 'aDSS', 'aRH', 'eNULL', 'DES', '3DES',
    'RC2', 'RC4', 'IDEA', 'MD5', 'SHA1', 'SHA', 'EXP', 'EXPORT40', 'EXPORT56', 'LOW',
    'MEDIUM', 'HIGH', 'RSA', 'DH', 'EDH', 'ADH', 'DSS', 'NULL',
    -- mod_usertrack
    'Netscape', 'Cookie', 'Cookie2', 'RFC2109', 'RFC2965'
}


buffers.visualizers.apa.categories.sections = {
    '<Directory', '</Directory', '<DirectoryMatch', '</DirectoryMatch', '<Files', '</Files',
    '<FilesMatch', '</FilesMatch', '<IfModule', '</IfModule', 
    '<IfDefine', '</IfDefine', '<Location', '</Location', '<LocationMatch', '</LocationMatch',
    '<VirtualHost', '</VirtualHost', '<ProxyMatch', '</ProxyMatch'
}
buffers.visualizers.apa.words = { }

for k,v in pairs(buffers.visualizers.apa.categories) do
    for _,w in pairs(v) do
        buffers.visualizers.apa.words[w] = k
    end
end

function buffers.flush_apa_word(state, word, result)
    if #word>0 then
        local id = buffers.visualizers.apa.words[word]
        if id == 'sections' then
            state = buffers.change_state(1,state,result)
            result[#result+1] = buffers.escaped(word)
            state = buffers.finish_state(state,result)
            return state
        elseif id == 'options' then
            state = buffers.change_state(5,state,result)
            result[#result+1] = buffers.escaped(word)
            state = buffers.finish_state(state,result)
            return state
        elseif id then
            state = buffers.change_state(3,state,result)
            result[#result+1] = buffers.escaped(word)
            state = buffers.finish_state(state,result)
            return state
        else
            result[#result+1] = buffers.escaped(word)
            return state
        end
    else
        state = buffers.finish_state(state,result)
        return state
    end
end


function buffers.visualizers.apa.flush_line(str,nested)
    local i, result , word = 1, { }, ""
    local state = 0
    local delimiters=buffers.visualizers.apa.delimiters
    local is_delimiter = false
    local in_string = false
  
    buffers.currentcolors = buffers.visualizers.apa.colors
  
    while i <= #str do
        c=string.sub(str,i,i)
  
        if in_string then
            if c=="\\" then
                result[#result+1] = buffers.escaped(string.sub(str,i,i+1))
                i=i+1
            elseif c=="\"" then
                result[#result+1] = buffers.escaped_chr(c)
                in_string=false
                state = buffers.finish_state(state,result)
            elseif c=="\'" then
                result[#result+1] = buffers.escaped_chr(c)
                in_string=false
                state = buffers.finish_state(state,result)
            else
                result[#result+1] = buffers.escaped_chr(c)
            end
        else
            for _,v in ipairs(delimiters) do
                if  c==v then
                    is_delimiter = true
                end
            end
            if is_delimiter then
                if c==" " then
                    state = buffers.flush_apa_word(state,word,result)
                    result[#result+1] = "\\obs "
                elseif (c=="#") then
                    state = buffers.flush_apa_word(state,word,result)
                    state = buffers.change_state(4,state,result)
                    result[#result+1] = buffers.escaped(string.sub(str,i))
                    i=#str
                elseif (c=="\"") and not in_string then
                    state = buffers.flush_apa_word(state,word,result)
                    in_string = true
                    state = buffers.change_state(2,state,result)
                    result[#result+1] = buffers.escaped_chr(c)
                elseif (c=="\'") and not in_string then
                    state = buffers.flush_apa_word(state,word,result)
                    in_string = true
                    state = buffers.change_state(2,state,result)
                    result[#result+1] = buffers.escaped_chr(c)
                elseif (c==">") and not in_string then
                    state = buffers.flush_apa_word(state,word,result)
                    state = buffers.change_state(1,state,result)
                    result[#result+1] = buffers.escaped_chr(c)
                elseif (c==".") and (#word==0 or string.find(string.sub(word,1,1),'%d')) then
                    word = word .. c
                    is_delimiter=false
                else
                    state = buffers.flush_apa_word(state,word,result)
                    result[#result+1] = buffers.escaped_chr(c)
                end
                if is_delimiter then
                    word = ""
                    is_delimiter=false
                end
            else
                word = word .. c
            end
        end
        i=i+1
    end
    state = buffers.flush_apa_word(state,word,result)
    buffers.flush_result(result,false)
end

zc.buildout config files

The verb-py.cfg file distinguishes between the following four states:

  • sections
  • variables
  • keywords
  • comments
-- filename : verb-cfg.lua
-- comment  : Syntax highlighting for zc.buildout config files.
--            Used original tex/context/base/verb-*.lua files,
--            verb-cpp.lua posted by Shen Chen to the NTG-context
--            list (http://archive.contextgarden.net/message/20081002.173802.460c46fe.en.html)
--            and vim syntax files as starting points.
-- author   : Dražen Baić
if not buffers                  then buffers                  = { } end
if not buffers.visualizers      then buffers.visualizers      = { } end
if not buffers.visualizers.cfg  then buffers.visualizers.cfg  = { } end

buffers.visualizers.cfg.categories = {}

buffers.visualizers.cfg.delimiters = {
    '"', '\'', ' ', '#', '*', '>' ,'=', '[', ']', '{', '}', '$'
}

buffers.visualizers.cfg.colors = {
    "prettyone",   -- sections
    "prettytwo",   -- variables
    "prettythree", -- keywords
    "prettyfour"   -- comments
}

buffers.visualizers.cfg.categories.keywords = {
    'additional-fake-eggs', 
    'client1-address', 'client2-address', 'command', 
    'debug-mode', 'deprecation-warnings', 'develop', 'download-cache',
    'effective-user', 'eggs', 'eggs-directory', 'environment-vars', 'event-log', 'extends', 'extra-paths', 
    'fake-zope-eggs', 'find-links', 
    'http-address', 
    'instance-clone', 'interpreter', 
    'lock-file', 
    'nested-packages', 'newest', 
    'parts', 'pid-file', 'primary-port', 'products', 
    'recipe', 
    'scripts', 'socket-name', 'sudo-command', 
    'unzip', 'update-command', 'url', 'urls', 'user', 
    'verbose-security', 'version-suffix-packages', 'versions', 
    'z2-log', 'zcml', 'zeo-address', 'zeo-client', 'zeo-log', 'zope-directory', 'zope2-location'
}

buffers.visualizers.cfg.words = { }

for k,v in pairs(buffers.visualizers.cfg.categories) do
    for _,w in pairs(v) do
        buffers.visualizers.cfg.words[w] = k
    end
end

function buffers.flush_cfg_word(state, word, result)
    if #word>0 then
        local id = buffers.visualizers.cfg.words[word]
        if id == 'keywords' then
            state = buffers.change_state(3,state,result)
            result[#result+1] = buffers.escaped(word)
            state = buffers.finish_state(state,result)
            return state
        elseif id then
            state = buffers.change_state(3,state,result)
            result[#result+1] = buffers.escaped(word)
            state = buffers.finish_state(state,result)
            return state
        else
            result[#result+1] = buffers.escaped(word)
            return state
        end
    else
        state = buffers.finish_state(state,result)
        return state
    end
end


function buffers.visualizers.cfg.flush_line(str,nested)
    local i, result , word = 1, { }, ""
    local state = 0
    local delimiters=buffers.visualizers.cfg.delimiters
    local is_delimiter = false
    local in_variable = false
    local in_section = false
    buffers.currentcolors = buffers.visualizers.cfg.colors

    while i <= #str do
        c=string.sub(str,i,i)

        if in_variable then
            if c=="}" then
                result[#result+1] = buffers.escaped_chr(c)
                in_variable=false
                state = buffers.finish_state(state,result)
            else
                result[#result+1] = buffers.escaped_chr(c)
            end
        elseif in_section then
            if c=="]" then
                result[#result+1] = buffers.escaped_chr(c)
                in_section=false
                state = buffers.finish_state(state,result)
            else
                result[#result+1] = buffers.escaped_chr(c)
            end
        else
            for _,v in ipairs(delimiters) do
                if  c==v then
                    is_delimiter = true
                end
            end
            if is_delimiter then
                if c==" " then
                    state = buffers.flush_cfg_word(state,word,result)
                    result[#result+1] = "\\obs "
                elseif (c=="#") then
                    state = buffers.flush_cfg_word(state,word,result)
                    state = buffers.change_state(4,state,result)
                    result[#result+1] = buffers.escaped(string.sub(str,i))
                    i=#str
                elseif (c=="$") and string.sub(str,i,i+1)=="${" then
                    state = buffers.flush_cfg_word(state,word,result)
                    in_variable = true
                    state = buffers.change_state(2,state,result)
                    result[#result+1] = buffers.escaped(string.sub(str,i,i+1))
                    i=i+1
                elseif (c=="[") and not in_section then
                    state = buffers.flush_cfg_word(state,word,result)
                    in_section = true
                    state = buffers.change_state(1,state,result)
                    result[#result+1] = buffers.escaped_chr(c)
                else
                    state = buffers.flush_cfg_word(state,word,result)
                    result[#result+1] = buffers.escaped_chr(c)
                end
                if is_delimiter then
                    word = ""
                    is_delimiter=false
                end
            else
                word = word .. c
            end
        end
    i=i+1
    end
    state = buffers.flush_cfg_word(state,word,result)
    buffers.flush_result(result,false)
end

Sample Page

Here is an example how to use these files:

\setupcolors[state=start]
\definecolor[colorprettyone]  [r=.9, g=.0, b=.0] % red
\definecolor[colorprettytwo]  [r=.0, g=.8, b=.0] % green
\definecolor[colorprettythree][r=.0, g=.0, b=.9] % blue
\definecolor[colorprettyfour] [s=0.60]           % gray
\definecolor[colorprettyfive] [orange]
\definepalet[colorpretty]
            [prettyone=colorprettyone,
            prettytwo=colorprettytwo,
            prettythree=colorprettythree,
            prettyfour=colorprettyfour,
            prettyfive=colorprettyfive]
% Apache httpd.conf listings
\installprettytype[APA][APA]
\definetyping     [APA]           [option=APA]
\definepalet      [APAcolorpretty][colorpretty]
\setuptyping      [APA]           [bodyfont=10pt]
% Python listings
\installprettytype[PY][PY]
\definetyping     [PY]            [option=PY]
\definepalet      [PYcolorpretty] [colorpretty]
\setuptyping      [PY]            [bodyfont=10pt]
% buildout.cfg listings
\installprettytype[CFG][CFG]
\definetyping     [CFG]           [option=CFG]
\definepalet      [CFGcolorpretty][colorpretty]
\setuptyping      [CFG]           [bodyfont=10pt]

\starttext
\section{httpd.conf sample}
\startAPA

    ServerName www.example.com
    ErrorLog /var/log/apache2/error.log
    LogLevel error
    CustomLog /var/log/apache2/access.log combinedio

    RewriteEngine On
    RewriteLog /var/log/apache2/rewrite.log

    # allow access to ZMI only from local network
    
        Order Deny,Allow
        Deny from all
        Allow from 10.
    

\stopAPA

\section{Python sample}
\startPY
#!/usr/local/bin/python

import os.path, sys

# Just a comment
foo = os.environ.get('FOO')
bar = os.environ.get('BAR')

if foo:
    foo = os.path.realpath(foobar)
elif bar:
    bar = os.path.realpath(bar)
else:
    print >> sys.stderr, '''
    FOO or BAR need to be set!
    '''

# Another comment
def test_foobar_title(self): 
    nothing_special = getattr(self.types, 'FooBar') 
\stopPY

\section{buildout.cfg sample}
\startCFG
# Use this section to install and configure a Zope
# Enterprise Objects server.
# For options see http://pypi.python.org/pypi/plone.recipe.zope2zeoserver
[zeoserver]
recipe = plone.recipe.zope2zeoserver
zope2-location = ${zope2:location}
zeo-address = ${buildout:zeo-address}
effective-user = zeo
# Put the log, pid and socket files in var/zeoserver
zeo-log     = ${buildout:directory}/var/zeoserver/zeoserver.log
pid-file    = ${buildout:directory}/var/zeoserver/zeoserver.pid
socket-name = ${buildout:directory}/var/zeoserver/zeo.zdsock
\stopCFG
\stoptext