rouge 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -4
  3. data/lib/rouge.rb +9 -7
  4. data/lib/rouge/cli.rb +36 -2
  5. data/lib/rouge/guessers/disambiguation.rb +88 -0
  6. data/lib/rouge/guessers/glob_mapping.rb +3 -6
  7. data/lib/rouge/guessers/modeline.rb +4 -3
  8. data/lib/rouge/guessers/source.rb +6 -16
  9. data/lib/rouge/guessers/util.rb +32 -0
  10. data/lib/rouge/lexer.rb +20 -11
  11. data/lib/rouge/lexers/apiblueprint.rb +0 -4
  12. data/lib/rouge/lexers/awk.rb +2 -2
  13. data/lib/rouge/lexers/biml.rb +2 -2
  14. data/lib/rouge/lexers/c.rb +0 -5
  15. data/lib/rouge/lexers/coffeescript.rb +2 -2
  16. data/lib/rouge/lexers/coq.rb +0 -4
  17. data/lib/rouge/lexers/diff.rb +4 -4
  18. data/lib/rouge/lexers/digdag.rb +0 -4
  19. data/lib/rouge/lexers/erb.rb +0 -4
  20. data/lib/rouge/lexers/erlang.rb +0 -4
  21. data/lib/rouge/lexers/factor.rb +2 -2
  22. data/lib/rouge/lexers/gherkin.rb +2 -2
  23. data/lib/rouge/lexers/go.rb +0 -4
  24. data/lib/rouge/lexers/groovy.rb +2 -2
  25. data/lib/rouge/lexers/haml.rb +0 -4
  26. data/lib/rouge/lexers/haskell.rb +4 -4
  27. data/lib/rouge/lexers/html.rb +3 -3
  28. data/lib/rouge/lexers/idlang.rb +0 -6
  29. data/lib/rouge/lexers/ini.rb +0 -4
  30. data/lib/rouge/lexers/io.rb +2 -2
  31. data/lib/rouge/lexers/javascript.rb +1 -1
  32. data/lib/rouge/lexers/julia.rb +2 -2
  33. data/lib/rouge/lexers/kotlin.rb +9 -14
  34. data/lib/rouge/lexers/lasso.rb +3 -6
  35. data/lib/rouge/lexers/llvm.rb +0 -4
  36. data/lib/rouge/lexers/lua.rb +2 -2
  37. data/lib/rouge/lexers/make.rb +0 -4
  38. data/lib/rouge/lexers/matlab.rb +0 -4
  39. data/lib/rouge/lexers/moonscript.rb +2 -2
  40. data/lib/rouge/lexers/mosel.rb +3 -3
  41. data/lib/rouge/lexers/nasm.rb +0 -5
  42. data/lib/rouge/lexers/objective_c.rb +0 -14
  43. data/lib/rouge/lexers/perl.rb +2 -3
  44. data/lib/rouge/lexers/php.rb +2 -4
  45. data/lib/rouge/lexers/plist.rb +0 -4
  46. data/lib/rouge/lexers/praat.rb +2 -2
  47. data/lib/rouge/lexers/prolog.rb +0 -5
  48. data/lib/rouge/lexers/properties.rb +0 -4
  49. data/lib/rouge/lexers/puppet.rb +3 -3
  50. data/lib/rouge/lexers/python.rb +2 -2
  51. data/lib/rouge/lexers/q.rb +0 -4
  52. data/lib/rouge/lexers/r.rb +2 -2
  53. data/lib/rouge/lexers/racket.rb +5 -4
  54. data/lib/rouge/lexers/ruby.rb +2 -2
  55. data/lib/rouge/lexers/rust.rb +2 -2
  56. data/lib/rouge/lexers/sed.rb +2 -2
  57. data/lib/rouge/lexers/shell.rb +2 -2
  58. data/lib/rouge/lexers/smarty.rb +0 -11
  59. data/lib/rouge/lexers/sml.rb +0 -4
  60. data/lib/rouge/lexers/tap.rb +0 -4
  61. data/lib/rouge/lexers/tcl.rb +4 -4
  62. data/lib/rouge/lexers/tex.rb +2 -2
  63. data/lib/rouge/lexers/toml.rb +0 -4
  64. data/lib/rouge/lexers/tulip.rb +2 -3
  65. data/lib/rouge/lexers/turtle.rb +5 -14
  66. data/lib/rouge/lexers/vue.rb +0 -4
  67. data/lib/rouge/lexers/wollok.rb +0 -4
  68. data/lib/rouge/lexers/xml.rb +4 -6
  69. data/lib/rouge/lexers/yaml.rb +2 -2
  70. data/lib/rouge/version.rb +1 -1
  71. data/rouge.gemspec +1 -0
  72. metadata +6 -4
