rouge 3.20.0 → 3.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge.rb +1 -0
  3. data/lib/rouge/cli.rb +32 -2
  4. data/lib/rouge/demos/brightscript +6 -0
  5. data/lib/rouge/demos/email +11 -0
  6. data/lib/rouge/demos/j +12 -0
  7. data/lib/rouge/demos/janet +3 -0
  8. data/lib/rouge/demos/postscript +9 -0
  9. data/lib/rouge/demos/ssh +4 -0
  10. data/lib/rouge/demos/systemd +4 -0
  11. data/lib/rouge/formatters/html_line_highlighter.rb +24 -0
  12. data/lib/rouge/formatters/html_line_table.rb +1 -3
  13. data/lib/rouge/formatters/html_linewise.rb +2 -3
  14. data/lib/rouge/lexer.rb +38 -20
  15. data/lib/rouge/lexers/apex.rb +9 -7
  16. data/lib/rouge/lexers/batchfile.rb +3 -2
  17. data/lib/rouge/lexers/brightscript.rb +147 -0
  18. data/lib/rouge/lexers/cpp.rb +6 -5
  19. data/lib/rouge/lexers/css.rb +3 -1
  20. data/lib/rouge/lexers/docker.rb +2 -2
  21. data/lib/rouge/lexers/elm.rb +5 -5
  22. data/lib/rouge/lexers/email.rb +39 -0
  23. data/lib/rouge/lexers/ghc_core.rb +2 -1
  24. data/lib/rouge/lexers/graphql.rb +1 -1
  25. data/lib/rouge/lexers/hack.rb +1 -1
  26. data/lib/rouge/lexers/html.rb +6 -6
  27. data/lib/rouge/lexers/http.rb +8 -2
  28. data/lib/rouge/lexers/isbl.rb +2 -2
  29. data/lib/rouge/lexers/j.rb +244 -0
  30. data/lib/rouge/lexers/janet.rb +218 -0
  31. data/lib/rouge/lexers/javascript.rb +11 -3
  32. data/lib/rouge/lexers/jinja.rb +22 -7
  33. data/lib/rouge/lexers/jsl.rb +1 -1
  34. data/lib/rouge/lexers/jsonnet.rb +4 -3
  35. data/lib/rouge/lexers/jsp.rb +2 -3
  36. data/lib/rouge/lexers/julia.rb +4 -2
  37. data/lib/rouge/lexers/kotlin.rb +8 -4
  38. data/lib/rouge/lexers/opentype_feature_file.rb +0 -1
  39. data/lib/rouge/lexers/perl.rb +27 -7
  40. data/lib/rouge/lexers/php.rb +274 -128
  41. data/lib/rouge/lexers/postscript.rb +93 -0
  42. data/lib/rouge/lexers/powershell.rb +41 -29
  43. data/lib/rouge/lexers/q.rb +1 -1
  44. data/lib/rouge/lexers/rego.rb +27 -12
  45. data/lib/rouge/lexers/ruby.rb +1 -1
  46. data/lib/rouge/lexers/rust.rb +5 -3
  47. data/lib/rouge/lexers/sass/common.rb +1 -0
  48. data/lib/rouge/lexers/smarty.rb +1 -1
  49. data/lib/rouge/lexers/ssh.rb +33 -0
  50. data/lib/rouge/lexers/systemd.rb +34 -0
  51. data/lib/rouge/lexers/twig.rb +4 -4
  52. data/lib/rouge/lexers/velocity.rb +1 -1
  53. data/lib/rouge/lexers/wollok.rb +0 -1
  54. data/lib/rouge/lexers/xml.rb +5 -3
  55. data/lib/rouge/lexers/yaml.rb +5 -3
  56. data/lib/rouge/regex_lexer.rb +56 -1
  57. data/lib/rouge/version.rb +1 -1
  58. metadata +17 -2
