rouge 3.19.0 → 3.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge.rb +1 -0
  3. data/lib/rouge/cli.rb +32 -2
  4. data/lib/rouge/demos/augeas +16 -0
  5. data/lib/rouge/demos/bibtex +12 -0
  6. data/lib/rouge/demos/brightscript +6 -0
  7. data/lib/rouge/demos/email +11 -0
  8. data/lib/rouge/demos/hlsl +20 -0
  9. data/lib/rouge/demos/j +12 -0
  10. data/lib/rouge/demos/janet +3 -0
  11. data/lib/rouge/demos/livescript +15 -0
  12. data/lib/rouge/demos/ocl +4 -0
  13. data/lib/rouge/demos/postscript +9 -0
  14. data/lib/rouge/demos/rescript +26 -0
  15. data/lib/rouge/demos/ssh +4 -0
  16. data/lib/rouge/demos/systemd +4 -0
  17. data/lib/rouge/demos/velocity +9 -0
  18. data/lib/rouge/demos/zig +6 -0
  19. data/lib/rouge/formatters/html_line_highlighter.rb +24 -0
  20. data/lib/rouge/formatters/html_line_table.rb +1 -3
  21. data/lib/rouge/formatters/html_linewise.rb +2 -3
  22. data/lib/rouge/lexer.rb +38 -20
  23. data/lib/rouge/lexers/apex.rb +9 -7
  24. data/lib/rouge/lexers/augeas.rb +93 -0
  25. data/lib/rouge/lexers/batchfile.rb +3 -2
  26. data/lib/rouge/lexers/bibtex.rb +115 -0
  27. data/lib/rouge/lexers/brightscript.rb +147 -0
  28. data/lib/rouge/lexers/cmake.rb +10 -0
  29. data/lib/rouge/lexers/cpp.rb +12 -5
  30. data/lib/rouge/lexers/crystal.rb +14 -9
  31. data/lib/rouge/lexers/css.rb +3 -1
  32. data/lib/rouge/lexers/diff.rb +1 -1
  33. data/lib/rouge/lexers/docker.rb +2 -2
  34. data/lib/rouge/lexers/elm.rb +5 -5
  35. data/lib/rouge/lexers/email.rb +39 -0
  36. data/lib/rouge/lexers/ghc_core.rb +2 -1
  37. data/lib/rouge/lexers/graphql.rb +1 -1
  38. data/lib/rouge/lexers/hack.rb +1 -1
  39. data/lib/rouge/lexers/haskell.rb +27 -19
  40. data/lib/rouge/lexers/hlsl.rb +166 -0
  41. data/lib/rouge/lexers/html.rb +7 -7
  42. data/lib/rouge/lexers/http.rb +8 -2
  43. data/lib/rouge/lexers/isbl.rb +2 -2
  44. data/lib/rouge/lexers/j.rb +244 -0
  45. data/lib/rouge/lexers/janet.rb +218 -0
  46. data/lib/rouge/lexers/javascript.rb +11 -5
  47. data/lib/rouge/lexers/jinja.rb +22 -7
  48. data/lib/rouge/lexers/jsl.rb +20 -8
  49. data/lib/rouge/lexers/jsonnet.rb +4 -3
  50. data/lib/rouge/lexers/jsp.rb +2 -3
  51. data/lib/rouge/lexers/jsx.rb +47 -59
  52. data/lib/rouge/lexers/julia.rb +4 -2
  53. data/lib/rouge/lexers/kotlin.rb +8 -4
  54. data/lib/rouge/lexers/livescript.rb +310 -0
  55. data/lib/rouge/lexers/ocaml/common.rb +1 -1
  56. data/lib/rouge/lexers/ocl.rb +85 -0
  57. data/lib/rouge/lexers/opentype_feature_file.rb +26 -42
  58. data/lib/rouge/lexers/perl.rb +27 -7
  59. data/lib/rouge/lexers/php.rb +274 -128
  60. data/lib/rouge/lexers/postscript.rb +93 -0
  61. data/lib/rouge/lexers/powershell.rb +44 -32
  62. data/lib/rouge/lexers/python.rb +1 -1
  63. data/lib/rouge/lexers/q.rb +1 -1
  64. data/lib/rouge/lexers/reasonml.rb +6 -5
  65. data/lib/rouge/lexers/rego.rb +27 -12
  66. data/lib/rouge/lexers/rescript.rb +119 -0
  67. data/lib/rouge/lexers/ruby.rb +1 -1
  68. data/lib/rouge/lexers/rust.rb +6 -3
  69. data/lib/rouge/lexers/sass/common.rb +1 -0
  70. data/lib/rouge/lexers/smarty.rb +1 -1
  71. data/lib/rouge/lexers/ssh.rb +33 -0
  72. data/lib/rouge/lexers/systemd.rb +34 -0
  73. data/lib/rouge/lexers/tsx.rb +10 -3
  74. data/lib/rouge/lexers/twig.rb +4 -4
  75. data/lib/rouge/lexers/typescript.rb +1 -12
  76. data/lib/rouge/lexers/typescript/common.rb +18 -4
  77. data/lib/rouge/lexers/velocity.rb +71 -0
  78. data/lib/rouge/lexers/wollok.rb +0 -1
  79. data/lib/rouge/lexers/xml.rb +5 -3
  80. data/lib/rouge/lexers/yaml.rb +5 -3
  81. data/lib/rouge/lexers/zig.rb +139 -0
  82. data/lib/rouge/regex_lexer.rb +56 -1
  83. data/lib/rouge/themes/base16.rb +1 -0
  84. data/lib/rouge/themes/bw.rb +1 -0
  85. data/lib/rouge/themes/colorful.rb +1 -0
  86. data/lib/rouge/themes/github.rb +1 -0
  87. data/lib/rouge/themes/gruvbox.rb +2 -0
  88. data/lib/rouge/themes/igor_pro.rb +1 -0
  89. data/lib/rouge/themes/magritte.rb +1 -0
  90. data/lib/rouge/themes/monokai.rb +1 -0
  91. data/lib/rouge/themes/pastie.rb +1 -0
  92. data/lib/rouge/themes/thankful_eyes.rb +1 -0
  93. data/lib/rouge/themes/tulip.rb +1 -0
  94. data/lib/rouge/version.rb +1 -1
  95. metadata +33 -2
