rouge 2.0.5 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ module Rouge
2
+ module Lexers
3
+ load_lexer 'javascript.rb'
4
+
5
+ class JSX < Javascript
6
+ desc 'jsx'
7
+ tag 'jsx'
8
+ aliases 'jsx', 'react'
9
+ filenames '*.jsx'
10
+
11
+ mimetypes 'text/x-jsx', 'application/x-jsx'
12
+
13
+ id = Javascript.id_regex
14
+
15
+ def start_embed!
16
+ @embed ||= JSX.new(options)
17
+ @embed.reset!
18
+ @embed.push(:expr_start)
19
+ push :jsx_embed_root
20
+ end
21
+
22
+ def tag_token(name)
23
+ name[0] =~ /\p{Lower}/ ? Name::Tag : Name::Class
24
+ end
25
+
26
+ start { @html = HTML.new(options) }
27
+
28
+ state :jsx_tags do
29
+ rule /</, Punctuation, :jsx_element
30
+ end
31
+
32
+ state :jsx_internal do
33
+ rule %r(</) do
34
+ token Punctuation
35
+ goto :jsx_end_tag
36
+ end
37
+
38
+ rule /{/ do
39
+ token Str::Interpol
40
+ start_embed!
41
+ end
42
+
43
+ rule /[^<>{]+/ do
44
+ delegate @html
45
+ end
46
+
47
+ mixin :jsx_tags
48
+ end
49
+
50
+ prepend :expr_start do
51
+ mixin :jsx_tags
52
+ end
53
+
54
+ state :jsx_tag do
55
+ mixin :comments_and_whitespace
56
+ rule /#{id}/ do |m|
57
+ token tag_token(m[0])
58
+ end
59
+
60
+ rule /[.]/, Punctuation
61
+ end
62
+
63
+ state :jsx_end_tag do
64
+ mixin :jsx_tag
65
+ rule />/, Punctuation, :pop!
66
+ end
67
+
68
+ state :jsx_element do
69
+ rule /#{id}=/, Name::Attribute, :jsx_attribute
70
+ mixin :jsx_tag
71
+ rule />/ do token Punctuation; goto :jsx_internal end
72
+ rule %r(/>), Punctuation, :pop!
73
+ end
74
+
75
+ state :jsx_attribute do
76
+ rule /"(\\[\\"]|[^"])*"/, Str::Double, :pop!
77
+ rule /'(\\[\\']|[^'])*'/, Str::Single, :pop!
78
+ rule /{/ do
79
+ token Str::Interpol
80
+ pop!
81
+ start_embed!
82
+ end
83
+ end
84
+
85
+ state :jsx_embed_root do
86
+ rule /[.][.][.]/, Punctuation
87
+ rule /}/, Str::Interpol, :pop!
88
+ mixin :jsx_embed
89
+ end
90
+
91
+ state :jsx_embed do
92
+ rule /{/ do delegate @embed; push :jsx_embed end
93
+ rule /}/ do delegate @embed; pop! end
94
+ rule /[^{}]+/ do
95
+ delegate @embed
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
@@ -31,10 +31,10 @@ module Rouge
31
31
  rule /^#(?=[^#]).*?$/, Generic::Heading
32
32
  rule /^##*.*?$/, Generic::Subheading
33
33
 
34
- # TODO: syntax highlight the code block, github style
35
- rule /(\n[ \t]*)(```|~~~)(.*?)(\n.*?)(\2)/m do |m|
34
+ rule /(\n[ \t]*)(```|~~~)(.*?)(\n.*?\n)(\2)/m do |m|
36
35
  sublexer = Lexer.find_fancy(m[3].strip, m[4])
37
36
  sublexer ||= PlainText.new(:token => Str::Backtick)
37
+ sublexer.options(self.options)
38
38
  sublexer.reset!
39
39
 
40
40
  token Text, m[1]
@@ -46,7 +46,7 @@ module Rouge
46
46
 
47
47
  rule /\n\n(( |\t).*?\n|\n)+/, Str::Backtick
48
48
 
49
- rule /(`+)#{edot}+?\1/, Str::Backtick
49
+ rule /(`+)(?:#{edot}|\n)+?\1/, Str::Backtick
50
50
 
51
51
  # various uses of * are in order of precedence
52
52
 
@@ -0,0 +1,68 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class MXML < RegexLexer
6
+ title "MXML"
7
+ desc "MXML"
8
+ tag 'mxml'
9
+ filenames '*.mxml'
10
+ mimetypes 'application/xv+xml'
11
+
12
+ state :root do
13
+ rule /[^<&]+/, Text
14
+ rule /&\S*?;/, Name::Entity
15
+
16
+ rule /<!\[CDATA\[/m do
17
+ token Comment::Preproc
18
+ push :actionscript_content
19
+ end
20
+
21
+ rule /<!--/, Comment, :comment
22
+ rule /<\?.*?\?>/, Comment::Preproc
23
+ rule /<![^>]*>/, Comment::Preproc
24
+
25
+ rule %r(<\s*[\w:.-]+)m, Name::Tag, :tag # opening tags
26
+ rule %r(<\s*/\s*[\w:.-]+\s*>)m, Name::Tag # closing tags
27
+ end
28
+
29
+ state :comment do
30
+ rule /[^-]+/m, Comment
31
+ rule /-->/, Comment, :pop!
32
+ rule /-/, Comment
33
+ end
34
+
35
+ state :tag do
36
+ rule /\s+/m, Text
37
+ rule /[\w.:-]+\s*=/m, Name::Attribute, :attribute
38
+ rule %r(/?\s*>), Name::Tag, :root
39
+ end
40
+
41
+ state :attribute do
42
+ rule /\s+/m, Text
43
+ rule /(")({|@{)/m do
44
+ groups Str, Punctuation
45
+ push :actionscript_attribute
46
+ end
47
+ rule /".*?"|'.*?'|[^\s>]+/, Str, :tag
48
+ end
49
+
50
+ state :actionscript_content do
51
+ rule /\]\]\>/m, Comment::Preproc, :pop!
52
+ rule /.*?(?=\]\]\>)/m do
53
+ delegate Actionscript
54
+ end
55
+ end
56
+
57
+ state :actionscript_attribute do
58
+ rule /(})(")/m do
59
+ groups Punctuation, Str
60
+ push :tag
61
+ end
62
+ rule /.*?(?=}")/m do
63
+ delegate Actionscript
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -52,16 +52,16 @@ module Rouge
52
52
  re_tok = Str::Regex
53
53
 
54
54
  state :balanced_regex do
55
- rule %r(/(\\\\|\\/|[^/])*/[egimosx]*)m, re_tok, :pop!
56
- rule %r(!(\\\\|\\!|[^!])*![egimosx]*)m, re_tok, :pop!
55
+ rule %r(/(\\[\\/]|[^/])*/[egimosx]*)m, re_tok, :pop!
56
+ rule %r(!(\\[\\!]|[^!])*![egimosx]*)m, re_tok, :pop!
57
57
  rule %r(\\(\\\\|[^\\])*\\[egimosx]*)m, re_tok, :pop!
58
- rule %r({(\\\\|\\}|[^}])*}[egimosx]*), re_tok, :pop!
59
- rule %r(<(\\\\|\\>|[^>])*>[egimosx]*), re_tok, :pop!
60
- rule %r(\[(\\\\|\\\]|[^\]])*\][egimosx]*), re_tok, :pop!
61
- rule %r[\((\\\\|\\\)|[^\)])*\)[egimosx]*], re_tok, :pop!
62
- rule %r(@(\\\\|\\\@|[^\@])*@[egimosx]*), re_tok, :pop!
63
- rule %r(%(\\\\|\\\%|[^\%])*%[egimosx]*), re_tok, :pop!
64
- rule %r(\$(\\\\|\\\$|[^\$])*\$[egimosx]*), re_tok, :pop!
58
+ rule %r({(\\[\\}]|[^}])*}[egimosx]*), re_tok, :pop!
59
+ rule %r(<(\\[\\>]|[^>])*>[egimosx]*), re_tok, :pop!
60
+ rule %r(\[(\\[\\\]]|[^\]])*\][egimosx]*), re_tok, :pop!
61
+ rule %r[\((\\[\\\)]|[^\)])*\)[egimosx]*], re_tok, :pop!
62
+ rule %r(@(\\[\\@]|[^@])*@[egimosx]*), re_tok, :pop!
63
+ rule %r(%(\\[\\%]|[^%])*%[egimosx]*), re_tok, :pop!
64
+ rule %r(\$(\\[\\\$]|[^\$])*\$[egimosx]*), re_tok, :pop!
65
65
  end