@@ -8,10 +8,6 @@ module Rouge
8
8
 
9
9
  mimetypes 'text/x-plist', 'application/x-plist'
10
10
 
11
- def self.analyze_text(text)
12
- return 0.6 if text.start_with?("// !$*UTF8*$!")
13
- end
14
-
15
11
  state :whitespace do
16
12
  rule /\s+/, Text::Whitespace
17
13
  end
@@ -10,8 +10,8 @@ module Rouge
10
10
 
11
11
  filenames '*.praat', '*.proc', '*.psc'
12
12
 
13
- def self.analyze_text(text)
14
- return 1 if text.shebang? 'praat'
13
+ def self.detect?(text)
14
+ return true if text.shebang? 'praat'
15
15
  end
16
16
 
17
17
  keywords = %w(
@@ -10,11 +10,6 @@ module Rouge
10
10
  filenames '*.pro', '*.P', '*.prolog', '*.pl'
11
11
  mimetypes 'text/x-prolog'
12
12
 
13
- def self.analyze_text(text)
14
- return 0.1 if text =~ /\A\w+(\(\w+\,\s*\w+\))*\./
15
- return 0.1 if text.include? ':-'
16
- end
17
-
18
13
  state :basic do
19
14
  rule /\s+/, Text
20
15
  rule /^#.*/, Comment::Single
@@ -10,10 +10,6 @@ module Rouge
10
10
  filenames '*.properties'
11
11
  mimetypes 'text/x-java-properties'
12
12
 
13
- def self.analyze_text(text)
14
- return 0.1 if text =~ /\A\[[\w.-]+\]\s*\w+=\w+/
15
- end
16
-
17
13
  identifier = /[\w.-]+/
18
14
 
19
15
  state :basic do
@@ -9,9 +9,9 @@ module Rouge
9
9
  aliases 'pp'
10
10
  filenames '*.pp'
11
11
 
12
- def self.analyze_text(text)
13
- return 1 if text.shebang? 'puppet-apply'
14
- return 1 if text.shebang? 'puppet'
12
+ def self.detect?(text)
13
+ return true if text.shebang? 'puppet-apply'
14
+ return true if text.shebang? 'puppet'
15
15
  end
16
16
 
17
17
  def self.keywords
@@ -10,8 +10,8 @@ module Rouge
10
10
  filenames '*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac'
11
11
  mimetypes 'text/x-python', 'application/x-python'
12
12
 
13
- def self.analyze_text(text)
14
- return 1 if text.shebang?(/pythonw?(3|2(\.\d)?)?/)
13
+ def self.detect?(text)
14
+ return true if text.shebang?(/pythonw?(3|2(\.\d)?)?/)
15
15
  end
16
16
 
17
17
  def self.keywords
@@ -32,10 +32,6 @@ module Rouge
32
32
  ]
33
33
  end
34
34
 
35
- def self.analyze_text(text)
36
- return 0
37
- end
38
-
39
35
  state :root do
40
36
  # q allows a file to start with a shebang
41
37
  rule /#!(.*?)$/, Comment::Preproc, :top
@@ -43,8 +43,8 @@ module Rouge
43
43
  trigamma trunc unclass untracemem UseMethod xtfrm
44
44
  )
45
45
 
46
- def self.analyze_text(text)
47
- return 1 if text.shebang? 'Rscript'
46
+ def self.detect?(text)
47
+ return true if text.shebang? 'Rscript'
48
48
  end
49
49
 
50
50
  state :root do
@@ -9,10 +9,11 @@ module Rouge
9
9
  filenames '*.rkt', '*.rktd', '*.rktl'
