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,181 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Haskell < RegexLexer
4
+ title 'Haskell'
5
+ desc 'The Haskell programming language (haskell.org)'
6
+
7
+ tag 'haskell'
8
+ aliases 'hs'
9
+ filenames '*.hs'
10
+ mimetypes 'text/x-haskell'
11
+
12
+ def self.analyze_text(text)
13
+ return 1 if text.shebang?('runhaskell')
14
+ end
15
+
16
+ reserved = %w(
17
+ _ case class data default deriving do else if in
18
+ infix[lr]? instance let newtype of then type where
19
+ )
20
+
21
+ ascii = %w(
22
+ NUL SOH [SE]TX EOT ENQ ACK BEL BS HT LF VT FF CR S[OI] DLE
23
+ DC[1-4] NAK SYN ETB CAN EM SUB ESC [FGRU]S SP DEL
24
+ )
25
+
26
+ state :basic do
27
+ rule /\s+/m, Text
28
+ rule /{-#/, Comment::Preproc, :comment_preproc
29
+ rule /{-/, Comment::Multiline, :comment
30
+ rule /^--\s+\|.*?$/, Comment::Doc
31
+ # this is complicated in order to support custom symbols
32
+ # like -->
33
+ rule /--(?![!#\$\%&*+.\/<=>?@\^\|_~]).*?$/, Comment::Single
34
+ end
35
+
36
+ # nested commenting
37
+ state :comment do
38
+ rule /-}/, Comment::Multiline, :pop!
39
+ rule /{-/, Comment::Multiline, :comment
40
+ rule /[^-{}]+/, Comment::Multiline
41
+ rule /[-{}]/, Comment::Multiline
42
+ end
43
+
44
+ state :comment_preproc do
45
+ rule /-}/, Comment::Preproc, :pop!
46
+ rule /{-/, Comment::Preproc, :comment
47
+ rule /[^-{}]+/, Comment::Preproc
48
+ rule /[-{}]/, Comment::Preproc
49
+ end
50
+
51
+ state :root do
52
+ mixin :basic
53
+
54
+ rule /\bimport\b/, Keyword::Reserved, :import
55
+ rule /\bmodule\b/, Keyword::Reserved, :module
56
+ rule /\berror\b/, Name::Exception
57
+ rule /\b(?:#{reserved.join('|')})\b/, Keyword::Reserved
58
+ # not sure why, but ^ doesn't work here
59
+ # rule /^[_a-z][\w']*/, Name::Function
60
+ rule /[_a-z][\w']*/, Name
61
+ rule /[A-Z][\w']*/, Keyword::Type
62
+
63
+ # lambda operator
64
+ rule %r{\\(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)}, Name::Function
65
+ # special operators
66
+ rule %r{(<-|::|->|=>|=)(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)}, Operator
67
+ # constructor/type operators
68
+ rule %r{:[:!#\$\%&*+.\\/<=>?@^\|~-]*}, Operator
69
+ # other operators
70
+ rule %r{[:!#\$\%&*+.\\/<=>?@^\|~-]+}, Operator
71
+
72
+ rule /\d+e[+-]?\d+/i, Num::Float
73
+ rule /\d+\.\d+(e[+-]?\d+)?/i, Num::Float
74
+ rule /0o[0-7]+/i, Num::Oct
75
+ rule /0x[\da-f]+/i, Num::Hex
76
+ rule /\d+/, Num::Integer
77
+
78
+ rule /'/, Str::Char, :character
79
+ rule /"/, Str, :string
80
+
81
+ rule /\[\s*\]/, Keyword::Type
82
+ rule /\(\s*\)/, Name::Builtin
83
+ rule /[\[\](),;`{}]/, Punctuation
84
+ end
85
+
86
+ state :import do
87
+ rule /\s+/, Text
88
+ rule /"/, Str, :string
89
+ rule /\bqualified\b/, Keyword
90
+ # import X as Y
91
+ rule /([A-Z][\w.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)/ do
92
+ groups(
93
+ Name::Namespace, # X
94
+ Text, Keyword, # as
95
+ Text, Name # Y
96
+ )
97
+ pop!
98
+ end
99
+
100
+ # import X hiding (functions)
101
+ rule /([A-Z][\w.]*)(\s+)(hiding)(\s+)(\()/ do
102
+ groups(
103
+ Name::Namespace, # X
104
+ Text, Keyword, # hiding
105
+ Text, Punctuation # (
106
+ )
107
+ goto :funclist
108
+ end
109
+
110
+ # import X (functions)
111
+ rule /([A-Z][\w.]*)(\s+)(\()/ do
112
+ groups(
113
+ Name::Namespace, # X
114
+ Text,
115
+ Punctuation # (
116
+ )
117
+ goto :funclist
118
+ end
119
+
120
+ rule /[\w.]+/, Name::Namespace, :pop!
121
+ end
122
+
123
+ state :module do
124
+ rule /\s+/, Text
125
+ # module Foo (functions)
126
+ rule /([A-Z][\w.]*)(\s+)(\()/ do
127
+ groups Name::Namespace, Text, Punctuation
128
+ push :funclist
129
+ end
130
+
131
+ rule /\bwhere\b/, Keyword::Reserved, :pop!
132
+
133
+ rule /[A-Z][a-zA-Z0-9_.]*/, Name::Namespace, :pop!
134
+ end
135
+
136
+ state :funclist do
137
+ mixin :basic
138
+ rule /[A-Z]\w*/, Keyword::Type
139
+ rule /(_[\w\']+|[a-z][\w\']*)/, Name::Function
140
+ rule /,/, Punctuation
141
+ rule /[:!#\$\%&*+.\\\/<=>?@^\|~-]+/, Operator
142
+ rule /\(/, Punctuation, :funclist
143
+ rule /\)/, Punctuation, :pop!
144
+ end
145
+
146
+ state :character do
147
+ rule /\\/ do
148
+ token Str::Escape
149
+ push :character_end
150
+ push :escape
151
+ end
152
+
153
+ rule /./ do
154
+ token Str::Char
155
+ goto :character_end
156
+ end
157
+ end
158
+
159
+ state :character_end do
160
+ rule /'/, Str::Char, :pop!
161
+ rule /./, Error, :pop!
162
+ end
163
+
164
+ state :string do
165
+ rule /"/, Str, :pop!
166
+ rule /\\/, Str::Escape, :escape
167
+ rule /[^\\"]+/, Str
168
+ end
169
+
170
+ state :escape do
171
+ rule /[abfnrtv"'&\\]/, Str::Escape, :pop!
172
+ rule /\^[\]\[A-Z@\^_]/, Str::Escape, :pop!
173
+ rule /#{ascii.join('|')}/, Str::Escape, :pop!
174
+ rule /o[0-7]+/i, Str::Escape, :pop!
175
+ rule /x[\da-f]/i, Str::Escape, :pop!
176
+ rule /\d+/, Str::Escape, :pop!
177
+ rule /\s+\\/, Str::Escape, :pop!
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,92 @@
1
+ module Rugments
2
+ module Lexers
3
+ class HTML < RegexLexer
4
+ title 'HTML'
5
+ desc 'HTML, the markup language of the web'
6
+ tag 'html'
7
+ filenames '*.htm', '*.html', '*.xhtml'
8
+ mimetypes 'text/html', 'application/xhtml+xml'
9
+
10
+ def self.analyze_text(text)
11
+ return 1 if text.doctype?(/\bhtml\b/i)
12
+ return 1 if text =~ /<\s*html\b/
13
+ end
14
+
15
+ state :root do
16
+ rule /[^<&]+/m, Text
17
+ rule /&\S*?;/, Name::Entity
18
+ rule /<!DOCTYPE .*?>/im, Comment::Preproc
19
+ rule /<!\[CDATA\[.*?\]\]>/m, Comment::Preproc
20
+ rule /<!--/, Comment, :comment
21
+ rule /<\?.*?\?>/m, Comment::Preproc # php? really?
22
+
23
+ rule /<\s*script\s*/m do
24
+ token Name::Tag
25
+ push :script_content
26
+ push :tag
27
+ end
28
+
29
+ rule /<\s*style\s*/m do
30
+ token Name::Tag
31
+ push :style_content
32
+ push :tag
33
+ end
34
+
35
+ rule %r{<\s*[a-zA-Z0-9:-]+}, Name::Tag, :tag # opening tags
36
+ rule %r{<\s*/\s*[a-zA-Z0-9:-]+\s*>}, Name::Tag # closing tags
37
+ end
38
+
39
+ state :comment do
40
+ rule /[^-]+/, Comment
41
+ rule /-->/, Comment, :pop!
42
+ rule /-/, Comment
43
+ end
44
+
45
+ state :tag do
46
+ rule /\s+/m, Text
47
+ rule /[a-zA-Z0-9_:-]+\s*=/m, Name::Attribute, :attr
48
+ rule /[a-zA-Z0-9_:-]+/, Name::Attribute
49
+ rule %r{/?\s*>}m, Name::Tag, :pop!
50
+ end
51
+
52
+ state :attr do
53
+ # TODO: are backslash escapes valid here?
54
+ rule /"/ do
55
+ token Str
56
+ goto :dq
57
+ end
58
+
59
+ rule /'/ do
60
+ token Str
61
+ goto :sq
62
+ end
63
+
64
+ rule /[^\s>]+/, Str, :pop!
65
+ end
66
+
67
+ state :dq do
68
+ rule /"/, Str, :pop!
69
+ rule /[^"]+/, Str
70
+ end
71
+
72
+ state :sq do
73
+ rule /'/, Str, :pop!
74
+ rule /[^']+/, Str
75
+ end
76
+
77
+ state :script_content do
78
+ rule %r{<\s*/\s*script\s*>}m, Name::Tag, :pop!
79
+ rule %r{.*?(?=<\s*/\s*script\s*>)}m do
80
+ delegate Javascript
81
+ end
82
+ end
83
+
84
+ state :style_content do
85
+ rule %r{<\s*/\s*style\s*>}m, Name::Tag, :pop!
86
+ rule %r{.*(?=<\s*/\s*style\s*>)}m do
87
+ delegate CSS
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,78 @@
1
+ module Rugments
2
+ module Lexers
3
+ class HTTP < RegexLexer
4
+ tag 'http'
5
+ title 'HTTP'
6
+ desc 'http requests and responses'
7
+
8
+ def self.methods
9
+ @methods ||= %w(GET POST PUT DELETE HEAD OPTIONS TRACE PATCH)
10
+ end
11
+
12
+ def content_lexer
13
+ return Lexers::PlainText unless @content_type
14
+
15
+ @content_lexer ||= Lexer.guess_by_mimetype(@content_type)
16
+ rescue Lexer::AmbiguousGuess
17
+ @content_lexer = Lexers::PlainText
18
+ end
19
+
20
+ start { @content_type = 'text/plain' }
21
+
22
+ state :root do
23
+ # request
24
+ rule %r{
25
+ (#{HTTP.methods.join('|')})([ ]+) # method
26
+ ([^ ]+)([ ]+) # path
27
+ (HTTPS?)(/)(1[.][01])(\r?\n|$) # http version
28
+ }ox do
29
+ groups(
30
+ Name::Function, Text,
31
+ Name::Namespace, Text,
32
+ Keyword, Operator, Num, Text
33
+ )
34
+
35
+ push :headers
36
+ end
37
+
38
+ # response
39
+ rule %r(
40
+ (HTTPS?)(/)(1[.][01])([ ]+) # http version
41
+ (\d{3})([ ]+) # status
42
+ ([^\r\n]+)(\r?\n|$) # status message
43
+ )x do
44
+ groups(
45
+ Keyword, Operator, Num, Text,
46
+ Num, Text,
47
+ Name::Exception, Text
48
+ )
49
+ push :headers
50
+ end
51
+ end
52
+
53
+ state :headers do
54
+ rule /([^\s:]+)( *)(:)( *)([^\r\n]+)(\r?\n|$)/ do |m|
55
+ key = m[1]
56
+ value = m[5]
57
+ if key.strip.downcase == 'content-type'
58
+ @content_type = value.split(';')[0].downcase
59
+ end
60
+
61
+ groups Name::Attribute, Text, Punctuation, Text, Str, Text
62
+ end
63
+
64
+ rule /([^\r\n]+)(\r?\n|$)/ do
65
+ groups Str, Text
66
+ end
67
+
68
+ rule /\r?\n/, Text, :content
69
+ end
70
+
71
+ state :content do
72
+ rule /.+/m do |_m|
73
+ delegate(content_lexer)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,55 @@
1
+ module Rugments
2
+ module Lexers
3
+ class INI < RegexLexer
4
+ title 'INI'
5
+ desc 'the INI configuration format'
6
+ tag 'ini'
7
+
8
+ # TODO add more here
9
+ filenames '*.ini', '*.INI', '*.gitconfig'
10
+ mimetypes 'text/x-ini'
11
+
12
+ def self.analyze_text(text)
13
+ return 0.1 if text =~ /\A\[[\w.]+\]\s*\w+=\w+/
14
+ end
15
+
16
+ identifier = /[\w.]+/
17
+
18
+ state :basic do
19
+ rule /[;#].*?\n/, Comment
20
+ rule /\s+/, Text
21
+ rule /\\\n/, Str::Escape
22
+ end
23
+
24
+ state :root do
25
+ mixin :basic
26
+
27
+ rule /(#{identifier})(\s*)(=)/ do
28
+ groups Name::Property, Text, Punctuation
29
+ push :value
30
+ end
31
+
32
+ rule /\[.*?\]/, Name::Namespace
33
+ end
34
+
35
+ state :value do
36
+ rule /\n/, Text, :pop!
37
+ mixin :basic
38
+ rule /"/, Str, :dq
39
+ rule /'.*?'/, Str
40
+ mixin :esc_str
41
+ rule /[^\\\n]+/, Str
42
+ end
43
+
44
+ state :dq do
45
+ rule /"/, Str, :pop!
46
+ mixin :esc_str
47
+ rule /[^\\"]+/m, Str
48
+ end
49
+
50
+ state :esc_str do
51
+ rule /\\./m, Str::Escape
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,66 @@
1
+ module Rugments
2
+ module Lexers
3
+ class IO < RegexLexer
4
+ tag 'io'
5
+ title 'Io'
6
+ desc 'The IO programming language (http://iolanguage.com)'
7
+ mimetypes 'text/x-iosrc'
8
+ filenames '*.io'
9
+
10
+ def self.analyze_text(text)
11
+ return 1 if text.shebang? 'io'
12
+ end
13
+
14
+ def self.constants
15
+ @constants ||= Set.new %w(nil false true)
16
+ end
17
+
18
+ def self.builtins
19
+ @builtins ||= Set.new %w(
20
+ args call clone do doFile doString else elseif for if list
21
+ method return super then
22
+ )
23
+ end
24
+
25
+ state :root do
26
+ rule /\s+/m, Text
27
+ rule %r{//.*?\n}, Comment::Single
28
+ rule %r{#.*?\n}, Comment::Single
29
+ rule %r{/(\\\n)?[*].*?[*](\\\n)?/}m, Comment::Multiline
30
+ rule %r{/[+]}, Comment::Multiline, :nested_comment
31
+
32
+ rule /"(\\\\|\\"|[^"])*"/, Str
33
+
34
+ rule %r{:?:=}, Keyword
35
+ rule /[()]/, Punctuation
36
+
37
+ rule %r([-=;,*+><!/|^.%&\[\]{}]), Operator
38
+
39
+ rule /[A-Z]\w*/, Name::Class
40
+
41
+ rule /[a-z_]\w*/ do |m|
42
+ name = m[0]
43
+
44
+ if self.class.constants.include? name
45
+ token Keyword::Constant
46
+ elsif self.class.builtins.include? name
47
+ token Name::Builtin
48
+ else
49
+ token Name
50
+ end
51
+ end
52
+
53
+ rule %r{(\d+[.]?\d*|\d*[.]\d+)(e[+-]?[0-9]+)?}i, Num::Float
54
+ rule /\d+/, Num::Integer
55
+
56
+ rule /@@?/, Keyword
57
+ end
58
+
59
+ state :nested_comment do
60
+ rule %r{[^/+]+}m, Comment::Multiline
61
+ rule %r{/[+]}, Comment::Multiline, :nested_comment
62
+ rule %r{[+]/}, Comment::Multiline, :pop!
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,74 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Java < RegexLexer
4
+ title 'Java'
5
+ desc 'The Java programming language (java.com)'
6
+
7
+ tag 'java'
8
+ filenames '*.java'
9
+ mimetypes 'text/x-java'
10
+
11
+ keywords = %w(
12
+ assert break case catch continue default do else finally for
13
+ if goto instanceof new return switch this throw try while
14
+ )
15
+
16
+ declarations = %w(
17
+ abstract const enum extends final implements native private protected
18
+ public static strictfp super synchronized throws transient volatile
19
+ )
20
+
21
+ types = %w(boolean byte char double float int long short void)
22
+
23
+ id = /[a-zA-Z_][a-zA-Z0-9_]*/
24
+
25
+ state :root do
26
+ rule %r{^
27
+ (\s*(?:[a-zA-Z_][a-zA-Z0-9_.\[\]]*\s+)+?) # return arguments
28
+ ([a-zA-Z_][a-zA-Z0-9_]*) # method name
29
+ (\s*)(\() # signature start
30
+ }mx do |m|
31
+ # TODO: do this better, this shouldn't need a delegation
32
+ delegate Java, m[1]
33
+ token Name::Function, m[2]
34
+ token Text, m[3]
35
+ token Punctuation, m[4]
36
+ end
37
+
38
+ rule /\s+/, Text
39
+ rule %r{//.*?$}, Comment::Single
40
+ rule %r{/\*.*?\*/}m, Comment::Multiline
41
+ rule /@#{id}/, Name::Decorator
42
+ rule /(?:#{keywords.join('|')})\b/, Keyword
43
+ rule /(?:#{declarations.join('|')})\b/, Keyword::Declaration
44
+ rule /(?:#{types.join('|')})\b/, Keyword::Type
45
+ rule /package\b/, Keyword::Namespace
46
+ rule /(?:true|false|null)\b/, Keyword::Constant
47
+ rule /(?:class|interface)\b/, Keyword::Declaration, :class
48
+ rule /import\b/, Keyword::Namespace, :import
49
+ rule /"(\\\\|\\"|[^"])*"/, Str
50
+ rule /'(?:\\.|[^\\]|\\u[0-9a-f]{4})'/, Str::Char
51
+ rule /(\.)(#{id})/ do
52
+ groups Operator, Name::Attribute
53
+ end
54
+ rule /#{id}:/, Name::Label
55
+ rule /\$?#{id}/, Name
56
+ rule /[~^*!%&\[\](){}<>\|+=:;,.\/?-]/, Operator
57
+ rule /[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
58
+ rule /0x[0-9a-f]+/, Num::Hex
59
+ rule /[0-9]+L?/, Num::Integer
60
+ # rule /\n/, Text
61
+ end
62
+
63
+ state :class do
64
+ rule /\s+/m, Text
65
+ rule id, Name::Class, :pop!
66
+ end
67
+
68
+ state :import do
69
+ rule /\s+/m, Text
70
+ rule /[a-z0-9_.]+\*?/i, Name::Namespace, :pop!
71
+ end
72
+ end
73
+ end
74
+ end