Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
Use plain Ruby files for built-in keyword lists (rouge-ruby#1418)
Browse files Browse the repository at this point in the history
Rouge has a number of lexers that include a list of the names of
built-in functions for more accurate tokenisation. Some of these lists
consist of YAML files that need to be computed at runtime. Rather than
take this approach, this commit ensures that the lists are plain Ruby
files that can be loaded by the respective lexers.
  • Loading branch information
ashmaroli authored and mattt committed May 21, 2020
1 parent 1491518 commit 68d3a45
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 21 deletions.
12 changes: 4 additions & 8 deletions lib/rouge/lexers/apache.rb
Expand Up @@ -11,14 +11,10 @@ class Apache < RegexLexer
mimetypes 'text/x-httpd-conf', 'text/x-apache-conf'
filenames '.htaccess', 'httpd.conf'

class << self
attr_reader :keywords
end
# Load Apache keywords from separate YML file
@keywords = ::YAML.load_file(File.join(Lexers::BASE_DIR, 'apache/keywords.yml')).tap do |h|
h.each do |k,v|
h[k] = Set.new v
end
# self-modifying method that loads the keywords file
def self.keywords
load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
keywords
end

def name_for_token(token, kwtype, tktype)
Expand Down
15 changes: 15 additions & 0 deletions lib/rouge/lexers/apache/keywords.rb
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

# automatically generated by `rake builtins:apache`
module Rouge
module Lexers
def Apache.keywords
@keywords ||= {}.tap do |h|
h[:sections] = Set.new ["directory", "directorymatch", "files", "filesmatch", "ifdefine", "ifmodule", "limit", "limitexcept", "location", "locationmatch", "proxy", "proxymatch", "virtualhost"]
h[:directives] = Set.new ["acceptfilter", "acceptmutex", "acceptpathinfo", "accessconfig", "accessfilename", "action", "addalt", "addaltbyencoding", "addaltbytype", "addcharset", "adddefaultcharset", "adddescription", "addencoding", "addhandler", "addicon", "addiconbyencoding", "addiconbytype", "addinputfilter", "addlanguage", "addmodule", "addmoduleinfo", "addoutputfilter", "addoutputfilterbytype", "addtype", "agentlog", "alias", "aliasmatch", "allow", "allowconnect", "allowencodedslashes", "allowmethods", "allowoverride", "allowoverridelist", "anonymous", "anonymous_authoritative", "anonymous_logemail", "anonymous_mustgiveemail", "anonymous_nouserid", "anonymous_verifyemail", "assignuserid", "authauthoritative", "authdbauthoritative", "authdbgroupfile", "authdbmauthoritative", "asyncrequestworkerfactor", "authbasicauthoritative", "authbasicfake", "authbasicprovider", "authbasicusedigestalgorithm", "authdbduserpwquery", "authdbduserrealmquery", "authdbmgroupfile", "authdbmtype", "authdbmuserfile", "authdbuserfile", "authdigestalgorithm", "authdigestdomain", "authdigestfile", "authdigestgroupfile", "authdigestnccheck", "authdigestnonceformat", "authdigestnoncelifetime", "authdigestprovider", "authdigestqop", "authdigestshmemsize", "authformauthoritative", "authformbody", "authformdisablenostore", "authformfakebasicauth", "authformlocation", "authformloginrequiredlocation", "authformloginsuccesslocation", "authformlogoutlocation", "authformmethod", "authformmimetype", "authformpassword", "authformprovider", "authformsitepassphrase", "authformsize", "authformusername", "authgroupfile", "authldapauthoritative", "authldapauthorizeprefix", "authldapbindauthoritative", "authldapbinddn", "authldapbindpassword", "authldapcharsetconfig", "authldapcompareasuser", "authldapcomparednonserver", "authldapdereferencealiases", "authldapenabled", "authldapfrontpagehack", "authldapgroupattribute", "authldapgroupattributeisdn", "authldapinitialbindasuser", "authldapinitialbindpattern", "authldapmaxsubgroupdepth", "authldapremoteuserattribute", "authldapremoteuserisdn", "authldapsearchasuser", "authldapsubgroupattribute", "authldapsubgroupclass", "authldapurl", "authmerging", "authname", "authncachecontext", "authncacheenable", "authncacheprovidefor", "authncachesocache", "authncachetimeout", "authnzfcgicheckauthnprovider", "authnzfcgidefineprovider", "authtype", "authuserfile", "authzdbdlogintoreferer", "authzdbdquery", "authzdbdredirectquery", "authzdbmtype", "authzsendforbiddenonfailure", "balancergrowth", "balancerinherit", "balancermember", "balancerpersist", "bindaddress", "browsermatch", "browsermatchnocase", "bs2000account", "bufferedlogs", "buffersize", "cachedefaultexpire", "cachedetailheader", "cachedirlength", "cachedirlevels", "cachedisable", "cacheenable", "cacheexpirycheck", "cachefile", "cacheforcecompletion", "cachegcclean", "cachegcdaily", "cachegcinterval", "cachegcmemusage", "cachegcunused", "cacheheader", "cacheignorecachecontrol", "cacheignoreheaders", "cacheignorenolastmod", "cacheignorequerystring", "cacheignoreurlsessionidentifiers", "cachekeybaseurl", "cachelastmodifiedfactor", "cachelock", "cachelockmaxage", "cachelockpath", "cachemaxexpire", "cachemaxfilesize", "cacheminexpire", "cacheminfilesize", "cachenegotiateddocs", "cachequickhandler", "cachereadsize", "cachereadtime", "cacheroot", "cachesize", "cachetimemargin", "cachesocache", "cachesocachemaxsize", "cachesocachemaxtime", "cachesocachemintime", "cachesocachereadsize", "cachesocachereadtime", "cachestaleonerror", "cachestoreexpired", "cachestorenostore", "cachestoreprivate", "cgidscripttimeout", "cgimapextension", "cgipassauth", "charsetdefault", "charsetoptions", "charsetsourceenc", "checkcaseonly", "checkspelling", "childperuserid", "clearmodulelist", "chrootdir", "contentdigest", "cookiedomain", "cookieexpires", "cookielog", "cookiename", "cookiestyle", "cookietracking", "coredumpdirectory", "customlog", "dav", "davdepthinfinity", "davgenericlockdb", "davlockdb", "davmintimeout", "dbdexptime", "dbdinitsql", "dbdkeep", "dbdmax", "dbdmin", "dbdparams", "dbdpersist", "dbdpreparesql", "dbdriver", "defaulticon", "defaultlanguage", "defaultmode", "defaultruntimedir", "defaulttype", "define", "deflatebuffersize", "deflatecompressionlevel", "deflatefilternote", "deflateinflatelimitrequestbody", "deflateinflateratioburst", "deflateinflateratiolimit", "deflatememlevel", "deflatewindowsize", "deny", "directorycheckhandler", "directoryindex", "directoryindexredirect", "directoryslash", "doctitle", "doctrailer", "documentroot", "dtraceprivileges", "dumpioinput", "dumpiooutput", "enableexceptionhook", "enablemmap", "enablesendfile", "error", "errordocument", "errorlog", "errorlogformat", "example", "expiresactive", "expiresbytype", "expiresdefault", "extendedstatus", "extfilterdefine", "extfilteroptions", "fallbackresource", "fancyindexing", "fileetag", "filterchain", "filterdeclare", "filterprotocol", "filterprovider", "filtertrace", "forcelanguagepriority", "forcetype", "forensiclog", "globallog", "gprofdir", "gracefulshutdowntimeout", "group", "h2direct", "h2keepalivetimeout", "h2maxsessionstreams", "h2maxworkeridleseconds", "h2maxworkers", "h2minworkers", "h2moderntlsonly", "h2push", "h2pushdiarysize", "h2pushpriority", "h2serializeheaders", "h2sessionextrafiles", "h2streammaxmemsize", "h2streamtimeout", "h2timeout", "h2tlscooldownsecs", "h2tlswarmupsize", "h2upgrade", "h2windowsize", "header", "headername", "headprefix", "headsuffix", "hidesys", "hideurl", "heartbeataddress", "heartbeatlisten", "heartbeatmaxservers", "heartbeatstorage", "heartbeatstorage", "hostnamelookups", "htmldir", "httplogfile", "identitycheck", "identitychecktimeout", "imapbase", "imapdefault", "imapmenu", "include", "includeoptional", "indexheadinsert", "indexignore", "indexignorereset", "indexoptions", "indexorderdefault", "indexstylesheet", "inputsed", "isapiappendlogtoerrors", "isapiappendlogtoquery", "isapicachefile", "isapifakeasync", "isapilognotsupported", "isapireadaheadbuffer", "keepalive", "keepalivetimeout", "keptbodysize", "languagepriority", "lasturls", "ldapcacheentries", "ldapcachettl", "ldapconnectionpoolttl", "ldapconnectiontimeout", "ldaplibrarydebug", "ldapopcacheentries", "ldapopcachettl", "ldapreferralhoplimit", "ldapreferrals", "ldapretries", "ldapretrydelay", "ldapsharedcachefile", "ldapsharedcachesize", "ldaptimeout", "ldaptrustedca", "ldaptrustedcatype", "ldaptrustedclientcert", "ldaptrustedglobalcert", "ldaptrustedmode", "ldapverifyservercert", "limitinternalrecursion", "limitrequestbody", "limitrequestfields", "limitrequestfieldsize", "limitrequestline", "limitxmlrequestbody", "listen", "listenbacklog", "listencoresbucketsratio", "loadfile", "loadmodule", "lockfile", "logformat", "logiotrackttfb", "loglevel", "logmessage", "luaauthzprovider", "luacodecache", "luahookaccesschecker", "luahookauthchecker", "luahookcheckuserid", "luahookfixups", "luahookinsertfilter", "luahooklog", "luahookmaptostorage", "luahooktranslatename", "luahooktypechecker", "luainherit", "luainputfilter", "luamaphandler", "luaoutputfilter", "luapackagecpath", "luapackagepath", "luaquickhandler", "luaroot", "luascope", "maxclients", "maxconnectionsperchild", "maxkeepaliverequests", "maxmemfree", "maxrequestsperchild", "maxrequestsperthread", "maxrangeoverlaps", "maxrangereversals", "maxranges", "maxrequestworkers", "maxspareservers", "maxsparethreads", "maxthreads", "maxthreadsperchild", "mcachemaxobjectcount", "mcachemaxobjectsize", "mcachemaxstreamingbuffer", "mcacheminobjectsize", "mcacheremovalalgorithm", "mcachesize", "memcacheconnttl", "mergetrailers", "metadir", "metafiles", "metasuffix", "mimemagicfile", "minspareservers", "minsparethreads", "mmapfile", "modemstandard", "modmimeusepathinfo", "multiviewsmatch", "mutex", "namevirtualhost", "nocache", "noproxy", "numservers", "nwssltrustedcerts", "nwsslupgradeable", "options", "order", "outputsed", "passenv", "pidfile", "port", "privatedir", "privilegesmode", "protocol", "protocolecho", "protocols", "protocolshonororder", "proxyaddheaders", "proxybadheader", "proxyblock", "proxydomain", "proxyerroroverride", "proxyexpressdbmfile", "proxyexpressdbmtype", "proxyexpressenable", "proxyftpdircharset", "proxyftpescapewildcards", "proxyftplistonwildcard", "proxyhtmlbufsize", "proxyhtmlcharsetout", "proxyhtmldoctype", "proxyhtmlenable", "proxyhtmlevents", "proxyhtmlextended", "proxyhtmlfixups", "proxyhtmlinterp", "proxyhtmllinks", "proxyhtmlmeta", "proxyhtmlstripcomments", "proxyhtmlurlmap", "proxyiobuffersize", "proxymaxforwards", "proxypass", "proxypassinherit", "proxypassinterpolateenv", "proxypassmatch", "proxypassreverse", "proxypassreversecookiedomain", "proxypassreversecookiepath", "proxypreservehost", "proxyreceivebuffersize", "proxyremote", "proxyremotematch", "proxyrequests", "proxyscgiinternalredirect", "proxyscgisendfile", "proxyset", "proxysourceaddress", "proxystatus", "proxytimeout", "proxyvia", "qualifyredirecturl", "readmename", "receivebuffersize", "redirect", "redirectmatch", "redirectpermanent", "redirecttemp", "refererignore", "refererlog", "reflectorheader", "remoteipheader", "remoteipinternalproxy", "remoteipinternalproxylist", "remoteipproxiesheader", "remoteiptrustedproxy", "remoteiptrustedproxylist", "removecharset", "removeencoding", "removehandler", "removeinputfilter", "removelanguage", "removeoutputfilter", "removetype", "requestheader", "requestreadtimeout", "require", "resourceconfig", "rewritebase", "rewritecond", "rewriteengine", "rewritelock", "rewritelog", "rewriteloglevel", "rewritemap", "rewriteoptions", "rewriterule", "rlimitcpu", "rlimitmem", "rlimitnproc", "satisfy", "scoreboardfile", "script", "scriptalias", "scriptaliasmatch", "scriptinterpretersource", "scriptlog", "scriptlogbuffer", "scriptloglength", "scriptsock", "securelisten", "seerequesttail", "sendbuffersize", "serveradmin", "serveralias", "serverlimit", "servername", "serverpath", "serverroot", "serversignature", "servertokens", "servertype", "session", "sessioncookiename", "sessioncookiename2", "sessioncookieremove", "sessioncryptocipher", "sessioncryptodriver", "sessioncryptopassphrase", "sessioncryptopassphrasefile", "sessiondbdcookiename", "sessiondbdcookiename2", "sessiondbdcookieremove", "sessiondbddeletelabel", "sessiondbdinsertlabel", "sessiondbdperuser", "sessiondbdselectlabel", "sessiondbdupdatelabel", "sessionenv", "sessionexclude", "sessionheader", "sessioninclude", "sessionmaxage", "setenv", "setenvif", "setenvifexpr", "setenvifnocase", "sethandler", "setinputfilter", "setoutputfilter", "ssiendtag", "ssierrormsg", "ssietag", "ssilastmodified", "ssilegacyexprparser", "ssistarttag", "ssitimeformat", "ssiundefinedecho", "sslcacertificatefile", "sslcacertificatepath", "sslcadnrequestfile", "sslcadnrequestpath", "sslcarevocationcheck", "sslcarevocationfile", "sslcarevocationpath", "sslcertificatechainfile", "sslcertificatefile", "sslcertificatekeyfile", "sslciphersuite", "sslcompression", "sslcryptodevice", "sslengine", "sslfips", "sslhonorcipherorder", "sslinsecurerenegotiation", "sslmutex", "sslocspdefaultresponder", "sslocspenable", "sslocspoverrideresponder", "sslocspproxyurl", "sslocsprespondertimeout", "sslocspresponsemaxage", "sslocspresponsetimeskew", "sslocspuserequestnonce", "sslopensslconfcmd", "ssloptions", "sslpassphrasedialog", "sslprotocol", "sslproxycacertificatefile", "sslproxycacertificatepath", "sslproxycarevocationcheck", "sslproxycarevocationfile", "sslproxycarevocationpath", "sslproxycheckpeercn", "sslproxycheckpeerexpire", "sslproxycheckpeername", "sslproxyciphersuite", "sslproxyengine", "sslproxymachinecertificatechainfile", "sslproxymachinecertificatefile", "sslproxymachinecertificatepath", "sslproxyprotocol", "sslproxyverify", "sslproxyverifydepth", "sslrandomseed", "sslrenegbuffersize", "sslrequire", "sslrequiressl", "sslsessioncache", "sslsessioncachetimeout", "sslsessionticketkeyfile", "sslsessiontickets", "sslsrpunknownuserseed", "sslsrpverifierfile", "sslstaplingcache", "sslstaplingerrorcachetimeout", "sslstaplingfaketrylater", "sslstaplingforceurl", "sslstaplingrespondertimeout", "sslstaplingresponsemaxage", "sslstaplingresponsetimeskew", "sslstaplingreturnrespondererrors", "sslstaplingstandardcachetimeout", "sslstrictsnivhostcheck", "sslusername", "sslusestapling", "sslverifyclient", "sslverifydepth", "startservers", "startthreads", "substitute", "substituteinheritbefore", "substitutemaxlinelength", "suexec", "suexecusergroup", "threadlimit", "threadsperchild", "threadstacksize", "timeout", "topsites", "topurls", "traceenable", "transferlog", "typesconfig", "undefine", "undefmacro", "unsetenv", "use", "usecanonicalname", "usecanonicalphysicalport", "user", "userdir", "vhostcgimode", "vhostcgiprivs", "vhostgroup", "vhostprivs", "vhostsecure", "vhostuser", "virtualdocumentroot", "virtualdocumentrootip", "virtualscriptalias", "virtualscriptaliasip", "win32disableacceptex", "watchdoginterval", "xbithack", "xml2encalias", "xml2encdefault", "xml2startparse"]
h[:values] = Set.new ["add", "All", "allow", "any", "append", "AuthConfig", "Basic", "CONNECT", "DELETE", "deny", "Digest", "double", "downgrade-1.0", "email", "env", "error", "ExecCGI", "FancyIndexing", "FileInfo", "FollowSymLinks", "force-response-1.0", "formatted", "from", "full", "Full", "GET", "gone", "group", "IconsAreLinks", "Includes", "IncludesNOEXEC", "Indexes", "inetd", "inherit", "Limit", "map", "Minimal", "MultiViews", "mutual-failure", "nocontent", "nokeepalive", "none", "None", "off", "on", "Options", "OPTIONS", "OS", "permanent", "POST", "PUT", "referer", "ScanHTMLTitles", "seeother", "semi-formatted", "set", "standalone", "SuppressDescription", "SuppressLastModified", "SuppressSize", "SymLinksIfOwnerMatch", "temporary", "unformatted", "unset", "URL", "user", "valid-user"]
end
end
end
end
13 changes: 4 additions & 9 deletions lib/rouge/lexers/lasso.rb
Expand Up @@ -34,15 +34,10 @@ def start_inline?
push :lasso if start_inline?
end

class << self
attr_reader :keywords
end

# Load Lasso keywords from separate YML file
@keywords = ::YAML.load_file(File.join(Lexers::BASE_DIR, 'lasso/keywords.yml')).tap do |h|
h.each do |k,v|
h[k] = Set.new v
end
# self-modifying method that loads the keywords file
def self.keywords
load File.join(Lexers::BASE_DIR, 'lasso/keywords.rb')
keywords
end

id = /[a-z_][\w.]*/i
Expand Down

0 comments on commit 68d3a45

Please sign in to comment.