Skip to content

Commit

Permalink
Update keyword-generation Rake tasks (#1500)
Browse files Browse the repository at this point in the history
A number of the Rake tasks that generate lists of built-in keywords
for particular languages have bugs. These range from actual errors (as
in the case of the Lua task) to deprecation warnings (in the case of
tasks using `Kernel#open` to open URIs).

This commit fixes these bugs and includes freshly generated lists of
the built-in keywords that have changed.
  • Loading branch information
pyrmont committed May 12, 2020
1 parent c68336e commit 76430f3
Show file tree
Hide file tree
Showing 35 changed files with 964 additions and 1,865 deletions.
28 changes: 21 additions & 7 deletions lib/rouge/lexers/apache.rb
Expand Up @@ -12,13 +12,27 @@ class Apache < RegexLexer
filenames '.htaccess', 'httpd.conf'

# self-modifying method that loads the keywords file
def self.keywords
def self.directives
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
keywords
directives
end

def name_for_token(token, kwtype, tktype)
if self.class.keywords[kwtype].include? token
def self.sections
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
sections
end

def self.values
Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb')
values
end

def name_for_token(token, tktype)
if self.class.sections.include? token
tktype
elsif self.class.directives.include? token
tktype
elsif self.class.values.include? token
tktype
else
Text
Expand All @@ -34,12 +48,12 @@ def name_for_token(token, kwtype, tktype)
mixin :whitespace

rule %r/(<\/?)(\w+)/ do |m|
groups Punctuation, name_for_token(m[2].downcase, :sections, Name::Label)
groups Punctuation, name_for_token(m[2].downcase, Name::Label)
push :section
end

rule %r/\w+/ do |m|
token name_for_token(m[0].downcase, :directives, Name::Class)
token name_for_token(m[0].downcase, Name::Class)
push :directive
end
end
Expand All @@ -61,7 +75,7 @@ def name_for_token(token, kwtype, tktype)
mixin :whitespace

rule %r/\S+/ do |m|
token name_for_token(m[0], :values, Literal::String::Symbol)
token name_for_token(m[0].downcase, Literal::String::Symbol)
end
end
end
Expand Down
23 changes: 16 additions & 7 deletions lib/rouge/lexers/apache/keywords.rb

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions lib/rouge/lexers/gherkin/keywords.rb

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions lib/rouge/lexers/lasso.rb
Expand Up @@ -120,7 +120,6 @@ def self.keywords
rule %r/(?<!->)(self|inherited|currentcapture|givenblock)\b/i, Name::Builtin::Pseudo
rule %r/-(?!infinity)#{id}/i, Name::Attribute
rule %r/::\s*#{id}/, Name::Label
rule %r/error_((code|msg)_\w+|adderror|columnrestriction|databaseconnectionunavailable|databasetimeout|deleteerror|fieldrestriction|filenotfound|invaliddatabase|invalidpassword|invalidusername|modulenotfound|noerror|nopermission|outofmemory|reqcolumnmissing|reqfieldmissing|requiredcolumnmissing|requiredfieldmissing|updateerror)/i, Name::Exception

# definitions
rule %r/(define)(\s+)(#{id})(\s*=>\s*)(type|trait|thread)\b/i do
Expand All @@ -145,7 +144,6 @@ def self.keywords
# keywords
rule %r/(true|false|none|minimal|full|all|void)\b/i, Keyword::Constant
rule %r/(local|var|variable|global|data(?=\s))\b/i, Keyword::Declaration
rule %r/(array|date|decimal|duration|integer|map|pair|string|tag|xml|null|boolean|bytes|keyword|list|locale|queue|set|stack|staticarray)\b/i, Keyword::Type
rule %r/(#{id})(\s+)(in)\b/i do
groups Name, Text, Keyword
end
Expand All @@ -169,9 +167,15 @@ def self.keywords

if name == 'namespace_using'
token Keyword::Namespace, m[2]
elsif self.class.keywords[:exceptions].include? name
token Name::Exception, m[2]
elsif self.class.keywords[:types].include? name
token Keyword::Type, m[2]
elsif self.class.keywords[:traits].include? name
token Name::Decorator, m[2]
elsif self.class.keywords[:keywords].include? name
token Keyword, m[2]
elsif self.class.keywords[:types_traits].include? name
elsif self.class.keywords[:builtins].include? name
token Name::Builtin, m[2]
else
token Name::Other, m[2]
Expand Down
12 changes: 9 additions & 3 deletions lib/rouge/lexers/lasso/keywords.rb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/rouge/lexers/lua.rb
Expand Up @@ -25,8 +25,8 @@ def self.detect?(text)
end

def self.builtins
Kernel::load File.join(Lexers::BASE_DIR, 'lua/builtins.rb')
self.builtins
Kernel::load File.join(Lexers::BASE_DIR, 'lua/keywords.rb')
builtins
end

def builtins
Expand Down
24 changes: 0 additions & 24 deletions lib/rouge/lexers/lua/builtins.rb

This file was deleted.

28 changes: 28 additions & 0 deletions lib/rouge/lexers/lua/keywords.rb
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

# DO NOT EDIT

# This file is automatically generated by `rake builtins:lua`.
# See tasks/builtins/lua.rake for more info.

module Rouge
module Lexers
class Lua
def self.builtins
@builtins ||= {}.tap do |b|
b["basic"] = Set.new ["_g", "_version", "assert", "collectgarbage", "dofile", "error", "getmetatable", "ipairs", "load", "loadfile", "next", "pairs", "pcall", "print", "rawequal", "rawget", "rawlen", "rawset", "select", "setmetatable", "tonumber", "tostring", "type", "xpcall", "file:close", "file:flush", "file:lines", "file:read", "file:seek", "file:setvbuf", "file:write", "lua_cpath", "lua_cpath_5_3", "lua_init", "lua_init_5_3", "lua_path", "lua_path_5_3", "luaopen_base", "luaopen_coroutine", "luaopen_debug", "luaopen_io", "luaopen_math", "luaopen_os", "luaopen_package", "luaopen_string", "luaopen_table", "luaopen_utf8", "lua_errerr", "lua_errfile", "lua_errgcmm", "lua_errmem", "lua_errrun", "lua_errsyntax", "lua_hookcall", "lua_hookcount", "lua_hookline", "lua_hookret", "lua_hooktailcall", "lua_maskcall", "lua_maskcount", "lua_maskline", "lua_maskret", "lua_maxinteger", "lua_mininteger", "lua_minstack", "lua_multret", "lua_noref", "lua_ok", "lua_opadd", "lua_opband", "lua_opbnot", "lua_opbor", "lua_opbxor", "lua_opdiv", "lua_opeq", "lua_opidiv", "lua_ople", "lua_oplt", "lua_opmod", "lua_opmul", "lua_oppow", "lua_opshl", "lua_opshr", "lua_opsub", "lua_opunm", "lua_refnil", "lua_registryindex", "lua_ridx_globals", "lua_ridx_mainthread", "lua_tboolean", "lua_tfunction", "lua_tlightuserdata", "lua_tnil", "lua_tnone", "lua_tnumber", "lua_tstring", "lua_ttable", "lua_tthread", "lua_tuserdata", "lua_use_apicheck", "lua_yield", "lual_buffersize"]
b["modules"] = Set.new ["require", "package.config", "package.cpath", "package.loaded", "package.loadlib", "package.path", "package.preload", "package.searchers", "package.searchpath"]
b["coroutine"] = Set.new ["coroutine.create", "coroutine.isyieldable", "coroutine.resume", "coroutine.running", "coroutine.status", "coroutine.wrap", "coroutine.yield"]
b["debug"] = Set.new ["debug.debug", "debug.gethook", "debug.getinfo", "debug.getlocal", "debug.getmetatable", "debug.getregistry", "debug.getupvalue", "debug.getuservalue", "debug.sethook", "debug.setlocal", "debug.setmetatable", "debug.setupvalue", "debug.setuservalue", "debug.traceback", "debug.upvalueid", "debug.upvaluejoin"]
b["io"] = Set.new ["io.close", "io.flush", "io.input", "io.lines", "io.open", "io.output", "io.popen", "io.read", "io.stderr", "io.stdin", "io.stdout", "io.tmpfile", "io.type", "io.write"]
b["math"] = Set.new ["math.abs", "math.acos", "math.asin", "math.atan", "math.ceil", "math.cos", "math.deg", "math.exp", "math.floor", "math.fmod", "math.huge", "math.log", "math.max", "math.maxinteger", "math.min", "math.mininteger", "math.modf", "math.pi", "math.rad", "math.random", "math.randomseed", "math.sin", "math.sqrt", "math.tan", "math.tointeger", "math.type", "math.ult"]
b["os"] = Set.new ["os.clock", "os.date", "os.difftime", "os.execute", "os.exit", "os.getenv", "os.remove", "os.rename", "os.setlocale", "os.time", "os.tmpname"]
b["string"] = Set.new ["string.byte", "string.char", "string.dump", "string.find", "string.format", "string.gmatch", "string.gsub", "string.len", "string.lower", "string.match", "string.pack", "string.packsize", "string.rep", "string.reverse", "string.sub", "string.unpack", "string.upper"]
b["table"] = Set.new ["table.concat", "table.insert", "table.move", "table.pack", "table.remove", "table.sort", "table.unpack"]
b["utf8"] = Set.new ["utf8.char", "utf8.charpattern", "utf8.codepoint", "utf8.codes", "utf8.len", "utf8.offset"]
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/rouge/lexers/mathematica.rb
Expand Up @@ -56,8 +56,8 @@ def self.keywords

# The list of built-in symbols comes from a wolfram server and is created automatically by rake
def self.builtins
Kernel::load File.join(Lexers::BASE_DIR, 'mathematica/builtins.rb')
self.builtins
Kernel::load File.join(Lexers::BASE_DIR, 'mathematica/keywords.rb')
builtins
end

state :root do
Expand Down
13 changes: 0 additions & 13 deletions lib/rouge/lexers/mathematica/builtins.rb

This file was deleted.

17 changes: 17 additions & 0 deletions lib/rouge/lexers/mathematica/keywords.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/rouge/lexers/matlab.rb
Expand Up @@ -20,7 +20,7 @@ def self.keywords

# self-modifying method that loads the builtins file
def self.builtins
Kernel::load File.join(Lexers::BASE_DIR, 'matlab/builtins.rb')
Kernel::load File.join(Lexers::BASE_DIR, 'matlab/keywords.rb')
builtins
end

Expand Down
15 changes: 15 additions & 0 deletions lib/rouge/lexers/matlab/keywords.rb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/rouge/lexers/php.rb
Expand Up @@ -29,8 +29,8 @@ def initialize(*)
end

def self.builtins
Kernel::load File.join(Lexers::BASE_DIR, 'php/builtins.rb')
self.builtins
Kernel::load File.join(Lexers::BASE_DIR, 'php/keywords.rb')
builtins
end

def builtins
Expand Down

0 comments on commit 76430f3

Please sign in to comment.