66
66
 
67
67
  state :root do
@@ -0,0 +1,121 @@
1
+ module Rouge
2
+ module Lexers
3
+ class Prometheus < RegexLexer
4
+ desc 'prometheus'
5
+ tag 'prometheus'
6
+ aliases 'prometheus'
7
+ filenames '*.prometheus'
8
+
9
+ mimetypes 'text/x-prometheus', 'application/x-prometheus'
10
+
11
+ def self.functions
12
+ @functions ||= Set.new %w(
13
+ abs absent ceil changes clamp_max clamp_min count_scalar day_of_month
14
+ day_of_week days_in_month delta deriv drop_common_labels exp floor
15
+ histogram_quantile holt_winters hour idelta increase irate label_replace
16
+ ln log2 log10 month predict_linear rate resets round scalar sort
17
+ sort_desc sqrt time vector year avg_over_time min_over_time
18
+ max_over_time sum_over_time count_over_time quantile_over_time
19
+ stddev_over_time stdvar_over_time
20
+ )
21
+ end
22
+
23
+ state :root do
24
+ mixin :strings
25
+ mixin :whitespace
26
+
27
+ rule /-?\d+\.\d+/, Num::Float
28
+ rule /-?\d+[smhdwy]?/, Num::Integer
29
+
30
+ mixin :operators
31
+
32
+ rule /(ignoring|on)(\()/ do
33
+ groups Keyword::Pseudo, Punctuation
34
+ push :label_list
35
+ end
36
+ rule /(group_left|group_right)(\()/ do
37
+ groups Keyword::Type, Punctuation
38
+ end
39
+ rule /(bool|offset)\b/, Keyword
40
+ rule /(without|by)\b/, Keyword, :label_list
41
+ rule /[\w:]+/ do |m|
42
+ if self.class.functions.include?(m[0])
43
+ token Name::Builtin
44
+ else
45
+ token Name
46
+ end
47
+ end
48
+
49
+ mixin :metrics
50
+ end
51
+
52
+ state :metrics do
53
+ rule /[a-zA-Z0-9_-]+/, Name
54
+
55
+ rule /[\(\)\]:.,]/, Punctuation
56
+ rule /\{/, Punctuation, :filters
57
+ rule /\[/, Punctuation
58
+ end
59
+
60
+ state :strings do
61
+ rule /"/, Str::Double, :double_string_escaped
62
+ rule /'/, Str::Single, :single_string_escaped
63
+ rule /`.*`/, Str::Backtick
64
+ end
65
+
66
+ [
67
+ [:double, Str::Double, '"'],
68
+ [:single, Str::Single, "'"]
69
+ ].each do |name, tok, fin|
70
+ state :"#{name}_string_escaped" do
71
+ rule /\\[\\abfnrtv#{fin}]/, Str::Escape
72
+ rule /[^\\#{fin}]+/m, tok
73
+ rule /#{fin}/, tok, :pop!
74
+ end
75
+ end
76
+
77
+ state :filters do
78
+ mixin :inline_whitespace
79
+ rule /,/, Punctuation
80
+ mixin :labels
81
+ mixin :filter_matching_operators
82
+ mixin :strings
83
+ rule /}/, Punctuation, :pop!
84
+ end
85
+
86
+ state :label_list do
87
+ rule /\(/, Punctuation
88
+ rule /[a-zA-Z0-9_:-]+/, Name::Attribute
89
+ rule /,/, Punctuation
90
+ mixin :whitespace
91
+ rule /\)/, Punctuation, :pop!
92
+ end
93
+
94
+ state :labels do
95
+ rule /[a-zA-Z0-9_:-]+/, Name::Attribute
96
+ end
97
+
98
+ state :operators do
99
+ rule %r([+\-\*/%\^]), Operator # Arithmetic
100
+ rule %r(=|==|!=|<|>|<=|>=), Operator # Comparison
101
+ rule /and|or|unless/, Operator # Logical/Set
102
+ rule /(sum|min|max|avg|stddev|stdvar|count|count_values|bottomk|topk)\b/, Name::Function
103
+ end
104
+
105
+ state :filter_matching_operators do
106
+ rule /!(=|~)|=~?/, Operator
107
+ end
108
+
109
+ state :inline_whitespace do
110
+ rule /[ \t\r]+/, Text
111
+ end
112
+
113
+ state :whitespace do
114
+ mixin :inline_whitespace
115
+ rule /\n\s*/m, Text
116
+ rule /#.*?$/, Comment
117
+ end
118
+ end
119
+ end
120
+ end
121
+
@@ -18,7 +18,7 @@ module Rouge
18
18
  @keywords ||= %w(
19
19
  assert break continue del elif else except exec
20
20
  finally for global if lambda pass print raise
21
- return try while yield as with
21
+ return try while yield as with from import yield
22
22
  )
23
23
  end
24
24
 
@@ -75,6 +75,17 @@ module Rouge
75
75
  rule /(in|is|and|or|not)\b/, Operator::Word
76
76
  rule /!=|==|<<|>>|[-~+\/*%=<>&^|.]/, Operator
77
77
 
78
+ rule /(from)((?:\\\s|\s)+)(#{dotted_identifier})((?:\\\s|\s)+)(import)/ do
79
+ groups Keyword::Namespace,
80
+ Text,
81
+ Name::Namespace,
82
+ Text,
83
+ Keyword::Namespace
84
+ end
85
+ rule /(import)(\s+)(#{dotted_identifier})/ do
86
+ groups Keyword::Namespace, Text, Name::Namespace
87
+ end
88
+
78
89
  rule /(def)((?:\s|\\\s)+)/ do
79
90
  groups Keyword, Text
80
91
  push :funcname
@@ -85,26 +96,6 @@ module Rouge
85
96
  push :classname
86
97
  end
87
98
 
88
- rule /(yield)((?:\s|\\\s)+)/ do
89
- groups Keyword, Text
90
- push :raise
91
- end
92
-
93
- rule /(raise)((?:\s|\\\s)+)/ do
94
- groups Keyword, Text
95
- push :raise
96
- end
97
-
98
- rule /(from)((?:\s|\\\s)+)/ do
99
- groups Keyword::Namespace, Text
100
- push :fromimport
101
- end
102
-
103
- rule /(import)((?:\s|\\\s)+)/ do
104
- groups Keyword::Namespace, Text
105
- push :import
106
- end
107
-
108
99
  # TODO: not in python 3
109
100
  rule /`.*?`/, Str::Backtick
110
101
  rule /(?:r|ur|ru)"""/i, Str, :raw_tdqs
@@ -18,11 +18,11 @@ module Rouge
18
18
 
19
19
  as dynamicType is new super self Self Type __COLUMN__ __FILE__ __FUNCTION__ __LINE__
20
20
 
21
- associativity didSet get infix inout left mutating none nonmutating operator override postfix precedence prefix right set unowned weak willSet throws rethrows associatedtype
21
+ associativity didSet get infix inout mutating none nonmutating operator override postfix precedence prefix set unowned weak willSet throws rethrows precedencegroup
22
22
  )
23
23
 
24
24
  declarations = Set.new %w(
25
- class deinit enum extension final func import init internal lazy let optional private protocol public required static struct subscript typealias var dynamic indirect associatedtype
25
+ class deinit enum extension final func import init internal lazy let optional private protocol public required static struct subscript typealias var dynamic indirect associatedtype open fileprivate
26
26
  )
27
27
 
28
28
  constants = Set.new %w(
@@ -97,9 +97,11 @@ module Rouge
97
97
 
98
98
  rule /#available\([^)]+\)/, Keyword::Declaration
99
99
 
100
- rule /(#selector\()([^)]+?(?:[(].*?[)])?)(\))/ do
100
+ rule /(#(?:selector|keyPath)\()([^)]+?(?:[(].*?[)])?)(\))/ do
101
101
  groups Keyword::Declaration, Name::Function, Keyword::Declaration
102
102
  end
103
+
104
+ rule /#(line|file|column|function|dsohandle)/, Keyword::Declaration
103
105
 
104
106
  rule /(let|var)\b(\s*)(#{id})/ do
105
107
  groups Keyword, Text, Name::Variable
@@ -28,21 +28,32 @@ module Rouge
28
28
  rule /@#{id}/, Keyword
29
29
 
30
30
 
31
- rule /[>,!\[\]:{}()=;\/]/, Punctuation
32
-
33
31
  rule /(\\#{id})([{])/ do
34
- groups Name::Variable, Str
32
+ groups Name::Function, Str
33
+ push :nested_string
34
+ end
35
+
36
+ rule /([+]#{id})([{])/ do
37
+ groups Name::Decorator, Str
35
38
  push :nested_string
36
39
  end
37
40
 
38
41
  rule /\\#{id}/, Name::Function
42
+ rule /[+]#{id}/, Name::Decorator
39
43
 
44
+ rule /"[{]/, Str, :dqi
40
45
  rule /"/, Str, :dq
41
46
 
42
47
  rule /'{/, Str, :nested_string
48
+ rule /'#{id}/, Str
43
49
 
44
50
  rule /[.]#{id}/, Name::Tag
45
- rule /[$]#{id}/, Name::Variable
51
+ rule /[$]#{id}?/, Name::Variable
52
+ rule /-#{id}:?/, Name::Label
53
+ rule /%#{id}/, Name::Function
54
+ rule /`#{id}/, Operator::Word
55
+
56
+ rule /[?~%._>,!\[\]:{}()=;\/-]/, Punctuation
46
57
 
47
58
  rule /[0-9]+([.][0-9]+)?/, Num
48
59
 
@@ -57,6 +68,25 @@ module Rouge
57
68
  rule /\\./, Str::Escape
58
69
  end
59
70
 
71
+ state :dqi do
72
+ rule /[$][(]/, Str::Interpol, :interp_root
73
+ rule /[{]/, Str, :dqi
74
+ rule /[}]/, Str, :pop!
75
+ rule /[^{}$]+/, Str
76
+ rule /./, Str
77
+ end
78
+
79
+ state :interp_root do
80
+ rule /[)]/, Str::Interpol, :pop!
81
+ mixin :interp
82
+ end
83
+
84
+ state :interp do
85
+ rule /[(]/, Punctuation, :interp
86
+ rule /[)]/, Punctuation, :pop!
87
+ mixin :root
88
+ end
89
+
60
90
  state :nested_string do
61
91
  rule /\\./, Str::Escape
62
92
  rule(/{/) { token Str; push :nested_string }