rouge 2.0.7 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -9
  3. data/lib/rouge.rb +1 -0
  4. data/lib/rouge/cli.rb +20 -0
  5. data/lib/rouge/demos/awk +4 -0
  6. data/lib/rouge/demos/console +6 -0
  7. data/lib/rouge/demos/digdag +19 -0
  8. data/lib/rouge/demos/dot +5 -0
  9. data/lib/rouge/demos/graphql +17 -0
  10. data/lib/rouge/demos/hylang +10 -0
  11. data/lib/rouge/demos/igorpro +9 -0
  12. data/lib/rouge/demos/irb +4 -0
  13. data/lib/rouge/demos/irb_output +2 -0
  14. data/lib/rouge/demos/lasso +12 -0
  15. data/lib/rouge/demos/mosel +10 -0
  16. data/lib/rouge/demos/plist +142 -0
  17. data/lib/rouge/demos/pony +17 -0
  18. data/lib/rouge/demos/q +2 -0
  19. data/lib/rouge/demos/sieve +10 -0
  20. data/lib/rouge/demos/tsx +17 -0
  21. data/lib/rouge/demos/turtle +0 -0
  22. data/lib/rouge/demos/wollok +11 -0
  23. data/lib/rouge/formatters/html_inline.rb +9 -1
  24. data/lib/rouge/formatters/html_pygments.rb +2 -2
  25. data/lib/rouge/formatters/html_table.rb +1 -1
  26. data/lib/rouge/formatters/terminal256.rb +1 -1
  27. data/lib/rouge/lexer.rb +124 -37
  28. data/lib/rouge/lexers/abap.rb +2 -2
  29. data/lib/rouge/lexers/apache.rb +1 -1
  30. data/lib/rouge/lexers/awk.rb +161 -0
  31. data/lib/rouge/lexers/clojure.rb +2 -2
  32. data/lib/rouge/lexers/coffeescript.rb +1 -1
  33. data/lib/rouge/lexers/console.rb +136 -0
  34. data/lib/rouge/lexers/csharp.rb +26 -7
  35. data/lib/rouge/lexers/digdag.rb +72 -0
  36. data/lib/rouge/lexers/docker.rb +1 -1
  37. data/lib/rouge/lexers/dot.rb +68 -0
  38. data/lib/rouge/lexers/elixir.rb +52 -27
  39. data/lib/rouge/lexers/fortran.rb +56 -28
  40. data/lib/rouge/lexers/fsharp.rb +1 -1
  41. data/lib/rouge/lexers/gherkin/keywords.rb +4 -4
  42. data/lib/rouge/lexers/graphql.rb +243 -0
  43. data/lib/rouge/lexers/groovy.rb +5 -1
  44. data/lib/rouge/lexers/haml.rb +19 -24
  45. data/lib/rouge/lexers/html.rb +48 -4
  46. data/lib/rouge/lexers/hylang.rb +93 -0
  47. data/lib/rouge/lexers/igorpro.rb +407 -0
  48. data/lib/rouge/lexers/irb.rb +66 -0
  49. data/lib/rouge/lexers/javascript.rb +21 -10
  50. data/lib/rouge/lexers/json.rb +3 -2
  51. data/lib/rouge/lexers/json_doc.rb +6 -0
  52. data/lib/rouge/lexers/jsx.rb +2 -1
  53. data/lib/rouge/lexers/lasso.rb +217 -0
  54. data/lib/rouge/lexers/lasso/keywords.yml +446 -0
  55. data/lib/rouge/lexers/lua.rb +3 -0
  56. data/lib/rouge/lexers/lua/builtins.rb +1 -1
  57. data/lib/rouge/lexers/markdown.rb +2 -3
  58. data/lib/rouge/lexers/matlab/builtins.rb +1 -1
  59. data/lib/rouge/lexers/moonscript.rb +8 -4
  60. data/lib/rouge/lexers/mosel.rb +231 -0
  61. data/lib/rouge/lexers/ocaml.rb +9 -20
  62. data/lib/rouge/lexers/php.rb +40 -20
  63. data/lib/rouge/lexers/php/builtins.rb +27 -37
  64. data/lib/rouge/lexers/plain_text.rb +4 -3
  65. data/lib/rouge/lexers/plist.rb +49 -0
  66. data/lib/rouge/lexers/pony.rb +93 -0
  67. data/lib/rouge/lexers/powershell.rb +36 -0
  68. data/lib/rouge/lexers/properties.rb +2 -2
  69. data/lib/rouge/lexers/q.rb +124 -0
  70. data/lib/rouge/lexers/r.rb +2 -2
  71. data/lib/rouge/lexers/ruby.rb +26 -13
  72. data/lib/rouge/lexers/rust.rb +7 -5
  73. data/lib/rouge/lexers/sed.rb +4 -2
  74. data/lib/rouge/lexers/shell.rb +38 -16
  75. data/lib/rouge/lexers/sieve.rb +96 -0
  76. data/lib/rouge/lexers/sml.rb +3 -2
  77. data/lib/rouge/lexers/tsx.rb +19 -0
  78. data/lib/rouge/lexers/turtle.rb +0 -0
  79. data/lib/rouge/lexers/typescript.rb +3 -27
  80. data/lib/rouge/lexers/typescript/common.rb +33 -0
  81. data/lib/rouge/lexers/viml/keywords.rb +2 -2
  82. data/lib/rouge/lexers/wollok.rb +107 -0
  83. data/lib/rouge/lexers/xml.rb +1 -1
  84. data/lib/rouge/lexers/yaml.rb +4 -1
  85. data/lib/rouge/regex_lexer.rb +1 -0
  86. data/lib/rouge/template_lexer.rb +3 -5
  87. data/lib/rouge/theme.rb +14 -4
  88. data/lib/rouge/themes/igor_pro.rb +20 -0
  89. data/lib/rouge/themes/pastie.rb +69 -0
  90. data/lib/rouge/themes/thankful_eyes.rb +8 -5
  91. data/lib/rouge/version.rb +1 -1
  92. metadata +40 -6
  93. data/lib/rouge/demos/shell_session +0 -10
  94. data/lib/rouge/lexers/shell_session.rb +0 -29
