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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class JSP < TemplateLexer
desc 'JSP'
tag 'jsp'
filenames '*.jsp'
mimetypes 'text/x-jsp', 'application/x-jsp'
def initialize(*)
super
@java = Java.new
end
directives = %w(page include taglib)
actions = %w(scriptlet declaration expression)
state :root do
rule %r/<%--/, Comment, :jsp_comment
rule %r/<%@\s*(#{directives.join('|')})\s*/, Name::Tag, :jsp_directive
rule %r/<jsp:directive\.(#{directives.join('|')})/, Name::Tag, :jsp_directive2
rule %r/<jsp:(#{actions.join('|')})>/, Name::Tag, :jsp_expression
# start of tag, e.g. <c:if>
rule %r/<[a-zA-Z]*:[a-zA-Z]*\s*/, Name::Tag, :jsp_tag
# end of tag, e.g. </c:if>
rule %r(</[a-zA-Z]*:[a-zA-Z]*>), Name::Tag
rule %r/<%[!=]?/, Name::Tag, :jsp_expression2
# fallback to HTML
rule(/(.+?)(?=(<%|<\/?[a-zA-Z]*:))/m) { delegate parent }
rule(/.+/m) { delegate parent }
end
state :jsp_comment do
rule %r/(--%>)/, Comment, :pop!
rule %r/./m, Comment
end
state :jsp_directive do
rule %r/(%>)/, Name::Tag, :pop!
mixin :attributes
rule(/(.+?)(?=%>)/m) { delegate parent }
end
state :jsp_directive2 do
rule %r!(/>)!, Name::Tag, :pop!
mixin :attributes
rule(/(.+?)(?=\/>)/m) { delegate parent }
end
state :jsp_expression do
rule %r/<\/jsp:(#{actions.join('|')})>/, Name::Tag, :pop!
mixin :attributes
rule(/[^<\/]+/) { delegate @java }
end
state :jsp_expression2 do
rule %r/%>/, Name::Tag, :pop!
rule(/[^%>]+/) { delegate @java }
end
state :jsp_tag do
rule %r/\/?>/, Name::Tag, :pop!
mixin :attributes
rule(/(.+?)(?=\/?>)/m) { delegate parent }
end
state :attributes do
rule %r/\s*[a-zA-Z0-9_:-]+\s*=\s*/m, Name::Attribute, :attr
end
state :attr do
rule %r/"/ do
token Str
goto :double_quotes
end
rule %r/'/ do
token Str
goto :single_quotes
end
rule %r/[^\s>]+/, Str, :pop!
end
state :double_quotes do
rule %r/"/, Str, :pop!
rule %r/\$\{/, Str::Interpol, :jsp_interp
rule %r/[^"]+/, Str
end
state :single_quotes do
rule %r/'/, Str, :pop!
rule %r/\$\{/, Str::Interpol, :jsp_interp
rule %r/[^']+/, Str
end
state :jsp_interp do
rule %r/\}/, Str::Interpol, :pop!
rule %r/'/, Literal, :jsp_interp_literal_start
rule(/[^'\}]+/) { delegate @java }
end
state :jsp_interp_literal_start do
rule %r/'/, Literal, :pop!
rule %r/[^']+/, Literal
end
end
end
end
|