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
@@ -42,7 +42,7 @@ module Rouge
42
42
 
43
43
  state :comments_and_whitespace do
44
44
  rule /\s+/m, Text
45
- rule /###.*?###/m, Comment::Multiline
45
+ rule /###\s*\n.*?###/m, Comment::Multiline
46
46
  rule /#.*$/, Comment::Single
47
47
  end
48
48
 
@@ -0,0 +1,136 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class ConsoleLexer < Lexer
6
+ tag 'console'
7
+ aliases 'terminal', 'shell_session', 'shell-session'
8
+ filenames '*.cap'
9
+ desc 'A generic lexer for shell sessions. Accepts ?lang and ?output lexer options, a ?prompt option, and ?comments to enable # comments.'
10
+
11
+ option :lang, 'the shell language to lex (default: shell)'
12
+ option :output, 'the output language (default: plaintext?token=Generic.Output)'
13
+ option :prompt, 'comma-separated list of strings that indicate the end of a prompt. (default: $,#,>,;)'
14
+ option :comments, 'enable hash-comments at the start of a line - otherwise interpreted as a prompt. (default: false, implied by ?prompt not containing `#`)'
15
+
16
+ def initialize(*)
17
+ super
18
+ @prompt = list_option(:prompt) { nil }
19
+ @lang = lexer_option(:lang) { 'shell' }
20
+ @output = lexer_option(:output) { PlainText.new(token: Generic::Output) }
21
+ @comments = bool_option(:comments) { :guess }
22
+ end
23
+
24
+ def prompt_regex
25
+ @prompt_regex ||= begin
26
+ /^#{prompt_prefix_regex}(?:#{end_chars.map(&Regexp.method(:escape)).join('|')})/
27
+ end
28
+ end
29
+
30
+ def end_chars
31
+ @end_chars ||= if @prompt.any?
32
+ @prompt.reject { |c| c.empty? }
33
+ else
34
+ %w($ # > ;)
35
+ end
36
+ end
37
+
38
+ # whether to allow comments. if manually specifying a prompt that isn't
39
+ # simply "#", we flag this to on
40
+ def allow_comments?
41
+ case @comments
42
+ when :guess
43
+ @prompt && !@prompt.empty? && !end_chars.include?('#')
44
+ else
45
+ @comments
46
+ end
47
+ end
48
+
49
+ def prompt_prefix_regex
50
+ if allow_comments?
51
+ /^[^<#]*?/
52
+ else
53
+ /^.*?/
54
+ end
55
+ end
56
+
57
+ def lang_lexer
58
+ @lang_lexer ||= case @lang
59
+ when Lexer
60
+ @lang
61
+ when nil
62
+ Shell.new(options)
63
+ when Class
64
+ @lang.new(options)
65
+ when String
66
+ Lexer.find(@lang).new(options)
67
+ end
68
+ end
69
+
70
+ def output_lexer
71
+ @output_lexer ||= case @output
72
+ when nil
73
+ PlainText.new(token: Generic::Output)
74
+ when Lexer
75
+ @output
76
+ when Class
77
+ @output.new(options)
78
+ when String
79
+ Lexer.find(@output).new(options)
80
+ end
81
+ end
82
+
83
+ def line_regex
84
+ /(\\.|[^\\])*?(\n|$)/m
85
+ end
86
+
87
+ def comment_regex
88
+ /\A\s*?#/
89
+ end
90
+
91
+ def stream_tokens(input, &output)
92
+ input = StringScanner.new(input)
93
+ lang_lexer.reset!
94
+ output_lexer.reset!
95
+
96
+ process_line(input, &output) while !input.eos?
97
+ end
98
+
99
+ def process_line(input, &output)
100
+ input.scan(line_regex)
101
+
102
+ if input[0] =~ /\A\s*(?:<[.]+>|[.]+)\s*\z/
103
+ puts "console: matched snip #{input[0].inspect}" if @debug
104
+ output_lexer.reset!
105
+ lang_lexer.reset!
106
+
107
+ yield Comment, input[0]
108
+ elsif prompt_regex =~ input[0]
109
+ puts "console: matched prompt #{input[0].inspect}" if @debug
110
+ output_lexer.reset!
111
+
112
+ yield Generic::Prompt, $&
113
+
114
+ # make sure to take care of initial whitespace
115
+ # before we pass to the lang lexer so it can determine where
116
+ # the "real" beginning of the line is
117
+ $' =~ /\A\s*/
118
+ yield Text, $& unless $&.empty?
119
+
120
+ lang_lexer.lex($', continue: true, &output)
121
+ elsif comment_regex =~ input[0].strip
122
+ puts "console: matched comment #{input[0].inspect}" if @debug
123
+ output_lexer.reset!
124
+ lang_lexer.reset!
125
+
126
+ yield Comment, input[0]
127
+ else
128
+ puts "console: matched output #{input[0].inspect}" if @debug
129
+ lang_lexer.reset!
130
+
131
+ output_lexer.lex(input[0], continue: true, &output)
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -26,7 +26,7 @@ module Rouge
26
26
  static switch this throw true try typeof unchecked unsafe
27
27
  virtual void volatile while
28
28
  add alias async await get global partial remove set value where
29
- yield
29
+ yield nameof
30
30
  ascending by descending equals from group in into join let on
31
31
  orderby select
32
32
  )
@@ -47,19 +47,38 @@ module Rouge
47
47
  rule %r(/[*].*?[*]/)m, Comment::Multiline
48
48
  end
49
49
 
50
+ state :nest do
51
+ rule /{/, Punctuation, :nest
52
+ rule /}/, Punctuation, :pop!
53
+ mixin :root
54
+ end
55
+
56
+ state :splice_string do
57
+ rule /\\./, Str
58
+ rule /{/, Punctuation, :nest
59
+ rule /"|\n/, Str, :pop!
60
+ rule /./, Str
61
+ end
62
+
63
+ state :splice_literal do
64
+ rule /""/, Str
65
+ rule /{/, Punctuation, :nest
66
+ rule /"/, Str, :pop!
67
+ rule /./, Str
68
+ end
69
+
50
70
  state :root do
51
71
  mixin :whitespace
52
72
 
53
73
  rule /^\s*\[.*?\]/, Name::Attribute
54
- # rule /[$]\s*"/, Str, :splice_string
55
- # rule /[$]\s*<#/, Str, :splice_recstring
56
- # rule /<#/, Str, :recstring
74
+ rule /[$]\s*"/, Str, :splice_string
75
+ rule /[$]@\s*"/, Str, :splice_literal
57
76
 
58
77
  rule /(<\[)\s*(#{id}:)?/, Keyword
59
78
  rule /\]>/, Keyword
60
79
 
61
80
  rule /[~!%^&*()+=|\[\]{}:;,.<>\/?-]/, Punctuation
62
- rule /@"(\\.|.)*?"/, Str
81
+ rule /@"(""|[^"])*"/m, Str
63
82
  rule /"(\\.|.)*?["\n]/, Str
64
83
  rule /'(\\.|.)'/, Str::Char
65
84
  rule /0x[0-9a-f]+[lu]?/i, Num
@@ -69,12 +88,12 @@ module Rouge
69
88
  (e[+-][0-9]+)? # exponent
70
89
  [fldu]? # type
71
90
  )ix, Num
91
+ rule /\b(?:class|struct|interface)\b/, Keyword, :class
92
+ rule /\b(?:namespace|using)\b/, Keyword, :namespace
72
93
  rule /^#[ \t]*(#{cpp_keywords.join('|')})\b.*?\n/,
73
94
  Comment::Preproc
74
95
  rule /\b(#{keywords.join('|')})\b/, Keyword
75
96
  rule /\b(#{keywords_type.join('|')})\b/, Keyword::Type
76
- rule /class|struct/, Keyword, :class
77
- rule /namespace|using/, Keyword, :namespace
78
97
  rule /#{id}(?=\s*[(])/, Name::Function
79
98
  rule id, Name
80
99
  end
@@ -0,0 +1,72 @@
1
+ require 'set'
2
+ module Rouge
3
+ module Lexers
4
+ load_lexer 'yaml.rb'
5
+
6
+ class Digdag < YAML
7
+ title 'digdag'
8
+ desc 'A simple, open source, multi-cloud workflow engine (https://www.digdag.io/)'
9
+ tag 'digdag'
10
+ filenames '*.dig'
11
+
12
+ mimetypes 'application/x-digdag'
13
+
14
+ def self.analyze_text(text)
15
+ # disable YAML.analyze_text
16
+ end
17
+
18
+ # http://docs.digdag.io/operators.html
19
+ # as of digdag v0.9.10
20
+ KEYWORD_PATTERN = Regexp.union(%w(
21
+ call
22
+ require
23
+ loop
24
+ for_each
25
+ if
26
+ fail
27
+ echo
28
+
29
+ td
30
+ td_run
31
+ td_ddl
32
+ td_load
33
+ td_for_each
34
+ td_wait
35
+ td_wait_table
36
+ td_partial_delete
37
+ td_table_export
38
+
39
+ pg
40
+
41
+ mail
42
+ http
43
+ s3_wait
44
+ redshift
45
+ redshift_load
46
+ redshift_unload
47
+ emr
48
+
49
+ gcs_wait
50
+ bq
51
+ bq_ddl
52
+ bq_extract
53
+ bq_load
54
+
55
+ sh
56
+ py
57
+ rb
58
+ embulk
59
+ ).map { |name| "#{name}>"} + %w(
60
+ _do
61
+ _parallel
62
+ ))
63
+
64
+ prepend :block_nodes do
65
+ rule /(#{KEYWORD_PATTERN})(:)(?=\s|$)/ do |m|
66
+ groups Keyword::Reserved, Punctuation::Indicator
67
+ set_indent m[0], :implicit => true
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -11,7 +11,7 @@ module Rouge
11
11
  mimetypes 'text/x-dockerfile-config'
12
12
 
13
13
  KEYWORDS = %w(
14
- FROM MAINTAINER CMD EXPOSE ENV ADD ENTRYPOINT VOLUME WORKDIR
14
+ FROM MAINTAINER CMD LABEL EXPOSE ENV ADD COPY ENTRYPOINT VOLUME USER WORKDIR ARG STOPSIGNAL HEALTHCHECK SHELL
15
15
  ).join('|')
16
16
 
17
17
  start { @shell = Shell.new(@options) }
@@ -0,0 +1,68 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Dot < RegexLexer
6
+ title "DOT"
7
+ desc "graph description language"
8
+
9
+ tag 'dot'
10
+ filenames '*.dot'
11
+ mimetypes 'text/vnd.graphviz'
12
+
13
+ start do
14
+ @html = HTML.new(options)
15
+ end
16
+
17
+ state :comments_and_whitespace do
18
+ rule /\s+/, Text
19
+ rule %r(#.*?\n), Comment::Single
20
+ rule %r(//.*?\n), Comment::Single
21
+ rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
22
+ end
23
+
24
+ state :html do
25
+ rule /[^<>]+/ do
26
+ delegate @html
27
+ end
28
+ rule /<.+?>/m do
29
+ delegate @html
30
+ end
31
+ rule />/, Punctuation, :pop!
32
+ end
33
+
34
+ state :ID do
35
+ rule /([a-zA-Z][a-zA-Z_0-9]*)(\s*)(=)/ do |m|
36
+ token Name, m[1]
37
+ token Text, m[2]
38
+ token Punctuation, m[3]
39
+ end
40
+ rule /[a-zA-Z][a-zA-Z_0-9]*/, Name::Variable
41
+ rule /([0-9]+)?\.[0-9]+/, Num::Float
42
+ rule /[0-9]+/, Num::Integer
43
+ rule /"(\\"|[^"])*"/, Str::Double
44
+ rule /</ do
45
+ token Punctuation
46
+ @html.reset!
47
+ push :html
48
+ end
49
+ end
50
+
51
+ state :a_list do
52
+ mixin :comments_and_whitespace
53
+ mixin :ID
54
+ rule /[=;,]/, Punctuation
55
+ rule /\]/, Operator, :pop!
56
+ end
57
+
58
+ state :root do
59
+ mixin :comments_and_whitespace
60
+ rule /\b(strict|graph|digraph|subgraph|node|edge)\b/i, Keyword
61
+ rule /[{};:=]/, Punctuation
62
+ rule /-[->]/, Operator
63
+ rule /\[/, Operator, :a_list
64
+ mixin :ID
65
+ end
66
+ end
67
+ end
68
+ end
@@ -15,13 +15,6 @@ module Rouge
15
15
 
16
16
  mimetypes 'text/x-elixir', 'application/x-elixir'
17
17
 
18
- BRACES = [
19
- ['\{', '\}', 'cb'],
20
- ['\[', '\]', 'sb'],
21
- ['\(', '\)', 'pa'],
22
- ['\<', '\>', 'lt']
23
- ]
24
-
25
18
  state :root do
26
19
  rule /\s+/m, Text
27
20
  rule /#.*$/, Comment::Single
@@ -46,9 +39,9 @@ module Rouge
46
39
  rule /@[a-zA-Z_]\w*|&\d/, Name::Variable
47
40
  rule %r{\b(0[xX][0-9A-Fa-f]+|\d(_?\d)*(\.(?![^\d\s])
48
41
  (_?\d)*)?([eE][-+]?\d(_?\d)*)?|0[bB][01]+)\b}x, Num
49
- rule %r{~r\/.*\/}, Str::Regex
50
42
 
51
43
  mixin :strings
44
+ mixin :sigil_strings
52
45
  end
53
46
 
54
47
  state :strings do
@@ -58,25 +51,6 @@ module Rouge
58
51
  rule /'.*?'/, Str::Single
59
52
  rule %r{(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b[^x0MC])|(\\[MC]-)+\w|[^\s\\])}, Str::Other
60
53
 
61
- BRACES.each do |_, _, name|
62
- mixin :"braces_#{name}"
63
- end
64
- end
65
-
66
- BRACES.each do |lbrace, rbrace, name|
67
- state :"braces_#{name}" do
68
- rule /%[a-z]#{lbrace}/, Str::Double, :"braces_#{name}_intp"
69
- rule /%[A-Z]#{lbrace}/, Str::Double, :"braces_#{name}_no_intp"
70
- end
71
-
72
- state :"braces_#{name}_intp" do
73
- rule /#{rbrace}[a-z]*/, Str::Double, :pop!
74
- mixin :enddoublestr
75
- end
76
-
77
- state :"braces_#{name}_no_intp" do
78
- rule /.*#{rbrace}[a-z]*/, Str::Double, :pop!
79
- end
80
54
  end
81
55
 
82
56
  state :dqs do
@@ -103,6 +77,57 @@ module Rouge
103
77
  mixin :interpoling
104
78
  rule /[^#"]+/, Str::Double
105
79
  end
80
+
81
+ state :sigil_strings do
82
+ # ~-sigiled strings
83
+ # ~(abc), ~[abc], ~<abc>, ~|abc|, ~r/abc/, etc
84
+ # Cribbed and adjusted from Ruby lexer
85
+ delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
86
+ # Match a-z for custom sigils too
87
+ sigil_opens = Regexp.union(delimiter_map.keys + %w(| / ' "))
88
+ rule /~([A-Za-z])?(#{sigil_opens})/ do |m|
89
+ open = Regexp.escape(m[2])
90
+ close = Regexp.escape(delimiter_map[m[2]] || m[2])
91
+ interp = /[SRCW]/ === m[1]
92
+ toktype = Str::Other
93
+
94
+ puts " open: #{open.inspect}" if @debug
95
+ puts " close: #{close.inspect}" if @debug
96
+
97
+ # regexes
98
+ if 'Rr'.include? m[1]
99
+ toktype = Str::Regex
100
+ push :regex_flags
101
+ end
102
+
103
+ if 'Ww'.include? m[1]
104
+ push :list_flags
105
+ end
106
+
107
+ token toktype
108
+
109
+ push do
110
+ rule /#{close}/, toktype, :pop!
111
+
112
+ if interp
113
+ mixin :interpoling
114
+ rule /#/, toktype
115
+ else
116
+ rule /[\\#]/, toktype
117
+ end
118
+
119
+ rule /[^##{open}#{close}\\]+/m, toktype
120
+ end
121
+ end
122
+ end
123
+
124
+ state :regex_flags do
125
+ rule /[fgimrsux]*/, Str::Regex, :pop!
126
+ end
127
+
128
+ state :list_flags do
129
+ rule /[csa]?/, Str::Other, :pop!
130
+ end
106
131
  end
107
132
  end
108
133
  end