rugments 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +52 -0
  3. data/README.md +195 -0
  4. data/bin/rugmentize +6 -0
  5. data/lib/rugments/cli.rb +357 -0
  6. data/lib/rugments/formatter.rb +29 -0
  7. data/lib/rugments/formatters/html.rb +142 -0
  8. data/lib/rugments/formatters/null.rb +17 -0
  9. data/lib/rugments/formatters/terminal256.rb +174 -0
  10. data/lib/rugments/lexer.rb +431 -0
  11. data/lib/rugments/lexers/apache/keywords.yml +453 -0
  12. data/lib/rugments/lexers/apache.rb +67 -0
  13. data/lib/rugments/lexers/apple_script.rb +366 -0
  14. data/lib/rugments/lexers/c.rb +210 -0
  15. data/lib/rugments/lexers/clojure.rb +109 -0
  16. data/lib/rugments/lexers/coffeescript.rb +172 -0
  17. data/lib/rugments/lexers/common_lisp.rb +343 -0
  18. data/lib/rugments/lexers/conf.rb +22 -0
  19. data/lib/rugments/lexers/cpp.rb +63 -0
  20. data/lib/rugments/lexers/csharp.rb +85 -0
  21. data/lib/rugments/lexers/css.rb +269 -0
  22. data/lib/rugments/lexers/dart.rb +102 -0
  23. data/lib/rugments/lexers/diff.rb +39 -0
  24. data/lib/rugments/lexers/elixir.rb +105 -0
  25. data/lib/rugments/lexers/erb.rb +54 -0
  26. data/lib/rugments/lexers/erlang.rb +116 -0
  27. data/lib/rugments/lexers/factor.rb +300 -0
  28. data/lib/rugments/lexers/gherkin/keywords.rb +13 -0
  29. data/lib/rugments/lexers/gherkin.rb +135 -0
  30. data/lib/rugments/lexers/go.rb +176 -0
  31. data/lib/rugments/lexers/groovy.rb +102 -0
  32. data/lib/rugments/lexers/haml.rb +226 -0
  33. data/lib/rugments/lexers/handlebars.rb +77 -0
  34. data/lib/rugments/lexers/haskell.rb +181 -0
  35. data/lib/rugments/lexers/html.rb +92 -0
  36. data/lib/rugments/lexers/http.rb +78 -0
  37. data/lib/rugments/lexers/ini.rb +55 -0
  38. data/lib/rugments/lexers/io.rb +66 -0
  39. data/lib/rugments/lexers/java.rb +74 -0
  40. data/lib/rugments/lexers/javascript.rb +258 -0
  41. data/lib/rugments/lexers/literate_coffeescript.rb +31 -0
  42. data/lib/rugments/lexers/literate_haskell.rb +34 -0
  43. data/lib/rugments/lexers/llvm.rb +82 -0
  44. data/lib/rugments/lexers/lua/builtins.rb +21 -0
  45. data/lib/rugments/lexers/lua.rb +120 -0
  46. data/lib/rugments/lexers/make.rb +114 -0
  47. data/lib/rugments/lexers/markdown.rb +151 -0
  48. data/lib/rugments/lexers/matlab/builtins.rb +10 -0
  49. data/lib/rugments/lexers/matlab.rb +70 -0
  50. data/lib/rugments/lexers/moonscript.rb +108 -0
  51. data/lib/rugments/lexers/nginx.rb +69 -0
  52. data/lib/rugments/lexers/nim.rb +149 -0
  53. data/lib/rugments/lexers/objective_c.rb +188 -0
  54. data/lib/rugments/lexers/ocaml.rb +109 -0
  55. data/lib/rugments/lexers/perl.rb +195 -0
  56. data/lib/rugments/lexers/php/builtins.rb +192 -0
  57. data/lib/rugments/lexers/php.rb +162 -0
  58. data/lib/rugments/lexers/plain_text.rb +23 -0
  59. data/lib/rugments/lexers/prolog.rb +62 -0
  60. data/lib/rugments/lexers/properties.rb +53 -0
  61. data/lib/rugments/lexers/puppet.rb +126 -0
  62. data/lib/rugments/lexers/python.rb +225 -0
  63. data/lib/rugments/lexers/qml.rb +70 -0
  64. data/lib/rugments/lexers/r.rb +55 -0
  65. data/lib/rugments/lexers/racket.rb +540 -0
  66. data/lib/rugments/lexers/ruby.rb +413 -0
  67. data/lib/rugments/lexers/rust.rb +188 -0
  68. data/lib/rugments/lexers/sass/common.rb +172 -0
  69. data/lib/rugments/lexers/sass.rb +72 -0
  70. data/lib/rugments/lexers/scala.rb +140 -0
  71. data/lib/rugments/lexers/scheme.rb +109 -0
  72. data/lib/rugments/lexers/scss.rb +32 -0
  73. data/lib/rugments/lexers/sed.rb +167 -0
  74. data/lib/rugments/lexers/shell.rb +150 -0
  75. data/lib/rugments/lexers/slim.rb +222 -0
  76. data/lib/rugments/lexers/smalltalk.rb +114 -0
  77. data/lib/rugments/lexers/sml.rb +345 -0
  78. data/lib/rugments/lexers/sql.rb +138 -0
  79. data/lib/rugments/lexers/swift.rb +153 -0
  80. data/lib/rugments/lexers/tcl.rb +189 -0
  81. data/lib/rugments/lexers/tex.rb +70 -0
  82. data/lib/rugments/lexers/toml.rb +68 -0
  83. data/lib/rugments/lexers/vb.rb +162 -0
  84. data/lib/rugments/lexers/viml/keywords.rb +11 -0
  85. data/lib/rugments/lexers/viml.rb +99 -0
  86. data/lib/rugments/lexers/xml.rb +57 -0
  87. data/lib/rugments/lexers/yaml.rb +362 -0
  88. data/lib/rugments/plugins/redcarpet.rb +28 -0
  89. data/lib/rugments/regex_lexer.rb +432 -0
  90. data/lib/rugments/template_lexer.rb +23 -0
  91. data/lib/rugments/text_analyzer.rb +46 -0
  92. data/lib/rugments/theme.rb +202 -0
  93. data/lib/rugments/themes/base16.rb +128 -0
  94. data/lib/rugments/themes/colorful.rb +65 -0
  95. data/lib/rugments/themes/github.rb +69 -0
  96. data/lib/rugments/themes/monokai.rb +88 -0
  97. data/lib/rugments/themes/monokai_sublime.rb +89 -0
  98. data/lib/rugments/themes/thankful_eyes.rb +69 -0
  99. data/lib/rugments/token.rb +180 -0
  100. data/lib/rugments/util.rb +99 -0
  101. data/lib/rugments/version.rb +3 -0
  102. data/lib/rugments.rb +33 -0
  103. metadata +149 -0
