ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Drazen Baic <dpeterx@googlemail.com>
To: ntg-context@ntg.nl
Subject: Files for verbatim output of Python source, zc.buildout and Apache 	config files
Date: Thu, 16 Apr 2009 22:35:32 +0200	[thread overview]
Message-ID: <6607a2f30904161335r62c2942eh640f3fba761eb9c1@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2115 bytes --]

Hello,

I'm using MKIV and needed syntax highlighting for a few source and config files.
I read on the Wiki and on this list that it should be pretty easy to do this in
Lua and although I never wrote anything in Lua I just tried it.

Maybe the result will be of use for somebody so I'm posting them to this list. I
read on the Wiki that the best place for putting custom formatter files would be
the context distribution or http://modules.contextgarden.net but as I'm pretty
sure that some stuff is missing and I'm sure there are some bugs included I'm
just posting them here.

Would it be OK to put the files in a section on the Wiki to start something like
a repository for verb-*.lua files where it would be easy to extend and correct
them?

I have created verb-*.lua files for pretty printing Python source code Apache
http.conf and zc.buildout config files. For the zc.buildout files I used a
simple solution and just defined the keywords that appear in a standard Plone
buildout.cfg file. I hope to finish two additional verbatim files for XML and
Shell scripts in the next days.

As I don't have any experience in writing Lua code I chose to use the
tex/context/base/verb-*.lua and the verb-cpp.lua files posted by Shen Chen in
http://archive.contextgarden.net/message/20081002.173802.460c46fe.en.html) for
a start. Additionally I used the vim syntax files and the official Apache
documentation.

Here is an overview of what is covered:

The verb-apa.lua file distinguishes between the following five states:
- declarations
- strings
- sections (like <Directory> and </Directory>)
- comments
- options

The verb-py.lua file distinguishes between the following five states:
- all statements, repeats, conditionals and operators
- strings (multi line comment wit ''' or """ are supported)
- preconditions (import, from, as)
- comments
- builtins

The verb-py.cfg file distinguishes between the following four states:
- sections
- variables
- keywords
- comments

I've attached a minimal test file to show how they work. Just put everything in
one directory and execute

texexec --lua test.tex

Regards,
Drazen

[-- Attachment #2: test.tex --]
[-- Type: application/x-tex, Size: 3698 bytes --]

[-- Attachment #3: verb-apa.lua --]
[-- Type: application/octet-stream, Size: 16437 bytes --]

-- 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

[-- Attachment #4: verb-cfg.lua --]
[-- Type: application/octet-stream, Size: 5391 bytes --]

-- 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

[-- Attachment #5: verb-py.lua --]
[-- Type: application/octet-stream, Size: 9394 bytes --]

-- 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

[-- Attachment #6: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

             reply	other threads:[~2009-04-16 20:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-16 20:35 Drazen Baic [this message]
2009-04-19 16:54 Drazen Baic
2009-04-19 17:09 ` Hans Hagen
2009-04-19 20:23   ` Drazen Baic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6607a2f30904161335r62c2942eh640f3fba761eb9c1@mail.gmail.com \
    --to=dpeterx@googlemail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).