1- import re
2- from pygments .lexer import RegexLexer , bygroups , using , this , default
3- from pygments .token import Comment , Operator , Keyword , Name , String , Number , Whitespace
4- from pygments .util import shebang_matches
5-
6- class FijiGroovyLexer (RegexLexer ):
7- """
8- For Groovy source code.
9-
10- .. versionadded:: 1.5
11- """
12-
13- name = 'Groovy'
14- url = 'https://groovy-lang.org/'
15- aliases = ['fijigroovy' ]
16- filenames = ['*.groovy' ,'*.gradle' ]
17- mimetypes = ['text/x-groovy' ]
18-
19- flags = re .MULTILINE | re .DOTALL
1+ from pygments .lexer import inherit
2+ from pygments .lexers .jvm import GroovyLexer
3+ from pygments .token import Comment
204
5+ class SciJavaGroovyLexer (GroovyLexer ):
216 tokens = {
22- 'root' : [
23- # Groovy allows a file to start with a shebang
24- (r'#!(.*?)$' , Comment .Preproc , 'base' ),
25- default ('base' ),
26- ],
277 'base' : [
28- (r'[^\S\n]+' , Whitespace ),
298 (r'#@.*?$' , Comment .Single ),
30- (r'(//.*?)(\n)' , bygroups (Comment .Single , Whitespace )),
31- (r'/\*.*?\*/' , Comment .Multiline ),
32- # keywords: go before method names to avoid lexing "throw new XYZ"
33- # as a method signature
34- (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
35- r'if|goto|instanceof|new|return|switch|this|throw|try|while|in|as)\b' ,
36- Keyword ),
37- # method names
38- (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments
39- r'('
40- r'[a-zA-Z_]\w*' # method name
41- r'|"(?:\\\\|\\[^\\]|[^"\\])*"' # or double-quoted method name
42- r"|'(?:\\\\|\\[^\\]|[^'\\])*'" # or single-quoted method name
43- r')'
44- r'(\s*)(\()' , # signature start
45- bygroups (using (this ), Name .Function , Whitespace , Operator )),
46- (r'@[a-zA-Z_][\w.]*' , Name .Decorator ),
47- (r'(abstract|const|enum|extends|final|implements|native|private|'
48- r'protected|public|static|strictfp|super|synchronized|throws|'
49- r'transient|volatile)\b' , Keyword .Declaration ),
50- (r'(def|boolean|byte|char|double|float|int|long|short|void)\b' ,
51- Keyword .Type ),
52- (r'(package)(\s+)' , bygroups (Keyword .Namespace , Whitespace )),
53- (r'(true|false|null)\b' , Keyword .Constant ),
54- (r'(class|interface)(\s+)' , bygroups (Keyword .Declaration , Whitespace ),
55- 'class' ),
56- (r'(import)(\s+)' , bygroups (Keyword .Namespace , Whitespace ), 'import' ),
57- (r'""".*?"""' , String .Double ),
58- (r"'''.*?'''" , String .Single ),
59- (r'"(\\\\|\\[^\\]|[^"\\])*"' , String .Double ),
60- (r"'(\\\\|\\[^\\]|[^'\\])*'" , String .Single ),
61- (r'\$/((?!/\$).)*/\$' , String ),
62- (r'/(\\\\|\\[^\\]|[^/\\])*/' , String ),
63- (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'" , String .Char ),
64- (r'(\.)([a-zA-Z_]\w*)' , bygroups (Operator , Name .Attribute )),
65- (r'[a-zA-Z_]\w*:' , Name .Label ),
66- (r'[a-zA-Z_$]\w*' , Name ),
67- (r'[~^*!%&\[\](){}<>|+=:;,./?-]' , Operator ),
68- (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?' , Number .Float ),
69- (r'0x[0-9a-fA-F]+' , Number .Hex ),
70- (r'[0-9]+L?' , Number .Integer ),
71- (r'\n' , Whitespace )
72- ],
73- 'class' : [
74- (r'[a-zA-Z_]\w*' , Name .Class , '#pop' )
75- ],
76- 'import' : [
77- (r'[\w.]+\*?' , Name .Namespace , '#pop' )
78- ],
79- }
80-
81- def analyse_text (text ):
82- return shebang_matches (text , r'groovy' )
9+ inherit ,
10+ ]
11+ }
0 commit comments