@@ -48,8 +48,8 @@ module Rouge
48
48
  end
49
49
 
50
50
  state :root do
51
- rule /#'.*?\n/, Comment::Doc
52
- rule /#.*?\n/, Comment::Single
51
+ rule /#'.*?$/, Comment::Doc
52
+ rule /#.*?$/, Comment::Single
53
53
  rule /\s+/m, Text::Whitespace
54
54
 
55
55
  rule /`[^`]+?`/, Name
@@ -108,12 +108,14 @@ module Rouge
108
108
  )
109
109
 
110
110
  keywords_pseudo = %w(
111
- initialize new loop include extend raise attr_reader attr_writer
112
- attr_accessor alias_method attr catch throw private module_function
111
+ loop include extend raise
112
+ alias_method attr catch throw private module_function
113
113
  public protected true false nil __FILE__ __LINE__
114
114
  )
115
115
 
116
116
  builtins_g = %w(
117
+ attr_reader attr_writer attr_accessor
118
+
117
119
  __id__ __send__ abort ancestors at_exit autoload binding callcc
118
120
  caller catch chomp chop class_eval class_variables clone
119
121
  const_defined\? const_get const_missing const_set constants
@@ -150,7 +152,7 @@ module Rouge
150
152
  rule /\n\s*/m, Text, :expr_start
151
153
  rule /#.*$/, Comment::Single
152
154
 
153
- rule %r(=begin\b.*?end\b)m, Comment::Multiline
155
+ rule %r(=begin\b.*?\n=end\b)m, Comment::Multiline
154
156
  end
155
157
 
156
158
  state :inline_whitespace do
@@ -164,6 +166,7 @@ module Rouge
164
166
  rule /0_?[0-7]+(?:_[0-7]+)*/, Num::Oct
165
167
  rule /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
166
168
  rule /0b[01]+(?:_[01]+)*/, Num::Bin
169
+ rule /\d+\.\d+(e[\+\-]?\d+)?/, Num::Float
167
170
  rule /[\d]+(?:_\d+)*/, Num::Integer
168
171
 
169
172
  # names
@@ -204,6 +207,10 @@ module Rouge
204
207
 
205
208
  mixin :has_heredocs
206
209
 
210
+ # `..` and `...` for ranges must have higher priority than `.`
211
+ # Otherwise, they will be parsed as :method_call
212
+ rule /\.{2,3}/, Operator, :expr_start
213
+
207
214
  rule /[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
208
215
  rule /(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
209
216
  groups Punctuation, Text, Name::Function
@@ -212,7 +219,7 @@ module Rouge
212
219
 
213
220
  rule /[a-zA-Z_]\w*[?!]/, Name, :expr_start
214
221
  rule /[a-zA-Z_]\w*/, Name, :method_call
215
- rule /\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\.{1,3}/,
222
+ rule /\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
216
223
  Operator, :expr_start
217
224
  rule /[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
218
225
  rule(/[?]/) { token Punctuation; push :ternary; push :expr_start }
@@ -247,25 +254,31 @@ module Rouge
247
254
  state :resolve_heredocs do
248
255
  mixin :string_intp_escaped
249
256
 
250
- rule /(\n)([^#\\\n]*)$/ do |m|
257
+ rule /\n/, Str::Heredoc, :test_heredoc
258
+ rule /[#\\\n]/, Str::Heredoc
259
+ rule /[^#\\\n]+/, Str::Heredoc
260
+ end
261
+
262
+ state :test_heredoc do
263
+ rule /[^#\\\n]*$/ do |m|
251
264
  tolerant, heredoc_name = @heredoc_queue.first
252
- check = tolerant ? m[2].strip : m[2].rstrip
265
+ check = tolerant ? m[0].strip : m[0].rstrip
253
266
 
254
267
  # check if we found the end of the heredoc
255
- line_tok = if check == heredoc_name
268
+ puts " end heredoc check #{check.inspect} = #{heredoc_name.inspect}" if @debug
269
+ if check == heredoc_name
256
270
  @heredoc_queue.shift
257
271
  # if there's no more, we're done looking.
258
272
  pop! if @heredoc_queue.empty?
259
- Name::Constant
273
+ token Name::Constant
260
274
  else
261
- Str::Heredoc
275
+ token Str::Heredoc
262
276
  end
263
277
 
264
- groups(Str::Heredoc, line_tok)
278
+ pop!
265
279
  end
266
280
 
267
- rule /[#\\\n]/, Str::Heredoc
268
- rule /[^#\\\n]+/, Str::Heredoc
281
+ rule(//) { pop! }
269
282
  end
270
283
 
271
284
  state :funcname do
@@ -301,7 +314,7 @@ module Rouge
301
314
  goto :expr_start
302
315
  end
303
316
 
304
- rule /[A-Z_]\w*/, Name::Class
317
+ rule /[A-Z_]\w*/, Name::Class, :pop!
305
318
 
306
319
  rule(//) { pop! }
307
320
  end
@@ -58,17 +58,18 @@ module Rouge
58
58
  mixin :whitespace
59
59
  rule /\s+/, Text
60
60
  rule /#\[/ do
61
- token Comment::Preproc; push :attribute
61
+ token Name::Decorator; push :attribute
62
62
  end
63
63
  rule(//) { pop! }
64
+ rule /#\s[^\n]*/, Comment::Preproc
64
65
  end
65
66
 
66
67
  state :attribute do
67
68
  mixin :whitespace
68
69
  mixin :has_literals
69
- rule /[(,)=]/, Comment::Preproc
70
- rule /\]/, Comment::Preproc, :pop!
71
- rule id, Comment::Preproc
70
+ rule /[(,)=]/, Name::Decorator
71
+ rule /\]/, Name::Decorator, :pop!
72
+ rule id, Name::Decorator
72
73
  end
73
74
 
74
75
  state :whitespace do
@@ -86,7 +87,7 @@ module Rouge
86
87
  rule %r([=-]>), Keyword
87
88
  rule %r(<->), Keyword
88
89
  rule /[()\[\]{}|,:;]/, Punctuation
89
- rule /[*!@~&+%^<>=-\?]/, Operator
90
+ rule /[*!@~&+%^<>=-\?]|\.{2,3}/, Operator
90
91
 
91
92
  rule /([.]\s*)?#{id}(?=\s*[(])/m, Name::Function
92
93
  rule /[.]\s*#{id}/, Name::Property
@@ -98,6 +99,7 @@ module Rouge
98
99
  rule /\bmacro_rules!/, Name::Decorator, :macro_rules
99
100
  rule /#{id}!/, Name::Decorator, :macro
100
101
 
102
+ rule /'#{id}/, Name::Variable
101
103
  rule /#{id}/ do |m|
102
104
  name = m[0]
103
105
  if self.class.builtins.include? name
@@ -24,10 +24,12 @@ module Rouge
24
24
  end
25
25
 
26
26
  state :brackets do
27
- rule /\^?/ do
27
+ rule /\^/ do
28
28
  token Punctuation
29
29
  goto :brackets_int
30
30
  end
31
+
32
+ rule(//) { goto :brackets_int }
31
33
  end
32
34
 
33
35
  state :brackets_int do
@@ -133,7 +135,7 @@ module Rouge
133
135
  rule /\d+/, addr_tok
134
136
  rule /[$,~+!]/, addr_tok
135
137
 
136
- rule %r((/)(\\.|.)*?(/)) do |m|
138
+ rule %r((/)((?:\\.|.)*?)(/)) do |m|
137
139
  token addr_tok, m[1]; delegate regex, m[2]; token addr_tok, m[3]
138
140
  end
139
141
 
@@ -29,6 +29,8 @@ module Rouge
29
29
  local logout popd printf pushd pwd read readonly set shift
30
30
  shopt source suspend test time times trap true type typeset
31
31
  ulimit umask unalias unset wait
32
+
33
+ ls tar cat grep sudo
32
34
  ).join('|')
33
35
 
34
36
  state :basic do
@@ -37,30 +39,47 @@ module Rouge
37
39
  rule /\b(#{KEYWORDS})\s*\b/, Keyword
38
40
  rule /\bcase\b/, Keyword, :case
39
41
 
40
- rule /\b(#{BUILTINS})\s*\b(?!\.)/, Name::Builtin
41
-
42
- rule /^\S*[\$%>#] +/, Generic::Prompt
42
+ rule /\b(#{BUILTINS})\s*\b(?!(\.|-))/, Name::Builtin
43
+ rule /[.](?=\s)/, Name::Builtin
43
44
 
44
45
  rule /(\b\w+)(=)/ do |m|
45
46
  groups Name::Variable, Operator
46
47
  end
47
48
 
48
- rule /[\[\]{}()=]/, Operator
49
+ rule /[\[\]{}()!=>]/, Operator
49
50
  rule /&&|\|\|/, Operator
50
51
 
51
- rule /<<</, Operator # here-string
52
- rule /<<-?\s*(\'?)\\?(\w+)\1/ do |m|
53
- lsh = Str::Heredoc
54
- token lsh
55
- heredocstr = Regexp.escape(m[2])
52
+ # here-string
53
+ rule /<<</, Operator
54
+
55
+ rule /(<<-?)(\s*)(\'?)(\\?)(\w+)(\3)/ do |m|
56
+ groups Operator, Text, Str::Heredoc, Str::Heredoc, Name::Constant, Str::Heredoc
57
+ @heredocstr = Regexp.escape(m[5])
58
+ push :heredoc
59
+ end
60
+ end
56
61
 
57
- push do
58
- rule /\s*#{heredocstr}\s*\n/, lsh, :pop!
59
- rule /.*?\n/, lsh
62
+ state :heredoc do
63
+ rule /\n/, Str::Heredoc, :heredoc_nl
64
+ rule /[^$\n]+/, Str::Heredoc
65
+ mixin :interp
66
+ rule /[$]/, Str::Heredoc
67
+ end
68
+
69
+ state :heredoc_nl do
70
+ rule /\s*(\w+)\s*\n/ do |m|
71
+ if m[1] == @heredocstr
72
+ token Name::Constant
73
+ pop! 2
74
+ else
75
+ token Str::Heredoc
60
76
  end
61
77
  end
78
+
79
+ rule(//) { pop! }
62
80
  end
63
81
 
82
+
64
83
  state :double_quotes do
65
84
  # NB: "abc$" is literally the string abc$.
66
85
  # Here we prevent :interp from interpreting $" as a variable.
@@ -95,8 +114,10 @@ module Rouge
95
114
 
96
115
  rule /\*/, Keyword
97
116
 
98
- rule /;/, Text
99
- rule /[^=\*\s{}()$"'`\\<]+/, Text
117
+ rule /;/, Punctuation
118
+
119
+ rule /--?[\w-]+/, Name::Tag
120
+ rule /[^=\*\s{}()$"'`;\\<]+/, Text
100
121
  rule /\d+(?= |\Z)/, Num
101
122
  rule /</, Text
102
123
  mixin :interp
@@ -117,8 +138,8 @@ module Rouge
117
138
 
118
139
  state :math do
119
140
  rule /\)\)/, Keyword, :pop!
