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
|
# -*- coding: utf-8 -*- #
module Rouge
module Lexers
class Velocity < TemplateLexer
title 'Velocity'
desc 'Velocity is a Java-based template engine (velocity.apache.org)'
tag 'velocity'
filenames '*.vm', '*.velocity', '*.fhtml'
mimetypes 'text/html+velocity'
id = /[a-z_]\w*/i
state :root do
rule %r/[^{#$]+/ do
delegate parent
end
rule %r/(#)(\*.*?\*)(#)/m, Comment::Multiline
rule %r/(##)(.*?$)/, Comment::Single
rule %r/(#\{?)(#{id})(\}?)(\s?\()/m do
groups Punctuation, Name::Function, Punctuation, Punctuation
push :directive_params
end
rule %r/(#\{?)(#{id})(\}|\b)/m do
groups Punctuation, Name::Function, Punctuation
end
rule %r/\$\{?/, Punctuation, :variable
end
state :variable do
rule %r/#{id}/, Name::Variable
rule %r/\(/, Punctuation, :func_params
rule %r/(\.)(#{id})/ do
groups Punctuation, Name::Variable
end
rule %r/\}/, Punctuation, :pop!
rule(//) { pop! }
end
state :directive_params do
rule %r/(&&|\|\||==?|!=?|[-<>+*%&|^\/])|\b(eq|ne|gt|lt|ge|le|not|in)\b/, Operator
rule %r/\[/, Operator, :range_operator
rule %r/\b#{id}\b/, Name::Function
mixin :func_params
end
state :range_operator do
rule %r/[.]{2}/, Operator
mixin :func_params
rule %r/\]/, Operator, :pop!
end
state :func_params do
rule %r/\$\{?/, Punctuation, :variable
rule %r/\s+/, Text
rule %r/,/, Punctuation
rule %r/"(\\\\|\\"|[^"])*"/, Str::Double
rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
rule %r/0[xX][0-9a-fA-F]+[Ll]?/, Num::Hex
rule %r/\b[0-9]+\b/, Num::Integer
rule %r/(true|false|null)\b/, Keyword::Constant
rule %r/[(\[]/, Punctuation, :push
rule %r/[)\]}]/, Punctuation, :pop!
end
end
end
end
|