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,63 @@
1
+ module Rugments
2
+ module Lexers
3
+ load_const :C, 'c.rb'
4
+
5
+ class Cpp < C
6
+ title 'C++'
7
+ desc 'The C++ programming language'
8
+
9
+ tag 'cpp'
10
+ aliases 'c++'
11
+ # the many varied filenames of c++ source files...
12
+ filenames '*.cpp', '*.hpp',
13
+ '*.c++', '*.h++',
14
+ '*.cc', '*.hh',
15
+ '*.cxx', '*.hxx'
16
+ mimetypes 'text/x-c++hdr', 'text/x-c++src'
17
+
18
+ def self.keywords
19
+ @keywords ||= super + Set.new(%w(
20
+ asm catch const_cast delete dynamic_cast explicit export
21
+ friend mutable namespace new operator private protected public
22
+ reinterpret_cast restrict static_cast template this throw
23
+ throws typeid typename using virtual
24
+ ))
25
+ end
26
+
27
+ def self.reserved
28
+ @reserved ||= super + Set.new(%w(
29
+ __virtual_inheritance __uuidof __super __single_inheritance
30
+ __multiple_inheritance __interface __event
31
+ ))
32
+ end
33
+
34
+ id = /[a-zA-Z_][a-zA-Z0-9]*/
35
+
36
+ prepend :root do
37
+ # Offload C++ extensions, http://offload.codeplay.com/
38
+ rule /(?:__offload|__blockingoffload|__outer)\b/, Keyword::Pseudo
39
+ end
40
+
41
+ # digits with optional inner quotes
42
+ # see www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3781.pdf
43
+ dq = /\d('?\d)*/
44
+
45
+ prepend :statements do
46
+ rule /class\b/, Keyword, :classname
47
+ rule %r{(#{dq}[.]#{dq}?|[.]#{dq})(e[+-]?#{dq}[lu]*)?}i, Num::Float
48
+ rule %r{#{dq}e[+-]?#{dq}[lu]*}i, Num::Float
49
+ rule /0x\h('?\h)*[lu]*/i, Num::Hex
50
+ rule /0[0-7]('?[0-7])*[lu]*/i, Num::Oct
51
+ rule /#{dq}[lu]*/i, Num::Integer
52
+ end
53
+
54
+ state :classname do
55
+ rule id, Name::Class, :pop!
56
+
57
+ # template specification
58
+ rule /\s*(?=>)/m, Text, :pop!
59
+ mixin :whitespace
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,85 @@
1
+ module Rugments
2
+ module Lexers
3
+ class CSharp < RegexLexer
4
+ tag 'csharp'
5
+ aliases 'c#', 'cs'
6
+ filenames '*.cs'
7
+ mimetypes 'text/x-csharp'
8
+
9
+ title 'C#'
10
+ desc 'a multi-paradigm language targeting .NET'
11
+
12
+ # TODO: support more of unicode
13
+ id = /@?[_a-z]\w*/i
14
+
15
+ keywords = %w(
16
+ abstract alias as base break case catch checked const continue
17
+ default delegate do else enum event explicit extern false
18
+ finally fixed for foreach global goto if implicit in interface
19
+ internal is lock new null operator out override params private
20
+ protected public readonly ref return sealed sizeof stackalloc
21
+ static switch this throw true try typeof unchecked unsafe
22
+ virtual void while get set new partial yield add remove value
23
+ )
24
+
25
+ keywords_type = %w(
26
+ bool byte char decimal double float int long object sbyte
27
+ short string uint ulong ushort
28
+ )
29
+
30
+ cpp_keywords = %w(
31
+ if endif else elif define undef line error warning region
32
+ endregion pragma
33
+ )
34
+
35
+ state :whitespace do
36
+ rule /\s+/m, Text
37
+ rule %r{//.*?\n}, Comment::Single
38
+ rule %r{/[*].*?[*]/}m, Comment::Multiline
39
+ end
40
+
41
+ state :root do
42
+ mixin :whitespace
43
+
44
+ rule /^\s*\[.*?\]/, Name::Attribute
45
+ rule /[$]\s*"/, Str, :splice_string
46
+ rule /[$]\s*<#/, Str, :splice_recstring
47
+ rule /<#/, Str, :recstring
48
+
49
+ rule /(<\[)\s*(#{id}:)?/, Keyword
50
+ rule /\]>/, Keyword
51
+
52
+ rule /[~!%^&*()+=|\[\]{}:;,.<>\/?-]/, Punctuation
53
+ rule /@"(\\.|.)*?"/, Str
54
+ rule /"(\\.|.)*?["\n]/, Str
55
+ rule /'(\\.|.)'/, Str::Char
56
+ rule /0x[0-9a-f]+[lu]?/i, Num
57
+ rule %r{
58
+ [0-9]
59
+ ([.][0-9]*)? # decimal
60
+ (e[+-][0-9]+)? # exponent
61
+ [fldu]? # type
62
+ }ix, Num
63
+ rule /^#[ \t]*(#{cpp_keywords.join('|')})\b.*?\n/,
64
+ Comment::Preproc
65
+ rule /\b(#{keywords.join('|')})\b/, Keyword
66
+ rule /\b(#{keywords_type.join('|')})\b/, Keyword::Type
67
+ rule /class|struct/, Keyword, :class
68
+ rule /namespace|using/, Keyword, :namespace
69
+ rule /#{id}(?=\s*[(])/, Name::Function
70
+ rule id, Name
71
+ end
72
+
73
+ state :class do
74
+ mixin :whitespace
75
+ rule id, Name::Class, :pop!
76
+ end
77
+
78
+ state :namespace do
79
+ mixin :whitespace
80
+ rule /(?=[(])/, Text, :pop!
81
+ rule /(#{id}|[.])+/, Name::Namespace, :pop!
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,269 @@
1
+ module Rugments
2
+ module Lexers
3
+ class CSS < RegexLexer
4
+ title 'CSS'
5
+ desc 'Cascading Style Sheets, used to style web pages'
6
+
7
+ tag 'css'
8
+ filenames '*.css'
9
+ mimetypes 'text/css'
10
+
11
+ identifier = /[a-zA-Z0-9_-]+/
12
+ number = /-?(?:[0-9]+(\.[0-9]+)?|\.[0-9]+)/
13
+
14
+ def self.attributes
15
+ @attributes ||= Set.new %w(
16
+ align-content align-items align-self alignment-adjust
17
+ alignment-baseline all anchor-point animation
18
+ animation-delay animation-direction animation-duration
19
+ animation-fill-mode animation-iteration-count animation-name
20
+ animation-play-state animation-timing-function appearance
21
+ azimuth backface-visibility background background-attachment
22
+ background-clip background-color background-image
23
+ background-origin background-position background-repeat
24
+ background-size baseline-shift binding bleed bookmark-label
25
+ bookmark-level bookmark-state bookmark-target border
26
+ border-bottom border-bottom-color border-bottom-left-radius
27
+ border-bottom-right-radius border-bottom-style
28
+ border-bottom-width border-collapse border-color
29
+ border-image border-image-outset border-image-repeat
30
+ border-image-slice border-image-source border-image-width
31
+ border-left border-left-color border-left-style
32
+ border-left-width border-radius border-right
33
+ border-right-color border-right-style border-right-width
34
+ border-spacing border-style border-top border-top-color
35
+ border-top-left-radius border-top-right-radius
36
+ border-top-style border-top-width border-width bottom
37
+ box-align box-decoration-break box-direction box-flex
38
+ box-flex-group box-lines box-ordinal-group box-orient
39
+ box-pack box-shadow box-sizing break-after break-before
40
+ break-inside caption-side clear clip clip-path
41
+ clip-rule color color-profile columns column-count
42
+ column-fill column-gap column-rule column-rule-color
43
+ column-rule-style column-rule-width column-span
44
+ column-width content counter-increment counter-reset
45
+ crop cue cue-after cue-before cursor direction display
46
+ dominant-baseline drop-initial-after-adjust
47
+ drop-initial-after-align drop-initial-before-adjust
48
+ drop-initial-before-align drop-initial-size
49
+ drop-initial-value elevation empty-cells filter fit
50
+ fit-position flex flex-basis flex-direction flex-flow
51
+ flex-grow flex-shrink flex-wrap float float-offset
52
+ font font-family font-feature-settings
53
+ font-kerning font-language-override font-size
54
+ font-size-adjust font-stretch font-style font-synthesis
55
+ font-variant font-variant-alternates font-variant-caps
56
+ font-variant-east-asian font-variant-ligatures
57
+ font-variant-numeric font-variant-position font-weight
58
+ grid-cell grid-column grid-column-align grid-column-sizing
59
+ grid-column-span grid-columns grid-flow grid-row
60
+ grid-row-align grid-row-sizing grid-row-span
61
+ grid-rows grid-template hanging-punctuation height
62
+ hyphenate-after hyphenate-before hyphenate-character
63
+ hyphenate-lines hyphenate-resource hyphens icon
64
+ image-orientation image-rendering image-resolution
65
+ ime-mode inline-box-align justify-content
66
+ left letter-spacing line-break line-height
67
+ line-stacking line-stacking-ruby line-stacking-shift
68
+ line-stacking-strategy list-style list-style-image
69
+ list-style-position list-style-type margin
70
+ margin-bottom margin-left margin-right margin-top
71
+ mark marker-offset marks mark-after mark-before
72
+ marquee-direction marquee-loop marquee-play-count
73
+ marquee-speed marquee-style mask max-height max-width
74
+ min-height min-width move-to nav-down
75
+ nav-index nav-left nav-right nav-up object-fit
76
+ object-position opacity order orphans outline
77
+ outline-color outline-offset outline-style
78
+ outline-width overflow overflow-style overflow-wrap
79
+ overflow-x overflow-y padding padding-bottom
80
+ padding-left padding-right padding-top
81
+ page page-break-after page-break-before
82
+ page-break-inside page-policy pause pause-after
83
+ pause-before perspective perspective-origin
84
+ phonemes pitch pitch-range play-during pointer-events
85
+ position presentation-level punctuation-trim quotes
86
+ rendering-intent resize rest rest-after rest-before
87
+ richness right rotation rotation-point ruby-align
88
+ ruby-overhang ruby-position ruby-span size speak
89
+ speak-as speak-header speak-numeral speak-punctuation
90
+ speech-rate src stress string-set
91
+ tab-size table-layout target target-name
92
+ target-new target-position text-align
93
+ text-align-last text-combine-horizontal
94
+ text-decoration text-decoration-color
95
+ text-decoration-line text-decoration-skip
96
+ text-decoration-style text-emphasis
97
+ text-emphasis-color text-emphasis-position
98
+ text-emphasis-style text-height text-indent
99
+ text-justify text-orientation text-outline
100
+ text-overflow text-rendering text-shadow
101
+ text-space-collapse text-transform
102
+ text-underline-position text-wrap top
103
+ transform transform-origin transform-style
104
+ transition transition-delay transition-duration
105
+ transition-property transition-timing-function
106
+ unicode-bidi vertical-align
107
+ visibility voice-balance voice-duration
108
+ voice-family voice-pitch voice-pitch-range
109
+ voice-range voice-rate voice-stress voice-volume
110
+ volume white-space widows width word-break
111
+ word-spacing word-wrap writing-mode z-index
112
+ )
113
+ end
114
+
115
+ def self.builtins
116
+ @builtins ||= Set.new %w(
117
+ above absolute always armenian aural auto avoid left bottom
118
+ baseline behind below bidi-override blink block bold bolder
119
+ both bottom capitalize center center-left center-right circle
120
+ cjk-ideographic close-quote collapse condensed continuous crop
121
+ cross crosshair cursive dashed decimal decimal-leading-zero
122
+ default digits disc dotted double e-resize embed expanded
123
+ extra-condensed extra-expanded fantasy far-left far-right fast
124
+ faster fixed georgian groove hebrew help hidden hide high higher
125
+ hiragana hiragana-iroha icon inherit inline inline-table inset
126
+ inside invert italic justify katakana katakana-iroha landscape
127
+ large larger left left-side leftwards level lighter line-through
128
+ list-item loud low lower lower-alpha lower-greek lower-roman
129
+ lowercase ltr medium message-box middle mix monospace n-resize
130
+ narrower ne-resize no-close-quote no-open-quote no-repeat none
131
+ normal nowrap nw-resize oblique once open-quote outset outside
132
+ overline pointer portrait px relative repeat repeat-x repeat-y
133
+ rgb ridge right right-side rightwards s-resize sans-serif scroll
134
+ se-resize semi-condensed semi-expanded separate serif show
135
+ silent slow slower small-caps small-caption smaller soft solid
136
+ spell-out square static status-bar super sw-resize table-caption
137
+ table-cell table-column table-column-group table-footer-group
138
+ table-header-group table-row table-row-group text text-bottom
139
+ text-top thick thin top transparent ultra-condensed
140
+ ultra-expanded underline upper-alpha upper-latin upper-roman
141
+ uppercase url visible w-resize wait wider x-fast x-high x-large
142
+ x-loud x-low x-small x-soft xx-large xx-small yes
143
+ )
144
+ end
145
+
146
+ def self.constants
147
+ @constants ||= Set.new %w(
148
+ indigo gold firebrick indianred yellow darkolivegreen
149
+ darkseagreen mediumvioletred mediumorchid chartreuse
150
+ mediumslateblue black springgreen crimson lightsalmon brown
151
+ turquoise olivedrab cyan silver skyblue gray darkturquoise
152
+ goldenrod darkgreen darkviolet darkgray lightpink teal
153
+ darkmagenta lightgoldenrodyellow lavender yellowgreen thistle
154
+ violet navy orchid blue ghostwhite honeydew cornflowerblue
155
+ darkblue darkkhaki mediumpurple cornsilk red bisque slategray
156
+ darkcyan khaki wheat deepskyblue darkred steelblue aliceblue
157
+ gainsboro mediumturquoise floralwhite coral purple lightgrey
158
+ lightcyan darksalmon beige azure lightsteelblue oldlace
159
+ greenyellow royalblue lightseagreen mistyrose sienna lightcoral
160
+ orangered navajowhite lime palegreen burlywood seashell
161
+ mediumspringgreen fuchsia papayawhip blanchedalmond peru
162
+ aquamarine white darkslategray ivory dodgerblue lemonchiffon
163
+ chocolate orange forestgreen slateblue olive mintcream
164
+ antiquewhite darkorange cadetblue moccasin limegreen saddlebrown
165
+ darkslateblue lightskyblue deeppink plum aqua darkgoldenrod
166
+ maroon sandybrown magenta tan rosybrown pink lightblue
167
+ palevioletred mediumseagreen dimgray powderblue seagreen snow
168
+ mediumblue midnightblue paleturquoise palegoldenrod whitesmoke
169
+ darkorchid salmon lightslategray lawngreen lightgreen tomato
170
+ hotpink lightyellow lavenderblush linen mediumaquamarine green
171
+ blueviolet peachpuff
172
+ )
173
+ end
174
+
175
+ # source: http://www.w3.org/TR/CSS21/syndata.html#vendor-keyword-history
176
+ def self.vendor_prefixes
177
+ @vendor_prefixes ||= Set.new %w(
178
+ -ah- -atsc- -hp- -khtml- -moz- -ms- -o- -rim- -ro- -tc- -wap-
179
+ -webkit- -xv- mso- prince-
180
+ )
181
+ end
182
+
183
+ state :root do
184
+ mixin :basics
185
+ rule /{/, Punctuation, :stanza
186
+ rule /:[:]?#{identifier}/, Name::Decorator
187
+ rule /\.#{identifier}/, Name::Class
188
+ rule /##{identifier}/, Name::Function
189
+ rule /@#{identifier}/, Keyword, :at_rule
190
+ rule identifier, Name::Tag
191
+ rule %r{[~^*!%&\[\]()<>|+=@:;,./?-]}, Operator
192
+ end
193
+
194
+ state :value do
195
+ mixin :basics
196
+ rule /url\(.*?\)/, Str::Other
197
+ rule /#[0-9a-f]{1,6}/i, Num # colors
198
+ rule /#{number}(?:%|(?:em|px|pt|pc|in|mm|cm|ex|rem|ch|vw|vh|vmin|vmax|dpi|dpcm|dppx|deg|grad|rad|turn|s|ms|Hz|kHz)\b)?/, Num
199
+ rule /[\[\]():\/.,]/, Punctuation
200
+ rule /"(\\\\|\\"|[^"])*"/, Str::Single
201
+ rule /'(\\\\|\\'|[^'])*'/, Str::Double
202
+ rule(identifier) do |m|
203
+ if self.class.constants.include? m[0]
204
+ token Name::Constant
205
+ elsif self.class.builtins.include? m[0]
206
+ token Name::Builtin
207
+ else
208
+ token Name
209
+ end
210
+ end
211
+ end
212
+
213
+ state :at_rule do
214
+ rule /{(?=\s*#{identifier}\s*:)/m, Punctuation, :at_stanza
215
+ rule /{/, Punctuation, :at_body
216
+ rule /;/, Punctuation, :pop!
217
+ mixin :value
218
+ end
219
+
220
+ state :at_body do
221
+ mixin :at_content
222
+ mixin :root
223
+ end
224
+
225
+ state :at_stanza do
226
+ mixin :at_content
227
+ mixin :stanza
228
+ end
229
+
230
+ state :at_content do
231
+ rule /}/ do
232
+ token Punctuation
233
+ pop! 2
234
+ end
235
+ end
236
+
237
+ state :basics do
238
+ rule /\s+/m, Text
239
+ rule %r{/\*(?:.*?)\*/}m, Comment
240
+ end
241
+
242
+ state :stanza do
243
+ mixin :basics
244
+ rule /}/, Punctuation, :pop!
245
+ rule /(#{identifier})(\s*)(:)/m do |m|
246
+ name_tok = if self.class.attributes.include? m[1]
247
+ Name::Label
248
+ elsif self.class.vendor_prefixes.any? { |p| m[1].start_with?(p) }
249
+ Name::Label
250
+ else
251
+ Name::Property
252
+ end
253
+
254
+ groups name_tok, Text, Punctuation
255
+
256
+ push :stanza_value
257
+ end
258
+ end
259
+
260
+ state :stanza_value do
261
+ rule /;/, Punctuation, :pop!
262
+ rule(/(?=})/) { pop! }
263
+ rule /!important\b/, Comment::Preproc
264
+ rule /^@.*?$/, Comment::Preproc
265
+ mixin :value
266
+ end
267
+ end
268
+ end
269
+ end
@@ -0,0 +1,102 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Dart < RegexLexer
4
+ title 'Dart'
5
+ desc 'The Dart programming language (dartlang.com)'
6
+
7
+ tag 'dart'
8
+ filenames '*.dart'
9
+ mimetypes 'text/x-dart'
10
+
11
+ keywords = %w(
12
+ as assert break case catch continue default do else finally for
13
+ if in is new rethrow return super switch this throw try while with
14
+ )
15
+
16
+ declarations = %w(
17
+ abstract dynamic const external extends factory final get implements
18
+ native operator set static typedef var
19
+ )
20
+
21
+ types = %w(bool double Dynamic enum int num Object Set String void)
22
+
23
+ imports = %w(import export library part\s*of part source)
24
+
25
+ id = /[a-zA-Z_]\w*/
26
+
27
+ state :root do
28
+ rule %r{^
29
+ (\s*(?:[a-zA-Z_][a-zA-Z\d_.\[\]]*\s+)+?) # return arguments
30
+ ([a-zA-Z_][\w]*) # method name
31
+ (\s*)(\() # signature start
32
+ }mx do |m|
33
+ # TODO: do this better, this shouldn't need a delegation
34
+ delegate Dart, m[1]
35
+ token Name::Function, m[2]
36
+ token Text, m[3]
37
+ token Punctuation, m[4]
38
+ end
39
+
40
+ rule /\s+/, Text
41
+ rule %r{//.*?$}, Comment::Single
42
+ rule %r{/\*.*?\*/}m, Comment::Multiline
43
+ rule /"/, Str, :dqs
44
+ rule /'/, Str, :sqs
45
+ rule /r"[^"]*"/, Str::Other
46
+ rule /r'[^']*'/, Str::Other
47
+ rule /##{id}*/i, Str::Symbol
48
+ rule /@#{id}/, Name::Decorator
49
+ rule /(?:#{keywords.join('|')})\b/, Keyword
50
+ rule /(?:#{declarations.join('|')})\b/, Keyword::Declaration
51
+ rule /(?:#{types.join('|')})\b/, Keyword::Type
52
+ rule /(?:true|false|null)\b/, Keyword::Constant
53
+ rule /(?:class|interface)\b/, Keyword::Declaration, :class
54
+ rule /(?:#{imports.join('|')})\b/, Keyword::Namespace, :import
55
+ rule /(\.)(#{id})/ do
56
+ groups Operator, Name::Attribute
57
+ end
58
+
59
+ rule /#{id}:/, Name::Label
60
+ rule /\$?#{id}/, Name
61
+ rule /[~^*!%&\[\](){}<>\|+=:;,.\/?-]/, Operator
62
+ rule /\d*\.\d+([eE]\-?\d+)?/, Num::Float
63
+ rule /0x[\da-fA-F]+/, Num::Hex
64
+ rule /\d+L?/, Num::Integer
65
+ rule /\n/, Text
66
+ end
67
+
68
+ state :class do
69
+ rule /\s+/m, Text
70
+ rule id, Name::Class, :pop!
71
+ end
72
+
73
+ state :dqs do
74
+ rule /"/, Str, :pop!
75
+ rule /[^\\\$"]+/, Str
76
+ mixin :string
77
+ end
78
+
79
+ state :sqs do
80
+ rule /'/, Str, :pop!
81
+ rule /[^\\\$']+/, Str
82
+ mixin :string
83
+ end
84
+
85
+ state :import do
86
+ rule /;/, Operator, :pop!
87
+ rule /(?:show|hide)\b/, Keyword::Declaration
88
+ mixin :root
89
+ end
90
+
91
+ state :string do
92
+ mixin :interpolation
93
+ rule /\\[nrt\"\'\\]/, Str::Escape
94
+ end
95
+
96
+ state :interpolation do
97
+ rule /\$#{id}/, Str::Interpol
98
+ rule /\$\{[^\}]+\}/, Str::Interpol
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,39 @@
1
+ module Rugments
2
+ module Lexers
3
+ class Diff < RegexLexer
4
+ title 'diff'
5
+ desc 'Lexes unified diffs or patches'
6
+
7
+ tag 'diff'
8
+ aliases 'patch', 'udiff'
9
+ filenames '*.diff', '*.patch'
10
+ mimetypes 'text/x-diff', 'text/x-patch'
11
+
12
+ def self.analyze_text(text)
13
+ return 1 if text.start_with?('Index: ')
14
+ return 1 if text.start_with?('diff ')
15
+
16
+ return 0.9 if text =~ /\A---.*?\n\+\+\+/m
17
+ end
18
+
19
+ state :header do
20
+ rule /^diff .*?\n(?=---|\+\+\+)/m, Generic::Heading
21
+ rule /^--- .*?\n/, Generic::Deleted
22
+ rule /^\+\+\+ .*?\n/, Generic::Inserted
23
+ end
24
+
25
+ state :diff do
26
+ rule /@@ -\d+,\d+ \+\d+,\d+ @@.*?\n/, Generic::Heading
27
+ rule /^\+.*?\n/, Generic::Inserted
28
+ rule /^-.*?\n/, Generic::Deleted
29
+ rule /^ .*?\n/, Text
30
+ rule /^.*?\n/, Error
31
+ end
32
+
33
+ state :root do
34
+ mixin :header
35
+ mixin :diff
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,105 @@
1
+ module Rugments
2
+ module Lexers
3
+ # Direct port of pygments Lexer.
4
+ # See: https://bitbucket.org/birkenfeld/pygments-main/src/7304e4759ae65343d89a51359ca538912519cc31/pygments/lexers/functional.py?at=default#cl-2362
5
+ class Elixir < RegexLexer
6
+ title 'Elixir'
7
+ desc 'Elixir language (elixir-lang.org)'
8
+
9
+ tag 'elixir'
10
+
11
+ filenames '*.ex', '*.exs'
12
+
13
+ mimetypes 'text/x-elixir', 'application/x-elixir'
14
+
15
+ BRACES = [
16
+ ['\{', '\}', 'cb'],
17
+ ['\[', '\]', 'sb'],
18
+ ['\(', '\)', 'pa'],
19
+ ['\<', '\>', 'lt']
20
+ ]
21
+
22
+ state :root do
23
+ rule /\s+/m, Text
24
+ rule /#.*$/, Comment::Single
25
+ rule %r{\b(case|cond|end|bc|lc|if|unless|try|loop|receive|fn|defmodule|
26
+ defp?|defprotocol|defimpl|defrecord|defmacrop?|defdelegate|
27
+ defexception|exit|raise|throw|unless|after|rescue|catch|else)\b(?![?!])|
28
+ (?<!\.)\b(do|\-\>)\b}x, Keyword
29
+ rule /\b(import|require|use|recur|quote|unquote|super|refer)\b(?![?!])/, Keyword::Namespace
30
+ rule /(?<!\.)\b(and|not|or|when|xor|in)\b/, Operator::Word
31
+ rule %r{%=|\*=|\*\*=|\+=|\-=|\^=|\|\|=|
32
+ <=>|<(?!<|=)|>(?!<|=|>)|<=|>=|===|==|=~|!=|!~|(?=[\s\t])\?|
33
+ (?<=[\s\t])!+|&(&&?|(?!\d))|\|\||\^|\*|\+|\-|/|
34
+ \||\+\+|\-\-|\*\*|\/\/|\<\-|\<\>|<<|>>|=|\.|~~~}x, Operator
35
+ rule %r{(?<!:)(:)([a-zA-Z_]\w*([?!]|=(?![>=]))?|\<\>|===?|>=?|<=?|
36
+ <=>|&&?|%\(\)|%\[\]|%\{\}|\+\+?|\-\-?|\|\|?|\!|//|[%&`/\|]|
37
+ \*\*?|=?~|<\-)|([a-zA-Z_]\w*([?!])?)(:)(?!:)}, Str::Symbol
38
+ rule /:"/, Str::Symbol, :interpoling_symbol
39
+ rule /\b(nil|true|false)\b(?![?!])|\b[A-Z]\w*\b/, Name::Constant
40
+ rule /\b(__(FILE|LINE|MODULE|MAIN|FUNCTION)__)\b(?![?!])/, Name::Builtin::Pseudo
41
+ rule /[a-zA-Z_!][\w_]*[!\?]?/, Name
42
+ rule %r{::|[%(){};,/\|:\\\[\]]}, Punctuation
43
+ rule /@[a-zA-Z_]\w*|&\d/, Name::Variable
44
+ rule %r{\b(0[xX][0-9A-Fa-f]+|\d(_?\d)*(\.(?![^\d\s])
45
+ (_?\d)*)?([eE][-+]?\d(_?\d)*)?|0[bB][01]+)\b}x, Num
46
+ rule %r{~r\/.*\/}, Str::Regex
47
+
48
+ mixin :strings
49
+ end
50
+
51
+ state :strings do
52
+ rule /(%[A-Ba-z])?"""(?:.|\n)*?"""/, Str::Doc
53
+ rule /'''(?:.|\n)*?'''/, Str::Doc
54
+ rule /"/, Str::Doc, :dqs
55
+ rule /'.*?'/, Str::Single
56
+ rule %r{(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b[^x0MC])|(\\[MC]-)+\w|[^\s\\])}, Str::Other
57
+
58
+ BRACES.each do |_, _, name|
59
+ mixin :"braces_#{name}"
60
+ end
61
+ end
62
+
63
+ BRACES.each do |lbrace, rbrace, name|
64
+ state :"braces_#{name}" do
65
+ rule /%[a-z]#{lbrace}/, Str::Double, :"braces_#{name}_intp"
66
+ rule /%[A-Z]#{lbrace}/, Str::Double, :"braces_#{name}_no_intp"
67
+ end
68
+
69
+ state :"braces_#{name}_intp" do
70
+ rule /#{rbrace}[a-z]*/, Str::Double, :pop!
71
+ mixin :enddoublestr
72
+ end
73
+
74
+ state :"braces_#{name}_no_intp" do
75
+ rule /.*#{rbrace}[a-z]*/, Str::Double, :pop!
76
+ end
77
+ end
78
+
79
+ state :dqs do
80
+ rule /"/, Str::Double, :pop!
81
+ mixin :enddoublestr
82
+ end
83
+
84
+ state :interpoling do
85
+ rule /#\{/, Str::Interpol, :interpoling_string
86
+ end
87
+
88
+ state :interpoling_string do
89
+ rule /\}/, Str::Interpol, :pop!
90
+ mixin :root
91
+ end
92
+
93
+ state :interpoling_symbol do
94
+ rule /"/, Str::Symbol, :pop!
95
+ mixin :interpoling
96
+ rule /[^#"]+/, Str::Symbol
97
+ end
98
+
99
+ state :enddoublestr do
100
+ mixin :interpoling
101
+ rule /[^#"]+/, Str::Double
102
+ end
103
+ end
104
+ end
105
+ end