120
- rule %r([-+*/%^|&]|\*\*|\|\|), Operator
121
- rule /\d+/, Num
141
+ rule %r([-+*/%^|&!]|\*\*|\|\|), Operator
142
+ rule /\d+(#\w+)?/, Num
122
143
  mixin :root
123
144
  end
124
145
 
@@ -147,6 +168,7 @@ module Rouge
147
168
  rule /\${#?/, Keyword, :curly
148
169
  rule /`/, Str::Backtick, :backticks
149
170
  rule /\$#?(\w+|.)/, Name::Variable
171
+ rule /\$[*@]/, Name::Variable
150
172
  end
151
173
 
152
174
  state :root do
@@ -0,0 +1,96 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Sieve < RegexLexer
6
+ title "Sieve"
7
+ desc "mail filtering language"
8
+
9
+ tag 'sieve'
10
+ filenames '*.sieve'
11
+
12
+ id = /:?[a-zA-Z_][a-zA-Z0-9_]*/
13
+
14
+ # control commands (rfc5228 § 3)
15
+ def self.controls
16
+ @controls ||= %w(if elsif else require stop)
17
+ end
18
+
19
+ def self.actions
20
+ @actions ||= Set.new(
21
+ # action commands (rfc5228 § 2.9)
22
+ %w(keep fileinto redirect discard) +
23
+ # Editheader Extension (rfc5293)
24
+ %w(addheader deleteheader) +
25
+ # Reject and Extended Reject Extensions (rfc5429)
26
+ %w(reject ereject) +
27
+ # Extension for Notifications (rfc5435)
28
+ %w(notify) +
29
+ # Imap4flags Extension (rfc5232)
30
+ %w(setflag addflag removeflag) +
31
+ # Vacation Extension (rfc5230)
32
+ %w(vacation) +
33
+ # MIME Part Tests, Iteration, Extraction, Replacement, and Enclosure (rfc5703)
34
+ %w(replace enclose extracttext)
35
+ )
36
+ end
37
+
38
+ def self.tests
39
+ @tests ||= Set.new(
40
+ # test commands (rfc5228 § 5)
41
+ %w(address allof anyof exists false header not size true) +
42
+ # Body Extension (rfc5173)
43
+ %w(body) +
44
+ # Imap4flags Extension (rfc5232)
45
+ %w(hasflag) +
46
+ # Spamtest and Virustest Extensions (rfc5235)
47
+ %w(spamtest virustest) +
48
+ # Date and Index Extensions (rfc5260)
49
+ %w(date currentdate) +
50
+ # Extension for Notifications (rfc5435)
51
+ %w(valid_notify_method notify_method_capability) +
52
+ # Extensions for Checking Mailbox Status and Accessing Mailbox
53
+ # Metadata (rfc5490)
54
+ %w(mailboxexists metadata metadataexists servermetadata servermetadataexists)
55
+ )
56
+ end
57
+
58
+ state :comments_and_whitespace do
59
+ rule /\s+/, Text
60
+ rule %r(#.*?\n), Comment::Single
61
+ rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
62
+ end
63
+
64
+ state :string do
65
+ rule /\\./, Str::Escape
66
+ rule /"/, Str::Double, :pop!
67
+ # Variables Extension (rfc5229)
68
+ rule /\${(?:[0-9][.0-9]*|[a-zA-Z_][.a-zA-Z0-9_]*)}/, Str::Interpol
69
+ rule /./, Str::Double
70
+ end
71
+
72
+ state :root do
73
+ mixin :comments_and_whitespace
74
+
75
+ rule /[\[\](),;{}]/, Punctuation
76
+
77
+ rule id do |m|
78
+ if self.class.controls.include? m[0]
79
+ token Keyword
80
+ elsif self.class.tests.include? m[0]
81
+ token Name::Variable
82
+ elsif self.class.actions.include? m[0]
83
+ token Name::Function
84
+ elsif m[0] =~ /^:/ # tags like :contains, :matches etc.
85
+ token Operator
86
+ else
87
+ token Name::Other
88
+ end
89
+ end
90
+
91
+ rule /"/, Str::Double, :string
92
+ rule /[0-9]+[KMG]/, Num::Integer
93
+ end
94
+ end
95
+ end
96
+ end
@@ -41,7 +41,8 @@ module Rouge
41
41
  rule /[(\[{]/, Punctuation, :main
42
42
  rule /[)\]}]/, Punctuation, :pop!
43
43
 
44
- rule /\b(let|if|local)\b(?!')/, Keyword::Reserved do
44
+ rule /\b(let|if|local)\b(?!')/ do
45
+ token Keyword::Reserved
45
46
  push; push
46
47
  end
47
48
 
@@ -190,7 +191,7 @@ module Rouge
190
191
  end
191
192
 
192
193
  state :breakout do
193
- rule /(?=\w+\b(#{SML.keywords.to_a.join('|')})\b(?!'))/ do
194
+ rule /(?=\b(#{SML.keywords.to_a.join('|')})\b(?!'))/ do
194
195
  pop!
195
196
  end
196
197
  end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ load_lexer 'jsx.rb'
6
+ load_lexer 'typescript/common.rb'
7
+
8
+ class TSX < JSX
9
+ include TypescriptCommon
10
+
11
+ title 'TypeScript'
12
+ desc 'tsx'
13
+
14
+ tag 'tsx'
15
+ filenames '*.tsx'
16
+ end
17
+ end
18
+ end
19
+
File without changes
@@ -3,8 +3,11 @@
3
3
  module Rouge
4
4
  module Lexers
5
5
  load_lexer 'javascript.rb'
6
+ load_lexer 'typescript/common.rb'
6
7
 
7
8
  class Typescript < Javascript
9
+ include TypescriptCommon
10
+
8
11
  title "TypeScript"
9
12
  desc "TypeScript, a superset of JavaScript"
10
13
 
@@ -14,33 +17,6 @@ module Rouge
14
17
  filenames '*.ts', '*.d.ts'
15
18
 
16
19
  mimetypes 'text/typescript'
17
-
18
- def self.keywords
19
- @keywords ||= super + Set.new(%w(
20
- import export from as is
21
- namespace new static private protected public
22
- super async await extends implements readonly
23
- ))
24
- end
25
-
26
- def self.declarations
27
- @declarations ||= super + Set.new(%w(
28
- const type constructor abstract
29
- ))
30
- end
31
-
32
- def self.reserved
33
- @reserved ||= super + Set.new(%w(
34
- string any number namespace module
35
- declare default interface
36
- ))
37
- end
38
-
39
- def self.builtins
40
- @builtins ||= super + %w(
41
- Promise Set Map WeakSet WeakMap Symbol
42
- )
43
- end
44
20
  end
45
21
  end
46
22
  end