10
10
  mimetypes 'text/x-racket', 'application/x-racket'
11
11
 
12
- def self.analyze_text(text)
13
- text = text.strip
14
- return 1 if text.start_with? '#lang racket'
15
- return 0.6 if text =~ %r(\A#lang [a-z/-]+$)i
12
+ def self.detect?(text)
13
+ text =~ /\A#lang\s*(.*?)$/
14
+ lang_attr = $1
15
+ return false unless lang_attr
16
+ return true if lang_attr =~ /racket|scribble/
16
17
  end
17
18
 
18
19
  def self.keywords
@@ -13,8 +13,8 @@ module Rouge
13
13
 
14
14
  mimetypes 'text/x-ruby', 'application/x-ruby'
15
15
 
16
- def self.analyze_text(text)
17
- return 1 if text.shebang? 'ruby'
16
+ def self.detect?(text)
17
+ return true if text.shebang? 'ruby'
18
18
  end
19
19
 
20
20
  state :symbols do
@@ -10,8 +10,8 @@ module Rouge
10
10
  filenames '*.rs'
11
11
  mimetypes 'text/x-rust'
12
12
 
13
- def self.analyze_text(text)
14
- return 1 if text.shebang? 'rustc'
13
+ def self.detect?(text)
14
+ return true if text.shebang? 'rustc'
15
15
  end
16
16
 
17
17
  def self.keywords
@@ -10,8 +10,8 @@ module Rouge
10
10
  filenames '*.sed'
11
11
  mimetypes 'text/x-sed'
12
12
 
13
- def self.analyze_text(text)
14
- return 1 if text.shebang? 'sed'
13
+ def self.detect?(text)
14
+ return true if text.shebang? 'sed'
15
15
  end
16
16
 
17
17
  class Regex < RegexLexer
@@ -13,8 +13,8 @@ module Rouge
13
13
 
14
14
  mimetypes 'application/x-sh', 'application/x-shellscript'
15
15
 
16
- def self.analyze_text(text)
17
- text.shebang?(/(ba|z|k)?sh/) ? 1 : 0
16
+ def self.detect?(text)
17
+ return true if text.shebang?(/(ba|z|k)?sh/)
18
18
  end
19
19
 
20
20
  KEYWORDS = %w(
@@ -10,17 +10,6 @@ module Rouge
10
10
  filenames '*.tpl', '*.smarty'
11
11
  mimetypes 'application/x-smarty', 'text/x-smarty'
12
12
 
13
- def self.analyze_text(text)
14
- rv = 0.0
15
- rv += 0.15 if text =~ /\{if\s+.*?\}.*?\{\/if\}/
16
- rv += 0.15 if text =~ /\{include\s+file=.*?\}/
17
- rv += 0.15 if text =~ /\{foreach\s+.*?\}.*?\{\/foreach\}/
18
- rv += 0.01 if text =~ /\{\$.*?\}/
19
- return rv
20
- end
21
-
22
-
23
-
24
13
  def self.builtins
25
14
  @builtins ||= %w(
26
15
  append assign block call capture config_load debug extends
@@ -28,10 +28,6 @@ module Rouge
28
28
  id = /[\w']+/i
29
29
  symbol = %r([!%&$#/:<=>?@\\~`^|*+-]+)
30
30
 
31
- def self.analyze_text(text)
32
- return 0
33
- end
34
-
35
31
  state :whitespace do
36
32
  rule /\s+/m, Text
37
33
  rule /[(][*]/, Comment, :comment
@@ -9,10 +9,6 @@ module Rouge
9
9
 
10
10
  mimetypes 'text/x-tap', 'application/x-tap'
11
11
 
12
- def self.analyze_text(text)
13
- return 0
14
- end
15
-
16
12
  state :root do
17
13
  # A TAP version may be specified.
18
14
  rule /^TAP version \d+\n/, Name::Namespace
@@ -9,10 +9,10 @@ module Rouge
9
9
  filenames '*.tcl'
10
10
  mimetypes 'text/x-tcl', 'text/x-script.tcl', 'application/x-tcl'
11
11
 
12
- def self.analyze_text(text)
13
- return 1 if text.shebang? 'tclsh'
14
- return 1 if text.shebang? 'wish'
15
- return 1 if text.shebang? 'jimsh'
12
+ def self.detect?(text)
13
+ return true if text.shebang? 'tclsh'
14
+ return true if text.shebang? 'wish'
15
+ return true if text.shebang? 'jimsh'
16
16
  end
17
17
 
18
18
  KEYWORDS = %w(
@@ -11,8 +11,8 @@ module Rouge
11
11
  filenames '*.tex', '*.aux', '*.toc', '*.sty', '*.cls'
12
12
  mimetypes 'text/x-tex', 'text/x-latex'
13
13
 
14
- def self.analyze_text(text)
15
- return 1 if text =~ /\A\s*\\(documentclass|input|documentstyle|relax|ProvidesPackage|ProvidesClass)/
14
+ def self.detect?(text)
15
+ return true if text =~ /\A\s*\\(documentclass|input|documentstyle|relax|ProvidesPackage|ProvidesClass)/
16
16
  end
17
17
 
18
18
  command = /\\([a-z]+|\s+|.)/i
@@ -10,10 +10,6 @@ module Rouge
10
10
  filenames '*.toml'
11
11
  mimetypes 'text/x-toml'
12
12
 
13
- def self.analyze_text(text)
14
- return 0.1 if text =~ /\A\[[\w.]+\]\s*\w+\s*=\s*("\w+")+/
15
- end
16
-
17
13
  identifier = /[\w.\S]+/
18
14
 
19
15
  state :basic do
@@ -9,9 +9,8 @@ module Rouge
9
9
 
10
10
  mimetypes 'text/x-tulip', 'application/x-tulip'
11
11
 
12
- def self.analyze_text(text)
13
- return 1 if text.shebang? 'tulip'
14
- return 0
12
+ def self.detect?(text)
13
+ return true if text.shebang? 'tulip'
15
14
  end
16
15
 
17
16
  id = /[a-z][\w-]*/i
@@ -12,29 +12,21 @@ module Rouge
12
12
  application/trig
13
13
  )
14
14
 
15
- def self.analyze_text(text)
16
- start = text[0..1000]
17
- return 0.5 if start =~ %r(@prefix\b)
18
- return 0.5 if start =~ %r(@base\b)
19
- return 0.4 if start =~ %r(PREFIX\b)i
20
- return 0.4 if start =~ %r(BASE\b)i
21
- end
22
-
23
15
  state :root do
24
16
  rule /@base\b/, Keyword::Declaration
25
17
  rule /@prefix\b/, Keyword::Declaration
26
18
  rule /true\b/, Keyword::Constant
27
19
  rule /false\b/, Keyword::Constant
28
-
20
+
29
21
  rule /""".*?"""/m, Literal::String
30
22
  rule /"([^"\\]|\\.)*"/, Literal::String
31
23
  rule /'''.*?'''/m, Literal::String
32
24
  rule /'([^'\\]|\\.)*'/, Literal::String
33
-
25
+
34
26
  rule /#.*$/, Comment::Single
35
-
27
+
36
28
  rule /@[^\s,.; ]+/, Name::Attribute
37
-
29
+
38
30
  rule /[+-]?[0-9]+\.[0-9]*E[+-]?[0-9]+/, Literal::Number::Float
39
31
  rule /[+-]?\.[0-9]+E[+-]?[0-9]+/, Literal::Number::Float
40
32
  rule /[+-]?[0-9]+E[+-]?[0-9]+/, Literal::Number::Float
@@ -53,7 +45,7 @@ module Rouge
53
45
  rule /\[/, Punctuation
54
46
  rule /\]/, Punctuation
55
47
  rule /\^\^/, Punctuation
56
-
48
+
57
49
  rule /<[^>]*>/, Name::Label
58
50
 
59
51
  rule /base\b/i, Keyword::Declaration
@@ -65,7 +57,6 @@ module Rouge
65
57
 
66
58
  rule /[^:;<>#\@"\(\).\[\]\{\} ]+:/, Name::Namespace
67
59
  rule /[^:;<>#\@"\(\).\[\]\{\} ]+/, Name
68
-
69
60
  end
70
61
  end
71
62
  end
@@ -15,10 +15,6 @@ module Rouge
15
15
  @js = Javascript.new(options)
16
16
  end
17
17
 
18
- def self.analyze_text(text)
19
- return 0
20
- end
21
-
22
18
  def lookup_lang(lang)
23
19
  case lang
24
20
  when 'html' then HTML
@@ -8,10 +8,6 @@ module Rouge
8
8
  tag 'wollok'
9
9
  filenames *%w(*.wlk *.wtest *.wpgm)
10
10
 
11
- def self.analyze_text(_text)
12
- 0.3
13
- end
14
-
15
11
  keywords = %w(new super return if else var const override constructor)
16
12
 
17
13
  entity_name = /[a-zA-Z][a-zA-Z0-9]*/
@@ -15,12 +15,10 @@ module Rouge
15
15
  application/atom+xml
16
16
  )
17
17
 
18
- def self.analyze_text(text)
19
- return 0.9 if text.doctype?
20
- return 0.8 if text =~ /\A<\?xml\b/
21
- start = text[0..1000]
22
- return 0.6 if start =~ %r(<xml\b)
23
- return 0.3 if start =~ %r(<.+?>.*?</.+?>)m
18
+ def self.detect?(text)
19
+ return false if text.doctype?(/html/)
20
+ return true if text =~ /\A<\?xml\b/
21
+ return true if text.doctype?
24
22
  end
25
23
 
26
24
  state :root do
@@ -10,9 +10,9 @@ module Rouge
10
10
  aliases 'yml'
11
11
  filenames '*.yaml', '*.yml'
12
12
 
13
- def self.analyze_text(text)
13
+ def self.detect?(text)
14
14
  # look for the %YAML directive
15
- return 1 if text =~ /\A\s*%YAML/m
15
+ return true if text =~ /\A\s*%YAML/m
16
16
  end
17
17
 
18
18
  SPECIAL_VALUES = Regexp.union(%w(true false null))
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rouge
4
4
  def self.version
5
- "2.2.1"
5
+ "3.0.0"
6
6
  end
7
7
  end
@@ -15,4 +15,5 @@ Gem::Specification.new do |s|
15
15
  s.files = Dir['Gemfile', 'LICENSE', 'rouge.gemspec', 'lib/**/*.rb', 'lib/**/*.yml', 'bin/rougify', 'lib/rouge/demos/*']
16
16
  s.executables = %w(rougify)
17
17
  s.licenses = ['MIT', 'BSD-2-Clause']
18
+ s.required_ruby_version = '>= 2.0'
18
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeanine Adkisson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-22 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rouge aims to a be a simple, easy-to-extend drop-in replacement for pygments.
14
14
  email:
@@ -163,11 +163,13 @@ files:
163
163
  - lib/rouge/formatters/null.rb
164
164
  - lib/rouge/formatters/terminal256.rb
165
165
  - lib/rouge/guesser.rb
166
+ - lib/rouge/guessers/disambiguation.rb
166
167
  - lib/rouge/guessers/filename.rb
167
168
  - lib/rouge/guessers/glob_mapping.rb
168
169
  - lib/rouge/guessers/mimetype.rb
169
170
  - lib/rouge/guessers/modeline.rb
170
171
  - lib/rouge/guessers/source.rb
172
+ - lib/rouge/guessers/util.rb
171
173
  - lib/rouge/lexer.rb
172
174
  - lib/rouge/lexers/abap.rb
173
175
  - lib/rouge/lexers/actionscript.rb
@@ -340,7 +342,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
340
342
  requirements:
341
343
  - - ">="
342
344
  - !ruby/object:Gem::Version
343
- version: '0'
345
+ version: '2.0'
344
346
  required_rubygems_version: !ruby/object:Gem::Requirement
345
347
  requirements:
346
348
  - - ">="
@@ -348,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
348
350
  version: '0'
349
351
  requirements: []
350
352
  rubyforge_project: rouge
351
- rubygems_version: 2.6.11
353
+ rubygems_version: 2.6.13
352
354
  signing_key:
353
355
  specification_version: 4
354
356
  summary: A pure-ruby colorizer based on pygments