rouge 1.10.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge/cli.rb +1 -1
  3. data/lib/rouge/demos/actionscript +4 -0
  4. data/lib/rouge/demos/apiblueprint +33 -0
  5. data/lib/rouge/demos/biml +38 -0
  6. data/lib/rouge/demos/ceylon +7 -0
  7. data/lib/rouge/demos/cmake +7 -0
  8. data/lib/rouge/demos/coq +11 -0
  9. data/lib/rouge/demos/d +16 -0
  10. data/lib/rouge/demos/eiffel +30 -0
  11. data/lib/rouge/demos/fortran +22 -0
  12. data/lib/rouge/demos/gradle +10 -0
  13. data/lib/rouge/demos/jinja +9 -0
  14. data/lib/rouge/demos/jsonnet +28 -0
  15. data/lib/rouge/demos/julia +11 -0
  16. data/lib/rouge/demos/nasm +26 -0
  17. data/lib/rouge/demos/objective_c +4 -0
  18. data/lib/rouge/demos/protobuf +5 -0
  19. data/lib/rouge/demos/shell_session +10 -0
  20. data/lib/rouge/demos/smarty +12 -0
  21. data/lib/rouge/demos/tap +5 -0
  22. data/lib/rouge/demos/twig +9 -0
  23. data/lib/rouge/demos/typescript +1 -0
  24. data/lib/rouge/demos/verilog +27 -0
  25. data/lib/rouge/demos/viml +14 -5
  26. data/lib/rouge/formatters/html_wrapper.rb +11 -0
  27. data/lib/rouge/formatters/terminal256.rb +1 -1
  28. data/lib/rouge/lexer.rb +4 -2
  29. data/lib/rouge/lexers/actionscript.rb +195 -0
  30. data/lib/rouge/lexers/apache.rb +23 -20
  31. data/lib/rouge/lexers/apache/keywords.yml +721 -410
  32. data/lib/rouge/lexers/apiblueprint.rb +51 -0
  33. data/lib/rouge/lexers/biml.rb +41 -0
  34. data/lib/rouge/lexers/c.rb +7 -2
  35. data/lib/rouge/lexers/ceylon.rb +123 -0
  36. data/lib/rouge/lexers/clojure.rb +1 -1
  37. data/lib/rouge/lexers/cmake.rb +206 -0
  38. data/lib/rouge/lexers/coffeescript.rb +1 -1
  39. data/lib/rouge/lexers/coq.rb +187 -0
  40. data/lib/rouge/lexers/cpp.rb +12 -1
  41. data/lib/rouge/lexers/csharp.rb +12 -5
  42. data/lib/rouge/lexers/css.rb +2 -0
  43. data/lib/rouge/lexers/d.rb +176 -0
  44. data/lib/rouge/lexers/diff.rb +9 -9
  45. data/lib/rouge/lexers/eiffel.rb +65 -0
  46. data/lib/rouge/lexers/fortran.rb +142 -0
  47. data/lib/rouge/lexers/gradle.rb +37 -0
  48. data/lib/rouge/lexers/groovy.rb +2 -2
  49. data/lib/rouge/lexers/ini.rb +2 -2
  50. data/lib/rouge/lexers/java.rb +11 -8
  51. data/lib/rouge/lexers/javascript.rb +2 -1
  52. data/lib/rouge/lexers/jinja.rb +137 -0
  53. data/lib/rouge/lexers/jsonnet.rb +151 -0
  54. data/lib/rouge/lexers/julia.rb +172 -0
  55. data/lib/rouge/lexers/markdown.rb +1 -0
  56. data/lib/rouge/lexers/nasm.rb +203 -0
  57. data/lib/rouge/lexers/objective_c.rb +11 -0
  58. data/lib/rouge/lexers/php.rb +1 -1
  59. data/lib/rouge/lexers/powershell.rb +1 -1
  60. data/lib/rouge/lexers/protobuf.rb +70 -0
  61. data/lib/rouge/lexers/python.rb +23 -0
  62. data/lib/rouge/lexers/r.rb +53 -20
  63. data/lib/rouge/lexers/ruby.rb +4 -4
  64. data/lib/rouge/lexers/rust.rb +2 -2
  65. data/lib/rouge/lexers/shell_session.rb +29 -0
  66. data/lib/rouge/lexers/smarty.rb +91 -0
  67. data/lib/rouge/lexers/sql.rb +1 -1
  68. data/lib/rouge/lexers/swift.rb +20 -5
  69. data/lib/rouge/lexers/tap.rb +91 -0
  70. data/lib/rouge/lexers/twig.rb +37 -0
  71. data/lib/rouge/lexers/typescript.rb +46 -0
  72. data/lib/rouge/lexers/verilog.rb +164 -0
  73. data/lib/rouge/regex_lexer.rb +1 -1
  74. data/lib/rouge/version.rb +1 -1
  75. data/rouge.gemspec +1 -1
  76. metadata +47 -6
  77. data/lib/rouge/formatters/html_inline.rb +0 -20
  78. data/lib/rouge/formatters/html_linewise.rb +0 -31
