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,53 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Properties < RegexLexer
4
+ title '.properties'
5
+ desc '.properties config files for Java'
6
+ tag 'properties'
7
+
8
+ filenames '*.properties'
9
+ mimetypes 'text/x-java-properties'
10
+
11
+ def self.analyze_text(text)
12
+ return 0.1 if text =~ /\A\[[\w.]+\]\s*\w+=\w+/
13
+ end
14
+
15
+ identifier = /[\w.]+/
16
+
17
+ state :basic do
18
+ rule /[!#].*?\n/, Comment
19
+ rule /\s+/, Text
20
+ rule /\\\n/, Str::Escape
21
+ end
22
+
23
+ state :root do
24
+ mixin :basic
25
+
26
+ rule /(#{identifier})(\s*)([=:])/ do
27
+ groups Name::Property, Text, Punctuation
28
+ push :value
29
+ end
30
+ end
31
+
32
+ state :value do
33
+ rule /\n/, Text, :pop!
34
+ mixin :basic
35
+ rule /"/, Str, :dq
36
+ rule /'.*?'/, Str
37
+ mixin :esc_str
38
+ rule /[^\\\n]+/, Str
39
+ end
40
+
41
+ state :dq do
42
+ rule /"/, Str, :pop!
43
+ mixin :esc_str
44
+ rule /[^\\"]+/m, Str
45
+ end
46
+
47
+ state :esc_str do
48
+ rule /\\u[0-9]{4}/, Str::Escape
49
+ rule /\\./m, Str::Escape
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,126 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Puppet < RegexLexer
4
+ title 'Puppet'
5
+ desc 'The Puppet configuration management language (puppetlabs.org)'
6
+ tag 'puppet'
7
+ aliases 'pp'
8
+ filenames '*.pp'
9
+
10
+ def self.analyze_text(text)
11
+ return 1 if text.shebang? 'puppet-apply'
12
+ return 1 if text.shebang? 'puppet'
13
+ end
14
+
15
+ def self.keywords
16
+ @keywords ||= Set.new %w(
17
+ and case class default define else elsif if in import inherits
18
+ node unless
19
+ )
20
+ end
21
+
22
+ def self.constants
23
+ @constants ||= Set.new %w(
24
+ false true undef
25
+ )
26
+ end
27
+
28
+ def self.metaparameters
29
+ @metaparameters ||= Set.new %w(
30
+ before require notify subscribe
31
+ )
32
+ end
33
+
34
+ id = /[a-z]\w*/
35
+ cap_id = /[A-Z]\w*/
36
+ qualname = /(::)?(#{id}::)*\w+/
37
+
38
+ state :whitespace do
39
+ rule /\s+/m, Text
40
+ rule /#.*?\n/, Comment
41
+ end
42
+
43
+ state :root do
44
+ mixin :whitespace
45
+
46
+ rule /[$]#{qualname}/, Name::Variable
47
+ rule /(#{id})(?=\s*[=+]>)/m do |m|
48
+ if self.class.metaparameters.include? m[0]
49
+ token Keyword::Pseudo
50
+ else
51
+ token Name::Property
52
+ end
53
+ end
54
+
55
+ rule /(#{qualname})(?=\s*[(])/m, Name::Function
56
+ rule cap_id, Name::Class
57
+
58
+ rule /[+=|~-]>|<[|~-]/, Punctuation
59
+ rule /[:}();\[\]]/, Punctuation
60
+
61
+ # HACK for case statements and selectors
62
+ rule /{/, Punctuation, :regex_allowed
63
+ rule /,/, Punctuation, :regex_allowed
64
+
65
+ rule /(in|and|or)\b/, Operator::Word
66
+ rule /[=!<>]=/, Operator
67
+ rule /[=!]~/, Operator, :regex_allowed
68
+ rule %r{[<>!+*/-]}, Operator
69
+
70
+ rule /(class|include)(\s*)(#{qualname})/ do
71
+ groups Keyword, Text, Name::Class
72
+ end
73
+
74
+ rule /node\b/, Keyword, :regex_allowed
75
+
76
+ rule /'(\\[\\']|[^'])*'/m, Str::Single
77
+ rule /"/, Str::Double, :dquotes
78
+
79
+ rule /\d+([.]\d+)?(e[+-]\d+)?/, Num
80
+
81
+ # a valid regex. TODO: regexes are only allowed
82
+ # in certain places in puppet.
83
+ rule qualname do |m|
84
+ if self.class.keywords.include? m[0]
85
+ token Keyword
86
+ elsif self.class.constants.include? m[0]
87
+ token Keyword::Constant
88
+ else
89
+ token Name
90
+ end
91
+ end
92
+ end
93
+
94
+ state :regex_allowed do
95
+ mixin :whitespace
96
+ rule %r{/}, Str::Regex, :regex
97
+
98
+ rule(//) { pop! }
99
+ end
100
+
101
+ state :regex do
102
+ rule %r{/}, Str::Regex, :pop!
103
+ rule /\\./, Str::Escape
104
+ rule /[(){}]/, Str::Interpol
105
+ rule /\[/, Str::Interpol, :regex_class
106
+ rule /./, Str::Regex
107
+ end
108
+
109
+ state :regex_class do
110
+ rule /\]/, Str::Interpol, :pop!
111
+ rule /(?<!\[)-(?=\])/, Str::Regex
112
+ rule /-/, Str::Interpol
113
+ rule /\\./, Str::Escape
114
+ rule /[^\\\]-]+/, Str::Regex
115
+ end
116
+
117
+ state :dquotes do
118
+ rule /"/, Str::Double, :pop!
119
+ rule /[^$\\"]+/m, Str::Double
120
+ rule /\\./m, Str::Escape
121
+ rule /[$]#{qualname}/, Name::Variable
122
+ rule /[$][{]#{qualname}[}]/, Name::Variable
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,225 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Python < RegexLexer
4
+ title 'Python'
5
+ desc 'The Python programming language (python.org)'
6
+ tag 'python'
7
+ aliases 'py'
8
+ filenames '*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript', '*.tac'
9
+ mimetypes 'text/x-python', 'application/x-python'
10
+
11
+ def self.analyze_text(text)
12
+ return 1 if text.shebang?(/pythonw?(3|2(\.\d)?)?/)
13
+ end
14
+
15
+ def self.keywords
16
+ @keywords ||= %w(
17
+ assert break continue del elif else except exec
18
+ finally for global if lambda pass print raise
19
+ return try while yield as with
20
+ )
21
+ end
22
+
23
+ def self.builtins
24
+ @builtins ||= %w(
25
+ __import__ abs all any apply basestring bin bool buffer
26
+ bytearray bytes callable chr classmethod cmp coerce compile
27
+ complex delattr dict dir divmod enumerate eval execfile exit
28
+ file filter float frozenset getattr globals hasattr hash hex id
29
+ input int intern isinstance issubclass iter len list locals
30
+ long map max min next object oct open ord pow property range
31
+ raw_input reduce reload repr reversed round set setattr slice
32
+ sorted staticmethod str sum super tuple type unichr unicode
33
+ vars xrange zip
34
+ )
35
+ end
36
+
37
+ def self.builtins_pseudo
38
+ @builtins_pseudo ||= %w(self None Ellipsis NotImplemented False True)
39
+ end
40
+
41
+ def self.exceptions
42
+ @exceptions ||= %w(
43
+ ArithmeticError AssertionError AttributeError
44
+ BaseException DeprecationWarning EOFError EnvironmentError
45
+ Exception FloatingPointError FutureWarning GeneratorExit IOError
46
+ ImportError ImportWarning IndentationError IndexError KeyError
47
+ KeyboardInterrupt LookupError MemoryError NameError
48
+ NotImplemented NotImplementedError OSError OverflowError
49
+ OverflowWarning PendingDeprecationWarning ReferenceError
50
+ RuntimeError RuntimeWarning StandardError StopIteration
51
+ SyntaxError SyntaxWarning SystemError SystemExit TabError
52
+ TypeError UnboundLocalError UnicodeDecodeError
53
+ UnicodeEncodeError UnicodeError UnicodeTranslateError
54
+ UnicodeWarning UserWarning ValueError VMSError Warning
55
+ WindowsError ZeroDivisionError
56
+ )
57
+ end
58
+
59
+ identifier = /[a-z_][a-z0-9_]*/i
60
+ dotted_identifier = /[a-z_.][a-z0-9_.]*/i
61
+ state :root do
62
+ rule /\n+/m, Text
63
+ rule /^(:)(\s*)([ru]{,2}""".*?""")/mi do
64
+ groups Punctuation, Text, Str::Doc
65
+ end
66
+
67
+ rule /[^\S\n]+/, Text
68
+ rule /#.*$/, Comment
69
+ rule /[\[\]{}:(),;]/, Punctuation
70
+ rule /\\\n/, Text
71
+ rule /\\/, Text
72
+
73
+ rule /(in|is|and|or|not)\b/, Operator::Word
74
+ rule /!=|==|<<|>>|[-~+\/*%=<>&^|.]/, Operator
75
+
76
+ rule /(def)((?:\s|\\\s)+)/ do
77
+ groups Keyword, Text
78
+ push :funcname
79
+ end
80
+
81
+ rule /(class)((?:\s|\\\s)+)/ do
82
+ groups Keyword, Text
83
+ push :classname
84
+ end
85
+
86
+ rule /(from)((?:\s|\\\s)+)/ do
87
+ groups Keyword::Namespace, Text
88
+ push :fromimport
89
+ end
90
+
91
+ rule /(import)((?:\s|\\\s)+)/ do
92
+ groups Keyword::Namespace, Text
93
+ push :import
94
+ end
95
+
96
+ # TODO: not in python 3
97
+ rule /`.*?`/, Str::Backtick
98
+ rule /(?:r|ur|ru)"""/i, Str, :tdqs
99
+ rule /(?:r|ur|ru)'''/i, Str, :tsqs
100
+ rule /(?:r|ur|ru)"/i, Str, :dqs
101
+ rule /(?:r|ur|ru)'/i, Str, :sqs
102
+ rule /u?"""/i, Str, :escape_tdqs
103
+ rule /u?'''/i, Str, :escape_tsqs
104
+ rule /u?"/i, Str, :escape_dqs
105
+ rule /u?'/i, Str, :escape_sqs
106
+
107
+ rule /@#{dotted_identifier}/i, Name::Decorator
108
+
109
+ # using negative lookbehind so we don't match property names
110
+ rule /(?<!\.)#{identifier}/ do |m|
111
+ if self.class.keywords.include? m[0]
112
+ token Keyword
113
+ elsif self.class.exceptions.include? m[0]
114
+ token Name::Builtin
115
+ elsif self.class.builtins.include? m[0]
116
+ token Name::Builtin
117
+ elsif self.class.builtins_pseudo.include? m[0]
118
+ token Name::Builtin::Pseudo
119
+ else
120
+ token Name
121
+ end
122
+ end
123
+
124
+ rule identifier, Name
125
+
126
+ rule /(\d+\.\d*|\d*\.\d+)(e[+-]?[0-9]+)?/i, Num::Float
127
+ rule /\d+e[+-]?[0-9]+/i, Num::Float
128
+ rule /0[0-7]+/, Num::Oct
129
+ rule /0x[a-f0-9]+/i, Num::Hex
130
+ rule /\d+L/, Num::Integer::Long
131
+ rule /\d+/, Num::Integer
132
+ end
133
+
134
+ state :funcname do
135
+ rule identifier, Name::Function, :pop!
136
+ end
137
+
138
+ state :classname do
139
+ rule identifier, Name::Class, :pop!
140
+ end
141
+
142
+ state :import do
143
+ # non-line-terminating whitespace
144
+ rule /(?:[ \t]|\\\n)+/, Text
145
+
146
+ rule /as\b/, Keyword::Namespace
147
+ rule /,/, Operator
148
+ rule dotted_identifier, Name::Namespace
149
+ rule(//) { pop! } # anything else -> go back
150
+ end
151
+
152
+ state :fromimport do
153
+ # non-line-terminating whitespace
154
+ rule /(?:[ \t]|\\\n)+/, Text
155
+
156
+ rule /import\b/, Keyword::Namespace, :pop!
157
+ rule dotted_identifier, Name::Namespace
158
+ end
159
+
160
+ state :strings do
161
+ rule /%(\([a-z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?/i, Str::Interpol
162
+ end
163
+
164
+ state :strings_double do
165
+ rule /[^\\"%\n]+/, Str
166
+ mixin :strings
167
+ end
168
+
169
+ state :strings_single do
170
+ rule /[^\\'%\n]+/, Str
171
+ mixin :strings
172
+ end
173
+
174
+ state :nl do
175
+ rule /\n/, Str
176
+ end
177
+
178
+ state :escape do
179
+ rule %r(\\
180
+ ( [\\abfnrtv"']
181
+ | \n
182
+ | N{.*?}
183
+ | u[a-fA-F0-9]{4}
184
+ | U[a-fA-F0-9]{8}
185
+ | x[a-fA-F0-9]{2}
186
+ | [0-7]{1,3}
187
+ )
188
+ )x, Str::Escape
189
+ end
190
+
191
+ state :dqs do
192
+ rule /"/, Str, :pop!
193
+ rule /\\\\|\\"|\\\n/, Str::Escape
194
+ mixin :strings_double
195
+ end
196
+
197
+ state :sqs do
198
+ rule /'/, Str, :pop!
199
+ rule /\\\\|\\'|\\\n/, Str::Escape
200
+ mixin :strings_single
201
+ end
202
+
203
+ state :tdqs do
204
+ rule /"""/, Str, :pop!
205
+ rule /"/, Str
206
+ mixin :strings_double
207
+ mixin :nl
208
+ end
209
+
210
+ state :tsqs do
211
+ rule /'''/, Str, :pop!
212
+ rule /'/, Str
213
+ mixin :strings_single
214
+ mixin :nl
215
+ end
216
+
217
+ %w(tdqs tsqs dqs sqs).each do |qtype|
218
+ state :"escape_#{qtype}" do
219
+ mixin :escape
220
+ mixin :"#{qtype}"
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,70 @@
1
+ module Rugments
2
+ module Lexers
3
+ load_const :Javascript, 'javascript.rb'
4
+ class Qml < Javascript
5
+ title 'QML'
6
+ desc 'QML, a UI markup language'
7
+ tag 'qml'
8
+ aliases 'qml'
9
+ filenames '*.qml'
10
+
11
+ mimetypes 'application/x-qml', 'text/x-qml'
12
+
13
+ id_with_dots = /[$a-zA-Z_][a-zA-Z0-9_.]*/
14
+
15
+ prepend :root do
16
+ rule /(#{id_with_dots})(\s*)({)/ do
17
+ groups Keyword::Type, Text, Punctuation
18
+ push :type_block
19
+ end
20
+ rule /(#{id_with_dots})(\s+)(on)(\s+)(#{id_with_dots})(\s*)({)/ do
21
+ groups Keyword::Type, Text, Keyword, Text, Name::Label, Text, Punctuation
22
+ push :type_block
23
+ end
24
+
25
+ rule /[{]/, Punctuation, :push
26
+ end
27
+
28
+ state :type_block do
29
+ rule /(id)(\s*)(:)(\s*)(#{id_with_dots})/ do
30
+ groups Name::Label, Text, Punctuation, Text, Keyword::Declaration
31
+ end
32
+
33
+ rule /(#{id_with_dots})(\s*)(:)/ do
34
+ groups Name::Label, Text, Punctuation
35
+ push :expr_start
36
+ end
37
+
38
+ rule /(signal)(\s+)(#{id_with_dots})/ do
39
+ groups Keyword::Declaration, Text, Name::Label
40
+ push :signal
41
+ end
42
+
43
+ rule /(property)(\s+)(#{id_with_dots})(\s+)(#{id_with_dots})(\s*)(:?)/ do
44
+ groups Keyword::Declaration, Text, Keyword::Type, Text, Name::Label, Text, Punctuation
45
+ push :expr_start
46
+ end
47
+
48
+ rule /[}]/, Punctuation, :pop!
49
+ mixin :root
50
+ end
51
+
52
+ state :signal do
53
+ mixin :comments_and_whitespace
54
+ rule /\(/ do
55
+ token Punctuation
56
+ goto :signal_args
57
+ end
58
+ rule //, Text, :pop!
59
+ end
60
+
61
+ state :signal_args do
62
+ mixin :comments_and_whitespace
63
+ rule /(#{id_with_dots})(\s+)(#{id_with_dots})(\s*)(,?)/ do
64
+ groups Keyword::Type, Text, Name, Text, Punctuation
65
+ end
66
+ rule /\)/, Punctuation, :pop!
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,55 @@
1
+ module Rugments
2
+ module Lexers
3
+ class R < RegexLexer
4
+ title 'R'
5
+ desc 'The R statistics language (r-project.org)'
6
+ tag 'r'
7
+ aliases 'r', 'R', 's', 'S'
8
+ filenames '*.R', '*.S', '.Rhistory', '.Rprofile'
9
+ mimetypes 'text/x-r-source', 'text/x-r', 'text/x-R'
10
+
11
+ mimetypes 'text/x-r', 'application/x-r'
12
+
13
+ def self.keywords
14
+ @keywords ||= %w(
15
+ if else for while repeat in next break return switch function
16
+ )
17
+ end
18
+
19
+ def self.analyze_text(text)
20
+ return 1 if text.shebang? 'Rscript'
21
+ return 0.1 if text.include? '->'
22
+ end
23
+
24
+ state :root do
25
+ rule /#.*?\n/, Comment::Single
26
+ rule /\s+/m, Text
27
+ rule /[.]?[a-zA-Z_][\w.]*/ do |m|
28
+ if self.class.keywords.include? m[0]
29
+ token Keyword
30
+ else
31
+ token Name
32
+ end
33
+ end
34
+
35
+ rule /`.*?`/, Str::Backtick
36
+ rule /'(\\.|.)*?'/m, Str::Single
37
+ rule /"(\\.|.)*?"/m, Str::Double
38
+
39
+ rule /\b(NULL|Inf|TRUE|FALSE|NaN)\b/, Keyword::Constant
40
+ rule /\bNA(_(integer|real|complex|character)_)?\b/,
41
+ Keyword::Constant
42
+ rule /\b[TF]\b/, Keyword::Variable
43
+
44
+ rule /0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?/, Num::Hex
45
+ rule /[+-]?(\d+([.]\d+)?|[.]\d+)([eE][+-]?\d+)?[Li]?/,
46
+ Num
47
+
48
+ rule /[\[\]{}();,]/, Punctuation
49
+
50
+ rule %r{[-<>?*+^/!=~$@:%&|]}, Operator
51
+ rule /[.][.][.]/, Keyword
52
+ end
53
+ end
54
+ end
55
+ end