rouge 3.5.1 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge.rb +1 -0
  3. data/lib/rouge/cli.rb +19 -11
  4. data/lib/rouge/demos/openedge +4 -0
  5. data/lib/rouge/demos/powershell +12 -48
  6. data/lib/rouge/demos/xojo +2 -1
  7. data/lib/rouge/demos/xpath +2 -0
  8. data/lib/rouge/demos/xquery +22 -0
  9. data/lib/rouge/formatters/html.rb +18 -2
  10. data/lib/rouge/formatters/html_line_table.rb +51 -0
  11. data/lib/rouge/guessers/modeline.rb +1 -1
  12. data/lib/rouge/lexers/apache.rb +1 -1
  13. data/lib/rouge/lexers/bpf.rb +12 -12
  14. data/lib/rouge/lexers/ceylon.rb +5 -5
  15. data/lib/rouge/lexers/docker.rb +2 -2
  16. data/lib/rouge/lexers/elixir.rb +5 -2
  17. data/lib/rouge/lexers/elm.rb +1 -1
  18. data/lib/rouge/lexers/fsharp.rb +4 -4
  19. data/lib/rouge/lexers/glsl.rb +1 -1
  20. data/lib/rouge/lexers/http.rb +1 -1
  21. data/lib/rouge/lexers/idlang.rb +1 -1
  22. data/lib/rouge/lexers/json.rb +1 -1
  23. data/lib/rouge/lexers/jsp.rb +3 -3
  24. data/lib/rouge/lexers/liquid.rb +23 -0
  25. data/lib/rouge/lexers/magik.rb +2 -1
  26. data/lib/rouge/lexers/make.rb +5 -4
  27. data/lib/rouge/lexers/mosel.rb +43 -43
  28. data/lib/rouge/lexers/nim.rb +2 -1
  29. data/lib/rouge/lexers/nix.rb +1 -1
  30. data/lib/rouge/lexers/openedge.rb +429 -0
  31. data/lib/rouge/lexers/perl.rb +12 -14
  32. data/lib/rouge/lexers/powershell.rb +181 -635
  33. data/lib/rouge/lexers/ruby.rb +2 -2
  34. data/lib/rouge/lexers/scala.rb +1 -1
  35. data/lib/rouge/lexers/shell.rb +1 -1
  36. data/lib/rouge/lexers/swift.rb +4 -4
  37. data/lib/rouge/lexers/tex.rb +1 -1
  38. data/lib/rouge/lexers/toml.rb +1 -1
  39. data/lib/rouge/lexers/vala.rb +1 -1
  40. data/lib/rouge/lexers/vhdl.rb +1 -1
  41. data/lib/rouge/lexers/wollok.rb +1 -1
  42. data/lib/rouge/lexers/xml.rb +1 -1
  43. data/lib/rouge/lexers/xojo.rb +4 -4
  44. data/lib/rouge/lexers/xpath.rb +332 -0
  45. data/lib/rouge/lexers/xquery.rb +145 -0
  46. data/lib/rouge/lexers/yaml.rb +5 -3
  47. data/lib/rouge/regex_lexer.rb +14 -13
  48. data/lib/rouge/tex_theme_renderer.rb +2 -2
  49. data/lib/rouge/themes/monokai_sublime.rb +2 -1
  50. data/lib/rouge/themes/pastie.rb +1 -1
  51. data/lib/rouge/util.rb +2 -2
  52. data/lib/rouge/version.rb +1 -1
  53. metadata +10 -3
