rugments 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +52 -0
- data/README.md +195 -0
- data/bin/rugmentize +6 -0
- data/lib/rugments/cli.rb +357 -0
- data/lib/rugments/formatter.rb +29 -0
- data/lib/rugments/formatters/html.rb +142 -0
- data/lib/rugments/formatters/null.rb +17 -0
- data/lib/rugments/formatters/terminal256.rb +174 -0
- data/lib/rugments/lexer.rb +431 -0
- data/lib/rugments/lexers/apache/keywords.yml +453 -0
- data/lib/rugments/lexers/apache.rb +67 -0
- data/lib/rugments/lexers/apple_script.rb +366 -0
- data/lib/rugments/lexers/c.rb +210 -0
- data/lib/rugments/lexers/clojure.rb +109 -0
- data/lib/rugments/lexers/coffeescript.rb +172 -0
- data/lib/rugments/lexers/common_lisp.rb +343 -0
- data/lib/rugments/lexers/conf.rb +22 -0
- data/lib/rugments/lexers/cpp.rb +63 -0
- data/lib/rugments/lexers/csharp.rb +85 -0
- data/lib/rugments/lexers/css.rb +269 -0
- data/lib/rugments/lexers/dart.rb +102 -0
- data/lib/rugments/lexers/diff.rb +39 -0
- data/lib/rugments/lexers/elixir.rb +105 -0
- data/lib/rugments/lexers/erb.rb +54 -0
- data/lib/rugments/lexers/erlang.rb +116 -0
- data/lib/rugments/lexers/factor.rb +300 -0
- data/lib/rugments/lexers/gherkin/keywords.rb +13 -0
- data/lib/rugments/lexers/gherkin.rb +135 -0
- data/lib/rugments/lexers/go.rb +176 -0
- data/lib/rugments/lexers/groovy.rb +102 -0
- data/lib/rugments/lexers/haml.rb +226 -0
- data/lib/rugments/lexers/handlebars.rb +77 -0
- data/lib/rugments/lexers/haskell.rb +181 -0
- data/lib/rugments/lexers/html.rb +92 -0
- data/lib/rugments/lexers/http.rb +78 -0
- data/lib/rugments/lexers/ini.rb +55 -0
- data/lib/rugments/lexers/io.rb +66 -0
- data/lib/rugments/lexers/java.rb +74 -0
- data/lib/rugments/lexers/javascript.rb +258 -0
- data/lib/rugments/lexers/literate_coffeescript.rb +31 -0
- data/lib/rugments/lexers/literate_haskell.rb +34 -0
- data/lib/rugments/lexers/llvm.rb +82 -0
- data/lib/rugments/lexers/lua/builtins.rb +21 -0
- data/lib/rugments/lexers/lua.rb +120 -0
- data/lib/rugments/lexers/make.rb +114 -0
- data/lib/rugments/lexers/markdown.rb +151 -0
- data/lib/rugments/lexers/matlab/builtins.rb +10 -0
- data/lib/rugments/lexers/matlab.rb +70 -0
- data/lib/rugments/lexers/moonscript.rb +108 -0
- data/lib/rugments/lexers/nginx.rb +69 -0
- data/lib/rugments/lexers/nim.rb +149 -0
- data/lib/rugments/lexers/objective_c.rb +188 -0
- data/lib/rugments/lexers/ocaml.rb +109 -0
- data/lib/rugments/lexers/perl.rb +195 -0
- data/lib/rugments/lexers/php/builtins.rb +192 -0
- data/lib/rugments/lexers/php.rb +162 -0
- data/lib/rugments/lexers/plain_text.rb +23 -0
- data/lib/rugments/lexers/prolog.rb +62 -0
- data/lib/rugments/lexers/properties.rb +53 -0
- data/lib/rugments/lexers/puppet.rb +126 -0
- data/lib/rugments/lexers/python.rb +225 -0
- data/lib/rugments/lexers/qml.rb +70 -0
- data/lib/rugments/lexers/r.rb +55 -0
- data/lib/rugments/lexers/racket.rb +540 -0
- data/lib/rugments/lexers/ruby.rb +413 -0
- data/lib/rugments/lexers/rust.rb +188 -0
- data/lib/rugments/lexers/sass/common.rb +172 -0
- data/lib/rugments/lexers/sass.rb +72 -0
- data/lib/rugments/lexers/scala.rb +140 -0
- data/lib/rugments/lexers/scheme.rb +109 -0
- data/lib/rugments/lexers/scss.rb +32 -0
- data/lib/rugments/lexers/sed.rb +167 -0
- data/lib/rugments/lexers/shell.rb +150 -0
- data/lib/rugments/lexers/slim.rb +222 -0
- data/lib/rugments/lexers/smalltalk.rb +114 -0
- data/lib/rugments/lexers/sml.rb +345 -0
- data/lib/rugments/lexers/sql.rb +138 -0
- data/lib/rugments/lexers/swift.rb +153 -0
- data/lib/rugments/lexers/tcl.rb +189 -0
- data/lib/rugments/lexers/tex.rb +70 -0
- data/lib/rugments/lexers/toml.rb +68 -0
- data/lib/rugments/lexers/vb.rb +162 -0
- data/lib/rugments/lexers/viml/keywords.rb +11 -0
- data/lib/rugments/lexers/viml.rb +99 -0
- data/lib/rugments/lexers/xml.rb +57 -0
- data/lib/rugments/lexers/yaml.rb +362 -0
- data/lib/rugments/plugins/redcarpet.rb +28 -0
- data/lib/rugments/regex_lexer.rb +432 -0
- data/lib/rugments/template_lexer.rb +23 -0
- data/lib/rugments/text_analyzer.rb +46 -0
- data/lib/rugments/theme.rb +202 -0
- data/lib/rugments/themes/base16.rb +128 -0
- data/lib/rugments/themes/colorful.rb +65 -0
- data/lib/rugments/themes/github.rb +69 -0
- data/lib/rugments/themes/monokai.rb +88 -0
- data/lib/rugments/themes/monokai_sublime.rb +89 -0
- data/lib/rugments/themes/thankful_eyes.rb +69 -0
- data/lib/rugments/token.rb +180 -0
- data/lib/rugments/util.rb +99 -0
- data/lib/rugments/version.rb +3 -0
- data/lib/rugments.rb +33 -0
- metadata +149 -0
@@ -0,0 +1,189 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class TCL < RegexLexer
|
4
|
+
title 'Tcl'
|
5
|
+
desc 'The Tool Command Language (tcl.tk)'
|
6
|
+
tag 'tcl'
|
7
|
+
filenames '*.tcl'
|
8
|
+
mimetypes 'text/x-tcl', 'text/x-script.tcl', 'application/x-tcl'
|
9
|
+
|
10
|
+
def self.analyze_text(text)
|
11
|
+
return 1 if text.shebang? 'tclsh'
|
12
|
+
return 1 if text.shebang? 'wish'
|
13
|
+
return 1 if text.shebang? 'jimsh'
|
14
|
+
end
|
15
|
+
|
16
|
+
KEYWORDS = %w(
|
17
|
+
after apply array break catch continue elseif else error
|
18
|
+
eval expr for foreach global if namespace proc rename return
|
19
|
+
set switch then trace unset update uplevel upvar variable
|
20
|
+
vwait while
|
21
|
+
)
|
22
|
+
|
23
|
+
BUILTINS = %w(
|
24
|
+
append bgerror binary cd chan clock close concat dde dict
|
25
|
+
encoding eof exec exit fblocked fconfigure fcopy file
|
26
|
+
fileevent flush format gets glob history http incr info interp
|
27
|
+
join lappend lassign lindex linsert list llength load loadTk
|
28
|
+
lrange lrepeat lreplace lreverse lsearch lset lsort mathfunc
|
29
|
+
mathop memory msgcat open package pid pkg::create pkg_mkIndex
|
30
|
+
platform platform::shell puts pwd re_syntax read refchan
|
31
|
+
regexp registry regsub scan seek socket source split string
|
32
|
+
subst tell time tm unknown unload
|
33
|
+
)
|
34
|
+
|
35
|
+
OPEN = %w| \( \[ \{ " |
|
36
|
+
CLOSE = %w| \) \] \} |
|
37
|
+
ALL = OPEN + CLOSE
|
38
|
+
END_LINE = CLOSE + %w(; \n)
|
39
|
+
END_WORD = END_LINE + %w(\s)
|
40
|
+
|
41
|
+
CHARS = lambda { |list| Regexp.new %([#{list.join}]) }
|
42
|
+
NOT_CHARS = lambda { |list| Regexp.new %([^#{list.join}]) }
|
43
|
+
|
44
|
+
state :word do
|
45
|
+
rule /\{\*\}/, Keyword
|
46
|
+
|
47
|
+
mixin :brace_abort
|
48
|
+
mixin :interp
|
49
|
+
rule /\{/, Punctuation, :brace
|
50
|
+
rule /\(/, Punctuation, :paren
|
51
|
+
rule /"/, Str::Double, :string
|
52
|
+
rule /#{NOT_CHARS[END_WORD]}+?(?=#{CHARS[OPEN + ['\\\\']]})/, Text
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.gen_command_state(name = '')
|
56
|
+
state(:"command#{name}") do
|
57
|
+
mixin :word
|
58
|
+
|
59
|
+
rule /##{NOT_CHARS[END_LINE]}+/, Comment::Single
|
60
|
+
|
61
|
+
rule /(?=#{CHARS[END_WORD]})/ do
|
62
|
+
push :"params#{name}"
|
63
|
+
end
|
64
|
+
|
65
|
+
rule /#{NOT_CHARS[END_WORD]}+/ do |m|
|
66
|
+
if KEYWORDS.include? m[0]
|
67
|
+
token Keyword
|
68
|
+
elsif BUILTINS.include? m[0]
|
69
|
+
token Name::Builtin
|
70
|
+
else
|
71
|
+
token Text
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
mixin :whitespace
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.gen_delimiter_states(name, close, opts = {})
|
80
|
+
gen_command_state("_in_#{name}")
|
81
|
+
|
82
|
+
state :"params_in_#{name}" do
|
83
|
+
rule close do
|
84
|
+
token Punctuation
|
85
|
+
pop! 2
|
86
|
+
end
|
87
|
+
|
88
|
+
# mismatched delimiters. Braced strings with mismatched
|
89
|
+
# closing delimiters should be okay, since this is standard
|
90
|
+
# practice, like {]]]]}
|
91
|
+
if opts[:strict]
|
92
|
+
rule CHARS[CLOSE - [close]], Error
|
93
|
+
else
|
94
|
+
rule CHARS[CLOSE - [close]], Text
|
95
|
+
end
|
96
|
+
|
97
|
+
mixin :params
|
98
|
+
end
|
99
|
+
|
100
|
+
state name do
|
101
|
+
rule close, Punctuation, :pop!
|
102
|
+
mixin :"command_in_#{name}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# tcl is freaking impossible. If we're in braces and we encounter
|
107
|
+
# a close brace, we have to drop everything and close the brace.
|
108
|
+
# This is so silly things like {abc"def} and {abc]def} don't b0rk
|
109
|
+
# everything after them.
|
110
|
+
|
111
|
+
# TODO: TCL seems to have this aborting behavior quite a lot.
|
112
|
+
# such things as [ abc" ] are a runtime error, but will still
|
113
|
+
# parse. Currently something like this will muck up the lex.
|
114
|
+
state :brace_abort do
|
115
|
+
rule /}/ do
|
116
|
+
if in_state? :brace
|
117
|
+
pop! until state? :brace
|
118
|
+
pop!
|
119
|
+
token Punctuation
|
120
|
+
else
|
121
|
+
token Error
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
state :params do
|
127
|
+
rule /;/, Punctuation, :pop!
|
128
|
+
rule /\n/, Text, :pop!
|
129
|
+
rule /else|elseif|then/, Keyword
|
130
|
+
mixin :word
|
131
|
+
mixin :whitespace
|
132
|
+
rule /#{NOT_CHARS[END_WORD]}+/, Text
|
133
|
+
end
|
134
|
+
|
135
|
+
gen_delimiter_states :brace, /\}/, strict: false
|
136
|
+
gen_delimiter_states :paren, /\)/, strict: true
|
137
|
+
gen_delimiter_states :bracket, /\]/, strict: true
|
138
|
+
gen_command_state
|
139
|
+
|
140
|
+
state :root do
|
141
|
+
mixin :command
|
142
|
+
end
|
143
|
+
|
144
|
+
state :whitespace do
|
145
|
+
# not a multiline regex because we want to capture \n sometimes
|
146
|
+
rule /\s+/, Text
|
147
|
+
end
|
148
|
+
|
149
|
+
state :interp do
|
150
|
+
rule /\[/, Punctuation, :bracket
|
151
|
+
rule /\$[a-z0-9.:-]+/, Name::Variable
|
152
|
+
rule /\$\{.*?\}/m, Name::Variable
|
153
|
+
rule /\$/, Text
|
154
|
+
|
155
|
+
# escape sequences
|
156
|
+
rule /\\[0-7]{3}/, Str::Escape
|
157
|
+
rule /\\x[0-9a-f]{2}/i, Str::Escape
|
158
|
+
rule /\\u[0-9a-f]{4}/i, Str::Escape
|
159
|
+
rule /\\./m, Str::Escape
|
160
|
+
end
|
161
|
+
|
162
|
+
state :string do
|
163
|
+
rule /"/, Str::Double, :pop!
|
164
|
+
mixin :interp
|
165
|
+
rule /[^\\\[\$"{}]+/m, Str::Double
|
166
|
+
|
167
|
+
# strings have to keep count of their internal braces, to support
|
168
|
+
# for example { "{ }" }.
|
169
|
+
rule /{/ do
|
170
|
+
@brace_count ||= 0
|
171
|
+
@brace_count += 1
|
172
|
+
|
173
|
+
token Str::Double
|
174
|
+
end
|
175
|
+
|
176
|
+
rule /}/ do
|
177
|
+
if in_state?(:brace) && @brace_count.to_i == 0
|
178
|
+
pop! until state? :brace
|
179
|
+
pop!
|
180
|
+
token Punctuation
|
181
|
+
else
|
182
|
+
@brace_count -= 1
|
183
|
+
token Str::Double
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class TeX < RegexLexer
|
4
|
+
title 'TeX'
|
5
|
+
desc 'The TeX typesetting system'
|
6
|
+
tag 'tex'
|
7
|
+
aliases 'TeX', 'LaTeX', 'latex'
|
8
|
+
|
9
|
+
filenames '*.tex', '*.aux', '*.toc'
|
10
|
+
mimetypes 'text/x-tex', 'text/x-latex'
|
11
|
+
|
12
|
+
def self.analyze_text(text)
|
13
|
+
return 1 if text =~ /\A\s*\\documentclass/
|
14
|
+
return 1 if text =~ /\A\s*\\input/
|
15
|
+
return 1 if text =~ /\A\s*\\documentstyle/
|
16
|
+
return 1 if text =~ /\A\s*\\relax/
|
17
|
+
end
|
18
|
+
|
19
|
+
command = /\\([a-z]+|\s+|.)/i
|
20
|
+
|
21
|
+
state :general do
|
22
|
+
rule /%.*$/, Comment
|
23
|
+
rule /[{}&_^]/, Punctuation
|
24
|
+
end
|
25
|
+
|
26
|
+
state :root do
|
27
|
+
rule /\\\[/, Punctuation, :displaymath
|
28
|
+
rule /\\\(/, Punctuation, :inlinemath
|
29
|
+
rule /\$\$/, Punctuation, :displaymath
|
30
|
+
rule /\$/, Punctuation, :inlinemath
|
31
|
+
rule /\\(begin|end)\{.*?\}/, Name::Tag
|
32
|
+
|
33
|
+
rule /(\\verb)\b(\S)(.*?)(\2)/ do |_m|
|
34
|
+
groups Name::Builtin, Keyword::Pseudo, Str::Other, Keyword::Pseudo
|
35
|
+
end
|
36
|
+
|
37
|
+
rule command, Keyword, :command
|
38
|
+
mixin :general
|
39
|
+
rule /[^\\$%&_^{}]+/, Text
|
40
|
+
end
|
41
|
+
|
42
|
+
state :math do
|
43
|
+
rule command, Name::Variable
|
44
|
+
mixin :general
|
45
|
+
rule /[0-9]+/, Num
|
46
|
+
rule /[-=!+*\/()\[\]]/, Operator
|
47
|
+
rule /[^=!+*\/()\[\]\\$%&_^{}0-9-]+/, Name::Builtin
|
48
|
+
end
|
49
|
+
|
50
|
+
state :inlinemath do
|
51
|
+
rule /\\\)/, Punctuation, :pop!
|
52
|
+
rule /\$/, Punctuation, :pop!
|
53
|
+
mixin :math
|
54
|
+
end
|
55
|
+
|
56
|
+
state :displaymath do
|
57
|
+
rule /\\\]/, Punctuation, :pop!
|
58
|
+
rule /\$\$/, Punctuation, :pop!
|
59
|
+
rule /\$/, Name::Builtin
|
60
|
+
mixin :math
|
61
|
+
end
|
62
|
+
|
63
|
+
state :command do
|
64
|
+
rule /\[.*?\]/, Name::Attribute
|
65
|
+
rule /\*/, Keyword
|
66
|
+
rule(//) { pop! }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class TOML < RegexLexer
|
4
|
+
title 'TOML'
|
5
|
+
desc 'the TOML configuration format (https://github.com/mojombo/toml)'
|
6
|
+
tag 'toml'
|
7
|
+
|
8
|
+
filenames '*.toml'
|
9
|
+
mimetypes 'text/x-toml'
|
10
|
+
|
11
|
+
def self.analyze_text(text)
|
12
|
+
return 0.1 if text =~ /\A\[[\w.]+\]\s*\w+\s*=\s*("\w+")+/
|
13
|
+
end
|
14
|
+
|
15
|
+
identifier = /[\w.\S]+/
|
16
|
+
|
17
|
+
state :basic do
|
18
|
+
rule /\s+/, Text
|
19
|
+
rule /#.*?$/, Comment
|
20
|
+
rule /(true|false)/, Keyword::Constant
|
21
|
+
rule /(?<!=)\s*\[[\w\d\S]+\]/, Name::Namespace
|
22
|
+
|
23
|
+
rule /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/, Literal::Date
|
24
|
+
|
25
|
+
rule /(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?/, Num::Float
|
26
|
+
rule /\d+[eE][+-]?[0-9]+j?/, Num::Float
|
27
|
+
rule /\-?\d+/, Num::Integer
|
28
|
+
end
|
29
|
+
|
30
|
+
state :root do
|
31
|
+
mixin :basic
|
32
|
+
|
33
|
+
rule /(#{identifier})(\s*)(=)/ do
|
34
|
+
groups Name::Property, Text, Punctuation
|
35
|
+
push :value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
state :value do
|
40
|
+
rule /\n/, Text, :pop!
|
41
|
+
mixin :content
|
42
|
+
end
|
43
|
+
|
44
|
+
state :content do
|
45
|
+
mixin :basic
|
46
|
+
rule /"/, Str, :dq
|
47
|
+
mixin :esc_str
|
48
|
+
rule /\,/, Punctuation
|
49
|
+
rule /\[/, Punctuation, :array
|
50
|
+
end
|
51
|
+
|
52
|
+
state :dq do
|
53
|
+
rule /"/, Str, :pop!
|
54
|
+
mixin :esc_str
|
55
|
+
rule /[^\\"]+/, Str
|
56
|
+
end
|
57
|
+
|
58
|
+
state :esc_str do
|
59
|
+
rule /\\[0t\tn\n "\\ r]/, Str::Escape
|
60
|
+
end
|
61
|
+
|
62
|
+
state :array do
|
63
|
+
mixin :content
|
64
|
+
rule /\]/, Punctuation, :pop!
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class VisualBasic < RegexLexer
|
4
|
+
title 'Visual Basic'
|
5
|
+
desc 'Visual Basic'
|
6
|
+
tag 'vb'
|
7
|
+
aliases 'visualbasic'
|
8
|
+
filenames '*.vbs'
|
9
|
+
mimetypes 'text/x-visualbasic', 'application/x-visualbasic'
|
10
|
+
|
11
|
+
def self.keywords
|
12
|
+
@keywords ||= Set.new %w(
|
13
|
+
AddHandler Alias ByRef ByVal CBool CByte CChar CDate CDbl CDec
|
14
|
+
CInt CLng CObj CSByte CShort CSng CStr CType CUInt CULng CUShort
|
15
|
+
Call Case Catch Class Const Continue Declare Default Delegate
|
16
|
+
Dim DirectCast Do Each Else ElseIf End EndIf Enum Erase Error
|
17
|
+
Event Exit False Finally For Friend Function Get Global GoSub
|
18
|
+
GoTo Handles If Implements Imports Inherits Interface Let
|
19
|
+
Lib Loop Me Module MustInherit MustOverride MyBase MyClass
|
20
|
+
Namespace Narrowing New Next Not NotInheritable NotOverridable
|
21
|
+
Nothing Of On Operator Option Optional Overloads Overridable
|
22
|
+
Overrides ParamArray Partial Private Property Protected Public
|
23
|
+
RaiseEvent ReDim ReadOnly RemoveHandler Resume Return Select Set
|
24
|
+
Shadows Shared Single Static Step Stop Structure Sub SyncLock
|
25
|
+
Then Throw To True Try TryCast Using Wend When While Widening
|
26
|
+
With WithEvents WriteOnly
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.keywords_type
|
31
|
+
@keywords_type ||= Set.new %w(
|
32
|
+
Boolean Byte Char Date Decimal Double Integer Long Object
|
33
|
+
SByte Short Single String Variant UInteger ULong UShort
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.operator_words
|
38
|
+
@operator_words ||= Set.new %w(
|
39
|
+
AddressOf And AndAlso As GetType In Is IsNot Like Mod Or OrElse
|
40
|
+
TypeOf Xor
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.builtins
|
45
|
+
@builtins ||= Set.new %w(
|
46
|
+
Console ConsoleColor
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
id = /[a-z_]\w*/i
|
51
|
+
upper_id = /[A-Z]\w*/
|
52
|
+
|
53
|
+
state :whitespace do
|
54
|
+
rule /\s+/, Text
|
55
|
+
rule /\n/, Text, :bol
|
56
|
+
rule /rem\b.*?$/i, Comment::Single
|
57
|
+
rule %r(%\{.*?%\})m, Comment::Multiline
|
58
|
+
rule /'.*$/, Comment::Single
|
59
|
+
end
|
60
|
+
|
61
|
+
state :bol do
|
62
|
+
rule /\s+/, Text
|
63
|
+
rule /<.*?>/, Name::Attribute
|
64
|
+
rule(//) { :pop! }
|
65
|
+
end
|
66
|
+
|
67
|
+
state :root do
|
68
|
+
mixin :whitespace
|
69
|
+
rule %r{
|
70
|
+
[#]If\b .*? \bThen
|
71
|
+
| [#]ElseIf\b .*? \bThen
|
72
|
+
| [#]End \s+ If
|
73
|
+
| [#]Const
|
74
|
+
| [#]ExternalSource .*? \n
|
75
|
+
| [#]End \s+ ExternalSource
|
76
|
+
| [#]Region .*? \n
|
77
|
+
| [#]End \s+ Region
|
78
|
+
| [#]ExternalChecksum
|
79
|
+
}x, Comment::Preproc
|
80
|
+
rule /[.]/, Punctuation, :dotted
|
81
|
+
rule /[(){}!#,:]/, Punctuation
|
82
|
+
rule /Option\s+(Strict|Explicit|Compare)\s+(On|Off|Binary|Text)/,
|
83
|
+
Keyword::Declaration
|
84
|
+
rule /End\b/, Keyword, :end
|
85
|
+
rule /(Dim|Const)\b/, Keyword, :dim
|
86
|
+
rule /(Function|Sub|Property)\b/, Keyword, :funcname
|
87
|
+
rule /(Class|Structure|Enum)\b/, Keyword, :classname
|
88
|
+
rule /(Module|Namespace|Imports)\b/, Keyword, :namespace
|
89
|
+
|
90
|
+
rule upper_id do |m|
|
91
|
+
match = m[0]
|
92
|
+
if self.class.keywords.include? match
|
93
|
+
token Keyword
|
94
|
+
elsif self.class.keywords_type.include? match
|
95
|
+
token Keyword::Type
|
96
|
+
elsif self.class.operator_words.include? match
|
97
|
+
token Operator::Word
|
98
|
+
elsif self.class.builtins.include? match
|
99
|
+
token Name::Builtin
|
100
|
+
else
|
101
|
+
token Name
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
rule(
|
106
|
+
%r{&=|[*]=|/=|\\=|\^=|\+=|-=|<<=|>>=|<<|>>|:=|<=|>=|<>|[-&*/\\^+=<>.]},
|
107
|
+
Operator
|
108
|
+
)
|
109
|
+
|
110
|
+
rule /"/, Str, :string
|
111
|
+
rule /#{id}[%&@!#\$]?/, Name
|
112
|
+
rule /#.*?#/, Literal::Date
|
113
|
+
|
114
|
+
rule /(\d+\.\d*|\d*\.\d+)(f[+-]?\d+)?/i, Num::Float
|
115
|
+
rule /\d+([SILDFR]|US|UI|UL)?/, Num::Integer
|
116
|
+
rule /&H[0-9a-f]+([SILDFR]|US|UI|UL)?/, Num::Integer
|
117
|
+
rule /&O[0-7]+([SILDFR]|US|UI|UL)?/, Num::Integer
|
118
|
+
|
119
|
+
rule /_\n/, Keyword
|
120
|
+
end
|
121
|
+
|
122
|
+
state :dotted do
|
123
|
+
mixin :whitespace
|
124
|
+
rule id, Name, :pop!
|
125
|
+
end
|
126
|
+
|
127
|
+
state :string do
|
128
|
+
rule /""/, Str::Escape
|
129
|
+
rule /"C?/, Str, :pop!
|
130
|
+
rule /[^"]+/, Str
|
131
|
+
end
|
132
|
+
|
133
|
+
state :dim do
|
134
|
+
mixin :whitespace
|
135
|
+
rule id, Name::Variable, :pop!
|
136
|
+
rule(//) { pop! }
|
137
|
+
end
|
138
|
+
|
139
|
+
state :funcname do
|
140
|
+
mixin :whitespace
|
141
|
+
rule id, Name::Function, :pop!
|
142
|
+
end
|
143
|
+
|
144
|
+
state :classname do
|
145
|
+
mixin :whitespace
|
146
|
+
rule id, Name::Class, :pop!
|
147
|
+
end
|
148
|
+
|
149
|
+
state :namespace do
|
150
|
+
mixin :whitespace
|
151
|
+
rule /#{id}([.]#{id})*/, Name::Namespace, :pop!
|
152
|
+
end
|
153
|
+
|
154
|
+
state :end do
|
155
|
+
mixin :whitespace
|
156
|
+
rule /(Function|Sub|Property|Class|Structure|Enum|Module|Namespace)\b/,
|
157
|
+
Keyword, :pop!
|
158
|
+
rule(//) { pop! }
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# DO NOT EDIT: automatically generated by `rake builtins:vim`.
|
2
|
+
# see tasks/vim.rake for more info.
|
3
|
+
module Rugments
|
4
|
+
module Lexers
|
5
|
+
class VimL
|
6
|
+
def self.keywords
|
7
|
+
@keywords ||= { command: [%w(a a), %w(ab ab), %w(abc abclear), %w(abo aboveleft), %w(al all), %w(ar ar), %w(ar args), %w(arga argadd), %w(argd argdelete), %w(argdo argdo), %w(arge argedit), %w(argg argglobal), %w(argl arglocal), %w(argu argument), %w(as ascii), %w(au au), %w(b buffer), %w(bN bNext), %w(ba ball), %w(bad badd), %w(bd bdelete), %w(bel belowright), %w(bf bfirst), %w(bl blast), %w(bm bmodified), %w(bn bnext), %w(bo botright), %w(bp bprevious), %w(br br), %w(br brewind), %w(brea break), %w(breaka breakadd), %w(breakd breakdel), %w(breakl breaklist), %w(bro browse), %w(bu bu), %w(buf buf), %w(bufdo bufdo), %w(buffers buffers), %w(bun bunload), %w(bw bwipeout), %w(c c), %w(c change), %w(cN cN), %w(cN cNext), %w(cNf cNf), %w(cNf cNfile), %w(cabc cabclear), %w(cad cad), %w(cad caddexpr), %w(caddb caddbuffer), %w(caddf caddfile), %w(cal call), %w(cat catch), %w(cb cbuffer), %w(cc cc), %w(ccl cclose), %w(cd cd), %w(ce center), %w(cex cexpr), %w(cf cfile), %w(cfir cfirst), %w(cg cgetfile), %w(cgetb cgetbuffer), %w(cgete cgetexpr), %w(changes changes), %w(chd chdir), %w(che checkpath), %w(checkt checktime), %w(cl cl), %w(cl clist), %w(cla clast), %w(clo close), %w(cmapc cmapclear), %w(cn cn), %w(cn cnext), %w(cnew cnewer), %w(cnf cnf), %w(cnf cnfile), %w(co copy), %w(col colder), %w(colo colorscheme), %w(com com), %w(comc comclear), %w(comp compiler), %w(con con), %w(con continue), %w(conf confirm), %w(cope copen), %w(cp cprevious), %w(cpf cpfile), %w(cq cquit), %w(cr crewind), %w(cs cs), %w(cscope cscope), %w(cstag cstag), %w(cuna cunabbrev), %w(cw cwindow), %w(d d), %w(d delete), %w(de de), %w(debug debug), %w(debugg debuggreedy), %w(del del), %w(delc delcommand), %w(delel delel), %w(delep delep), %w(deletel deletel), %w(deletep deletep), %w(deletl deletl), %w(deletp deletp), %w(delf delf), %w(delf delfunction), %w(dell dell), %w(delm delmarks), %w(delp delp), %w(dep dep), %w(di di), %w(di display), %w(diffg diffget), %w(diffo diffoff), %w(diffp diffpatch), %w(diffpu diffput), %w(diffs diffsplit), %w(difft diffthis), %w(diffu diffupdate), %w(dig dig), %w(dig digraphs), %w(dir dir), %w(dj djump), %w(dl dl), %w(dli dlist), %w(do do), %w(doau doau), %w(dp dp), %w(dr drop), %w(ds dsearch), %w(dsp dsplit), %w(e e), %w(e edit), %w(ea ea), %w(earlier earlier), %w(ec ec), %w(echoe echoerr), %w(echom echomsg), %w(echon echon), %w(el else), %w(elsei elseif), %w(em emenu), %w(en en), %w(en endif), %w(endf endf), %w(endf endfunction), %w(endfo endfor), %w(endfun endfun), %w(endt endtry), %w(endw endwhile), %w(ene enew), %w(ex ex), %w(exi exit), %w(exu exusage), %w(f f), %w(f file), %w(files files), %w(filet filet), %w(filetype filetype), %w(fin fin), %w(fin find), %w(fina finally), %w(fini finish), %w(fir first), %w(fix fixdel), %w(fo fold), %w(foldc foldclose), %w(foldd folddoopen), %w(folddoc folddoclosed), %w(foldo foldopen), %w(for for), %w(fu fu), %w(fu function), %w(fun fun), %w(g g), %w(go goto), %w(gr grep), %w(grepa grepadd), %w(gui gui), %w(gvim gvim), %w(h h), %w(h help), %w(ha hardcopy), %w(helpf helpfind), %w(helpg helpgrep), %w(helpt helptags), %w(hi hi), %w(hid hide), %w(his history), %w(i i), %w(ia ia), %w(iabc iabclear), %w(if if), %w(ij ijump), %w(il ilist), %w(imapc imapclear), %w(in in), %w(intro intro), %w(is isearch), %w(isp isplit), %w(iuna iunabbrev), %w(j join), %w(ju jumps), %w(k k), %w(kee keepmarks), %w(keepa keepa), %w(keepalt keepalt), %w(keepj keepjumps), %w(keepp keeppatterns), %w(l l), %w(l list), %w(lN lN), %w(lN lNext), %w(lNf lNf), %w(lNf lNfile), %w(la la), %w(la last), %w(lad lad), %w(lad laddexpr), %w(laddb laddbuffer), %w(laddf laddfile), %w(lan lan), %w(lan language), %w(lat lat), %w(later later), %w(lb lbuffer), %w(lc lcd), %w(lch lchdir), %w(lcl lclose), %w(lcs lcs), %w(lcscope lcscope), %w(le left), %w(lefta leftabove), %w(lex lexpr), %w(lf lfile), %w(lfir lfirst), %w(lg lgetfile), %w(lgetb lgetbuffer), %w(lgete lgetexpr), %w(lgr lgrep), %w(lgrepa lgrepadd), %w(lh lhelpgrep), %w(ll ll), %w(lla llast), %w(lli llist), %w(lmak lmake), %w(lmapc lmapclear), %w(lne lne), %w(lne lnext), %w(lnew lnewer), %w(lnf lnf), %w(lnf lnfile), %w(lo lo), %w(lo loadview), %w(loadk loadk), %w(loadkeymap loadkeymap), %w(loc lockmarks), %w(lockv lockvar), %w(lol lolder), %w(lop lopen), %w(lp lprevious), %w(lpf lpfile), %w(lr lrewind), %w(ls ls), %w(lt ltag), %w(lua lua), %w(luado luado), %w(luafile luafile), %w(lv lvimgrep), %w(lvimgrepa lvimgrepadd), %w(lw lwindow), %w(m move), %w(ma ma), %w(ma mark), %w(mak make), %w(marks marks), %w(mat match), %w(menut menut), %w(menut menutranslate), %w(mes mes), %w(messages messages), %w(mk mk), %w(mk mkexrc), %w(mks mksession), %w(mksp mkspell), %w(mkv mkv), %w(mkv mkvimrc), %w(mkvie mkview), %w(mo mo), %w(mod mode), %w(mz mz), %w(mz mzscheme), %w(mzf mzfile), %w(n n), %w(n next), %w(nb nbkey), %w(nbc nbclose), %w(nbs nbstart), %w(ne ne), %w(new new), %w(nmapc nmapclear), %w(noa noa), %w(noautocmd noautocmd), %w(noh nohlsearch), %w(nu number), %w(o o), %w(o open), %w(ol oldfiles), %w(omapc omapclear), %w(on only), %w(opt options), %w(ownsyntax ownsyntax), %w(p p), %w(p print), %w(pc pclose), %w(pe pe), %w(pe perl), %w(ped pedit), %w(perld perldo), %w(po pop), %w(popu popu), %w(popu popup), %w(pp ppop), %w(pr pr), %w(pre preserve), %w(prev previous), %w(pro pro), %w(prof profile), %w(profd profdel), %w(promptf promptfind), %w(promptr promptrepl), %w(ps psearch), %w(ptN ptN), %w(ptN ptNext), %w(pta ptag), %w(ptf ptfirst), %w(ptj ptjump), %w(ptl ptlast), %w(ptn ptn), %w(ptn ptnext), %w(ptp ptprevious), %w(ptr ptrewind), %w(pts ptselect), %w(pu put), %w(pw pwd), %w(py py), %w(py python), %w(py3 py3), %w(py3 py3), %w(py3do py3do), %w(pydo pydo), %w(pyf pyfile), %w(python3 python3), %w(q q), %w(q quit), %w(qa qall), %w(quita quitall), %w(r r), %w(r read), %w(re re), %w(rec recover), %w(red red), %w(red redo), %w(redi redir), %w(redr redraw), %w(redraws redrawstatus), %w(reg registers), %w(res resize), %w(ret retab), %w(retu return), %w(rew rewind), %w(ri right), %w(rightb rightbelow), %w(ru ru), %w(ru runtime), %w(rub ruby), %w(rubyd rubydo), %w(rubyf rubyfile), %w(rundo rundo), %w(rv rviminfo), %w(sN sNext), %w(sa sargument), %w(sal sall), %w(san sandbox), %w(sav saveas), %w(sb sbuffer), %w(sbN sbNext), %w(sba sball), %w(sbf sbfirst), %w(sbl sblast), %w(sbm sbmodified), %w(sbn sbnext), %w(sbp sbprevious), %w(sbr sbrewind), %w(scrip scrip), %w(scrip scriptnames), %w(scripte scriptencoding), %w(scs scs), %w(scscope scscope), %w(se set), %w(setf setfiletype), %w(setg setglobal), %w(setl setlocal), %w(sf sfind), %w(sfir sfirst), %w(sh shell), %w(si si), %w(sig sig), %w(sign sign), %w(sil silent), %w(sim simalt), %w(sl sl), %w(sl sleep), %w(sla slast), %w(sm smagic), %w(sm smap), %w(sme sme), %w(smenu smenu), %w(sn snext), %w(sni sniff), %w(sno snomagic), %w(snoreme snoreme), %w(snoremenu snoremenu), %w(so so), %w(so source), %w(sor sort), %w(sp split), %w(spe spe), %w(spe spellgood), %w(spelld spelldump), %w(spelli spellinfo), %w(spellr spellrepall), %w(spellu spellundo), %w(spellw spellwrong), %w(spr sprevious), %w(sre srewind), %w(st st), %w(st stop), %w(sta stag), %w(star star), %w(star startinsert), %w(start start), %w(startg startgreplace), %w(startr startreplace), %w(stj stjump), %w(stopi stopinsert), %w(sts stselect), %w(sun sunhide), %w(sunme sunme), %w(sunmenu sunmenu), %w(sus suspend), %w(sv sview), %w(sw swapname), %w(sy sy), %w(syn syn), %w(sync sync), %w(syncbind syncbind), %w(syntime syntime), %w(t t), %w(tN tN), %w(tN tNext), %w(ta ta), %w(ta tag), %w(tab tab), %w(tabN tabN), %w(tabN tabNext), %w(tabc tabclose), %w(tabd tabdo), %w(tabe tabedit), %w(tabf tabfind), %w(tabfir tabfirst), %w(tabl tablast), %w(tabm tabmove), %w(tabn tabnext), %w(tabnew tabnew), %w(tabo tabonly), %w(tabp tabprevious), %w(tabr tabrewind), %w(tabs tabs), %w(tags tags), %w(tc tcl), %w(tcld tcldo), %w(tclf tclfile), %w(te tearoff), %w(tf tfirst), %w(th throw), %w(tj tjump), %w(tl tlast), %w(tm tm), %w(tm tmenu), %w(tn tn), %w(tn tnext), %w(to topleft), %w(tp tprevious), %w(tr tr), %w(tr trewind), %w(try try), %w(ts tselect), %w(tu tu), %w(tu tunmenu), %w(u u), %w(u undo), %w(un un), %w(una unabbreviate), %w(undoj undojoin), %w(undol undolist), %w(unh unhide), %w(unl unl), %w(unlo unlockvar), %w(uns unsilent), %w(up update), %w(v v), %w(ve ve), %w(ve version), %w(verb verbose), %w(vert vertical), %w(vi vi), %w(vi visual), %w(vie view), %w(vim vimgrep), %w(vimgrepa vimgrepadd), %w(viu viusage), %w(vmapc vmapclear), %w(vne vnew), %w(vs vsplit), %w(w w), %w(w write), %w(wN wNext), %w(wa wall), %w(wh while), %w(win win), %w(win winsize), %w(winc wincmd), %w(windo windo), %w(winp winpos), %w(wn wnext), %w(wp wprevious), %w(wq wq), %w(wqa wqall), %w(ws wsverb), %w(wundo wundo), %w(wv wviminfo), %w(x x), %w(x xit), %w(xa xall), %w(xmapc xmapclear), %w(xme xme), %w(xmenu xmenu), %w(xnoreme xnoreme), %w(xnoremenu xnoremenu), %w(xunme xunme), %w(xunmenu xunmenu), %w(xwininfo xwininfo), %w(y yank)], option: [], auto: [%w(BufAdd BufAdd), %w(BufCreate BufCreate), %w(BufDelete BufDelete), %w(BufEnter BufEnter), %w(BufFilePost BufFilePost), %w(BufFilePre BufFilePre), %w(BufHidden BufHidden), %w(BufLeave BufLeave), %w(BufNew BufNew), %w(BufNewFile BufNewFile), %w(BufRead BufRead), %w(BufReadCmd BufReadCmd), %w(BufReadPost BufReadPost), %w(BufReadPre BufReadPre), %w(BufUnload BufUnload), %w(BufWinEnter BufWinEnter), %w(BufWinLeave BufWinLeave), %w(BufWipeout BufWipeout), %w(BufWrite BufWrite), %w(BufWriteCmd BufWriteCmd), %w(BufWritePost BufWritePost), %w(BufWritePre BufWritePre), %w(Cmd Cmd), %w(CmdwinEnter CmdwinEnter), %w(CmdwinLeave CmdwinLeave), %w(ColorScheme ColorScheme), %w(CompleteDone CompleteDone), %w(CursorHold CursorHold), %w(CursorHoldI CursorHoldI), %w(CursorMoved CursorMoved), %w(CursorMovedI CursorMovedI), %w(EncodingChanged EncodingChanged), %w(FileAppendCmd FileAppendCmd), %w(FileAppendPost FileAppendPost), %w(FileAppendPre FileAppendPre), %w(FileChangedRO FileChangedRO), %w(FileChangedShell FileChangedShell), %w(FileChangedShellPost FileChangedShellPost), %w(FileEncoding FileEncoding), %w(FileReadCmd FileReadCmd), %w(FileReadPost FileReadPost), %w(FileReadPre FileReadPre), %w(FileType FileType), %w(FileWriteCmd FileWriteCmd), %w(FileWritePost FileWritePost), %w(FileWritePre FileWritePre), %w(FilterReadPost FilterReadPost), %w(FilterReadPre FilterReadPre), %w(FilterWritePost FilterWritePost), %w(FilterWritePre FilterWritePre), %w(FocusGained FocusGained), %w(FocusLost FocusLost), %w(FuncUndefined FuncUndefined), %w(GUIEnter GUIEnter), %w(GUIFailed GUIFailed), %w(InsertChange InsertChange), %w(InsertCharPre InsertCharPre), %w(InsertEnter InsertEnter), %w(InsertLeave InsertLeave), %w(MenuPopup MenuPopup), %w(QuickFixCmdPost QuickFixCmdPost), %w(QuickFixCmdPre QuickFixCmdPre), %w(QuitPre QuitPre), %w(RemoteReply RemoteReply), %w(SessionLoadPost SessionLoadPost), %w(ShellCmdPost ShellCmdPost), %w(ShellFilterPost ShellFilterPost), %w(SourceCmd SourceCmd), %w(SourcePre SourcePre), %w(SpellFileMissing SpellFileMissing), %w(StdinReadPost StdinReadPost), %w(StdinReadPre StdinReadPre), %w(SwapExists SwapExists), %w(Syntax Syntax), %w(TabEnter TabEnter), %w(TabLeave TabLeave), %w(TermChanged TermChanged), %w(TermResponse TermResponse), %w(TextChanged TextChanged), %w(TextChangedI TextChangedI), %w(User User), %w(UserGettingBored UserGettingBored), %w(VimEnter VimEnter), %w(VimLeave VimLeave), %w(VimLeavePre VimLeavePre), %w(VimResized VimResized), %w(WinEnter WinEnter), %w(WinLeave WinLeave), %w(event event)] }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class VimL < RegexLexer
|
4
|
+
title 'VimL'
|
5
|
+
desc 'VimL, the scripting language for the Vim editor (vim.org)'
|
6
|
+
tag 'viml'
|
7
|
+
aliases 'vim', 'vimscript', 'ex'
|
8
|
+
filenames '*.vim', '*.vba', '.vimrc', '.exrc', '.gvimrc',
|
9
|
+
'_vimrc', '_exrc', '_gvimrc' # _ names for windows
|
10
|
+
|
11
|
+
mimetypes 'text/x-vim'
|
12
|
+
|
13
|
+
def self.keywords
|
14
|
+
load Pathname.new(__FILE__).dirname.join('viml/keywords.rb')
|
15
|
+
keywords
|
16
|
+
end
|
17
|
+
|
18
|
+
state :root do
|
19
|
+
rule /^(\s*)(".*?)$/ do
|
20
|
+
groups Text, Comment
|
21
|
+
end
|
22
|
+
|
23
|
+
rule /^\s*\\/, Str::Escape
|
24
|
+
|
25
|
+
rule /[ \t]+/, Text
|
26
|
+
|
27
|
+
# TODO: regexes can have other delimiters
|
28
|
+
rule %r{/(\\\\|\\/|[^\n/])*/}, Str::Regex
|
29
|
+
rule %r{"(\\\\|\\"|[^\n"])*"}, Str::Double
|
30
|
+
rule %r{'(\\\\|\\'|[^\n'])*'}, Str::Single
|
31
|
+
|
32
|
+
# if it's not a string, it's a comment.
|
33
|
+
rule /(?<=\s)"[^-:.%#=*].*?$/, Comment
|
34
|
+
|
35
|
+
rule /-?\d+/, Num
|
36
|
+
rule /#[0-9a-f]{6}/i, Num::Hex
|
37
|
+
rule /^:/, Punctuation
|
38
|
+
rule /[():<>+=!\[\]{}\|,~.-]/, Punctuation
|
39
|
+
rule /\b(let|if|else|endif|elseif|fun|function|endfunction)\b/,
|
40
|
+
Keyword
|
41
|
+
|
42
|
+
rule /\b(NONE|bold|italic|underline|dark|light)\b/, Name::Builtin
|
43
|
+
|
44
|
+
rule /[absg]:\w+\b/, Name::Variable
|
45
|
+
rule /\b\w+\b/ do |m|
|
46
|
+
name = m[0]
|
47
|
+
keywords = self.class.keywords
|
48
|
+
|
49
|
+
if mapping_contains?(keywords[:command], name)
|
50
|
+
token Keyword
|
51
|
+
elsif mapping_contains?(keywords[:option], name)
|
52
|
+
token Name::Builtin
|
53
|
+
elsif mapping_contains?(keywords[:auto], name)
|
54
|
+
token Name::Builtin
|
55
|
+
else
|
56
|
+
token Text
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# no errors in VimL!
|
61
|
+
rule /./m, Text
|
62
|
+
end
|
63
|
+
|
64
|
+
def mapping_contains?(mapping, word)
|
65
|
+
shortest, longest = find_likely_mapping(mapping, word)
|
66
|
+
|
67
|
+
shortest and word.start_with?(shortest) and
|
68
|
+
longest and longest.start_with?(word)
|
69
|
+
end
|
70
|
+
|
71
|
+
# binary search through the mappings to find the one that's likely
|
72
|
+
# to actually work.
|
73
|
+
def find_likely_mapping(mapping, word)
|
74
|
+
min = 0
|
75
|
+
max = mapping.size
|
76
|
+
|
77
|
+
until max == min
|
78
|
+
mid = (max + min) / 2
|
79
|
+
|
80
|
+
cmp, _ = mapping[mid]
|
81
|
+
|
82
|
+
case word <=> cmp
|
83
|
+
when 1
|
84
|
+
# too low
|
85
|
+
min = mid + 1
|
86
|
+
when -1
|
87
|
+
# too high
|
88
|
+
max = mid
|
89
|
+
when 0
|
90
|
+
# just right, abort!
|
91
|
+
return mapping[mid]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
mapping[max - 1]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Rugments
|
2
|
+
module Lexers
|
3
|
+
class XML < RegexLexer
|
4
|
+
title 'XML'
|
5
|
+
desc '<desc for="this-lexer">XML</desc>'
|
6
|
+
tag 'xml'
|
7
|
+
filenames *%w(*.xml *.xsl *.rss *.xslt *.xsd *.wsdl)
|
8
|
+
mimetypes *%w(
|
9
|
+
text/xml
|
10
|
+
application/xml
|
11
|
+
image/svg+xml
|
12
|
+
application/rss+xml
|
13
|
+
application/atom+xml
|
14
|
+
)
|
15
|
+
|
16
|
+
def self.analyze_text(text)
|
17
|
+
return 0.9 if text.doctype?
|
18
|
+
return 0.8 if text =~ /\A<\?xml\b/
|
19
|
+
start = text[0..1000]
|
20
|
+
return 0.6 if start =~ %r{<xml\b}
|
21
|
+
return 0.3 if start =~ %r{<.+?>.*?</.+?>}m
|
22
|
+
end
|
23
|
+
|
24
|
+
state :root do
|
25
|
+
rule /[^<&]+/, Text
|
26
|
+
rule /&\S*?;/, Name::Entity
|
27
|
+
rule /<!\[CDATA\[.*?\]\]\>/, Comment::Preproc
|
28
|
+
rule /<!--/, Comment, :comment
|
29
|
+
rule /<\?.*?\?>/, Comment::Preproc
|
30
|
+
rule /<![^>]*>/, Comment::Preproc
|
31
|
+
|
32
|
+
# open tags
|
33
|
+
rule %r{<\s*[\w:.-]+}m, Name::Tag, :tag
|
34
|
+
|
35
|
+
# self-closing tags
|
36
|
+
rule %r{<\s*/\s*[\w:.-]+\s*>}m, Name::Tag
|
37
|
+
end
|
38
|
+
|
39
|
+
state :comment do
|
40
|
+
rule /[^-]+/m, Comment
|
41
|
+
rule /-->/, Comment, :pop!
|
42
|
+
rule /-/, Comment
|
43
|
+
end
|
44
|
+
|
45
|
+
state :tag do
|
46
|
+
rule /\s+/m, Text
|
47
|
+
rule /[\w.:-]+\s*=/m, Name::Attribute, :attr
|
48
|
+
rule %r{/?\s*>}, Name::Tag, :pop!
|
49
|
+
end
|
50
|
+
|
51
|
+
state :attr do
|
52
|
+
rule /\s+/m, Text
|
53
|
+
rule /".*?"|'.*?'|[^\s>]+/, Str, :pop!
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|