@@ -0,0 +1,188 @@
1
+ module Rugments
2
+ module Lexers
3
+ load_const :C, 'c.rb'
4
+
5
+ class ObjectiveC < C
6
+ tag 'objective_c'
7
+ title 'Objective-C'
8
+ desc 'an extension of C commonly used to write Apple software'
9
+ aliases 'objc'
10
+ filenames '*.m', '*.h'
11
+
12
+ mimetypes 'text/x-objective_c', 'application/x-objective_c'
13
+
14
+ def self.at_keywords
15
+ @at_keywords ||= %w(
16
+ selector private protected public encode synchronized try
17
+ throw catch finally end property synthesize dynamic optional
18
+ interface implementation import
19
+ )
20
+ end
21
+
22
+ def self.at_builtins
23
+ @at_builtins ||= %w(true false YES NO)
24
+ end
25
+
26
+ def self.builtins
27
+ @builtins ||= %w(YES NO nil)
28
+ end
29
+
30
+ def self.analyze_text(text)
31
+ return 1 if text =~ /@(end|implementation|protocol|property)\b/
32
+
33
+ id = /[a-z$_][a-z0-9$_]*/i
34
+ return 0.4 if text =~ %r{
35
+ \[ \s* #{id} \s+
36
+ (?:
37
+ #{id} \s* \]
38
+ | #{id}? :
39
+ )
40
+ }x
41
+ return 0.4 if text.include? '@"'
42
+ end
43
+
44
+ id = /[a-z$_][a-z0-9$_]*/i
45
+
46
+ prepend :statements do
47
+ rule /@"/, Str, :string
48
+ rule /@'(\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|\\.|[^\\'\n]')/,
49
+ Str::Char
50
+ rule /@(\d+[.]\d*|[.]\d+|\d+)e[+-]?\d+l?/i,
51
+ Num::Float
52
+ rule /@(\d+[.]\d*|[.]\d+|\d+f)f?/i, Num::Float
53
+ rule /@0x\h+[lL]?/, Num::Hex
54
+ rule /@0[0-7]+l?/i, Num::Oct
55
+ rule /@\d+l?/, Num::Integer
56
+ rule /\bin\b/, Keyword
57
+
58
+ rule /@(?:interface|implementation)\b/ do
59
+ token Keyword
60
+ goto :classname
61
+ end
62
+
63
+ rule /@(?:class|protocol)\b/ do
64
+ token Keyword
65
+ goto :forward_classname
66
+ end
67
+
68
+ rule /@([[:alnum:]]+)/ do |m|
69
+ if self.class.at_keywords.include? m[1]
70
+ token Keyword
71
+ elsif self.class.at_builtins.include? m[1]
72
+ token Name::Builtin
73
+ else
74
+ token Error
75
+ end
76
+ end
77
+
78
+ rule /[?]/, Punctuation, :ternary
79
+ rule /\[/, Punctuation, :message
80
+ end
81
+
82
+ state :ternary do
83
+ rule /:/, Punctuation, :pop!
84
+ mixin :statements
85
+ end
86
+
87
+ state :message_shared do
88
+ rule /\]/, Punctuation, :pop!
89
+ rule /;/, Error
90
+
91
+ mixin :statement
92
+ end
93
+
94
+ state :message do
95
+ rule /(#{id})(\s*)(:)/ do
96
+ groups(Name::Function, Text, Punctuation)
97
+ goto :message_with_args
98
+ end
99
+
100
+ rule /(#{id})(\s*)(\])/ do
101
+ groups(Name::Function, Text, Punctuation)
102
+ pop!
103
+ end
104
+
105
+ mixin :message_shared
106
+ end
107
+
108
+ state :message_with_args do
109
+ rule /(#{id})(\s*)(:)/ do
110
+ groups(Name::Function, Text, Punctuation)
111
+ end
112
+
113
+ mixin :message_shared
114
+ end
115
+
116
+ state :classname do
117
+ mixin :whitespace
118
+
119
+ rule /(#{id})(\s*)(:)(\s*)(#{id})/ do
120
+ groups(Name::Class, Text,
121
+ Punctuation, Text,
122
+ Name::Class)
123
+ pop!
124
+ end
125
+
126
+ rule /(#{id})(\s*)([(])(\s*)(#{id})(\s*)([)])/ do
127
+ groups(Name::Class, Text,
128
+ Punctuation, Text,
129
+ Name::Label, Text,
130
+ Punctuation)
131
+ end
132
+
133
+ rule id, Name::Class, :pop!
134
+ end
135
+
136
+ state :forward_classname do
137
+ mixin :whitespace
138
+
139
+ rule /(#{id})(\s*)(,)(\s*)/ do
140
+ groups(Name::Class, Text, Punctuation, Text)
141
+ push
142
+ end
143
+
144
+ rule /(#{id})(\s*)(;?)/ do
145
+ groups(Name::Class, Text, Punctuation)
146
+ pop!
147
+ end
148
+ end
149
+
150
+ prepend :root do
151
+ rule %r{
152
+ ([-+])(\s*)
153
+ ([(].*?[)])?(\s*)
154
+ (?=#{id}:?)
155
+ }ix do |m|
156
+ token Keyword, m[1]; token Text, m[2]
157
+ recurse m[3]; token Text, m[4]
158
+ push :method_definition
159
+ end
160
+ end
161
+
162
+ state :method_definition do
163
+ rule /,/, Punctuation
164
+ rule /[.][.][.]/, Punctuation
165
+ rule /([(].*?[)])(#{id})/ do |m|
166
+ recurse m[1]; token Name::Variable, m[2]
167
+ end
168
+
169
+ rule /(#{id})(\s*)(:)/m do
170
+ groups(Name::Function, Text, Punctuation)
171
+ end
172
+
173
+ rule /;/, Punctuation, :pop!
174
+
175
+ rule /{/ do
176
+ token Punctuation
177
+ goto :function
178
+ end
179
+
180
+ mixin :inline_whitespace
181
+ rule %r{//.*?\n}, Comment::Single
182
+ rule /\s+/m, Text
183
+
184
+ rule(//) { pop! }
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,109 @@
1
+ module Rugments
2
+ module Lexers
3
+ class OCaml < RegexLexer
4
+ title 'OCaml'
5
+ desc 'Objective CAML (ocaml.org)'
6
+ tag 'ocaml'
7
+ filenames '*.ml', '*.mli', '*.mll', '*.mly'
8
+ mimetypes 'text/x-ocaml'
9
+
10
+ def self.keywords
11
+ @keywords ||= Set.new %w(
12
+ as assert begin class constraint do done downto else end
13
+ exception external false for fun function functor if in include
14
+ inherit initializer lazy let match method module mutable new
15
+ object of open private raise rec sig struct then to true try
16
+ type value val virtual when while with
17
+ )
18
+ end
19
+
20
+ def self.keyopts
21
+ @keyopts ||= Set.new %w(
22
+ != # & && ( ) * \+ , - -. -> . .. : :: := :> ; ;; < <- =
23
+ > >] >} ? ?? [ [< [> [| ] _ ` { {< | |] } ~
24
+ )
25
+ end
26
+
27
+ def self.word_operators
28
+ @word_operators ||= Set.new %w(and asr land lor lsl lxor mod or)
29
+ end
30
+
31
+ def self.primitives
32
+ @primitives ||= Set.new %w(unit int float bool string char list array)
33
+ end
34
+
35
+ operator = %r([\[\];,{}_()!$%&*+./:<=>?@^|~#-]+)
36
+ id = /[a-z][\w']*/i
37
+ upper_id = /[A-Z][\w']*/
38
+
39
+ state :root do
40
+ rule /\s+/m, Text
41
+ rule /false|true|[(][)]|\[\]/, Name::Builtin::Pseudo
42
+ rule /#{upper_id}(?=\s*[.])/, Name::Namespace, :dotted
43
+ rule upper_id, Name::Class
44
+ rule /[(][*](?![)])/, Comment, :comment
45
+ rule id do |m|
46
+ match = m[0]
47
+ if self.class.keywords.include? match
48
+ token Keyword
49
+ elsif self.class.word_operators.include? match
50
+ token Operator::Word
51
+ elsif self.class.primitives.include? match
52
+ token Keyword::Type
53
+ else
54
+ token Name
55
+ end
56
+ end
57
+
58
+ rule operator do |m|
59
+ match = m[0]
60
+ if self.class.keyopts.include? match
61
+ token Punctuation
62
+ else
63
+ token Operator
64
+ end
65
+ end
66
+
67
+ rule /-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
68
+ rule /0x\h[\h_]*/i, Num::Hex
69
+ rule /0o[0-7][0-7_]*/i, Num::Oct
70
+ rule /0b[01][01_]*/i, Num::Bin
71
+ rule /\d[\d_]*/, Num::Integer
72
+
73
+ rule /'(?:(\\[\\"'ntbr ])|(\\[0-9]{3})|(\\x\h{2}))'/, Str::Char
74
+ rule /'[.]'/, Str::Char
75
+ rule /'/, Keyword
76
+ rule /"/, Str::Double, :string
77
+ rule /[~?]#{id}/, Name::Variable
78
+ end
79
+
80
+ state :comment do
81
+ rule /[^(*)]+/, Comment
82
+ rule(/[(][*]/) { token Comment; push }
83
+ rule /[*][)]/, Comment, :pop!
84
+ rule /[(*)]/, Comment
85
+ end
86
+
87
+ state :string do
88
+ rule /[^\\"]+/, Str::Double
89
+ mixin :escape_sequence
90
+ rule /\\\n/, Str::Double
91
+ rule /"/, Str::Double, :pop!
92
+ end
93
+
94
+ state :escape_sequence do
95
+ rule /\\[\\"'ntbr]/, Str::Escape
96
+ rule /\\\d{3}/, Str::Escape
97
+ rule /\\x\h{2}/, Str::Escape
98
+ end
99
+
100
+ state :dotted do
101
+ rule /\s+/m, Text
102
+ rule /[.]/, Punctuation
103
+ rule /#{upper_id}(?=\s*[.])/, Name::Namespace
104
+ rule upper_id, Name::Class, :pop!
105
+ rule id, Name, :pop!
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,195 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Perl < RegexLexer
4
+ title 'Perl'
5
+ desc 'The Perl scripting language (perl.org)'
6
+
7
+ tag 'perl'
8
+ aliases 'pl'
9
+
10
+ filenames '*.pl', '*.pm'
11
+ mimetypes 'text/x-perl', 'application/x-perl'
12
+
13
+ def self.analyze_text(text)
14
+ return 1 if text.shebang? 'perl'
15
+ return 0.4 if text.include? 'my $'
16
+ end
17
+
18
+ keywords = %w(
19
+ case continue do else elsif for foreach if last my next our
20
+ redo reset then unless until while use print new BEGIN CHECK
21
+ INIT END return
22
+ )
23
+
24
+ builtins = %w(
25
+ abs accept alarm atan2 bind binmode bless caller chdir chmod
26
+ chomp chop chown chr chroot close closedir connect continue cos
27
+ crypt dbmclose dbmopen defined delete die dump each endgrent
28
+ endhostent endnetent endprotoent endpwent endservent eof eval
29
+ exec exists exit exp fcntl fileno flock fork format formline getc
30
+ getgrent getgrgid getgrnam gethostbyaddr gethostbyname gethostent
31
+ getlogin getnetbyaddr getnetbyname getnetent getpeername
32
+ getpgrp getppid getpriority getprotobyname getprotobynumber
33
+ getprotoent getpwent getpwnam getpwuid getservbyname getservbyport
34
+ getservent getsockname getsockopt glob gmtime goto grep hex
35
+ import index int ioctl join keys kill last lc lcfirst length
36
+ link listen local localtime log lstat map mkdir msgctl msgget
37
+ msgrcv msgsnd my next no oct open opendir ord our pack package
38
+ pipe pop pos printf prototype push quotemeta rand read readdir
39
+ readline readlink readpipe recv redo ref rename require reverse
40
+ rewinddir rindex rmdir scalar seek seekdir select semctl semget
41
+ semop send setgrent sethostent setnetent setpgrp setpriority
42
+ setprotoent setpwent setservent setsockopt shift shmctl shmget
43
+ shmread shmwrite shutdown sin sleep socket socketpair sort splice
44
+ split sprintf sqrt srand stat study substr symlink syscall sysopen
45
+ sysread sysseek system syswrite tell telldir tie tied time times
46
+ tr truncate uc ucfirst umask undef unlink unpack unshift untie
47
+ utime values vec wait waitpid wantarray warn write
48
+ )
49
+
50
+ re_tok = Str::Regex
51
+
52
+ state :balanced_regex do
53
+ rule %r{/(\\\\|\\/|[^/])*/[egimosx]*}m, re_tok, :pop!
54
+ rule %r{!(\\\\|\\!|[^!])*![egimosx]*}m, re_tok, :pop!
55
+ rule %r{\\(\\\\|[^\\])*\\[egimosx]*}m, re_tok, :pop!
56
+ rule %r({(\\\\|\\}|[^}])*}[egimosx]*), re_tok, :pop!
57
+ 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
+ end
64
+
65
+ state :root do
66
+ rule /#.*?$/, Comment::Single
67
+ rule /^=[a-zA-Z0-9]+\s+.*?\n=cut/, Comment::Multiline
68
+ rule /(?:#{keywords.join('|')})\b/, Keyword
69
+
70
+ rule /(format)(\s+)([a-zA-Z0-9_]+)(\s*)(=)(\s*\n)/ do
71
+ groups Keyword, Text, Name, Text, Punctuation, Text
72
+
73
+ push :format
74
+ end
75
+
76
+ rule /(?:eq|lt|gt|le|ge|ne|not|and|or|cmp)\b/, Operator::Word
77
+
78
+ # common delimiters
79
+ rule %r{s/(\\\\|\\/|[^/])*/(\\\\|\\/|[^/])*/[egimosx]*}, re_tok
80
+ rule %r{s!(\\\\|\\!|[^!])*!(\\\\|\\!|[^!])*![egimosx]*}, re_tok
81
+ rule %r{s\\(\\\\|[^\\])*\\(\\\\|[^\\])*\\[egimosx]*}, re_tok
82
+ rule %r{s@(\\\\|\\@|[^@])*@(\\\\|\\@|[^@])*@[egimosx]*}, re_tok
83
+ rule %r{s%(\\\\|\\%|[^%])*%(\\\\|\\%|[^%])*%[egimosx]*}, re_tok
84
+
85
+ # balanced delimiters
86
+ rule %r(s{(\\\\|\\}|[^}])*}\s*), re_tok, :balanced_regex
87
+ rule %r{s<(\\\\|\\>|[^>])*>\s*}, re_tok, :balanced_regex
88
+ rule %r{s\[(\\\\|\\\]|[^\]])*\]\s*}, re_tok, :balanced_regex
89
+ rule %r{s\((\\\\|\\\)|[^\)])*\)\s*}, re_tok, :balanced_regex
90
+
91
+ rule %r{m?/(\\\\|\\/|[^/\n])*/[gcimosx]*}, re_tok
92
+ rule %r(m(?=[/!\\{<\[\(@%\$])), re_tok, :balanced_regex
93
+ rule %r{((?<==~)|(?<=\())\s*/(\\\\|\\/|[^/])*/[gcimosx]*},
94
+ re_tok, :balanced_regex
95
+
96
+ rule /\s+/, Text
97
+ rule /(?:#{builtins.join('|')})\b/, Name::Builtin
98
+ rule /((__(DATA|DIE|WARN)__)|(STD(IN|OUT|ERR)))\b/,
99
+ Name::Builtin::Pseudo
100
+
101
+ rule /<<([\'"]?)([a-zA-Z_][a-zA-Z0-9_]*)\1;?\n.*?\n\2\n/m, Str
102
+
103
+ rule /__END__\b/, Comment::Preproc, :end_part
104
+ rule /\$\^[ADEFHILMOPSTWX]/, Name::Variable::Global
105
+ rule /\$[\\"'\[\]&`+*.,;=%~?@$!<>(^\|\/-](?!\w)/, Name::Variable::Global
106
+ rule /[$@%#]+/, Name::Variable, :varname
107
+
108
+ rule /0_?[0-7]+(_[0-7]+)*/, Num::Oct
109
+ rule /0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*/, Num::Hex
110
+ rule /0b[01]+(_[01]+)*/, Num::Bin
111
+ rule /(\d*(_\d*)*\.\d+(_\d*)*|\d+(_\d*)*\.\d+(_\d*)*)(e[+-]?\d+)?/i,
112
+ Num::Float
113
+ rule /\d+(_\d*)*e[+-]?\d+(_\d*)*/i, Num::Float
114
+ rule /\d+(_\d+)*/, Num::Integer
115
+
116
+ rule /'(\\\\|\\'|[^'])*'/, Str
117
+ rule /"(\\\\|\\"|[^"])*"/, Str
118
+ rule /`(\\\\|\\`|[^`])*`/, Str::Backtick
119
+ rule /<([^\s>]+)>/, re_tok
120
+ rule /(q|qq|qw|qr|qx)\{/, Str::Other, :cb_string
121
+ rule /(q|qq|qw|qr|qx)\(/, Str::Other, :rb_string
122
+ rule /(q|qq|qw|qr|qx)\[/, Str::Other, :sb_string
123
+ rule /(q|qq|qw|qr|qx)</, Str::Other, :lt_string
124
+ rule /(q|qq|qw|qr|qx)([^a-zA-Z0-9])(.|\n)*?\2/, Str::Other
125
+
126
+ rule /package\s+/, Keyword, :modulename
127
+ rule /sub\s+/, Keyword, :funcname
128
+ rule /\[\]|\*\*|::|<<|>>|>=|<=|<=>|={3}|!=|=~|!~|&&?|\|\||\.{1,3}/,
129
+ Operator
130
+ rule /[-+\/*%=<>&^\|!\\~]=?/, Operator
131
+ rule /[()\[\]:;,<>\/?{}]/, Punctuation
132
+ rule(/(?=\w)/) { push :name }
133
+ end
134
+
135
+ state :format do
136
+ rule /\.\n/, Str::Interpol, :pop!
137
+ rule /.*?\n/, Str::Interpol
138
+ end
139
+
140
+ state :name_common do
141
+ rule /\w+::/, Name::Namespace
142
+ rule /[\w:]+/, Name::Variable, :pop!
143
+ end
144
+
145
+ state :varname do
146
+ rule /\s+/, Text
147
+ rule /\{/, Punctuation, :pop! # hash syntax
148
+ rule /\)|,/, Punctuation, :pop! # arg specifier
149
+ mixin :name_common
150
+ end
151
+
152
+ state :name do
153
+ mixin :name_common
154
+ rule /[A-Z_]+(?=[^a-zA-Z0-9_])/, Name::Constant, :pop!
155
+ rule(/(?=\W)/) { pop! }
156
+ end
157
+
158
+ state :modulename do
159
+ rule /[a-z_]\w*/i, Name::Namespace, :pop!
160
+ end
161
+
162
+ state :funcname do
163
+ rule /[a-zA-Z_]\w*[!?]?/, Name::Function
164
+ rule /\s+/, Text
165
+
166
+ # argument declaration
167
+ rule /(\([$@%]*\))(\s*)/ do
168
+ groups Punctuation, Text
169
+ end
170
+
171
+ rule /.*?{/, Punctuation, :pop!
172
+ rule /;/, Punctuation, :pop!
173
+ end
174
+
175
+ [[:cb, '\{', '\}'],
176
+ [:rb, '\(', '\)'],
177
+ [:sb, '\[', '\]'],
178
+ [:lt, '<', '>']].each do |name, open, close|
179
+ tok = Str::Other
180
+ state :"#{name}_string" do
181
+ rule /\\[#{open}#{close}\\]/, tok
182
+ rule /\\/, tok
183
+ rule(/#{open}/) { token tok; push }
184
+ rule /#{close}/, tok, :pop!
185
+ rule /[^#{open}#{close}\\]+/, tok
186
+ end
187
+ end
188
+
189
+ state :end_part do
190
+ # eat the rest of the stream
191
+ rule /.+/m, Comment::Preproc, :pop!
192
+ end
193
+ end
194
+ end
195
+ end