@@ -374,7 +374,7 @@ module Rouge
374
374
  end
375
375
 
376
376
  state :method_call do
377
- rule %r(/) do
377
+ rule %r(/|%) do
378
378
  token Operator
379
379
  goto :expr_start
380
380
  end
@@ -22,8 +22,8 @@ module Rouge
22
22
 
23
23
  def self.keywords
24
24
  @keywords ||= %w(
25
- as assert async await break const copy do drop else enum extern fail false
26
- fn for if impl let log loop match mod move mut priv pub pure
25
+ as assert async await break const continue copy do drop else enum extern
26
+ fail false fn for if impl let log loop match mod move mut priv pub pure
27
27
  ref return self static struct true trait type unsafe use where
28
28
  while box
29
29
  )
@@ -99,7 +99,9 @@ module Rouge
99
99
  rule %r/[*\/!@~&+%^<>=\?-]|\.{2,3}/, Operator
100
100
 
101
101
  rule %r/([.]\s*)?#{id}(?=\s*[(])/m, Name::Function
102
+ rule %r/[.]\s*await\b/, Keyword
102
103
  rule %r/[.]\s*#{id}/, Name::Property
104
+ rule %r/[.]\s*\d+/, Name::Attribute
103
105
  rule %r/(#{id})(::)/m do
104
106
  groups Name::Namespace, Punctuation
105
107
  end
@@ -167,7 +169,7 @@ module Rouge
167
169
  flt = /f32|f64/
168
170
 
169
171
  rule %r(
170
- [0-9]+
172
+ [0-9_]+
171
173
  (#{dot} #{exp}? #{flt}?
172
174
  |#{dot}? #{exp} #{flt}?
173
175
  |#{dot}? #{exp}? #{flt}
@@ -177,6 +179,7 @@ module Rouge
177
179
  rule %r(
178
180
  ( 0b[10_]+
179
181
  | 0x[0-9a-fA-F_]+
182
+ | 0o[0-7]+
180
183
  | [0-9_]+
181
184
  ) (u#{size}?|i#{size})?
182
185
  )x, Num::Integer
@@ -29,6 +29,7 @@ module Rouge
29
29
  end
30
30
 
31
31
  rule %r/@#{id}/, Keyword, :selector
32
+ rule %r/&/, Keyword, :selector
32
33
 
33
34
  # $variable: assignment
34
35
  rule %r/([$]#{id})([ \t]*)(:)/ do
@@ -41,7 +41,7 @@ module Rouge
41
41
  end
42
42
 
43
43
 
44
- rule(/.*?(?={[\/a-zA-Z0-9$#*"'])|.*/m) { delegate parent }
44
+ rule(/.+?(?={[\/a-zA-Z0-9$#*"'])/m) { delegate parent }
45
45
  rule(/.+/m) { delegate parent }
46
46
  end
47
47
 
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class SSH < RegexLexer
7
+ tag 'ssh'
8
+
9
+ title "SSH Config File"
10
+ desc 'A lexer for SSH configuration files'
11
+ filenames 'ssh_config'
12
+
13
+ state :root do
14
+ rule %r/[a-z0-9]+/i, Keyword, :statement
15
+ mixin :base
16
+ end
17
+
18
+ state :statement do
19
+ rule %r/\n/, Text, :pop!
20
+ rule %r/(?:yes|no|confirm|ask|always|auto|none|force)\b/, Name::Constant
21
+
22
+ rule %r/\d+/, Num
23
+ rule %r/[^#\s;{}$\\]+/, Text
24
+ mixin :base
25
+ end
26
+
27
+ state :base do
28
+ rule %r/\s+/, Text
29
+ rule %r/#.*/, Comment::Single
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class SystemD < RegexLexer
7
+ tag 'systemd'
8
+ aliases 'unit-file'
9
+ filenames '*.service'
10
+ mimetypes 'text/x-systemd-unit'
11
+ desc 'A lexer for systemd unit files'
12
+
13
+ state :root do
14
+ rule %r/\s+/, Text
15
+ rule %r/[;#].*/, Comment
16
+ rule %r/\[.*?\]$/, Keyword
17
+ rule %r/(.*?)(=)(.*)(\\\n)/ do
18
+ groups Name::Tag, Punctuation, Text, Str::Escape
19
+ push :continuation
20
+ end
21
+ rule %r/(.*?)(=)(.*)/ do
22
+ groups Name::Tag, Punctuation, Text
23
+ end
24
+ end
25
+
26
+ state :continuation do
27
+ rule %r/(.*?)(\\\n)/ do
28
+ groups Text, Str::Escape
29
+ end
30
+ rule %r/(.*)'/, Text, :pop!
31
+ end
32
+ end
33
+ end
34
+ end
@@ -7,13 +7,20 @@ module Rouge
7
7
  load_lexer 'typescript/common.rb'
8
8
 
9
9
  class TSX < JSX
10
- include TypescriptCommon
10
+ extend TypescriptCommon
11
11
 
12
- title 'TypeScript'
13
- desc 'tsx'
12
+ title 'TSX'
13
+ desc 'TypeScript-compatible JSX (www.typescriptlang.org/docs/handbook/jsx.html)'
14
14
 
15
15
  tag 'tsx'
16
16
  filenames '*.tsx'
17
+
18
+ prepend :element_name do
19
+ rule %r/(\w+)(,)/ do
20
+ groups Name::Other, Punctuation
21
+ pop! 3
22
+ end
23
+ end
17
24
  end
18
25
  end
19
26
  end
@@ -17,10 +17,10 @@ module Rouge
17
17
 
18
18
  def self.keywords
19
19
  @@keywords ||= %w(as do extends flush from import include use else starts
20
- ends with without autoescape endautoescape block endblock
21
- embed endembed filter endfilter for endfor if endif
22
- macro endmacro sandbox endsandbox set endset
23
- spaceless endspaceless verbatim endverbatim)
20
+ ends with without autoescape endautoescape block
21
+ endblock embed endembed filter endfilter for endfor
22
+ if endif macro endmacro sandbox endsandbox set endset
23
+ spaceless endspaceless)
24
24
  end
25
25
 
26
26
  def self.tests
@@ -7,7 +7,7 @@ module Rouge
7
7
  load_lexer 'typescript/common.rb'
8
8
 
9
9
  class Typescript < Javascript
10
- include TypescriptCommon
10
+ extend TypescriptCommon
11
11
 
12
12
  title "TypeScript"
13
13
  desc "TypeScript, a superset of JavaScript"
@@ -18,17 +18,6 @@ module Rouge
18
18
  filenames '*.ts', '*.d.ts'
19
19
 
20
20
  mimetypes 'text/typescript'
21
-
22
- prepend :root do
23
- rule %r/[?][.]/, Punctuation
24
- end
25
-
26
- prepend :statement do
27
- rule %r/(#{Javascript.id_regex})(\??)(\s*)(:)/ do
28
- groups Name::Label, Punctuation, Text, Punctuation
29
- push :expr_start
30
- end
31
- end
32
21
  end
33
22
  end
34
23
  end
@@ -4,31 +4,45 @@
4
4
  module Rouge
5
5
  module Lexers
6
6
  module TypescriptCommon
7
- def self.keywords
7
+ def keywords
8
8
  @keywords ||= super + Set.new(%w(
9
9
  is namespace static private protected public
10
10
  implements readonly
11
11
  ))
12
12
  end
13
13
 
14
- def self.declarations
14
+ def declarations
15
15
  @declarations ||= super + Set.new(%w(
16
16
  type abstract
17
17
  ))
18
18
  end
19
19
 
20
- def self.reserved
20
+ def reserved
21
21
  @reserved ||= super + Set.new(%w(
22
22
  string any void number namespace module
23
23
  declare default interface keyof
24
24
  ))
25
25
  end
26
26
 
27
- def self.builtins
27
+ def builtins
28
28
  @builtins ||= super + %w(
29
29
  Pick Partial Readonly Record
30
30
  )
31
31
  end
32
+
33
+ def self.extended(base)
34
+ base.prepend :root do
35
+ rule %r/[?][.]/, base::Punctuation
36
+ rule %r/[?]{2}/, base::Operator
37
+ end
38
+
39
+ base.prepend :statement do
40
+ rule %r/(#{Javascript.id_regex})(\??)(\s*)(:)/ do
41
+ groups base::Name::Label, base::Punctuation, base::Text, base::Punctuation
42
+ push :expr_start
43
+ end
44
+ end
45
+ end
32
46
  end
33
47
  end
34
48
  end
@@ -0,0 +1,71 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Velocity < TemplateLexer
6
+ title 'Velocity'
7
+ desc 'Velocity is a Java-based template engine (velocity.apache.org)'
8
+ tag 'velocity'
9
+ filenames '*.vm', '*.velocity', '*.fhtml'
10
+ mimetypes 'text/html+velocity'
11
+
12
+ id = /[a-z_]\w*/i
13
+
14
+ state :root do
15
+ rule %r/[^{#$]+/ do
16
+ delegate parent
17
+ end
18
+
19
+ rule %r/(#)(\*.*?\*)(#)/m, Comment::Multiline
20
+ rule %r/(##)(.*?$)/, Comment::Single
21
+
22
+ rule %r/(#\{?)(#{id})(\}?)(\s?\()/m do
23
+ groups Punctuation, Name::Function, Punctuation, Punctuation
24
+ push :directive_params
25
+ end
26
+
27
+ rule %r/(#\{?)(#{id})(\}|\b)/m do
28
+ groups Punctuation, Name::Function, Punctuation
29
+ end
30
+
31
+ rule %r/\$\{?/, Punctuation, :variable
32
+ end
33
+
34
+ state :variable do
35
+ rule %r/#{id}/, Name::Variable
36
+ rule %r/\(/, Punctuation, :func_params
37
+ rule %r/(\.)(#{id})/ do
38
+ groups Punctuation, Name::Variable
39
+ end
40
+ rule %r/\}/, Punctuation, :pop!
41
+ rule(//) { pop! }
42
+ end
43
+
44
+ state :directive_params do
45
+ rule %r/(&&|\|\||==?|!=?|[-<>+*%&|^\/])|\b(eq|ne|gt|lt|ge|le|not|in)\b/, Operator
46
+ rule %r/\[/, Operator, :range_operator
47
+ rule %r/\b#{id}\b/, Name::Function
48
+ mixin :func_params
49
+ end
50
+
51
+ state :range_operator do
52
+ rule %r/[.]{2}/, Operator
53
+ mixin :func_params
54
+ rule %r/\]/, Operator, :pop!
55
+ end
56
+
57
+ state :func_params do
58
+ rule %r/\$\{?/, Punctuation, :variable
59
+ rule %r/\s+/, Text
60
+ rule %r/,/, Punctuation
61
+ rule %r/"(\\\\|\\"|[^"])*"/, Str::Double
62
+ rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
63
+ rule %r/0[xX][0-9a-fA-F]+[Ll]?/, Num::Hex
64
+ rule %r/\b[0-9]+\b/, Num::Integer
65
+ rule %r/(true|false|null)\b/, Keyword::Constant
66
+ rule %r/[(\[]/, Punctuation, :push
67
+ rule %r/[)\]}]/, Punctuation, :pop!
68
+ end
69
+ end
70
+ end
71
+ end
@@ -18,7 +18,6 @@ module Rouge
18
18
 
19
19
  state :whitespaces_and_comments do
20
20
  rule %r/\s+/m, Text::Whitespace
21
- rule %r/$+/m, Text::Whitespace
22
21
  rule %r(//.*$), Comment::Single
23
22
  rule %r(/\*(.|\s)*?\*/)m, Comment::Multiline
24
23
  end
@@ -12,6 +12,8 @@ module Rouge
12
12
  mimetypes 'text/xml', 'application/xml', 'image/svg+xml',
13
13
  'application/rss+xml', 'application/atom+xml'
14
14
 
15
+ # Documentation: https://www.w3.org/TR/xml11/#charsets and https://www.w3.org/TR/xml11/#sec-suggested-names
16
+
15
17
  def self.detect?(text)
16
18
  return false if text.doctype?(/html/)
17
19
  return true if text =~ /\A<\?xml\b/
@@ -27,10 +29,10 @@ module Rouge
27
29
  rule %r/<![^>]*>/, Comment::Preproc
28
30
 
29
31
  # open tags
30
- rule %r(<\s*[\w:.-]+)m, Name::Tag, :tag
32
+ rule %r(<\s*[\p{L}:_][\p{Word}\p{Cf}:.·-]*)m, Name::Tag, :tag
31
33
 
32
34
  # self-closing tags
33
- rule %r(<\s*/\s*[\w:.-]+\s*>)m, Name::Tag
35
+ rule %r(<\s*/\s*[\p{L}:_][\p{Word}\p{Cf}:.·-]*\s*>)m, Name::Tag
34
36
  end
35
37
 
36
38
  state :comment do
@@ -41,7 +43,7 @@ module Rouge
41
43
 
42
44
  state :tag do
43
45
  rule %r/\s+/m, Text
44
- rule %r/[\w.:-]+\s*=/m, Name::Attribute, :attr
46
+ rule %r/[\p{L}:_][\p{Word}\p{Cf}:.·-]*\s*=/m, Name::Attribute, :attr
45
47
  rule %r(/?\s*>), Name::Tag, :pop!
46
48
  end
47
49
 
@@ -11,6 +11,8 @@ module Rouge
11
11
  aliases 'yml'
12
12
  filenames '*.yaml', '*.yml'
13
13
 
14
+ # Documentation: https://yaml.org/spec/1.2/spec.html
15
+
14
16
  def self.detect?(text)
15
17
  # look for the %YAML directive
16
18
  return true if text =~ /\A\s*%YAML/m
@@ -165,15 +167,15 @@ module Rouge
165
167
  )x, Keyword::Type
166
168
 
167
169
  # an anchor
168
- rule %r/&[\w-]+/, Name::Label
170
+ rule %r/&[\p{L}\p{Nl}\p{Nd}_-]+/, Name::Label
169
171
 
170
172
  # an alias
171
- rule %r/\*[\w-]+/, Name::Variable
173
+ rule %r/\*[\p{L}\p{Nl}\p{Nd}_-]+/, Name::Variable
172
174
  end
173
175
 
174
176
  state :block_nodes do
175
177
  # implicit key
176
- rule %r/((?:\w[\w -]*)?)(:)(?=\s|$)/ do |m|
178
+ rule %r/((?:[\p{L}\p{Nl}\p{Nd}_][\p{L}\p{Nl}\p{Nd}\p{Blank}_-]*)?)(:)(?=\s|$)/ do |m|
177
179
  groups Name::Attribute, Punctuation::Indicator
178
180
  set_indent m[0], :implicit => true
179
181
  end
@@ -0,0 +1,139 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Zig < RegexLexer
7
+ tag 'zig'
8
+ aliases 'zir'
9
+ filenames '*.zig'
10
+ mimetypes 'text/x-zig'
11
+
12
+ title 'Zig'
13
+ desc 'The Zig programming language (ziglang.org)'
14
+
15
+ def self.keywords
16
+ @keywords ||= %w(
17
+ align linksection threadlocal struct enum union error break return
18
+ anyframe fn c_longlong c_ulonglong c_longdouble c_void comptime_float
19
+ c_short c_ushort c_int c_uint c_long c_ulong continue asm defer
20
+ errdefer const var extern packed export pub if else switch and or
21
+ orelse while for bool unreachable try catch async suspend nosuspend
22
+ await resume undefined usingnamespace test void noreturn type
23
+ anyerror usize noalias inline noinline comptime callconv volatile
24
+ allowzero
25
+ )
26
+ end
27
+
28
+ def self.builtins
29
+ @builtins ||= %w(
30
+ @addWithOverflow @as @atomicLoad @atomicStore @bitCast @breakpoint
31
+ @alignCast @alignOf @cDefine @cImport @cInclude @bitOffsetOf
32
+ @atomicRmw @bytesToSlice @byteOffsetOf @OpaqueType @panic @ptrCast
33
+ @bitReverse @Vector @sin @cUndef @canImplicitCast @clz @cmpxchgWeak
34
+ @cmpxchgStrong @compileError @compileLog @ctz @popCount @divExact
35
+ @divFloor @cos @divTrunc @embedFile @export @tagName @TagType
36
+ @errorName @call @errorReturnTrace @fence @fieldParentPtr @field
37
+ @unionInit @errorToInt @intToEnum @enumToInt @setAlignStack @frame
38
+ @Frame @exp @exp2 @log @log2 @log10 @fabs @floor @ceil @trunc @round
39
+ @floatCast @intToFloat @floatToInt @boolToInt @errSetCast @intToError
40
+ @frameAddress @import @newStackCall @asyncCall @intToPtr @intCast
41
+ @frameSize @memcpy @memset @mod @mulWithOverflow @splat @ptrToInt
42
+ @rem @returnAddress @setCold @Type @shuffle @setGlobalLinkage
43
+ @setGlobalSection @shlExact @This @hasDecl @hasField
44
+ @setRuntimeSafety @setEvalBranchQuota @setFloatMode @shlWithOverflow
45
+ @shrExact @sizeOf @bitSizeOf @sqrt @byteSwap @subWithOverflow
46
+ @sliceToBytes comptime_int @truncate @typeInfo @typeName @TypeOf
47
+ )
48
+ end
49
+
50
+ id = /[a-z_]\w*/i
51
+ escapes = /\\ ([nrt'"\\0] | x\h{2} | u\h{4} | U\h{8})/x
52
+
53
+ state :bol do
54
+ mixin :whitespace
55
+ rule %r/#\s[^\n]*/, Comment::Special
56
+ rule(//) { pop! }
57
+ end
58
+
59
+ state :attribute do
60
+ mixin :whitespace
61
+ mixin :literals
62
+ rule %r/[(,)=:]/, Name::Decorator
63
+ rule %r/\]/, Name::Decorator, :pop!
64
+ rule id, Name::Decorator
65
+ end
66
+
67
+ state :whitespace do
68
+ rule %r/\s+/, Text
69
+ rule %r(//[^\n]*), Comment
70
+ end
71
+
72
+ state :root do
73
+ rule %r/\n/, Text, :bol
74
+
75
+ mixin :whitespace
76
+
77
+ rule %r/\b(?:(i|u)[0-9]+)\b/, Keyword::Type
78
+ rule %r/\b(?:f(16|32|64|128))\b/, Keyword::Type
79
+ rule %r/\b(?:(isize|usize))\b/, Keyword::Type
80
+
81
+ mixin :literals
82
+
83
+ rule %r/'#{id}/, Name::Variable
84
+ rule %r/([.]?)(\s*)(@?#{id})(\s*)([(]?)/ do |m|
85
+ name = m[3]
86
+ t = if self.class.keywords.include? name
87
+ Keyword
88
+ elsif self.class.builtins.include? name
89
+ Name::Builtin
90
+ elsif !m[1].empty? && !m[5].empty?
91
+ Name::Function
92
+ elsif !m[1].empty?
93
+ Name::Property
94
+ else
95
+ Name
96
+ end
97
+
98
+ groups Punctuation, Text, t, Text, Punctuation
99
+ end
100
+
101
+ rule %r/[()\[\]{}|,:;]/, Punctuation
102
+ rule %r/[*\/!@~&+%^<>=\?-]|\.{1,3}/, Operator
103
+ end
104
+
105
+ state :literals do
106
+ rule %r/\b(?:true|false|null)\b/, Keyword::Constant
107
+ rule %r(
108
+ ' (?: #{escapes} | [^\\] ) '
109
+ )x, Str::Char
110
+
111
+ rule %r/"/, Str, :string
112
+ rule %r/r(#*)".*?"\1/m, Str
113
+
114
+ dot = /[.][0-9_]+/
115
+ exp = /e[-+]?[0-9_]+/
116
+
117
+ rule %r(
118
+ [0-9]+
119
+ (#{dot} #{exp}?
120
+ |#{dot}? #{exp}
121
+ )
122
+ )x, Num::Float
123
+
124
+ rule %r(
125
+ ( 0b[10_]+
126
+ | 0x[0-9a-fA-F_]+
127
+ | [0-9_]+
128
+ )
129
+ )x, Num::Integer
130
+ end
131
+
132
+ state :string do
133
+ rule %r/"/, Str, :pop!
134
+ rule escapes, Str::Escape
135
+ rule %r/[^"\\]+/m, Str
136
+ end
137
+ end
138
+ end
139
+ end