From eec7600206ca9e8ac7ee5f24de3ac02388f122a7 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Sun, 7 May 2023 15:46:20 -0700 Subject: [PATCH 01/12] Allow warnings in test if ENV["VERBOSE"] (no good way to set $VERBOSE from the outside) --- tasks/check/specs.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/check/specs.rake b/tasks/check/specs.rake index 08c78ae8c8..2c6cd10920 100644 --- a/tasks/check/specs.rake +++ b/tasks/check/specs.rake @@ -2,7 +2,7 @@ namespace :check do Rake::TestTask.new(:specs) do |t| t.libs << "lib" t.ruby_opts << "-r./spec/spec_helper" - t.warning = !!$VERBOSE + t.warning = $VERBOSE || ENV["VERBOSE"] t.pattern = FileList['spec/**/*_spec.rb'] end end From 35f8a971b0992b454e40a54b407ba0512a8b3c08 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Sun, 7 May 2023 15:47:33 -0700 Subject: [PATCH 02/12] Use #to_s to check for loaded lexers to avoid double loads. Drops `rake check:specs VERBOSE=1` from 331 lines to 144. --- lib/rouge/lexer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rouge/lexer.rb b/lib/rouge/lexer.rb index 0e7f7b18ac..b7d0cf9516 100644 --- a/lib/rouge/lexer.rb +++ b/lib/rouge/lexer.rb @@ -527,8 +527,8 @@ module Lexers @_loaded_lexers = {} def self.load_lexer(relpath) - return if @_loaded_lexers.key?(relpath) - @_loaded_lexers[relpath] = true + return if @_loaded_lexers.key?(relpath.to_s) + @_loaded_lexers[relpath.to_s] = true Kernel::load File.join(BASE_DIR, relpath) end end From edf557432cbf2677a601e1431ef845408ca65904 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 10 May 2023 11:26:03 -0700 Subject: [PATCH 03/12] Fix double load warnings by using require_relative load will load, always. Don't use it unless you really really mean it. --- lib/rouge.rb | 89 ++++++++++++++++--------------- lib/rouge/lexer.rb | 7 +-- lib/rouge/lexers/apache.rb | 16 +----- lib/rouge/lexers/apiblueprint.rb | 2 +- lib/rouge/lexers/biml.rb | 2 +- lib/rouge/lexers/cpp.rb | 2 +- lib/rouge/lexers/cuda.rb | 2 +- lib/rouge/lexers/cython.rb | 2 +- lib/rouge/lexers/digdag.rb | 2 +- lib/rouge/lexers/freefem.rb | 2 +- lib/rouge/lexers/gdscript.rb | 2 +- lib/rouge/lexers/gherkin.rb | 6 +-- lib/rouge/lexers/glsl.rb | 2 +- lib/rouge/lexers/gradle.rb | 2 +- lib/rouge/lexers/hack.rb | 2 +- lib/rouge/lexers/hlsl.rb | 2 +- lib/rouge/lexers/hocon.rb | 2 +- lib/rouge/lexers/hql.rb | 2 +- lib/rouge/lexers/irb.rb | 4 +- lib/rouge/lexers/isbl.rb | 5 +- lib/rouge/lexers/json_doc.rb | 2 +- lib/rouge/lexers/jsx.rb | 2 +- lib/rouge/lexers/lasso.rb | 6 +-- lib/rouge/lexers/llvm.rb | 15 +----- lib/rouge/lexers/lua.rb | 5 +- lib/rouge/lexers/lutin.rb | 2 +- lib/rouge/lexers/mathematica.rb | 6 +-- lib/rouge/lexers/matlab.rb | 6 +-- lib/rouge/lexers/moonscript.rb | 2 +- lib/rouge/lexers/objective_c.rb | 4 +- lib/rouge/lexers/objective_cpp.rb | 4 +- lib/rouge/lexers/ocaml.rb | 2 +- lib/rouge/lexers/php.rb | 5 +- lib/rouge/lexers/qml.rb | 2 +- lib/rouge/lexers/reasonml.rb | 2 +- lib/rouge/lexers/rescript.rb | 2 +- lib/rouge/lexers/sass.rb | 2 +- lib/rouge/lexers/scss.rb | 2 +- lib/rouge/lexers/slice.rb | 2 +- lib/rouge/lexers/sqf.rb | 5 +- lib/rouge/lexers/terraform.rb | 2 +- lib/rouge/lexers/tsx.rb | 4 +- lib/rouge/lexers/twig.rb | 2 +- lib/rouge/lexers/typescript.rb | 4 +- lib/rouge/lexers/viml.rb | 5 +- lib/rouge/lexers/vue.rb | 2 +- lib/rouge/lexers/xquery.rb | 2 +- 47 files changed, 96 insertions(+), 158 deletions(-) diff --git a/lib/rouge.rb b/lib/rouge.rb index f8cffcb75c..a3005185ee 100644 --- a/lib/rouge.rb +++ b/lib/rouge.rb @@ -40,7 +40,8 @@ def highlight(text, lexer, formatter, &b) # # @api private def load_file(path) - Kernel::load File.join(LIB_DIR, "rouge/#{path}.rb") + warn "just use require_relative %p" % ["rouge/#{path}"] + require_relative "rouge/#{path}" end # Load the lexers in the `lib/rouge/lexers` directory. @@ -55,52 +56,52 @@ def load_lexers end end -Rouge.load_file 'version' -Rouge.load_file 'util' -Rouge.load_file 'text_analyzer' -Rouge.load_file 'token' +require_relative 'rouge/version' +require_relative 'rouge/util' +require_relative 'rouge/text_analyzer' +require_relative 'rouge/token' -Rouge.load_file 'lexer' -Rouge.load_file 'regex_lexer' -Rouge.load_file 'template_lexer' +require_relative 'rouge/lexer' +require_relative 'rouge/regex_lexer' +require_relative 'rouge/template_lexer' Rouge.load_lexers -Rouge.load_file 'guesser' -Rouge.load_file 'guessers/util' -Rouge.load_file 'guessers/glob_mapping' -Rouge.load_file 'guessers/modeline' -Rouge.load_file 'guessers/filename' -Rouge.load_file 'guessers/mimetype' -Rouge.load_file 'guessers/source' -Rouge.load_file 'guessers/disambiguation' +require_relative 'rouge/guesser' +require_relative 'rouge/guessers/util' +require_relative 'rouge/guessers/glob_mapping' +require_relative 'rouge/guessers/modeline' +require_relative 'rouge/guessers/filename' +require_relative 'rouge/guessers/mimetype' +require_relative 'rouge/guessers/source' +require_relative 'rouge/guessers/disambiguation' -Rouge.load_file 'formatter' -Rouge.load_file 'formatters/html' -Rouge.load_file 'formatters/html_table' -Rouge.load_file 'formatters/html_pygments' -Rouge.load_file 'formatters/html_legacy' -Rouge.load_file 'formatters/html_linewise' -Rouge.load_file 'formatters/html_line_highlighter' -Rouge.load_file 'formatters/html_line_table' -Rouge.load_file 'formatters/html_inline' -Rouge.load_file 'formatters/terminal256' -Rouge.load_file 'formatters/terminal_truecolor' -Rouge.load_file 'formatters/tex' -Rouge.load_file 'formatters/null' +require_relative 'rouge/formatter' +require_relative 'rouge/formatters/html' +require_relative 'rouge/formatters/html_table' +require_relative 'rouge/formatters/html_pygments' +require_relative 'rouge/formatters/html_legacy' +require_relative 'rouge/formatters/html_linewise' +require_relative 'rouge/formatters/html_line_highlighter' +require_relative 'rouge/formatters/html_line_table' +require_relative 'rouge/formatters/html_inline' +require_relative 'rouge/formatters/terminal256' +require_relative 'rouge/formatters/terminal_truecolor' +require_relative 'rouge/formatters/tex' +require_relative 'rouge/formatters/null' -Rouge.load_file 'theme' -Rouge.load_file 'tex_theme_renderer' -Rouge.load_file 'themes/thankful_eyes' -Rouge.load_file 'themes/colorful' -Rouge.load_file 'themes/base16' -Rouge.load_file 'themes/github' -Rouge.load_file 'themes/igor_pro' -Rouge.load_file 'themes/monokai' -Rouge.load_file 'themes/molokai' -Rouge.load_file 'themes/monokai_sublime' -Rouge.load_file 'themes/gruvbox' -Rouge.load_file 'themes/tulip' -Rouge.load_file 'themes/pastie' -Rouge.load_file 'themes/bw' -Rouge.load_file 'themes/magritte' +require_relative 'rouge/theme' +require_relative 'rouge/tex_theme_renderer' +require_relative 'rouge/themes/thankful_eyes' +require_relative 'rouge/themes/colorful' +require_relative 'rouge/themes/base16' +require_relative 'rouge/themes/github' +require_relative 'rouge/themes/igor_pro' +require_relative 'rouge/themes/monokai' +require_relative 'rouge/themes/molokai' +require_relative 'rouge/themes/monokai_sublime' +require_relative 'rouge/themes/gruvbox' +require_relative 'rouge/themes/tulip' +require_relative 'rouge/themes/pastie' +require_relative 'rouge/themes/bw' +require_relative 'rouge/themes/magritte' diff --git a/lib/rouge/lexer.rb b/lib/rouge/lexer.rb index b7d0cf9516..28214759f9 100644 --- a/lib/rouge/lexer.rb +++ b/lib/rouge/lexer.rb @@ -523,13 +523,8 @@ def self.detect?(text) end module Lexers - BASE_DIR = "#{__dir__}/lexers".freeze - @_loaded_lexers = {} - def self.load_lexer(relpath) - return if @_loaded_lexers.key?(relpath.to_s) - @_loaded_lexers[relpath.to_s] = true - Kernel::load File.join(BASE_DIR, relpath) + require_relative "lexers/#{relpath}" end end end diff --git a/lib/rouge/lexers/apache.rb b/lib/rouge/lexers/apache.rb index 2b8046bd4a..ae341c0d24 100644 --- a/lib/rouge/lexers/apache.rb +++ b/lib/rouge/lexers/apache.rb @@ -11,21 +11,7 @@ class Apache < RegexLexer mimetypes 'text/x-httpd-conf', 'text/x-apache-conf' filenames '.htaccess', 'httpd.conf' - # self-modifying method that loads the keywords file - def self.directives - Kernel::load File.join(Lexers::BASE_DIR, 'apache/keywords.rb') - directives - end - - 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 + require_relative "apache/keywords" def name_for_token(token, tktype) if self.class.sections.include? token diff --git a/lib/rouge/lexers/apiblueprint.rb b/lib/rouge/lexers/apiblueprint.rb index 7695c39081..3f755e9089 100644 --- a/lib/rouge/lexers/apiblueprint.rb +++ b/lib/rouge/lexers/apiblueprint.rb @@ -2,7 +2,7 @@ module Rouge module Lexers - load_lexer 'markdown.rb' + require_relative 'markdown' class APIBlueprint < Markdown title 'API Blueprint' diff --git a/lib/rouge/lexers/biml.rb b/lib/rouge/lexers/biml.rb index 602a57a23c..1a0a521c92 100644 --- a/lib/rouge/lexers/biml.rb +++ b/lib/rouge/lexers/biml.rb @@ -2,7 +2,7 @@ module Rouge module Lexers - load_lexer 'xml.rb' + require_relative 'xml' class BIML < XML title "BIML" diff --git a/lib/rouge/lexers/cpp.rb b/lib/rouge/lexers/cpp.rb index 3fca7ec788..18afd578ed 100644 --- a/lib/rouge/lexers/cpp.rb +++ b/lib/rouge/lexers/cpp.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'c.rb' + require_relative 'c' class Cpp < C title "C++" diff --git a/lib/rouge/lexers/cuda.rb b/lib/rouge/lexers/cuda.rb index c973ddd62a..2164db6676 100644 --- a/lib/rouge/lexers/cuda.rb +++ b/lib/rouge/lexers/cuda.rb @@ -2,7 +2,7 @@ module Rouge module Lexers - load_lexer 'cpp.rb' + require_relative 'cpp' class CUDA < Cpp title "CUDA" diff --git a/lib/rouge/lexers/cython.rb b/lib/rouge/lexers/cython.rb index 945cbc198d..4f24b65524 100644 --- a/lib/rouge/lexers/cython.rb +++ b/lib/rouge/lexers/cython.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'python.rb' + require_relative 'python' class Cython < Python title "Cython" diff --git a/lib/rouge/lexers/digdag.rb b/lib/rouge/lexers/digdag.rb index 407d646ea7..fc27f2d8d3 100644 --- a/lib/rouge/lexers/digdag.rb +++ b/lib/rouge/lexers/digdag.rb @@ -3,7 +3,7 @@ require 'set' module Rouge module Lexers - load_lexer 'yaml.rb' + require_relative 'yaml' class Digdag < YAML title 'digdag' diff --git a/lib/rouge/lexers/freefem.rb b/lib/rouge/lexers/freefem.rb index 11df6676da..d9a9a7d24c 100644 --- a/lib/rouge/lexers/freefem.rb +++ b/lib/rouge/lexers/freefem.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'cpp.rb' + require_relative 'cpp' class FreeFEM < Cpp title "FreeFEM" diff --git a/lib/rouge/lexers/gdscript.rb b/lib/rouge/lexers/gdscript.rb index 372b6c1ded..df506cffed 100644 --- a/lib/rouge/lexers/gdscript.rb +++ b/lib/rouge/lexers/gdscript.rb @@ -28,7 +28,7 @@ def self.keywords_reserved end def self.builtins - builtins = %w( + %w( Color8 ColorN abs acos asin assert atan atan2 bytes2var ceil char clamp convert cos cosh db2linear decimals dectime deg2rad dict2inst ease exp floor fmod fposmod funcref hash inst2dict instance_from_id diff --git a/lib/rouge/lexers/gherkin.rb b/lib/rouge/lexers/gherkin.rb index 0b655b093d..80d4e0c094 100644 --- a/lib/rouge/lexers/gherkin.rb +++ b/lib/rouge/lexers/gherkin.rb @@ -17,11 +17,7 @@ def self.detect?(text) return true if text.shebang? 'cucumber' end - # self-modifying method that loads the keywords file - def self.keywords - Kernel::load File.join(Lexers::BASE_DIR, 'gherkin/keywords.rb') - keywords - end + require_relative "gherkin/keywords" def self.step_regex # in Gherkin's config, keywords that end in < don't diff --git a/lib/rouge/lexers/glsl.rb b/lib/rouge/lexers/glsl.rb index aea62eaa0b..8b2636d3ce 100644 --- a/lib/rouge/lexers/glsl.rb +++ b/lib/rouge/lexers/glsl.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'c.rb' + require_relative 'c' # This file defines the GLSL language lexer to the Rouge # syntax highlighter. diff --git a/lib/rouge/lexers/gradle.rb b/lib/rouge/lexers/gradle.rb index 27b5f967eb..dae9a3be71 100644 --- a/lib/rouge/lexers/gradle.rb +++ b/lib/rouge/lexers/gradle.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'groovy.rb' + require_relative 'groovy' class Gradle < Groovy title "Gradle" diff --git a/lib/rouge/lexers/hack.rb b/lib/rouge/lexers/hack.rb index 1e8f8317b5..6b227f6dbb 100644 --- a/lib/rouge/lexers/hack.rb +++ b/lib/rouge/lexers/hack.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'php.rb' + require_relative 'php' class Hack < PHP title 'Hack' diff --git a/lib/rouge/lexers/hlsl.rb b/lib/rouge/lexers/hlsl.rb index 8fac6fa86e..fa197f474d 100644 --- a/lib/rouge/lexers/hlsl.rb +++ b/lib/rouge/lexers/hlsl.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'c.rb' + require_relative 'c' class HLSL < C title "HLSL" diff --git a/lib/rouge/lexers/hocon.rb b/lib/rouge/lexers/hocon.rb index 881a969a00..d1c8af47ff 100644 --- a/lib/rouge/lexers/hocon.rb +++ b/lib/rouge/lexers/hocon.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'json.rb' + require_relative 'json' class HOCON < JSON title 'HOCON' diff --git a/lib/rouge/lexers/hql.rb b/lib/rouge/lexers/hql.rb index ba7dab474a..45d7860091 100644 --- a/lib/rouge/lexers/hql.rb +++ b/lib/rouge/lexers/hql.rb @@ -2,7 +2,7 @@ module Rouge module Lexers - load_lexer 'sql.rb' + require_relative 'sql' class HQL < SQL title "HQL" diff --git a/lib/rouge/lexers/irb.rb b/lib/rouge/lexers/irb.rb index ed912f4ee7..f6892c91d9 100644 --- a/lib/rouge/lexers/irb.rb +++ b/lib/rouge/lexers/irb.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'console.rb' + require_relative 'console' class IRBLexer < ConsoleLexer tag 'irb' @@ -31,7 +31,7 @@ def allow_comments? end end - load_lexer 'ruby.rb' + require_relative 'ruby' class IRBOutputLexer < Ruby tag 'irb_output' diff --git a/lib/rouge/lexers/isbl.rb b/lib/rouge/lexers/isbl.rb index 2e1184b79f..effa6ee6a6 100644 --- a/lib/rouge/lexers/isbl.rb +++ b/lib/rouge/lexers/isbl.rb @@ -9,10 +9,7 @@ class ISBL < RegexLexer tag 'isbl' filenames '*.isbl' - def self.builtins - Kernel::load File.join(Lexers::BASE_DIR, 'isbl/builtins.rb') - self.builtins - end + require_relative "isbl/builtins" def self.constants @constants ||= self.builtins["const"].merge(self.builtins["enum"]).collect!(&:downcase) diff --git a/lib/rouge/lexers/json_doc.rb b/lib/rouge/lexers/json_doc.rb index c243709100..d81e20fff6 100644 --- a/lib/rouge/lexers/json_doc.rb +++ b/lib/rouge/lexers/json_doc.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'json.rb' + require_relative 'json' class JSONDOC < JSON desc "JavaScript Object Notation with extensions for documentation" diff --git a/lib/rouge/lexers/jsx.rb b/lib/rouge/lexers/jsx.rb index 7b2ad339a5..e8e845c5f2 100644 --- a/lib/rouge/lexers/jsx.rb +++ b/lib/rouge/lexers/jsx.rb @@ -2,7 +2,7 @@ module Rouge module Lexers - load_lexer 'javascript.rb' + require_relative 'javascript' class JSX < Javascript title 'JSX' diff --git a/lib/rouge/lexers/lasso.rb b/lib/rouge/lexers/lasso.rb index cad38e9ec2..ae91b22d6f 100644 --- a/lib/rouge/lexers/lasso.rb +++ b/lib/rouge/lexers/lasso.rb @@ -34,11 +34,7 @@ def start_inline? push :lasso if start_inline? end - # self-modifying method that loads the keywords file - def self.keywords - Kernel::load File.join(Lexers::BASE_DIR, 'lasso/keywords.rb') - keywords - end + require_relative "lasso/keywords" id = /[a-z_][\w.]*/i diff --git a/lib/rouge/lexers/llvm.rb b/lib/rouge/lexers/llvm.rb index b5ffa4459c..cf03dd8c1e 100644 --- a/lib/rouge/lexers/llvm.rb +++ b/lib/rouge/lexers/llvm.rb @@ -14,20 +14,7 @@ class LLVM < RegexLexer string = /"[^"]*?"/ identifier = /([-a-zA-Z$._][-a-zA-Z$._0-9]*|#{string})/ - def self.keywords - Kernel::load File.join(Lexers::BASE_DIR, "llvm/keywords.rb") - keywords - end - - def self.instructions - Kernel::load File.join(Lexers::BASE_DIR, "llvm/keywords.rb") - instructions - end - - def self.types - Kernel::load File.join(Lexers::BASE_DIR, "llvm/keywords.rb") - types - end + require_relative "llvm/keywords" state :basic do rule %r/;.*?$/, Comment::Single diff --git a/lib/rouge/lexers/lua.rb b/lib/rouge/lexers/lua.rb index 6e1887b084..287b3137d1 100644 --- a/lib/rouge/lexers/lua.rb +++ b/lib/rouge/lexers/lua.rb @@ -24,10 +24,7 @@ def self.detect?(text) return true if text.shebang? 'lua' end - def self.builtins - Kernel::load File.join(Lexers::BASE_DIR, 'lua/keywords.rb') - builtins - end + require_relative "lua/keywords" def builtins return [] unless @function_highlighting diff --git a/lib/rouge/lexers/lutin.rb b/lib/rouge/lexers/lutin.rb index cc1ac539ed..b0e00fc5d3 100644 --- a/lib/rouge/lexers/lutin.rb +++ b/lib/rouge/lexers/lutin.rb @@ -4,7 +4,7 @@ # adapted from lustre.rf (adapted from ocaml.rb), hence some ocaml-ism migth remains module Rouge module Lexers - load_lexer 'lustre.rb' + require_relative 'lustre' class Lutin < Lustre title "Lutin" diff --git a/lib/rouge/lexers/mathematica.rb b/lib/rouge/lexers/mathematica.rb index 2fdeefc5a5..f69e56deb3 100644 --- a/lib/rouge/lexers/mathematica.rb +++ b/lib/rouge/lexers/mathematica.rb @@ -54,11 +54,7 @@ def self.keywords ) end - # 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/keywords.rb') - builtins - end + require_relative "mathematica/keywords" state :root do rule %r/\s+/, Text::Whitespace diff --git a/lib/rouge/lexers/matlab.rb b/lib/rouge/lexers/matlab.rb index d284401d5d..9ea102a279 100644 --- a/lib/rouge/lexers/matlab.rb +++ b/lib/rouge/lexers/matlab.rb @@ -19,11 +19,7 @@ def self.keywords ) end - # self-modifying method that loads the builtins file - def self.builtins - Kernel::load File.join(Lexers::BASE_DIR, 'matlab/keywords.rb') - builtins - end + require_relative 'matlab/keywords' state :root do rule %r/\s+/m, Text # Whitespace diff --git a/lib/rouge/lexers/moonscript.rb b/lib/rouge/lexers/moonscript.rb index 055422b640..861e2d0a96 100644 --- a/lib/rouge/lexers/moonscript.rb +++ b/lib/rouge/lexers/moonscript.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'lua.rb' + require_relative 'lua' class Moonscript < RegexLexer title "MoonScript" diff --git a/lib/rouge/lexers/objective_c.rb b/lib/rouge/lexers/objective_c.rb index 36ab6c5442..3a46d4b9f3 100644 --- a/lib/rouge/lexers/objective_c.rb +++ b/lib/rouge/lexers/objective_c.rb @@ -3,8 +3,8 @@ module Rouge module Lexers - load_lexer 'c.rb' - load_lexer 'objective_c/common.rb' + require_relative 'c' + require_relative 'objective_c/common' class ObjectiveC < C extend ObjectiveCCommon diff --git a/lib/rouge/lexers/objective_cpp.rb b/lib/rouge/lexers/objective_cpp.rb index 21606922b3..446eb35fe8 100644 --- a/lib/rouge/lexers/objective_cpp.rb +++ b/lib/rouge/lexers/objective_cpp.rb @@ -3,8 +3,8 @@ module Rouge module Lexers - load_lexer 'cpp.rb' - load_lexer 'objective_c/common.rb' + require_relative 'cpp' + require_relative 'objective_c/common' class ObjectiveCpp < Cpp extend ObjectiveCCommon diff --git a/lib/rouge/lexers/ocaml.rb b/lib/rouge/lexers/ocaml.rb index 684b367229..63ba51556c 100644 --- a/lib/rouge/lexers/ocaml.rb +++ b/lib/rouge/lexers/ocaml.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'ocaml/common.rb' + require_relative 'ocaml/common' class OCaml < OCamlCommon title "OCaml" diff --git a/lib/rouge/lexers/php.rb b/lib/rouge/lexers/php.rb index 1580b47068..9030852af4 100644 --- a/lib/rouge/lexers/php.rb +++ b/lib/rouge/lexers/php.rb @@ -48,10 +48,7 @@ def self.keywords ) end - def self.builtins - Kernel::load File.join(Lexers::BASE_DIR, 'php/keywords.rb') - builtins - end + require_relative "php/keywords" def builtins return [] unless @funcnamehighlighting diff --git a/lib/rouge/lexers/qml.rb b/lib/rouge/lexers/qml.rb index 577939fa2e..9ac77df61d 100644 --- a/lib/rouge/lexers/qml.rb +++ b/lib/rouge/lexers/qml.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'javascript.rb' + require_relative 'javascript' class Qml < Javascript title "QML" diff --git a/lib/rouge/lexers/reasonml.rb b/lib/rouge/lexers/reasonml.rb index 07c9f6c4e1..7ba2f6acc2 100644 --- a/lib/rouge/lexers/reasonml.rb +++ b/lib/rouge/lexers/reasonml.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'ocaml/common.rb' + require_relative 'ocaml/common' class ReasonML < OCamlCommon title "ReasonML" diff --git a/lib/rouge/lexers/rescript.rb b/lib/rouge/lexers/rescript.rb index 35daf12658..113a578a81 100644 --- a/lib/rouge/lexers/rescript.rb +++ b/lib/rouge/lexers/rescript.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'ocaml/common.rb' + require_relative 'ocaml/common' class ReScript < OCamlCommon title "ReScript" diff --git a/lib/rouge/lexers/sass.rb b/lib/rouge/lexers/sass.rb index 7758beb1be..3539e04d83 100644 --- a/lib/rouge/lexers/sass.rb +++ b/lib/rouge/lexers/sass.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'sass/common.rb' + require_relative 'sass/common' class Sass < SassCommon include Indentation diff --git a/lib/rouge/lexers/scss.rb b/lib/rouge/lexers/scss.rb index 7cf178ca93..8e8ac6ac5e 100644 --- a/lib/rouge/lexers/scss.rb +++ b/lib/rouge/lexers/scss.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'sass/common.rb' + require_relative 'sass/common' class Scss < SassCommon title "SCSS" diff --git a/lib/rouge/lexers/slice.rb b/lib/rouge/lexers/slice.rb index f2739cbd95..20381fc188 100644 --- a/lib/rouge/lexers/slice.rb +++ b/lib/rouge/lexers/slice.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'c.rb' + require_relative 'c' class Slice < C tag 'slice' diff --git a/lib/rouge/lexers/sqf.rb b/lib/rouge/lexers/sqf.rb index 331dafc29f..e7c15599fc 100644 --- a/lib/rouge/lexers/sqf.rb +++ b/lib/rouge/lexers/sqf.rb @@ -54,10 +54,7 @@ def self.diag_commands ) end - def self.commands - Kernel::load File.join(Lexers::BASE_DIR, "sqf/keywords.rb") - commands - end + require_relative "sqf/keywords" state :root do # Whitespace diff --git a/lib/rouge/lexers/terraform.rb b/lib/rouge/lexers/terraform.rb index 8b9545552f..b13a450caa 100644 --- a/lib/rouge/lexers/terraform.rb +++ b/lib/rouge/lexers/terraform.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'hcl.rb' + require_relative 'hcl' class Terraform < Hcl title "Terraform" diff --git a/lib/rouge/lexers/tsx.rb b/lib/rouge/lexers/tsx.rb index e003bfb905..5c3f8b91fd 100644 --- a/lib/rouge/lexers/tsx.rb +++ b/lib/rouge/lexers/tsx.rb @@ -3,8 +3,8 @@ module Rouge module Lexers - load_lexer 'jsx.rb' - load_lexer 'typescript/common.rb' + require_relative 'jsx' + require_relative 'typescript/common' class TSX < JSX extend TypescriptCommon diff --git a/lib/rouge/lexers/twig.rb b/lib/rouge/lexers/twig.rb index 036ee38aaa..12a25718b8 100644 --- a/lib/rouge/lexers/twig.rb +++ b/lib/rouge/lexers/twig.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'jinja.rb' + require_relative 'jinja' class Twig < Jinja title "Twig" diff --git a/lib/rouge/lexers/typescript.rb b/lib/rouge/lexers/typescript.rb index 270d97df43..dbfc3b7ee1 100644 --- a/lib/rouge/lexers/typescript.rb +++ b/lib/rouge/lexers/typescript.rb @@ -3,8 +3,8 @@ module Rouge module Lexers - load_lexer 'javascript.rb' - load_lexer 'typescript/common.rb' + require_relative 'javascript' + require_relative 'typescript/common' class Typescript < Javascript extend TypescriptCommon diff --git a/lib/rouge/lexers/viml.rb b/lib/rouge/lexers/viml.rb index 9ef1776b52..3c7cb977e1 100644 --- a/lib/rouge/lexers/viml.rb +++ b/lib/rouge/lexers/viml.rb @@ -13,10 +13,7 @@ class VimL < RegexLexer mimetypes 'text/x-vim' - def self.keywords - Kernel::load File.join(Lexers::BASE_DIR, 'viml/keywords.rb') - self.keywords - end + require_relative "viml/keywords" state :root do rule %r/^(\s*)(".*?)$/ do diff --git a/lib/rouge/lexers/vue.rb b/lib/rouge/lexers/vue.rb index 5b64f3d037..a0a78d5c58 100644 --- a/lib/rouge/lexers/vue.rb +++ b/lib/rouge/lexers/vue.rb @@ -2,7 +2,7 @@ module Rouge module Lexers - load_lexer 'html.rb' + require_relative 'html' class Vue < HTML desc 'Vue.js single-file components' diff --git a/lib/rouge/lexers/xquery.rb b/lib/rouge/lexers/xquery.rb index 2d23bb77d0..cf231d03f5 100644 --- a/lib/rouge/lexers/xquery.rb +++ b/lib/rouge/lexers/xquery.rb @@ -3,7 +3,7 @@ module Rouge module Lexers - load_lexer 'xpath.rb' + require_relative 'xpath' class XQuery < XPath title 'XQuery' desc 'XQuery 3.1: An XML Query Language' From ea56f894d758b5c1671ea451bd17c4aa79e76795 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 10 May 2023 11:25:15 -0700 Subject: [PATCH 04/12] Remove duplicate range regexp warnings --- lib/rouge/lexers/ada.rb | 2 +- lib/rouge/lexers/clean.rb | 8 ++++---- lib/rouge/lexers/ecl.rb | 4 ++-- lib/rouge/lexers/elixir.rb | 2 +- lib/rouge/lexers/ghc_cmm.rb | 6 +++--- lib/rouge/lexers/julia.rb | 5 +++-- lib/rouge/lexers/kotlin.rb | 2 +- lib/rouge/lexers/ocl.rb | 4 ++-- lib/rouge/lexers/plsql.rb | 10 +++++----- lib/rouge/lexers/ruby.rb | 2 +- lib/rouge/lexers/sql.rb | 2 +- lib/rouge/lexers/xojo.rb | 2 +- lib/rouge/lexers/yang.rb | 2 +- 13 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/rouge/lexers/ada.rb b/lib/rouge/lexers/ada.rb index 0e47ec71f0..21065bb218 100644 --- a/lib/rouge/lexers/ada.rb +++ b/lib/rouge/lexers/ada.rb @@ -155,7 +155,7 @@ def self.idents end # Flag word-like things that don't match the ID pattern. - rule %r{\b(\p{Pc}|[[alpha]])\p{Word}*}, Error + rule %r{\b(\p{Pc}|[[:alpha:]])\p{Word}*}, Error end end end diff --git a/lib/rouge/lexers/clean.rb b/lib/rouge/lexers/clean.rb index 894c5289ec..031cd61776 100644 --- a/lib/rouge/lexers/clean.rb +++ b/lib/rouge/lexers/clean.rb @@ -79,7 +79,7 @@ class instance rule %r/code(\s+inline)?\s*{/, Comment::Preproc, :abc - rule %r/_*[a-z][\w_`]*/ do |m| + rule %r/_*[a-z][\w`]*/ do |m| if self.class.keywords.include?(m[0]) token Keyword else @@ -87,7 +87,7 @@ class instance end end - rule %r/_*[A-Z][\w_`]*/ do |m| + rule %r/_*[A-Z][\w`]*/ do |m| if m[0]=='True' || m[0]=='False' token Keyword::Constant else @@ -95,7 +95,7 @@ class instance end end - rule %r/[^\w_\s`]/, Punctuation + rule %r/[^\w\s`]/, Punctuation rule %r/_\b/, Punctuation end @@ -136,7 +136,7 @@ class instance rule %r/}/, Comment::Preproc, :pop! rule %r/\.\w*/, Keyword, :abc_rest_of_line - rule %r/[\w_]+/, Name::Builtin, :abc_rest_of_line + rule %r/[\w]+/, Name::Builtin, :abc_rest_of_line end state :abc_rest_of_line do diff --git a/lib/rouge/lexers/ecl.rb b/lib/rouge/lexers/ecl.rb index 4fe7d6d2a1..1e8131a858 100644 --- a/lib/rouge/lexers/ecl.rb +++ b/lib/rouge/lexers/ecl.rb @@ -114,8 +114,8 @@ def self.typed mixin :single_quote rule %r(\b(?i:(and|not|or|in))\b), Operator::Word - rule %r([:=|>|<|<>|/|\\|\+|-|=]), Operator - rule %r([\[\]{}();,\&,\.,\%]), Punctuation + rule %r(:=|>|<|<>|/|\\|\+|-|=), Operator + rule %r([\[\]{}();,\&\.\%]), Punctuation rule %r(\b(?i:(beginc\+\+.*?endc\+\+)))m, Str::Single rule %r(\b(?i:(embed.*?endembed)))m, Str::Single diff --git a/lib/rouge/lexers/elixir.rb b/lib/rouge/lexers/elixir.rb index edfe5badd5..11216e7a18 100644 --- a/lib/rouge/lexers/elixir.rb +++ b/lib/rouge/lexers/elixir.rb @@ -131,7 +131,7 @@ class Elixir < RegexLexer rule %r/[\\#]/, toktype end - uniq_chars = "#{open}#{close}".squeeze + uniq_chars = [open, close].uniq.join rule %r/[^##{uniq_chars}\\]+/m, toktype end end diff --git a/lib/rouge/lexers/ghc_cmm.rb b/lib/rouge/lexers/ghc_cmm.rb index 1bbfb6be04..d2a89422bd 100644 --- a/lib/rouge/lexers/ghc_cmm.rb +++ b/lib/rouge/lexers/ghc_cmm.rb @@ -22,11 +22,11 @@ class GHCCmm < RegexLexer ws = %r(\s|//.*?\n|/[*](?:[^*]|(?:[*][^/]))*[*]+/)mx # Make sure that this is not a preprocessor macro, e.g. `#if` or `#define`. - id = %r((?!\#[a-zA-Z])[\w#\$%_']+) + id = %r((?!\#[a-zA-Z])[\w#\$%']+) complex_id = %r( - (?:[\w#$%_']|\(\)|\(,\)|\[\]|[0-9])* - (?:[\w#$%_']+) + (?:[\w#$%']|\(\)|\(,\)|\[\]|[0-9])* + (?:[\w#$%']+) )mx state :root do diff --git a/lib/rouge/lexers/julia.rb b/lib/rouge/lexers/julia.rb index 2820f330d1..9d5366c7f7 100644 --- a/lib/rouge/lexers/julia.rb +++ b/lib/rouge/lexers/julia.rb @@ -252,15 +252,16 @@ def self.detect?(text) rule %r/\d+/, Literal::Number::Integer end + NAME_RE = %r/[\p{L}\p{Nl}\p{S}_][\p{Word}\p{S}\p{Po}!]*/ state :funcname do - rule %r/[\p{L}\p{Nl}\p{S}_][\p{Word}\p{S}\p{Po}!]*/, Name::Function, :pop! + rule NAME_RE, Name::Function, :pop! rule %r/\([^\s\w{]{1,2}\)/, Operator, :pop! rule %r/[^\s\w{]{1,2}/, Operator, :pop! end state :typename do - rule %r/[\p{L}\p{Nl}\p{S}_][\p{Word}\p{S}\p{Po}!]*/, Name::Class, :pop! + rule NAME_RE, Name::Class, :pop! end state :stringescape do diff --git a/lib/rouge/lexers/kotlin.rb b/lib/rouge/lexers/kotlin.rb index f6afeac20e..53c5c001a5 100644 --- a/lib/rouge/lexers/kotlin.rb +++ b/lib/rouge/lexers/kotlin.rb @@ -24,7 +24,7 @@ class Kotlin < RegexLexer while yield ) - name_chars = %r'[-_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*' + name_chars = %r'[-\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*' class_name = %r'`?[\p{Lu}]#{name_chars}`?' name = %r'`?[_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}]#{name_chars}`?' diff --git a/lib/rouge/lexers/ocl.rb b/lib/rouge/lexers/ocl.rb index ae4cdac080..6511ffa03b 100644 --- a/lib/rouge/lexers/ocl.rb +++ b/lib/rouge/lexers/ocl.rb @@ -61,9 +61,9 @@ def self.functions rule %r/--.*/, Comment::Single rule %r/\d+/, Num::Integer rule %r/'/, Str::Single, :single_string - rule %r([->|+*/<>=~!@#%&|?^-]), Operator + rule %r([-|+*/<>=~!@#%&?^]), Operator rule %r/[;:()\[\],.]/, Punctuation - rule %r/\w[\w\d]*/ do |m| + rule %r/[a-zA-Z]\w*/ do |m| if self.class.operators.include? m[0] token Operator elsif self.class.keywords_type.include? m[0] diff --git a/lib/rouge/lexers/plsql.rb b/lib/rouge/lexers/plsql.rb index cc5fcdccdf..4674cc5a91 100644 --- a/lib/rouge/lexers/plsql.rb +++ b/lib/rouge/lexers/plsql.rb @@ -472,7 +472,7 @@ def self.keywords_type # A double-quoted string refers to a database object in our default SQL rule %r/"/, Operator, :double_string # preprocessor directive treated as special comment - rule %r/(\$(?:IF|THEN|ELSE|ELSIF|ERROR|END|(?:\$\$?\w[\w\d]*)))(\s+)/im do + rule %r/(\$(?:IF|THEN|ELSE|ELSIF|ERROR|END|(?:\$\$?[a-z]\w*)))(\s+)/im do groups Comment::Preproc, Text end @@ -503,7 +503,7 @@ def self.keywords_type # Special processing for keywords with multiple contexts # # this madness is to keep the word "replace" from being treated as a builtin function in this context - rule %r/(create)(\s+)(?:(or)(\s+)(replace)(\s+))?(package|function|procedure|type)(?:(\s+)(body))?(\s+)(\w[\w\d\$]*)/im do + rule %r/(create)(\s+)(?:(or)(\s+)(replace)(\s+))?(package|function|procedure|type)(?:(\s+)(body))?(\s+)([a-z][\w$]*)/im do groups Keyword::Reserved, Text, Keyword::Reserved, Text, Keyword::Reserved, Text, Keyword::Reserved, Text, Keyword::Reserved, Text, Name end # similar for MERGE keywords @@ -515,7 +515,7 @@ def self.keywords_type # General keyword classification with sepcial attention to names # in a chained "dot" notation. # - rule %r/(\w[\w\d\$]*)(\.(?=\w))?/ do |m| + rule %r/([a-zA-Z][\w$]*)(\.(?=\w))?/ do |m| if self.class.keywords_type.include? m[1].upcase tok = Keyword::Type elsif self.class.keywords_func.include? m[1].upcase @@ -556,11 +556,11 @@ def self.keywords_type state :dotnames do # if we are followed by a dot and another name, we are an ordinary name - rule %r/(\w[\w\d\$]*)(\.(?=\w))/ do + rule %r/([a-zA-Z][\w\$]*)(\.(?=\w))/ do groups Name, Punctuation end # this rule WILL be true if something pushed into our state. That is our state contract - rule %r/\w[\w\d\$]*/ do |m| + rule %r/[a-zA-Z][\w\$]*/ do |m| if self.class.keywords_func.include? m[0].upcase # The Function lookup allows collection methods like COUNT, FIRST, LAST, etc.. to be # classified correctly. Occasionally misidentifies ordinary names as builtin functions, diff --git a/lib/rouge/lexers/ruby.rb b/lib/rouge/lexers/ruby.rb index 8d4741b82b..ae6bf760e9 100644 --- a/lib/rouge/lexers/ruby.rb +++ b/lib/rouge/lexers/ruby.rb @@ -57,7 +57,7 @@ def self.detect?(text) token toktype push do - uniq_chars = "#{open}#{close}".squeeze + uniq_chars = [open, close].uniq.join uniq_chars = '' if open == close && open == "\\#" rule %r/\\[##{uniq_chars}\\]/, Str::Escape # nesting rules only with asymmetric delimiters diff --git a/lib/rouge/lexers/sql.rb b/lib/rouge/lexers/sql.rb index 6df5a100da..ff5c8a7d41 100644 --- a/lib/rouge/lexers/sql.rb +++ b/lib/rouge/lexers/sql.rb @@ -115,7 +115,7 @@ def self.keywords_type rule %r/"/, Name::Variable, :double_string rule %r/`/, Name::Variable, :backtick - rule %r/\w[\w\d]*/ do |m| + rule %r/\w+/ do |m| if self.class.keywords_type.include? m[0].upcase token Name::Builtin elsif self.class.keywords.include? m[0].upcase diff --git a/lib/rouge/lexers/xojo.rb b/lib/rouge/lexers/xojo.rb index 426990e93b..ce79ce253a 100644 --- a/lib/rouge/lexers/xojo.rb +++ b/lib/rouge/lexers/xojo.rb @@ -37,7 +37,7 @@ class Xojo < RegexLexer rule %r/\s+/, Text::Whitespace rule %r/rem\b.*?$/i, Comment::Single - rule %r([//'].*$), Comment::Single + rule %r((?://|').*$), Comment::Single rule %r/\#tag Note.*?\#tag EndNote/mi, Comment::Preproc rule %r/\s*[#].*$/x, Comment::Preproc diff --git a/lib/rouge/lexers/yang.rb b/lib/rouge/lexers/yang.rb index ce237e7705..a9d54f0663 100644 --- a/lib/rouge/lexers/yang.rb +++ b/lib/rouge/lexers/yang.rb @@ -10,7 +10,7 @@ class YANG < RegexLexer filenames '*.yang' mimetypes 'application/yang' - id = /[\w_-]+(?=[^\w\-\:])\b/ + id = /[\w-]+(?=[^\w\-\:])\b/ #Keywords from RFC7950 ; oriented at BNF style def self.top_stmts_keywords From 145529115de671616ae64db7459450b53d4277c1 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 10 May 2023 11:53:46 -0700 Subject: [PATCH 05/12] Fix regexp in make... I'm not comfortable with this change and want it checked --- lib/rouge/lexers/make.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rouge/lexers/make.rb b/lib/rouge/lexers/make.rb index edb4286ca9..7320632ecf 100644 --- a/lib/rouge/lexers/make.rb +++ b/lib/rouge/lexers/make.rb @@ -73,7 +73,7 @@ def initialize(opts={}) end state :export do - rule %r/[\w[\$]{1,2}{}()-]/, Name::Variable + rule %r/[\w\${}()-]/, Name::Variable rule %r/\n/, Text, :pop! rule %r/[\t ]+/, Text end From df4fb6c32cf5661b9600bcea5aca77e1e37bfe71 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 10 May 2023 11:54:09 -0700 Subject: [PATCH 06/12] Fix warnings about private_class_method usage --- lib/rouge/cli.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/rouge/cli.rb b/lib/rouge/cli.rb index b5b26a7cf4..49d9df4655 100644 --- a/lib/rouge/cli.rb +++ b/lib/rouge/cli.rb @@ -347,8 +347,7 @@ def run formatter.format(lexer.lex(input), &method(:print)) end - private_class_method - def self.parse_cgi(str) + private_class_method def self.parse_cgi(str) pairs = CGI.parse(str).map { |k, v| [k.to_sym, v.first] } Hash[pairs] end @@ -511,8 +510,7 @@ def run end - private_class_method - def self.normalize_syntax(argv) + private_class_method def self.normalize_syntax(argv) out = [] argv.each do |arg| case arg From a186bc6363eb2640b3a647a1606957a535cfe15d Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 10 May 2023 11:54:26 -0700 Subject: [PATCH 07/12] Unused variable warnings Most of these should just be removed instead of underscored... but I want eyeballs on this first. Some aren't being used the way they think they're being used. --- lib/rouge/lexers/meson.rb | 2 +- lib/rouge/lexers/objective_c/common.rb | 2 +- lib/rouge/lexers/openedge.rb | 2 +- lib/rouge/lexers/syzlang.rb | 2 +- lib/rouge/lexers/ttcn3.rb | 2 +- lib/rouge/tex_theme_renderer.rb | 2 +- spec/guesser_spec.rb | 2 -- 7 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/rouge/lexers/meson.rb b/lib/rouge/lexers/meson.rb index 616cb4f1c1..2051c7fe4a 100644 --- a/lib/rouge/lexers/meson.rb +++ b/lib/rouge/lexers/meson.rb @@ -38,7 +38,7 @@ def self.builtin_functions end identifier = /[[:alpha:]_][[:alnum:]_]*/ - dotted_identifier = /[[:alpha:]_.][[:alnum:]_.]*/ + _dotted_identifier = /[[:alpha:]_.][[:alnum:]_.]*/ def current_string @current_string ||= StringRegister.new diff --git a/lib/rouge/lexers/objective_c/common.rb b/lib/rouge/lexers/objective_c/common.rb index a0e69e7d5e..8eeeb0a78a 100644 --- a/lib/rouge/lexers/objective_c/common.rb +++ b/lib/rouge/lexers/objective_c/common.rb @@ -4,7 +4,7 @@ module Rouge module Lexers module ObjectiveCCommon - id = /[a-z$_][a-z0-9$_]*/i + _id = /[a-z$_][a-z0-9$_]*/i def at_keywords @at_keywords ||= %w( diff --git a/lib/rouge/lexers/openedge.rb b/lib/rouge/lexers/openedge.rb index f34aff2c9e..c196869487 100644 --- a/lib/rouge/lexers/openedge.rb +++ b/lib/rouge/lexers/openedge.rb @@ -13,7 +13,7 @@ class OpenEdge < RegexLexer desc 'The OpenEdge ABL programming language' # optional comment or whitespace - ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) + _ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) id = /[a-zA-Z_&{}!][a-zA-Z0-9_\-&!}]*/ def self.keywords diff --git a/lib/rouge/lexers/syzlang.rb b/lib/rouge/lexers/syzlang.rb index f203e828c9..6eaa87143d 100644 --- a/lib/rouge/lexers/syzlang.rb +++ b/lib/rouge/lexers/syzlang.rb @@ -27,7 +27,7 @@ def self.keywords_type comment = /#.*$/ inline_spaces = /[ \t]+/ - eol_spaces = /[\n\r]+/ + _eol_spaces = /[\n\r]+/ spaces = /\s+/ state :inline_break do diff --git a/lib/rouge/lexers/ttcn3.rb b/lib/rouge/lexers/ttcn3.rb index 4b8b27d35c..c3abebe205 100644 --- a/lib/rouge/lexers/ttcn3.rb +++ b/lib/rouge/lexers/ttcn3.rb @@ -47,7 +47,7 @@ def self.types end # optional comment or whitespace - ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) + _ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+) id = /[a-zA-Z_]\w*/ digit = /\d_+\d|\d/ bin_digit = /[01]_+[01]|[01]/ diff --git a/lib/rouge/tex_theme_renderer.rb b/lib/rouge/tex_theme_renderer.rb index e107d16579..e912e2ec8d 100644 --- a/lib/rouge/tex_theme_renderer.rb +++ b/lib/rouge/tex_theme_renderer.rb @@ -109,7 +109,7 @@ def token_name(tok) end def render_blank(tok, &b) - out = "\\expandafter\\def#{token_name(tok)}#1{#1}" + "\\expandafter\\def#{token_name(tok)}#1{#1}" end def render_style(tok, style, &b) diff --git a/spec/guesser_spec.rb b/spec/guesser_spec.rb index e6d80fe6bc..bcc9ba9478 100644 --- a/spec/guesser_spec.rb +++ b/spec/guesser_spec.rb @@ -47,8 +47,6 @@ it 'sequentially filters' do custom = Class.new(Rouge::Guesser) { define_method(:filter) { |lexers| - passed_lexers = lexers - [Rouge::Lexers::Javascript, Rouge::Lexers::Prolog] } }.new From 8d8b6236d8a460782a21aa503a1f994a2ead667b Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 11 May 2023 10:17:58 -0700 Subject: [PATCH 08/12] Fixed a LOT of warnings from scala. Turns out it was one local variable used in a lot of regexps. This updates the link to the reference and fixes it per reference. --- lib/rouge/lexers/scala.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/rouge/lexers/scala.rb b/lib/rouge/lexers/scala.rb index d13dbcbd94..0758699b60 100644 --- a/lib/rouge/lexers/scala.rb +++ b/lib/rouge/lexers/scala.rb @@ -13,7 +13,8 @@ class Scala < RegexLexer mimetypes 'text/x-scala', 'application/x-scala' # As documented in the ENBF section of the scala specification - # http://www.scala-lang.org/docu/files/ScalaReference.pdf + # https://scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html + # https://en.wikipedia.org/wiki/Unicode_character_property#General_Category whitespace = /\p{Space}/ letter = /[\p{L}$_]/ upper = /[\p{Lu}$_]/ @@ -24,8 +25,10 @@ class Scala < RegexLexer # negative lookahead to filter out other classes op = %r( (?!#{whitespace}|#{letter}|#{digits}|#{parens}|#{delims}) - [\u0020-\u007F\p{Sm}\p{So}] + [-!#%&*/:?@\\^\p{Sm}\p{So}] )x + # manually removed +<=>|~ from regexp because they're in property Sm + # pp CHRS:(0x00..0x7f).map(&:chr).grep(/\p{Sm}/) idrest = %r(#{letter}(?:#{letter}|#{digits})*(?:(?<=_)#{op}+)?)x From 3648a1d49c360bce326d5873abd259fc2e3b5c8d Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 11 May 2023 11:34:18 -0700 Subject: [PATCH 09/12] Strip trailing whitespace from changelog.rake --- tasks/update/changelog.rake | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tasks/update/changelog.rake b/tasks/update/changelog.rake index 7bc2cb7032..b6e7c4d82e 100644 --- a/tasks/update/changelog.rake +++ b/tasks/update/changelog.rake @@ -1,5 +1,5 @@ namespace :update do - desc "Insert lines in CHANGELOG.md for commits between SHAs (inclusive)" + desc "Insert lines in CHANGELOG.md for commits between SHAs (inclusive)" task :changelog, [:beg_sha, :end_sha] do |t, args| args.with_defaults(:end_sha => nil) @@ -9,20 +9,20 @@ namespace :update do working_dir = Rake.application.original_dir repo = Rouge::Tasks::Git.new(working_dir, remote) gitlog = repo.log(args.beg_sha, args.end_sha) - + text = '' not_inserted = true File.readlines(changelog).each do |l| if not_inserted && l.start_with?("##") text += Rouge::Tasks.version_line(Rouge.version) - text += Rouge::Tasks.comparison_line(remote, - repo.prev_version, + text += Rouge::Tasks.comparison_line(remote, + repo.prev_version, "v" + Rouge.version) text += gitlog.converted.join("") + "\n" not_inserted = false end - + text += l end @@ -44,7 +44,7 @@ module Rouge commits = @repo.log(100).between(beg_sha, end_sha) Log.new(@remote, commits) end - + def prev_version @prev_version ||= @repo .tags @@ -61,8 +61,8 @@ module Rouge return a[1] <=> b[1] if a[0] == b[0] return a[0] <=> b[0] end - - class Log + + class Log def initialize(remote, commits) @remote = remote @msgs = commits.map { |c| Message.new(c.message, c.author.name) } @@ -85,7 +85,7 @@ module Rouge end end end - + def self.comparison_line(remote, previous, current) "[Comparison with the previous version](https://#{remote}/compare/#{previous}...#{current})\n\n" end @@ -97,7 +97,7 @@ module Rouge def self.message_line(message) " - #{message}\n" end - + def self.version_line(version) "## version #{version}: #{Time.now.strftime("%Y-%m-%d")}\n\n" end From d8146a64cf743caa4039ea35cb9a737b19f6b737 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 11 May 2023 11:34:37 -0700 Subject: [PATCH 10/12] Move require git inside of Rogue::Tasks::Git#initialize to make it lazy git gem has warnings, this quells them --- tasks/update/changelog.rake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tasks/update/changelog.rake b/tasks/update/changelog.rake index b6e7c4d82e..ff78da3508 100644 --- a/tasks/update/changelog.rake +++ b/tasks/update/changelog.rake @@ -30,12 +30,11 @@ namespace :update do end end -require 'git' - module Rouge module Tasks class Git def initialize(dir, remote) + require 'git' @repo = ::Git.open(dir) @remote = remote end From 8e6150a2ef9cae0ce290193c221f82ec16059164 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 11 May 2023 11:35:47 -0700 Subject: [PATCH 11/12] Move several gems in Gemfile into development group to avoid eager require Bundler shouldn't require everything. Slows down the world. --- Gemfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 890cf642d2..2e880cdc6e 100644 --- a/Gemfile +++ b/Gemfile @@ -10,22 +10,22 @@ gem 'minitest', '>= 5.0' gem 'minitest-power_assert' gem 'power_assert', '~> 2.0' -gem 'rubocop', '~> 1.0', '<= 1.11' -gem 'rubocop-performance' - # don't try to install redcarpet under jruby gem 'redcarpet', platforms: :ruby # Profiling gem 'memory_profiler', require: false -# Needed for a Rake task -gem 'git' -gem 'yard' - group :development do gem 'pry' + # Needed for a Rake task + gem 'git' + gem 'yard' + + gem 'rubocop', '~> 1.0', '<= 1.11' + gem 'rubocop-performance' + # docs gem 'github-markup' From 8a67ee16bf018c1de8b0d0679f6a8edc2531ca82 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Thu, 11 May 2023 11:36:23 -0700 Subject: [PATCH 12/12] Removed unnecessary require of minitest/spec --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f0d65c7f57..9f59a09f4d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,7 +5,6 @@ require 'bundler' Bundler.require require 'rouge' -require 'minitest/spec' require 'minitest/autorun' Token = Rouge::Token