@@ -0,0 +1,93 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ # Adapted from pygments PostScriptLexer
5
+ module Rouge
6
+ module Lexers
7
+ class PostScript < RegexLexer
8
+ title "PostScript"
9
+ desc "The PostScript language (adobe.com/devnet/postscript.html)"
10
+ tag "postscript"
11
+ aliases "postscr", "postscript", "ps", "eps"
12
+ filenames "*.ps", "*.eps"
13
+ mimetypes "application/postscript"
14
+
15
+ def self.detect?(text)
16
+ return true if /^%!/ =~ text
17
+ end
18
+
19
+ delimiter = %s"()<>\[\]{}/%\s"
20
+ delimiter_end = Regexp.new("(?=[#{delimiter}])")
21
+ valid_name_chars = Regexp.new("[^#{delimiter}]")
22
+ valid_name = /#{valid_name_chars}+#{delimiter_end}/
23
+
24
+ # These keywords taken from
25
+ # <http://www.math.ubc.ca/~cass/graphics/manual/pdf/a1.pdf>
26
+ # Is there an authoritative list anywhere that doesn't involve
27
+ # trawling documentation?
28
+ keywords = %w/abs add aload arc arcn array atan begin
29
+ bind ceiling charpath clip closepath concat
30
+ concatmatrix copy cos currentlinewidth currentmatrix
31
+ currentpoint curveto cvi cvs def defaultmatrix
32
+ dict dictstackoverflow div dtransform dup end
33
+ exch exec exit exp fill findfont floor get
34
+ getinterval grestore gsave identmatrix idiv
35
+ idtransform index invertmatrix itransform length
36
+ lineto ln load log loop matrix mod moveto
37
+ mul neg newpath pathforall pathbbox pop print
38
+ pstack put quit rand rangecheck rcurveto repeat
39
+ restore rlineto rmoveto roll rotate round run
40
+ save scale scalefont setdash setfont setgray
41
+ setlinecap setlinejoin setlinewidth setmatrix
42
+ setrgbcolor shfill show showpage sin sqrt
43
+ stack stringwidth stroke strokepath sub syntaxerror
44
+ transform translate truncate typecheck undefined
45
+ undefinedfilename undefinedresult/
46
+
47
+ state :root do
48
+ # All comment types
49
+ rule %r'^%!.+?$', Comment::Preproc
50
+ rule %r'%%.*?$', Comment::Special
51
+ rule %r'(^%.*?$){2,}', Comment::Multiline
52
+ rule %r'%.*?$', Comment::Single
53
+
54
+ # String literals are awkward; enter separate state.
55
+ rule %r'\(', Str, :stringliteral
56
+
57
+ # References
58
+ rule %r'/#{valid_name}', Name::Variable
59
+
60
+ rule %r'[{}<>\[\]]', Punctuation
61
+
62
+ rule %r'(?:#{keywords.join('|')})#{delimiter_end}', Name::Builtin
63
+
64
+ # Conditionals / flow control
65
+ rule %r'(eq|ne|g[et]|l[et]|and|or|not|if(?:else)?|for(?:all)?)#{delimiter_end}', Keyword::Reserved
66
+ rule %r'(false|true)#{delimiter_end}', Keyword::Constant
67
+
68
+ # Numbers
69
+ rule %r'<[0-9A-Fa-f]+>#{delimiter_end}', Num::Hex
70
+ # Slight abuse: use Oct to signify any explicit base system
71
+ rule %r'[0-9]+\#(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)((e|E)[0-9]+)?#{delimiter_end}', Num::Oct
72
+ rule %r'(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)((e|E)[0-9]+)?#{delimiter_end}', Num::Float
73
+ rule %r'(\-|\+)?[0-9]+#{delimiter_end}', Num::Integer
74
+
75
+ # Names
76
+ rule valid_name, Name::Function # Anything else is executed
77
+
78
+ rule %r'\s+', Text
79
+ end
80
+
81
+ state :stringliteral do
82
+ rule %r'[^()\\]+', Str
83
+ rule %r'\\', Str::Escape, :escape
84
+ rule %r'\(', Str, :stringliteral
85
+ rule %r'\)', Str, :pop!
86
+ end
87
+
88
+ state :escape do
89
+ rule %r'[0-8]{3}|n|r|t|b|f|\\|\(|\)', Str::Escape, :pop!
90
+ end
91
+ end
92
+ end
93
+ end
@@ -131,40 +131,57 @@ module Rouge
131
131
  rule %r/[:,]/, Punctuation
132
132
  end
133
133
 
134
- state :hasht do
135
- rule %r/\s+/, Text::Whitespace
136
- rule %r/\}/, Punctuation, :pop!
134
+ state :expr do
135
+ mixin :comments
137
136
  rule %r/"/, Str::Double, :dq
138
137
  rule %r/'/, Str::Single, :sq
