rouge-lexers-crystal 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: debe44d625d7aa02fe518c3193a10d28356ad6558dc4b6bd66970edacf8fcd52
4
+ data.tar.gz: 420b9bf2a40e3d6a87a61165bd0f36b2ab379083ad3edb8a1af23b94394d37fc
5
+ SHA512:
6
+ metadata.gz: c252bc54d8c679682999e38c853b7c78a1bdc3fa52b0d99640275866f96f895ca432a5585ed4f53ba83a625d556a9bb6aa181d60412c1b4eed0bcbf080f90170
7
+ data.tar.gz: 2a0445ed1f76b4b9b43fb2c0638e4e128144dc7243b059554618f5ae6c322b97859a9218122522ee77ad35ab275734b3accfb3aa4a6cc291c98ec8da4cdc4376
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ sudo: false
2
+ dist: trusty
3
+ language: ruby
4
+ rvm:
5
+ - "2.0"
6
+ - "2.1"
7
+ - "2.2"
8
+ - "2.3"
9
+ - "2.4"
10
+ - "2.5"
11
+
12
+ cache:
13
+ bundler: true
14
+ bundler_args: --without development
15
+ before_install:
16
+ - gem install bundler
17
+ - gem update --system
18
+ script:
19
+ - bundle exec rake
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at peter@leitzen.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rouge-lexers-crystal.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Peter Leitzen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Rouge::Lexers::Crystal
2
+
3
+ [Crystal](https://crystal-lang.org) lexer for [rouge](http://rouge.jneen.net/).
4
+
5
+ This gem exists because rouge lacks support for the Crystal language. These PRs are pending: [441](https://github.com/jneen/rouge/pull/441) and [863](https://github.com/jneen/rouge/pull/863).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rouge-lexers-crystal'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rouge-lexers-crystal
22
+
23
+ ## Usage
24
+
25
+ See rouge's [README](https://github.com/jneen/rouge/blob/master/README.md) for the full description.
26
+
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/splattael/rouge-lexers-crystal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Rouge::Lexers::Crystal project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/splattael/rouge-lexers-crystal/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "spec"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["spec/**/*_spec.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rouge/lexers/crystal"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,439 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ require 'rouge'
4
+
5
+ module Rouge
6
+ module Lexers
7
+ class Crystal < RegexLexer
8
+ title "Crystal"
9
+ desc "Crystal The Programming Language (crystal-lang.org)"
10
+ tag 'crystal'
11
+ aliases 'cr'
12
+ filenames '*.cr'
13
+
14
+ mimetypes 'text/x-crystal', 'application/x-crystal'
15
+
16
+ # This plugin supports all versions of rouge
17
+ # TODO: Remove move
18
+ if Rouge.version >= '3.0.0'
19
+ def self.detect?(text)
20
+ return true if text.shebang? 'crystal'
21
+ end
22
+ else
23
+ def self.analyze_text(text)
24
+ return 1 if text.shebang? 'crystal'
25
+ end
26
+ end
27
+
28
+ state :symbols do
29
+ # symbols
30
+ rule %r(
31
+ : # initial :
32
+ @{0,2} # optional ivar, for :@foo and :@@foo
33
+ [a-z_]\w*[!?]? # the symbol
34
+ )xi, Str::Symbol
35
+
36
+ # special symbols
37
+ rule %r(:(?:\*\*|[-+]@|[/\%&\|^`~]|\[\]=?|<<|>>|<=?>|<=?|===?)),
38
+ Str::Symbol
39
+
40
+ rule /:'(\\\\|\\'|[^'])*'/, Str::Symbol
41
+ rule /:"/, Str::Symbol, :simple_sym
42
+ end
43
+
44
+ state :sigil_strings do
45
+ # %-sigiled strings
46
+ # %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
47
+ delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
48
+ rule /%([rqswQWxiI])?([^\w\s])/ do |m|
49
+ open = Regexp.escape(m[2])
50
+ close = Regexp.escape(delimiter_map[m[2]] || m[2])
51
+ interp = /[rQWxI]/ === m[1]
52
+ toktype = Str::Other
53
+
54
+ puts " open: #{open.inspect}" if @debug
55
+ puts " close: #{close.inspect}" if @debug
56
+
57
+ # regexes
58
+ if m[1] == 'r'
59
+ toktype = Str::Regex
60
+ push :regex_flags
61
+ end
62
+
63
+ token toktype
64
+
65
+ push do
66
+ rule /\\[##{open}#{close}\\]/, Str::Escape
67
+ # nesting rules only with asymmetric delimiters
68
+ if open != close
69
+ rule /#{open}/ do
70
+ token toktype
71
+ push
72
+ end
73
+ end
74
+ rule /#{close}/, toktype, :pop!
75
+
76
+ if interp
77
+ mixin :string_intp_escaped
78
+ rule /#/, toktype
79
+ else
80
+ rule /[\\#]/, toktype
81
+ end
82
+
83
+ rule /[^##{open}#{close}\\]+/m, toktype
84
+ end
85
+ end
86
+ end
87
+
88
+ state :strings do
89
+ mixin :symbols
90
+ rule /\b[a-z_]\w*?[?!]?:\s+/, Str::Symbol, :expr_start
91
+ rule /'(\\\\|\\'|[^'])*'/, Str::Single
92
+ rule /"/, Str::Double, :simple_string
93
+ rule /(?<!\.)`/, Str::Backtick, :simple_backtick
94
+ end
95
+
96
+ state :regex_flags do
97
+ rule /[mixounse]*/, Str::Regex, :pop!
98
+ end
99
+
100
+ # double-quoted string and symbol
101
+ [[:string, Str::Double, '"'],
102
+ [:sym, Str::Symbol, '"'],
103
+ [:backtick, Str::Backtick, '`']].each do |name, tok, fin|
104
+ state :"simple_#{name}" do
105
+ mixin :string_intp_escaped
106
+ rule /[^\\#{fin}#]+/m, tok
107
+ rule /[\\#]/, tok
108
+ rule /#{fin}/, tok, :pop!
109
+ end
110
+ end
111
+
112
+ keywords = %w(
113
+ BEGIN END alias begin break case defined\? do else elsif end
114
+ ensure for if ifdef in next redo rescue raise retry return super then
115
+ undef unless until when while yield lib fun type of as
116
+ )
117
+
118
+ keywords_pseudo = %w(
119
+ initialize new loop include extend raise attr_reader attr_writer
120
+ attr_accessor alias_method attr catch throw private module_function
121
+ public protected true false nil __FILE__ __LINE__
122
+ getter getter? getter! property property? property! struct record
123
+ )
124
+
125
+ builtins_g = %w(
126
+ abort ancestors at_exit
127
+ caller catch chomp chop clone constants
128
+ display dup eval exec exit extend fail fork format freeze
129
+ getc gets global_variables gsub hash id included_modules
130
+ inspect instance_eval instance_method instance_methods
131
+ lambda loop method method_missing
132
+ methods module_eval name object_id open p print printf
133
+ proc putc puts raise rand
134
+ readline readlines require scan select self send
135
+ sleep split sprintf srand sub syscall system
136
+ test throw to_a to_s trap warn
137
+ )
138
+
139
+ builtins_q = %w(
140
+ eql equal include is_a iterator kind_of nil
141
+ )
142
+
143
+ builtins_b = %w(chomp chop exit gsub sub)
144
+
145
+ start do
146
+ push :expr_start
147
+ @heredoc_queue = []
148
+ end
149
+
150
+ state :whitespace do
151
+ mixin :inline_whitespace
152
+ rule /\n\s*/m, Text, :expr_start
153
+ rule /#.*$/, Comment::Single
154
+
155
+ rule %r(=begin\b.*?\n=end\b)m, Comment::Multiline
156
+ end
157
+
158
+ state :inline_whitespace do
159
+ rule /[ \t\r]+/, Text
160
+ end
161
+
162
+ state :root do
163
+ mixin :whitespace
164
+ rule /__END__/, Comment::Preproc, :end_part
165
+
166
+ rule /0_?[0-7]+(?:_[0-7]+)*/, Num::Oct
167
+ rule /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
168
+ rule /0b[01]+(?:_[01]+)*/, Num::Bin
169
+ rule /\d+\.\d+(e[\+\-]?\d+)?/, Num::Float
170
+ rule /[\d]+(?:_\d+)*/, Num::Integer
171
+
172
+ rule /@\[([^\]]+)\]/, Name::Decorator
173
+
174
+ # names
175
+ rule /@@[a-z_]\w*/i, Name::Variable::Class
176
+ rule /@[a-z_]\w*/i, Name::Variable::Instance
177
+ rule /\$\w+/, Name::Variable::Global
178
+ rule %r(\$[!@&`'+~=/\\,;.<>_*\$?:"]), Name::Variable::Global
179
+ rule /\$-[0adFiIlpvw]/, Name::Variable::Global
180
+ rule /::/, Operator
181
+
182
+ mixin :strings
183
+
184
+ rule /(?:#{keywords.join('|')})\b/, Keyword, :expr_start
185
+ rule /(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start
186
+
187
+ rule %r(
188
+ (module)
189
+ (\s+)
190
+ ([a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*)
191
+ )x do
192
+ groups Keyword, Text, Name::Namespace
193
+ end
194
+
195
+ rule /(def\b)(\s*)/ do
196
+ groups Keyword, Text
197
+ push :funcname
198
+ end
199
+
200
+ rule /(class\b)(\s*)/ do
201
+ groups Keyword, Text
202
+ push :classname
203
+ end
204
+
205
+ rule /(?:#{builtins_q.join('|')})[?]/, Name::Builtin, :expr_start
206
+ rule /(?:#{builtins_b.join('|')})!/, Name::Builtin, :expr_start
207
+ rule /(?<!\.)(?:#{builtins_g.join('|')})\b/,
208
+ Name::Builtin, :method_call
209
+
210
+ mixin :has_heredocs
211
+
212
+ # `..` and `...` for ranges must have higher priority than `.`
213
+ # Otherwise, they will be parsed as :method_call
214
+ rule /\.{2,3}/, Operator, :expr_start
215
+
216
+ rule /[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
217
+ rule /(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
218
+ groups Punctuation, Text, Name::Function
219
+ push :method_call
220
+ end
221
+
222
+ rule /[a-zA-Z_]\w*[?!]/, Name, :expr_start
223
+ rule /[a-zA-Z_]\w*/, Name, :method_call
224
+ rule /\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
225
+ Operator, :expr_start
226
+ rule /[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
227
+ rule(/[?]/) { token Punctuation; push :ternary; push :expr_start }
228
+ rule %r<[\[({,:\\;/]>, Punctuation, :expr_start
229
+ rule %r<[\])}]>, Punctuation
230
+ end
231
+
232
+ state :has_heredocs do
233
+ rule /(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
234
+ token Operator, m[1]
235
+ token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
236
+ @heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
237
+ push :heredoc_queue unless state? :heredoc_queue
238
+ end
239
+
240
+ rule /(<<[-~]?)(["'])(\2)/ do |m|
241
+ token Operator, m[1]
242
+ token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
243
+ @heredoc_queue << [['<<-', '<<~'].include?(m[1]), '']
244
+ push :heredoc_queue unless state? :heredoc_queue
245
+ end
246
+ end
247
+
248
+ state :heredoc_queue do
249
+ rule /(?=\n)/ do
250
+ goto :resolve_heredocs
251
+ end
252
+
253
+ mixin :root
254
+ end
255
+
256
+ state :resolve_heredocs do
257
+ mixin :string_intp_escaped
258
+
259
+ rule /\n/, Str::Heredoc, :test_heredoc
260
+ rule /[#\\\n]/, Str::Heredoc
261
+ rule /[^#\\\n]+/, Str::Heredoc
262
+ end
263
+
264
+ state :test_heredoc do
265
+ rule /[^#\\\n]*$/ do |m|
266
+ tolerant, heredoc_name = @heredoc_queue.first
267
+ check = tolerant ? m[0].strip : m[0].rstrip
268
+
269
+ # check if we found the end of the heredoc
270
+ puts " end heredoc check #{check.inspect} = #{heredoc_name.inspect}" if @debug
271
+ if check == heredoc_name
272
+ @heredoc_queue.shift
273
+ # if there's no more, we're done looking.
274
+ pop! if @heredoc_queue.empty?
275
+ token Name::Constant
276
+ else
277
+ token Str::Heredoc
278
+ end
279
+
280
+ pop!
281
+ end
282
+
283
+ rule(//) { pop! }
284
+ end
285
+
286
+ state :funcname do
287
+ rule /\s+/, Text
288
+ rule /\(/, Punctuation, :defexpr
289
+ rule %r(
290
+ (?:([a-zA-Z_][\w_]*)(\.))?
291
+ (
292
+ [a-zA-Z_][\w_]*[!?]? |
293
+ \*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
294
+ <<? | >>? | <=>? | >= | ===?
295
+ )
296
+ )x do |m|
297
+ puts "matches: #{[m[0], m[1], m[2], m[3]].inspect}" if @debug
298
+ groups Name::Class, Operator, Name::Function
299
+ pop!
300
+ end
301
+
302
+ rule(//) { pop! }
303
+ end
304
+
305
+ state :classname do
306
+ rule /\s+/, Text
307
+ rule /\(/ do
308
+ token Punctuation
309
+ push :defexpr
310
+ push :expr_start
311
+ end
312
+
313
+ # class << expr
314
+ rule /<</ do
315
+ token Operator
316
+ goto :expr_start
317
+ end
318
+
319
+ rule /[A-Z_]\w*/, Name::Class, :pop!
320
+
321
+ rule(//) { pop! }
322
+ end
323
+
324
+ state :ternary do
325
+ rule(/:(?!:)/) { token Punctuation; goto :expr_start }
326
+
327
+ mixin :root
328
+ end
329
+
330
+ state :defexpr do
331
+ rule /(\))(\.|::)?/ do
332
+ groups Punctuation, Operator
333
+ pop!
334
+ end
335
+ rule /\(/ do
336
+ token Punctuation
337
+ push :defexpr
338
+ push :expr_start
339
+ end
340
+
341
+ mixin :root
342
+ end
343
+
344
+ state :in_interp do
345
+ rule /}/, Str::Interpol, :pop!
346
+ mixin :root
347
+ end
348
+
349
+ state :string_intp do
350
+ rule /[#][{]/, Str::Interpol, :in_interp
351
+ rule /#(@@?|\$)[a-z_]\w*/i, Str::Interpol
352
+ end
353
+
354
+ state :string_intp_escaped do
355
+ mixin :string_intp
356
+ rule /\\([\\abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/,
357
+ Str::Escape
358
+ rule /\\./, Str::Escape
359
+ end
360
+
361
+ state :method_call do
362
+ rule %r(/) do
363
+ token Operator
364
+ goto :expr_start
365
+ end
366
+
367
+ rule(/(?=\n)/) { pop! }
368
+
369
+ rule(//) { goto :method_call_spaced }
370
+ end
371
+
372
+ state :method_call_spaced do
373
+ mixin :whitespace
374
+
375
+ rule %r([%/]=) do
376
+ token Operator
377
+ goto :expr_start
378
+ end
379
+
380
+ rule %r((/)(?=\S|\s*/)) do
381
+ token Str::Regex
382
+ goto :slash_regex
383
+ end
384
+
385
+ mixin :sigil_strings
386
+
387
+ rule(%r((?=\s*/))) { pop! }
388
+
389
+ rule(/\s+/) { token Text; goto :expr_start }
390
+ rule(//) { pop! }
391
+ end
392
+
393
+ state :expr_start do
394
+ mixin :inline_whitespace
395
+
396
+ rule %r(/) do
397
+ token Str::Regex
398
+ goto :slash_regex
399
+ end
400
+
401
+ # char operator. ?x evaulates to "x", unless there's a digit
402
+ # beforehand like x>=0?n[x]:""
403
+ rule %r(
404
+ [?](\\[MC]-)* # modifiers
405
+ (\\([\\abefnrstv\#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)
406
+ (?!\w)
407
+ )x, Str::Char, :pop!
408
+
409
+ # special case for using a single space. Ruby demands that
410
+ # these be in a single line, otherwise it would make no sense.
411
+ rule /(\s*)(%[rqswQWxiI]? \S* )/ do
412
+ groups Text, Str::Other
413
+ pop!
414
+ end
415
+
416
+ mixin :sigil_strings
417
+
418
+ rule(//) { pop! }
419
+ end
420
+
421
+ state :slash_regex do
422
+ mixin :string_intp
423
+ rule %r(\\\\), Str::Regex
424
+ rule %r(\\/), Str::Regex
425
+ rule %r([\\#]), Str::Regex
426
+ rule %r([^\\/#]+)m, Str::Regex
427
+ rule %r(/) do
428
+ token Str::Regex
429
+ goto :regex_flags
430
+ end
431
+ end
432
+
433
+ state :end_part do
434
+ # eat up the rest of the stream as Comment::Preproc
435
+ rule /.+/m, Comment::Preproc, :pop!
436
+ end
437
+ end
438
+ end
439
+ end
@@ -0,0 +1 @@
1
+ require "rouge/lexers/crystal"
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rouge/lexers/crystal"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rouge-lexers-crystal"
8
+ spec.version = "1.0.0.rc1"
9
+ spec.authors = ["Peter Leitzen"]
10
+ spec.email = ["peter@leitzen.de"]
11
+
12
+ spec.summary = %q{Crystal lexer for rouge}
13
+ spec.description = %q{https://github.com/jneen/rouge/pull/441}
14
+ spec.homepage = "https://github.com/splattae/rouge-lexers-crystal"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ spec.add_development_dependency "minitest-power_assert"
30
+
31
+ spec.add_runtime_dependency "rouge"
32
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rouge-lexers-crystal
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Leitzen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-power_assert
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rouge
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: https://github.com/jneen/rouge/pull/441
84
+ email:
85
+ - peter@leitzen.de
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/rouge-lexers-crystal.rb
100
+ - lib/rouge/lexers/crystal.rb
101
+ - rouge-lexers-crystal.gemspec
102
+ homepage: https://github.com/splattae/rouge-lexers-crystal
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">"
118
+ - !ruby/object:Gem::Version
119
+ version: 1.3.1
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.7
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Crystal lexer for rouge
126
+ test_files: []