@@ -80,6 +80,7 @@ module Rouge
80
80
  rule /[?]/, Punctuation, :ternary
81
81
  rule /\[/, Punctuation, :message
82
82
  rule /@\[/, Punctuation, :array_literal
83
+ rule /@\{/, Punctuation, :dictionary_literal
83
84
  end
84
85
 
85
86
  state :ternary do
@@ -89,6 +90,7 @@ module Rouge
89
90
 
90
91
  state :message_shared do
91
92
  rule /\]/, Punctuation, :pop!
93
+ rule /\{/, Punctuation, :pop!
92
94
  rule /;/, Error
93
95
 
94
96
  mixin :statement
@@ -109,8 +111,10 @@ module Rouge
109
111
  end
110
112
 
111
113
  state :message_with_args do
114
+ rule /\{/, Punctuation, :function
112
115
  rule /(#{id})(\s*)(:)/ do
113
116
  groups(Name::Function, Text, Punctuation)
117
+ pop!
114
118
  end
115
119
 
116
120
  mixin :message_shared
@@ -122,6 +126,12 @@ module Rouge
122
126
  mixin :statements
123
127
  end
124
128
 
129
+ state :dictionary_literal do
130
+ rule /}/, Punctuation, :pop!
131
+ rule /,/, Punctuation
132
+ mixin :statements
133
+ end
134
+
125
135
  state :classname do
126
136
  mixin :whitespace
127
137
 
@@ -137,6 +147,7 @@ module Rouge
137
147
  Punctuation, Text,
138
148
  Name::Label, Text,
139
149
  Punctuation)
150
+ pop!
140
151
  end
141
152
 
142
153
  rule id, Name::Class, :pop!
@@ -7,7 +7,7 @@ module Rouge
7
7
  desc "The PHP scripting language (php.net)"
8
8
  tag 'php'
9
9
  aliases 'php', 'php3', 'php4', 'php5'
10
- filenames '*.php', '*.php[345]',
10
+ filenames '*.php', '*.php[345t]','*.phtml',
11
11
  # Support Drupal file extensions, see:
12
12
  # https://github.com/gitlabhq/gitlabhq/issues/8900
13
13
  '*.module', '*.inc', '*.profile', '*.install', '*.test'
@@ -10,7 +10,7 @@ module Rouge
10
10
  tag 'powershell'
11
11
  aliases 'posh'
12
12
  filenames '*.ps1', '*.psm1', '*.psd1'
13
- mimetypes 'text/plain'
13
+ mimetypes 'text/x-powershell'
14
14
 
15
15
  ATTRIBUTES = %w(
16
16
  CmdletBinding ConfirmImpact DefaultParameterSetName HelpURI SupportsPaging
@@ -0,0 +1,70 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Protobuf < RegexLexer
6
+ title 'Protobuf'
7
+ desc 'Google\'s language-neutral, platform-neutral, extensible mechanism for serializing structured data'
8
+ tag 'protobuf'
9
+ aliases 'proto'
10
+ filenames '*.proto'
11
+ mimetypes 'text/x-proto'
12
+
13
+ kw = /\b(ctype|default|extensions|import|max|oneof|option|optional|packed|repeated|required|returns|rpc|to)\b/
14
+ datatype = /\b(bool|bytes|double|fixed32|fixed64|float|int32|int64|sfixed32|sfixed64|sint32|sint64|string|uint32|uint64)\b/
15
+
16
+ state :root do
17
+ rule /[\s]+/, Text
18
+ rule /[,;{}\[\]()]/, Punctuation
19
+ rule /\/(\\\n)?\/(\n|(.|\n)*?[^\\]\n)/, Comment::Single
20
+ rule /\/(\\\n)?\*(.|\n)*?\*(\\\n)?\//, Comment::Multiline
21
+ rule kw, Keyword
22
+ rule datatype, Keyword::Type
23
+ rule /true|false/, Keyword::Constant
24
+ rule /(package)(\s+)/ do
25
+ groups Keyword::Namespace, Text
26
+ push :package
27
+ end
28
+
29
+ rule /(message|extend)(\s+)/ do
30
+ groups Keyword::Declaration, Text
31
+ push :message
32
+ end
33
+
34
+ rule /(enum|group|service)(\s+)/ do
35
+ groups Keyword::Declaration, Text
36
+ push :type
37
+ end
38
+
39
+ rule /".*?"/, Str
40
+ rule /'.*?'/, Str
41
+ rule /(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*/, Num::Float
42
+ rule /(\d+\.\d*|\.\d+|\d+[fF])[fF]?/, Num::Float
43
+ rule /(\-?(inf|nan))\b/, Num::Float
44
+ rule /0x[0-9a-fA-F]+[LlUu]*/, Num::Hex
45
+ rule /0[0-7]+[LlUu]*/, Num::Oct
46
+ rule /\d+[LlUu]*/, Num::Integer
47
+ rule /[+-=]/, Operator
48
+ rule /([a-zA-Z_][\w.]*)([ \t]*)(=)/ do
49
+ groups Name::Attribute, Text, Operator
50
+ end
51
+ rule /[a-zA-Z_][\w.]*/, Name
52
+ end
53
+
54
+ state :package do
55
+ rule /[a-zA-Z_]\w*/, Name::Namespace, :pop!
56
+ rule (//) { pop! }
57
+ end
58
+
59
+ state :message do
60
+ rule /[a-zA-Z_]\w*/, Name::Class, :pop!
61
+ rule (//) { pop! }
62
+ end
63
+
64
+ state :type do
65
+ rule /[a-zA-Z_]\w*/, Name, :pop!
66
+ rule (//) { pop! }
67
+ end
68
+ end
69
+ end
70
+ end
@@ -85,6 +85,16 @@ module Rouge
85
85
  push :classname
86
86
  end
87
87
 
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
+
88
98
  rule /(from)((?:\s|\\\s)+)/ do
89
99
  groups Keyword::Namespace, Text
90
100
  push :fromimport
@@ -141,6 +151,19 @@ module Rouge
141
151
  rule identifier, Name::Class, :pop!
142
152
  end
143
153
 
154
+ state :raise do
155
+ rule /from\b/, Keyword
156
+ rule /raise\b/, Keyword
157
+ rule /yield\b/, Keyword
158
+ rule /\n/, Text, :pop!
159
+ rule /;/, Punctuation, :pop!
160
+ mixin :root
161
+ end
162
+
163
+ state :yield do
164
+ mixin :raise
165
+ end
166
+
144
167
  state :import do
145
168
  # non-line-terminating whitespace
146
169
  rule /(?:[ \t]|\\\n)+/, Text
@@ -7,49 +7,82 @@ module Rouge
7
7
  desc 'The R statistics language (r-project.org)'
8
8
  tag 'r'
9
9
  aliases 'r', 'R', 's', 'S'
10
- filenames '*.R', '.Rhistory', '.Rprofile'
10
+ filenames '*.R', '*.r', '.Rhistory', '.Rprofile'
11
11
  mimetypes 'text/x-r-source', 'text/x-r', 'text/x-R'
12
12
 
13
13
  mimetypes 'text/x-r', 'application/x-r'
14
14
 
15
- def self.keywords
16
- @keywords ||= %w(
17
- if else for while repeat in next break return switch function
18
- )
19
- end
15
+ KEYWORDS = %w(if else for while repeat in next break function)
16
+
17
+ KEYWORD_CONSTANTS = %w(
18
+ NULL Inf TRUE FALSE NaN NA
19
+ NA_integer_ NA_real_ NA_complex_ NA_character_
20
+ )
21
+
22
+ BUILTIN_CONSTANTS = %w(LETTERS letters month.abb month.name pi T F)
23
+
24
+ # These are all the functions in `base` that are implemented as a
25
+ # `.Primitive`, minus those functions that are also keywords.
26
+ PRIMITIVE_FUNCTIONS = %w(
27
+ abs acos acosh all any anyNA Arg as.call as.character
28
+ as.complex as.double as.environment as.integer as.logical
29
+ as.null.default as.numeric as.raw asin asinh atan atanh attr
30
+ attributes baseenv browser c call ceiling class Conj cos cosh
31
+ cospi cummax cummin cumprod cumsum digamma dim dimnames
32
+ emptyenv exp expression floor forceAndCall gamma gc.time
33
+ globalenv Im interactive invisible is.array is.atomic is.call
34
+ is.character is.complex is.double is.environment is.expression
35
+ is.finite is.function is.infinite is.integer is.language
36
+ is.list is.logical is.matrix is.na is.name is.nan is.null
37
+ is.numeric is.object is.pairlist is.raw is.recursive is.single
38
+ is.symbol lazyLoadDBfetch length lgamma list log max min
39
+ missing Mod names nargs nzchar oldClass on.exit pos.to.env
40
+ proc.time prod quote range Re rep retracemem return round
41
+ seq_along seq_len seq.int sign signif sin sinh sinpi sqrt
42
+ standardGeneric substitute sum switch tan tanh tanpi tracemem
43
+ trigamma trunc unclass untracemem UseMethod xtfrm
44
+ )
20
45
 
21
46
  def self.analyze_text(text)
22
47
  return 1 if text.shebang? 'Rscript'
23
48
  end
24
49
 
25
50
  state :root do
51
+ rule /#'.*?\n/, Comment::Doc
26
52
  rule /#.*?\n/, Comment::Single
27
- rule /\s+/m, Text
28
- rule /[.]?[a-zA-Z_][\w.]*/ do |m|
29
- if self.class.keywords.include? m[0]
30
- token Keyword
31
- else
32
- token Name
33
- end
34
- end
53
+ rule /\s+/m, Text::Whitespace
35
54
 
36
- rule /`.*?`/, Str::Backtick
55
+ rule /`[^`]+?`/, Name
37
56
  rule /'(\\.|.)*?'/m, Str::Single
38
57
  rule /"(\\.|.)*?"/m, Str::Double
39
58
 
40
- rule /\b(NULL|Inf|TRUE|FALSE|NaN)\b/, Keyword::Constant
41
- rule /\bNA(_(integer|real|complex|character)_)?\b/,
42
- Keyword::Constant
43
- rule /\b[TF]\b/, Keyword::Variable
59
+ rule /%[^%]*?%/, Operator
44
60
 
45
61
  rule /0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?/, Num::Hex
46
62
  rule /[+-]?(\d+([.]\d+)?|[.]\d+)([eE][+-]?\d+)?[Li]?/,
47
63
  Num
48
64
 
65
+ # Only recognize built-in functions when they are actually used as a
66
+ # function call, i.e. followed by an opening parenthesis.
67
+ # `Name::Builtin` would be more logical, but is usually not
68
+ # highlighted specifically; thus use `Name::Function`.
69
+ rule /\b(?<!.)(#{PRIMITIVE_FUNCTIONS.join('|')})(?=\()/, Name::Function
70
+
71
+ rule /[a-zA-Z.]([a-zA-Z_][\w.]*)?/ do |m|
72
+ if KEYWORDS.include? m[0]
73
+ token Keyword
74
+ elsif KEYWORD_CONSTANTS.include? m[0]
75
+ token Keyword::Constant
76
+ elsif BUILTIN_CONSTANTS.include? m[0]
77
+ token Name::Builtin
78
+ else
79
+ token Name
80
+ end
81
+ end
82
+
49
83
  rule /[\[\]{}();,]/, Punctuation
50
84
 
51
85
  rule %r([-<>?*+^/!=~$@:%&|]), Operator
52
- rule /[.][.][.]/, Keyword
53
86
  end
54
87
  end
55
88
  end
@@ -228,17 +228,17 @@ module Rouge
228
228
  end
229
229
 
230
230
  state :has_heredocs do
231
- rule /(?<!\w)(<<-?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
231
+ rule /(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
232
232
  token Operator, m[1]
233
233
  token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
234
- @heredoc_queue << [m[1] == '<<-', m[3]]
234
+ @heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
235
235
  push :heredoc_queue unless state? :heredoc_queue
236
236
  end
237
237
 
238
- rule /(<<-?)(["'])(\2)/ do |m|
238
+ rule /(<<[-~]?)(["'])(\2)/ do |m|
239
239
  token Operator, m[1]
240
240
  token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
241
- @heredoc_queue << [m[1] == '<<-', '']
241
+ @heredoc_queue << [['<<-', '<<~'].include?(m[1]), '']
242
242
  push :heredoc_queue unless state? :heredoc_queue
243
243
  end
244
244
  end
@@ -29,10 +29,10 @@ module Rouge
29
29
  c_int clock_t c_long c_longlong Cons Const Copy c_schar c_short
30
30
  c_uchar c_uint c_ulong c_ulonglong c_ushort c_void dev_t DIR
31
31
  dirent Div Either Eq Err f32 f64 Failure FILE float fpos_t
32
- i16 i32 i64 i8 Index ino_t int intptr_t Left mode_t Modulo Mul
32
+ i16 i32 i64 i8 isize Index ino_t int intptr_t Left mode_t Modulo Mul
33
33
  Neg Nil None Num off_t Ok Option Ord Owned pid_t Ptr ptrdiff_t
34
34
  Right Send Shl Shr size_t Some ssize_t str Sub Success time_t
35
- u16 u32 u64 u8 uint uintptr_t
35
+ u16 u32 u64 u8 usize uint uintptr_t
36
36
  Box Vec String Gc Rc Arc
37
37
  )
38
38
  end
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class ShellSession < RegexLexer
6
+ tag 'shell_session'
7
+ title "Shell Session"
8
+ desc 'A generic lexer for shell session and command line'
9
+ aliases 'terminal', 'console'
10
+ filenames '*.cap'
11
+
12
+ state :root do
13
+ rule /^([^ \n]*# )([^ \n]*)(.*(\n|$))/ do |m|
14
+ token Name::Entity, m[1]
15
+ token Name::Class, m[2]
16
+ token Keyword::Variable, m[3]
17
+ end
18
+ rule /^([^ \n]*\$ )([^ \n]*)(.*(\n|$))/ do |m|
19
+ token Text::Whitespace, m[1]
20
+ token Name::Class, m[2]
21
+ token Keyword::Variable, m[3]
22
+ end
23
+ rule /^<...>$/, Comment
24
+ rule /.*\n/, Text
25
+ end
26
+ end
27
+ end
28
+ end
29
+ ### tag function class label
@@ -0,0 +1,91 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Smarty < TemplateLexer
6
+ title "Smarty"
7
+ desc 'Smarty Template Engine'
8
+ tag 'smarty'
9
+ aliases 'smarty'
10
+ filenames '*.tpl', '*.smarty'
11
+ mimetypes 'application/x-smarty', 'text/x-smarty'
12
+
13
+ def self.analyze_text(text)
14
+ rv = 0.0
15
+ rv += 0.15 if text =~ /\{if\s+.*?\}.*?\{\/if\}/
16
+ rv += 0.15 if text =~ /\{include\s+file=.*?\}/
17
+ rv += 0.15 if text =~ /\{foreach\s+.*?\}.*?\{\/foreach\}/
18
+ rv += 0.01 if text =~ /\{\$.*?\}/
19
+ return rv
20
+ end
21
+
22
+
23
+
24
+ def self.builtins
25
+ @builtins ||= %w(
26
+ append assign block call capture config_load debug extends
27
+ for foreach foreachelse break continue function if elseif
28
+ else include include_php insert ldelim rdelim literal nocache
29
+ php section sectionelse setfilter strip while
30
+ counter cycle eval fetch html_checkboxes html_image html_options
31
+ html_radios html_select_date html_select_time html_table
32
+ mailto math textformat
33
+ capitalize cat count_characters count_paragraphs
34
+ count_sentences count_words date_format default escape
35
+ from_charset indent lower nl2br regex_replace replace spacify
36
+ string_format strip strip_tags to_charset truncate unescape
37
+ upper wordwrap
38
+ )
39
+ end
40
+
41
+
42
+ state :root do
43
+ rule(/\{\s+/) { delegate parent }
44
+
45
+ # block comments
46
+ rule /\{\*.*?\*\}/m, Comment
47
+
48
+ rule /\{\/?(?![\s*])/ do
49
+ token Keyword
50
+ push :smarty
51
+ end
52
+
53
+
54
+ rule(/.*?(?={[\/a-zA-Z0-9$#*"'])|.*/m) { delegate parent }
55
+ rule(/.+/m) { delegate parent }
56
+ end
57
+
58
+ state :comment do
59
+ rule(/{\*/) { token Comment; push }
60
+ rule(/\*}/) { token Comment; pop! }
61
+ rule(/[^{}]+/m) { token Comment }
62
+ end
63
+
64
+ state :smarty do
65
+ # allow nested tags
66
+ rule /\{\/?(?![\s*])/ do
67
+ token Keyword
68
+ push :smarty
69
+ end
70
+
71
+ rule /}/, Keyword, :pop!
72
+ rule /\s+/m, Text
73
+ rule %r([~!%^&*()+=|\[\]:;,.<>/@?-]), Operator
74
+ rule /#[a-zA-Z_]\w*#/, Name::Variable
75
+ rule /\$[a-zA-Z_]\w*(\.\w+)*/, Name::Variable
76
+ rule /(true|false|null)\b/, Keyword::Constant
77
+ rule /[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?/, Num
78
+ rule /"(\\.|.)*?"/, Str::Double
79
+ rule /'(\\.|.)*?'/, Str::Single
80
+ rule /([a-zA-Z_]\w*)/ do |m|
81
+ if self.class.builtins.include? m[0]
82
+ token Name::Builtin
83
+ else
84
+ token Name::Attribute
85
+ end
86
+ end
87
+ end
88
+
89
+ end
90
+ end
91
+ end
@@ -89,7 +89,7 @@ module Rouge
89
89
 
90
90
  state :root do
91
91
  rule /\s+/m, Text
92
- rule /--.*?\n/, Comment::Single
92
+ rule /--.*/, Comment::Single
93
93
  rule %r(/\*), Comment::Multiline, :multiline_comments
94
94
  rule /\d+/, Num::Integer
95
95
  rule /'/, Str::Single, :single_string
@@ -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
21
+ associativity didSet get infix inout left mutating none nonmutating operator override postfix precedence prefix right set unowned weak willSet throws rethrows associatedtype
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
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
26
26
  )
27
27
 
28
28
  constants = Set.new %w(
@@ -42,7 +42,7 @@ module Rouge
42
42
 
43
43
  state :inline_whitespace do
44
44
  rule /\s+/m, Text
45
- rule %r((?<re>\/\*(?:(?>[^\/\*\*\/]+)|\g<re>)*\*\/))m, Comment::Multiline
45
+ mixin :has_comments
46
46
  end
47
47
 
48
48
  state :whitespace do
@@ -51,6 +51,17 @@ module Rouge
51
51
  mixin :inline_whitespace
52
52
  end
53
53
 
54
+ state :has_comments do
55
+ rule %r(/[*]), Comment::Multiline, :nested_comment
56
+ end
57
+
58
+ state :nested_comment do
59
+ mixin :has_comments
60
+ rule %r([*]/), Comment::Multiline, :pop!
61
+ rule %r([^*/]+)m, Comment::Multiline
62
+ rule /./, Comment::Multiline
63
+ end
64
+
54
65
  state :root do
55
66
  mixin :whitespace
56
67
  rule /\$(([1-9]\d*)?\d)/, Name::Variable
@@ -85,6 +96,10 @@ module Rouge
85
96
  end
86
97
 
87
98
  rule /#available\([^)]+\)/, Keyword::Declaration
99
+
100
+ rule /(#selector\()([^)]+?(?:[(].*?[)])?)(\))/ do
101
+ groups Keyword::Declaration, Name::Function, Keyword::Declaration
102
+ end
88
103
 
89
104
  rule /(let|var)\b(\s*)(#{id})/ do
90
105
  groups Keyword, Text, Name::Variable
@@ -98,8 +113,8 @@ module Rouge
98
113
  end
99
114
  end
100
115
 
101
- rule /as[?!]?/, Keyword
102
- rule /try[!]?/, Keyword
116
+ rule /as[?!]?(?=\s)/, Keyword
117
+ rule /try[!]?(?=\s)/, Keyword
103
118
 
104
119
  rule /(#?(?!default)(?![[:upper:]])#{id})(\s*)(:)/ do
105
120
  groups Name::Variable, Text, Punctuation