139
- rule %r/\w+/, Name::Other
138
+ rule %r/@"/, Str::Heredoc, :heredoc
139
+ rule %r/@'.*?'@/m, Str::Heredoc
140
+ rule %r/\d*\.\d+/, Num::Float
141
+ rule %r/\d+/, Num::Integer
142
+ rule %r/@\{/, Punctuation, :hasht
143
+ rule %r/@\(/, Punctuation, :array
144
+ rule %r/{/, Punctuation, :brace
145
+ rule %r/\[/, Punctuation, :bracket
146
+ end
147
+
148
+ state :hasht do
149
+ rule %r/\}/, Punctuation, :pop!
140
150
  rule %r/=/, Operator
141
- rule %r/,/, Punctuation
151
+ rule %r/[,;]/, Punctuation
152
+ mixin :expr
153
+ rule %r/\w+/, Name::Other
142
154
  mixin :variable
143
155
  end
144
156
 
145
157
  state :array do
146
158
  rule %r/\s+/, Text::Whitespace
147
159
  rule %r/\)/, Punctuation, :pop!
148
- rule %r/"/, Str::Double, :dq
149
- rule %r/'/, Str::Single, :sq
150
- rule %r/,/, Punctuation
160
+ rule %r/[,;]/, Punctuation
161
+ mixin :expr
151
162
  mixin :variable
152
163
  end
153
164
 
165
+ state :brace do
166
+ rule %r/[}]/, Punctuation, :pop!
167
+ mixin :root
168
+ end
169
+
154
170
  state :bracket do
155
171
  rule %r/\]/, Punctuation, :pop!
156
- rule %r/[A-Za-z]\w+\./, Name::Constant
172
+ rule %r/[A-Za-z]\w+\./, Name
157
173
  rule %r/([A-Za-z]\w+)/ do |m|
158
174
  if ATTRIBUTES.include? m[0]
159
175
  token Name::Builtin::Pseudo
160
176
  else
161
- token Keyword::Type
177
+ token Name
162
178
  end
163
179
  end
164
180
  mixin :root
165
181
  end
166
182
 
167
183
  state :parameters do