@@ -0,0 +1,145 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'xpath.rb'
7
+ class XQuery < XPath
8
+ title 'XQuery'
9
+ desc 'XQuery 3.1: An XML Query Language'
10
+ tag 'xquery'
11
+ filenames '*.xquery', '*.xq'
12
+ mimetypes 'application/xquery'
13
+
14
+ def self.keywords
15
+ @keywords ||= Regexp.union super, Regexp.union(%w(
16
+ xquery encoding version declare module
17
+ namespace copy-namespaces boundary-space construction
18
+ default collation base-uri preserve strip
19
+ ordering ordered unordered order empty greatest least
20
+ preserve no-preserve inherit no-inherit
21
+ decimal-format decimal-separator grouping-separator
22
+ infinity minus-sign NaN percent per-mille
23
+ zero-digit digit pattern-separator exponent-separator
24
+ import schema at element option
25
+ function external context item
26
+ typeswitch switch case
27
+ try catch
28
+ validate lax strict type
29
+ document element attribute text comment processing-instruction
30
+ for let where order group by return
31
+ allowing tumbling stable sliding window
32
+ start end only when previous next count collation
33
+ ascending descending
34
+ ))
35
+ end
36
+
37
+ # Mixin states:
38
+
39
+ state :tags do
40
+ rule %r/<#{XPath.qName}/, Name::Tag, :start_tag
41
+ rule %r/<!--/, Comment, :xml_comment
42
+ rule %r/<\?.*?\?>/, Comment::Preproc
43
+ rule %r/<!\[CDATA\[.*?\]\]>/, Comment::Preproc
44
+ rule %r/&\S*?;/, Name::Entity
45
+ end
46
+
47
+ # Lexical states:
48
+
49
+ prepend :root do
50
+ mixin :tags
51
+
52
+ rule %r/\{/, Punctuation
53
+ rule %r/\}`?/ do
54
+ token Punctuation
55
+ if stack.length > 1
56
+ pop!
57
+ end
58
+ end
59
+
60
+ rule %r/(namespace)(\s+)(#{XPath.ncName})/ do
61
+ groups Keyword, Text::Whitespace, Name::Namespace
62
+ end
63
+
64
+ rule %r/(#{XQuery.keywords})\b/, Keyword
65
+ rule %r/;/, Punctuation
66
+ rule %r/%/, Keyword::Declaration, :annotation
67
+
68
+ rule %r/(\(#)(\s*)(#{XPath.eqName})/ do
69
+ groups Comment::Preproc, Text::Whitespace, Name::Tag
70
+ push :pragma
71
+ end
72
+
73
+ rule %r/``\[/, Str, :str_constructor
74
+ end
75
+
76
+ state :annotation do
77
+ mixin :commentsAndWhitespace
78
+ rule XPath.eqName, Keyword::Declaration, :pop!
79
+ end
80
+
81
+ state :pragma do
82
+ mixin :commentsAndWhitespace
83
+ rule %r/#\)/, Comment::Preproc, :pop!
84
+ rule %r/./, Comment::Preproc
85
+ end
86
+
87
+ # https://www.w3.org/TR/xquery-31/#id-string-constructors
88
+ state :str_constructor do
89
+ rule %r/`\{/, Punctuation, :root
90
+ rule %r/\]``/, Str, :pop!
91
+ rule %r/[^`\]]+/m, Str
92
+ rule %r/[`\]]/, Str
93
+ end
94
+
95
+ state :xml_comment do
96
+ rule %r/[^-]+/m, Comment
97
+ rule %r/-->/, Comment, :pop!
98
+ rule %r/-/, Comment
99
+ end
100
+
101
+ state :start_tag do
102
+ rule %r/\s+/m, Text::Whitespace
103
+ rule %r/([\w.:-]+\s*=)(")/m do
104
+ groups Name::Attribute, Str
105
+ push :quot_attr
106
+ end
107
+ rule %r/([\w.:-]+\s*=)(')/m do
108
+ groups Name::Attribute, Str
109
+ push :apos_attr
110
+ end
111
+ rule %r/>/, Name::Tag, :tag_content
112
+ rule %r(/>), Name::Tag, :pop!
113
+ end
114
+
115
+ state :quot_attr do
116
+ rule %r/"/, Str, :pop!
117
+ rule %r/\{\{/, Str
118
+ rule %r/\{/, Punctuation, :root
119
+ rule %r/[^"{>]+/m, Str
120
+ end
121
+
122
+ state :apos_attr do
123
+ rule %r/'/, Str, :pop!
124
+ rule %r/\{\{/, Str
125
+ rule %r/\{/, Punctuation, :root
126
+ rule %r/[^'{>]+/m, Str
127
+ end
128
+
129
+ state :tag_content do
130
+ rule %r/\s+/m, Text::Whitespace
131
+ mixin :tags
132
+
133
+ rule %r/(\{\{|\}\})/, Text
134
+ rule %r/\{/, Punctuation, :root
135
+
136
+ rule %r/[^{}<&]/, Text
137
+
138
+ rule %r(</#{XPath.qName}(\s*)>) do
139
+ token Name::Tag
140
+ pop! 2 # pop self and tag_start
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -179,7 +179,7 @@ module Rouge
179
179
  end
180
180
 
181
181
  # literal and folded scalars
182
- rule %r/[\|>]/ do
182
+ rule %r/[\|>][+-]?/ do
183
183
  token Punctuation::Indicator
184
184
  push :block_scalar_content
185
185
  push :block_scalar_header
@@ -246,7 +246,7 @@ module Rouge
246
246
  end
247
247
  end
248
248
 
249
- rule %r/[^\n\r\f\v]+/, Name::Constant
249
+ rule %r/[^\n\r\f\v]+/, Str
250
250
  end
251
251
 
252
252
  state :block_scalar_header do
@@ -328,7 +328,7 @@ module Rouge
328
328
  state :plain_scalar_in_block_context do
329
329
  # the : indicator ends a scalar
330
330
  rule %r/[ ]*(?=:[ \n]|:$)/, Text, :pop!
331
- rule %r/[ ]*:/, Str
331
+ rule %r/[ ]*:\S+/, Str
332
332
  rule %r/[ ]+(?=#)/, Text, :pop!
333
333
  rule %r/[ ]+$/, Text
334
334
  # check for new documents or dedents at the new line
@@ -339,6 +339,8 @@ module Rouge
339
339
 
340
340
  rule %r/[ ]+/, Str
341
341
  rule SPECIAL_VALUES, Name::Constant
342
+ rule %r/\d+(?:\.\d+)?(?=(\r?\n)| +#)/, Literal::Number, :pop!
343
+
342
344
  # regular non-whitespace characters
343
345
  rule %r/[^\s:]+/, Str
344
346
  end
@@ -102,21 +102,21 @@ module Rouge
102
102
  callback ||= case next_state
103
103
  when :pop!
104
104
  proc do |stream|
105
- puts " yielding #{tok.qualname}, #{stream[0].inspect}" if @debug
105
+ puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug
106
106
  @output_stream.call(tok, stream[0])
107
107
  puts " popping stack: 1" if @debug
108
108
  @stack.pop or raise 'empty stack!'
109
109
  end
110
110
  when :push
111
111
  proc do |stream|
112
- puts " yielding #{tok.qualname}, #{stream[0].inspect}" if @debug
112
+ puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug
113
113
  @output_stream.call(tok, stream[0])
114
114
  puts " pushing :#{@stack.last.name}" if @debug
115
115
  @stack.push(@stack.last)
116
116
  end
117
117
  when Symbol
118
118
  proc do |stream|
119
- puts " yielding #{tok.qualname}, #{stream[0].inspect}" if @debug
119
+ puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug
120
120
  @output_stream.call(tok, stream[0])
121
121
  state = @states[next_state] || self.class.get_state(next_state)
122
122
  puts " pushing :#{state.name}" if @debug
@@ -124,7 +124,7 @@ module Rouge
124
124
  end
125
125
  when nil
126
126
  proc do |stream|
127
- puts " yielding #{tok.qualname}, #{stream[0].inspect}" if @debug
127
+ puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug
128
128
  @output_stream.call(tok, stream[0])
129
129
  end
130
130
  else
@@ -263,6 +263,7 @@ module Rouge
263
263
 
264
264
  until stream.eos?
265
265
  if @debug
266
+ puts
266
267
  puts "lexer: #{self.class.tag}"
267
268
  puts "stack: #{stack.map(&:name).map(&:to_sym).inspect}"
268
269
  puts "stream: #{stream.peek(20).inspect}"
@@ -289,11 +290,11 @@ module Rouge
289
290
  def step(state, stream)
290
291
  state.rules.each do |rule|
291
292
  if rule.is_a?(State)
292
- puts " entering mixin #{rule.name}" if @debug
293
+ puts " entering: mixin :#{rule.name}" if @debug
293
294
  return true if step(rule, stream)
294
- puts " exiting mixin #{rule.name}" if @debug
295
+ puts " exiting: mixin :#{rule.name}" if @debug
295
296
  else
296
- puts " trying #{rule.inspect}" if @debug
297
+ puts " trying: #{rule.inspect}" if @debug
297
298
 
298
299
  # XXX HACK XXX
299
300
  # StringScanner's implementation of ^ is b0rken.
@@ -303,14 +304,14 @@ module Rouge
303
304
  next if rule.beginning_of_line && !stream.beginning_of_line?
304
305
 
305
306
  if (size = stream.skip(rule.re))
306
- puts " got #{stream[0].inspect}" if @debug
307
+ puts " got: #{stream[0].inspect}" if @debug
307
308
 
308
309
  instance_exec(stream, &rule.callback)
309
310
 
310
311
  if size.zero?
311
312
  @null_steps += 1
312
313
  if @null_steps > MAX_NULL_SCANS
313
- puts " too many scans without consuming the string!" if @debug
314
+ puts " warning: too many scans without consuming the string!" if @debug
314
315
  return false
315
316
  end
316
317
  else
@@ -362,7 +363,7 @@ module Rouge
362
363
  # @param [String] text
363
364
  # The text to delegate. This defaults to the last matched string.
364
365
  def delegate(lexer, text=nil)
365
- puts " delegating to #{lexer.inspect}" if @debug
366
+ puts " delegating to: #{lexer.inspect}" if @debug
366
367
  text ||= @current_stream[0]
367
368
 
368
369
  lexer.continue_lex(text) do |tok, val|
@@ -388,7 +389,7 @@ module Rouge
388
389
  self.state
389
390
  end
390
391
 
391
- puts " pushing :#{push_state.name}" if @debug
392
+ puts " pushing: :#{push_state.name}" if @debug
392
393
  stack.push(push_state)
393
394
  end
394
395
 
@@ -408,7 +409,7 @@ module Rouge
408
409
  def goto(state_name)
409
410
  raise 'empty stack!' if stack.empty?
410
411
 
411
- puts " going to state :#{state_name} " if @debug
412
+ puts " going to: state :#{state_name} " if @debug
412
413
  stack[-1] = get_state(state_name)
413
414
  end
414
415
 
@@ -435,7 +436,7 @@ module Rouge
435
436
  private
436
437
  def yield_token(tok, val)
437
438
  return if val.nil? || val.empty?
438
- puts " yielding #{tok.qualname}, #{val.inspect}" if @debug
439
+ puts " yielding: #{tok.qualname}, #{val.inspect}" if @debug
439
440
  @output_stream.yield(tok, val)
440
441
  end
441
442
  end
@@ -35,8 +35,8 @@ module Rouge
35
35
  END
36
36
 
37
37
  base = @theme.class.base_style
38
- yield "\\definecolor{#{@prefix}@fgcolor}{HTML}{#{inline_name(base.fg)}}"
39
- yield "\\definecolor{#{@prefix}@bgcolor}{HTML}{#{inline_name(base.bg)}}"
38
+ yield "\\definecolor{#{@prefix}@fgcolor}{HTML}{#{inline_name(base.fg || '#000000')}}"
39
+ yield "\\definecolor{#{@prefix}@bgcolor}{HTML}{#{inline_name(base.bg || '#FFFFFF')}}"
40
40
 
41
41
  render_palette(@theme.palette, &b)
42
42
 
@@ -11,6 +11,7 @@ module Rouge
11
11
  palette :bright_pink => '#f92672'
12
12
  palette :carmine => '#960050'
13
13
  palette :dark => '#49483e'
14
+ palette :dark_graphite => '#272822'
14
15
  palette :dark_grey => '#888888'
15
16
  palette :dark_red => '#aa0000'
16
17
  palette :dimgrey => '#75715e'
@@ -80,7 +81,7 @@ module Rouge
80
81
  Name::Variable,
81
82
  Text::Whitespace,
82
83
  Text,
83
- Name, :fg => :white
84
+ Name, :fg => :white, :bg => :dark_graphite
84
85
  style Operator::Word,
85
86
  Name::Tag,
86
87
  Keyword,
@@ -6,7 +6,7 @@ module Rouge
6
6
  # A port of the pastie style from Pygments.
7
7
  # See https://bitbucket.org/birkenfeld/pygments-main/src/default/pygments/styles/pastie.py
8
8
  class Pastie < CSSTheme
9
- name 'pastie'
9
+ name 'pastie'
10
10
 
11
11
  style Comment, :fg => '#888888'
12
12
  style Comment::Preproc, :fg => '#cc0000', :bold => true
@@ -75,13 +75,13 @@ module Rouge
75
75
  def starts_block(block_state)
76
76
  @block_state = block_state
77
77
  @block_indentation = @last_indentation || ''
78
- puts " starts_block #{block_state.inspect}" if @debug
78
+ puts " starts_block: #{block_state.inspect}" if @debug
79
79
  puts " block_indentation: #{@block_indentation.inspect}" if @debug
80
80
  end
81
81
 
82
82
  # handle a single indented line
83
83
  def indentation(indent_str)
84
- puts " indentation #{indent_str.inspect}" if @debug
84
+ puts " indentation: #{indent_str.inspect}" if @debug
85
85
  puts " block_indentation: #{@block_indentation.inspect}" if @debug
86
86
  @last_indentation = indent_str
87
87
 
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Rouge
5
5
  def self.version
6
- "3.5.1"
6
+ "3.6.0"
7
7
  end
8
8
  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: 3.5.1
4
+ version: 3.6.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: 2019-06-25 00:00:00.000000000 Z
11
+ date: 2019-07-09 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:
@@ -113,6 +113,7 @@ files:
113
113
  - lib/rouge/demos/nix
114
114
  - lib/rouge/demos/objective_c
115
115
  - lib/rouge/demos/ocaml
116
+ - lib/rouge/demos/openedge
116
117
  - lib/rouge/demos/pascal
117
118
  - lib/rouge/demos/perl
118
119
  - lib/rouge/demos/php
@@ -167,11 +168,14 @@ files:
167
168
  - lib/rouge/demos/wollok
168
169
  - lib/rouge/demos/xml
169
170
  - lib/rouge/demos/xojo
171
+ - lib/rouge/demos/xpath
172
+ - lib/rouge/demos/xquery
170
173
  - lib/rouge/demos/yaml
171
174
  - lib/rouge/formatter.rb
172
175
  - lib/rouge/formatters/html.rb
173
176
  - lib/rouge/formatters/html_inline.rb
174
177
  - lib/rouge/formatters/html_legacy.rb
178
+ - lib/rouge/formatters/html_line_table.rb
175
179
  - lib/rouge/formatters/html_linewise.rb
176
180
  - lib/rouge/formatters/html_pygments.rb
177
181
  - lib/rouge/formatters/html_table.rb
@@ -282,6 +286,7 @@ files:
282
286
  - lib/rouge/lexers/nix.rb
283
287
  - lib/rouge/lexers/objective_c.rb
284
288
  - lib/rouge/lexers/ocaml.rb
289
+ - lib/rouge/lexers/openedge.rb
285
290
  - lib/rouge/lexers/pascal.rb
286
291
  - lib/rouge/lexers/perl.rb
287
292
  - lib/rouge/lexers/php.rb
@@ -341,6 +346,8 @@ files:
341
346
  - lib/rouge/lexers/wollok.rb
342
347
  - lib/rouge/lexers/xml.rb
343
348
  - lib/rouge/lexers/xojo.rb
349
+ - lib/rouge/lexers/xpath.rb
350
+ - lib/rouge/lexers/xquery.rb
344
351
  - lib/rouge/lexers/yaml.rb
345
352
  - lib/rouge/plugins/redcarpet.rb
346
353
  - lib/rouge/regex_lexer.rb
@@ -387,7 +394,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
387
394
  - !ruby/object:Gem::Version
388
395
  version: '0'
389
396
  requirements: []
390
- rubygems_version: 3.0.3
397
+ rubygems_version: 3.0.4
391
398
  signing_key:
392
399
  specification_version: 4
393
400
  summary: A pure-ruby colorizer based on pygments