-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjava.rb
35 lines (26 loc) · 957 Bytes
/
java.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#encoding: utf-8
require_relative 'base'
class JavaFormatter < Formatter
KEYWORDS = %w(public private protected static class interface if else switch instanceof extends implements void)
def initialize
super
# Keywords
register_token(/#{KEYWORDS.join("|")}/) { |keyword| span_tag "keyword", keyword }
# Strings
register_noparse('"', '"', &string_callback)
register_noparse("'", "'", &string_callback)
register_noparse(""", """, &string_callback)
register_noparse("'", "'", &string_callback)
# "Embedded" strings
register_token(/".+?"/, allow_left: :any, allow_right: :any, partial: true) do |string|
require 'pry'; binding.pry
span_tag "string", string
end
end
def string_callback
lambda do |type, token|
return "<span class='string'>#{token}" if type == :start
return "#{token}</span>" if type == :stop
end
end
end