184
+ rule %r/`./m, Str::Escape
168
185
  rule %r/\s*?\n/, Text::Whitespace, :pop!
169
186
  rule %r/[;(){}\]]/, Punctuation, :pop!
170
187
  rule %r/[|=]/, Operator, :pop!
@@ -173,20 +190,15 @@ module Rouge
173
190
  mixin :root
174
191
  end
175
192
 
176
- state :root do
193
+ state :comments do
177
194
  rule %r/\s+/, Text::Whitespace
178
-
179
- rule %r/#requires\s-version \d(?:\.\d+)?/, Comment::Preproc
180
195
  rule %r/#.*/, Comment
181
196
  rule %r/<#/, Comment::Multiline, :multiline
197
+ end
182
198
 
183
- rule %r/"/, Str::Double, :dq
184
- rule %r/'/, Str::Single, :sq
185
- rule %r/@"/, Str::Heredoc, :heredoc
186
- rule %r/@'.*?'@/m, Str::Heredoc
187
-
188
- rule %r/\d*\.\d+/, Num::Float
189
- rule %r/\d+/, Num::Integer
199
+ state :root do
200
+ mixin :comments
201
+ rule %r/#requires\s-version \d(?:\.\d+)?/, Comment::Preproc
190
202
 
191
203
  rule %r/\.\.(?=\.?\d)/, Operator
192
204
  rule %r/(?:#{OPERATORS})\b/i, Operator
@@ -203,27 +215,27 @@ module Rouge
203
215
  rule %r/-{1,2}\w+/, Name::Tag
204
216
 
205
217
  rule %r/(\.)?([-\w]+)(\[)/ do |m|
206
- groups Operator, Name::Function, Punctuation
218
+ groups Operator, Name, Punctuation
207
219
  push :bracket
208
220
  end
209
221
 
210
- rule %r/([\/\\~\w][-.:\/\\~\w]*)(\n)?/ do |m|
211
- groups Name::Function, Text::Whitespace
222
+ rule %r/([\/\\~[a-z]][-.:\/\\~\w]*)(\n)?/i do |m|
223
+ groups Name, Text::Whitespace
212
224
  push :parameters
213
225
  end
214
226
 
215
- rule %r/(\.)?([-\w]+)(?:(\()|(\n))?/ do |m|
227
+ rule %r/(\.)([-\w]+)(?:(\()|(\n))?/ do |m|
216
228
  groups Operator, Name::Function, Punctuation, Text::Whitespace
217
229
  push :parameters unless m[3].nil?
218
230
  end
219
231
 
220
- rule %r/[-+*\/%=!.&|]/, Operator
221
- rule %r/@\{/, Punctuation, :hasht
222
- rule %r/@\(/, Punctuation, :array
223
- rule %r/\[/, Punctuation, :bracket
224
- rule %r/[{}(),:;]/, Punctuation
232
+ rule %r/\?/, Name::Function, :parameters
225
233
 
234
+ mixin :expr
226
235
  mixin :variable
236
+
237
+ rule %r/[-+*\/%=!.&|]/, Operator
238
+ rule %r/[{}(),:;]/, Punctuation
227
239
  end
228
240
  end
229
241
  end
@@ -118,7 +118,7 @@ module Rouge
118
118
  end
119
119
 
120
120
  state :bottom do
121
- rule %r/.*\z/m, Comment::Multiline
121
+ rule %r/.+\z/m, Comment::Multiline
122
122
  end
123
123
  end
124
124
  end
@@ -9,36 +9,51 @@ module Rouge
9
9
  tag 'rego'
10
10
  filenames '*.rego'
11
11
 
12
+ def self.constants
13
+ @constants ||= Set.new %w(
14
+ true false null
15
+ )
16
+ end
17
+
18
+ def self.operators
19
+ @operators ||= Set.new %w(
20
+ as default else import not package some with
21
+ )
22
+ end
23
+
12
24
  state :basic do
13
25
  rule %r/\s+/, Text
14
26
  rule %r/#.*/, Comment::Single
15
-
27
+
16
28
  rule %r/[\[\](){}|.,;!]/, Punctuation
17
-
29
+
18
30
  rule %r/"[^"]*"/, Str::Double
19
-
31
+
20
32
  rule %r/-?\d+\.\d+([eE][+-]?\d+)?/, Num::Float
21
33
  rule %r/-?\d+([eE][+-]?\d+)?/, Num
22
34
 
23
35
  rule %r/\\u[0-9a-fA-F]{4}/, Num::Hex
24
36
  rule %r/\\["\/bfnrt]/, Str::Escape
25
37
  end
26
-
27
- state :atoms do
28
- rule %r/(true|false|null)/, Keyword::Constant
29
- rule %r/[[:word:]]*/, Str::Symbol
30
- end
31
-
38
+
32
39
  state :operators do
33
40
  rule %r/(=|!=|>=|<=|>|<|\+|-|\*|%|\/|\||&|:=)/, Operator
34
- rule %r/(default|not|package|import|as|with|else|some)/, Operator
35
41
  rule %r/[\/:?@^~]+/, Operator
36
42
  end
37
-
43
+
38
44
  state :root do
39
45
  mixin :basic
40
46
  mixin :operators
41
- mixin :atoms
47
+
48
+ rule %r/[[:word:]]+/ do |m|
49
+ if self.class.constants.include? m[0]
50
+ token Keyword::Constant
51
+ elsif self.class.operators.include? m[0]
52
+ token Operator::Word
53
+ else
54
+ token Name
55
+ end
56
+ end
42
57
  end
43
58
  end
44
59
  end
@@ -374,7 +374,7 @@ module Rouge
374
374
  end
375
375
 
376
376
  state :method_call do
377
- rule %r(/) do
377
+ rule %r(/|%) do
378
378
  token Operator
379
379
  goto :expr_start
380
380
  end
@@ -22,8 +22,8 @@ module Rouge
22
22
 
23
23
  def self.keywords
24
24
  @keywords ||= %w(
25
- as assert async await break const copy do drop else enum extern fail false
26
- fn for if impl let log loop match mod move mut priv pub pure
25
+ as assert async await break const continue copy do drop else enum extern
26
+ fail false fn for if impl let log loop match mod move mut priv pub pure
27
27
  ref return self static struct true trait type unsafe use where
28
28
  while box
29
29
  )
@@ -99,7 +99,9 @@ module Rouge
99
99
  rule %r/[*\/!@~&+%^<>=\?-]|\.{2,3}/, Operator
100
100
 
101
101
  rule %r/([.]\s*)?#{id}(?=\s*[(])/m, Name::Function
102
+ rule %r/[.]\s*await\b/, Keyword
102
103
  rule %r/[.]\s*#{id}/, Name::Property
104
+ rule %r/[.]\s*\d+/, Name::Attribute
103
105
  rule %r/(#{id})(::)/m do
104
106
  groups Name::Namespace, Punctuation
105
107
  end
@@ -167,7 +169,7 @@ module Rouge
167
169
  flt = /f32|f64/
168
170
 
169
171
  rule %r(
170
- [0-9]+
172
+ [0-9_]+
171
173
  (#{dot} #{exp}? #{flt}?
172
174
  |#{dot}? #{exp} #{flt}?
173
175
  |#{dot}? #{exp}? #{flt}
@@ -29,6 +29,7 @@ module Rouge
29
29
  end
30
30
 
31
31
  rule %r/@#{id}/, Keyword, :selector
32
+ rule %r/&/, Keyword, :selector
32
33
 
33
34
  # $variable: assignment
34
35
  rule %r/([$]#{id})([ \t]*)(:)/ do
@@ -41,7 +41,7 @@ module Rouge
41
41
  end
42
42
 
43
43
 
44
- rule(/.*?(?={[\/a-zA-Z0-9$#*"'])|.*/m) { delegate parent }
44
+ rule(/.+?(?={[\/a-zA-Z0-9$#*"'])/m) { delegate parent }
45
45
  rule(/.+/m) { delegate parent }
46
46
  end
47
47
 
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class SSH < RegexLexer
7
+ tag 'ssh'
8
+
9
+ title "SSH Config File"
10
+ desc 'A lexer for SSH configuration files'
11
+ filenames 'ssh_config'
12
+
13
+ state :root do
14
+ rule %r/[a-z0-9]+/i, Keyword, :statement
15
+ mixin :base
16
+ end
17
+
18
+ state :statement do
19
+ rule %r/\n/, Text, :pop!
20
+ rule %r/(?:yes|no|confirm|ask|always|auto|none|force)\b/, Name::Constant
21
+
22
+ rule %r/\d+/, Num
23
+ rule %r/[^#\s;{}$\\]+/, Text
24
+ mixin :base
25
+ end
26
+
27
+ state :base do
28
+ rule %r/\s+/, Text
29
+ rule %r/#.*/, Comment::Single
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class SystemD < RegexLexer
7
+ tag 'systemd'
8
+ aliases 'unit-file'
9
+ filenames '*.service'
10
+ mimetypes 'text/x-systemd-unit'
11
+ desc 'A lexer for systemd unit files'
12
+
13
+ state :root do
14
+ rule %r/\s+/, Text
15
+ rule %r/[;#].*/, Comment
16
+ rule %r/\[.*?\]$/, Keyword
17
+ rule %r/(.*?)(=)(.*)(\\\n)/ do
18
+ groups Name::Tag, Punctuation, Text, Str::Escape
19
+ push :continuation
20
+ end
21
+ rule %r/(.*?)(=)(.*)/ do
22
+ groups Name::Tag, Punctuation, Text
23
+ end
24
+ end
25
+
26
+ state :continuation do
27
+ rule %r/(.*?)(\\\n)/ do
28
+ groups Text, Str::Escape
29
+ end
30
+ rule %r/(.*)'/, Text, :pop!
31
+ end
32
+ end
33
+ end
34
+ end
@@ -17,10 +17,10 @@ module Rouge
17
17
 
18
18
  def self.keywords
19
19
  @@keywords ||= %w(as do extends flush from import include use else starts
20
- ends with without autoescape endautoescape block endblock
21
- embed endembed filter endfilter for endfor if endif
22
- macro endmacro sandbox endsandbox set endset
23
- spaceless endspaceless verbatim endverbatim)
20
+ ends with without autoescape endautoescape block
21
+ endblock embed endembed filter endfilter for endfor
22
+ if endif macro endmacro sandbox endsandbox set endset
23
+ spaceless endspaceless)
24
24
  end
25
25
 
26
26
  def self.tests
@@ -63,7 +63,7 @@ module Rouge
63
63
  rule %r/0[xX][0-9a-fA-F]+[Ll]?/, Num::Hex
64
64
  rule %r/\b[0-9]+\b/, Num::Integer
65
65
  rule %r/(true|false|null)\b/, Keyword::Constant
66
- rule %r/[(\[]/, Punctuation, :push!
66
+ rule %r/[(\[]/, Punctuation, :push
67
67
  rule %r/[)\]}]/, Punctuation, :pop!
68
68
  end
69
69
  end