22
33import re
44from pygments .lexer import RegexLexer , bygroups
5- from pygments .token import Text , Comment , Operator , Keyword , Name , String , \
6- Number , Punctuation
5+ from pygments .token import (
6+ Text ,
7+ Comment ,
8+ Operator ,
9+ Keyword ,
10+ Name ,
11+ String ,
12+ Number ,
13+ Punctuation ,
14+ )
715
816
917def get_lexer_tokens (tag_highlighting = False , project_support = False ):
@@ -20,105 +28,120 @@ def get_lexer_tokens(tag_highlighting=False, project_support=False):
2028 :rtype: dict
2129 """
2230 if project_support :
23- project_pattern = r'project\s+|'
24- project_pattern2 = \
25- r'aggregate|extends|external|external_as_list|library|project|'
31+ project_pattern = r"project\s+|"
32+ project_pattern2 = (
33+ r"aggregate|extends|external|external_as_list|library|project|"
34+ )
2635 else :
27- project_pattern = r''
28- project_pattern2 = r''
36+ project_pattern = r""
37+ project_pattern2 = r""
2938
3039 result = {
31- ' root' : [
40+ " root" : [
3241 # Comments
33- (r' --.*$' , Comment ),
42+ (r" --.*$" , Comment ),
3443 # Character literal
3544 (r"'.'" , String .Char ),
3645 # Strings
3746 (r'"[^"]*"' , String ),
3847 # Numeric
3948 # Based literal
40- (r'[0-9][0-9_]*#[0-9a-f][0-9a-f_]*#(E[\+-]?[0-9][0-9_]*)?' ,
41- Number .Integer ),
42- (r'[0-9][0-9_]*#[0-9a-f][0-9a-f_]*'
43- r'\.[0-9a-f][0-9a-f_]*#(E[\+-]?[0-9][0-9_]*)?' , Number .Float ),
49+ (r"[0-9][0-9_]*#[0-9a-f][0-9a-f_]*#(E[\+-]?[0-9][0-9_]*)?" , Number .Integer ),
50+ (
51+ r"[0-9][0-9_]*#[0-9a-f][0-9a-f_]*"
52+ r"\.[0-9a-f][0-9a-f_]*#(E[\+-]?[0-9][0-9_]*)?" ,
53+ Number .Float ,
54+ ),
4455 # Decimal literal
45- (r' [0-9][0-9_]*\.[0-9][0-9_](E[\+-]?[0-9][0-9_]*)?' , Number .Float ),
46- (r' [0-9][0-9_]*(E[\+-]?[0-9][0-9_]*)?' , Number .Integer ),
56+ (r" [0-9][0-9_]*\.[0-9][0-9_](E[\+-]?[0-9][0-9_]*)?" , Number .Float ),
57+ (r" [0-9][0-9_]*(E[\+-]?[0-9][0-9_]*)?" , Number .Integer ),
4758 # Match use and with statements
4859 # The first part of the pattern is be sure we don't match
4960 # for/use constructs.
50- (r'(\n\s*|;\s*)(with|use)(\s+[\w\.]+\s*;)' ,
51- bygroups (Punctuation , Keyword .Reserved , Name .Namespace )),
61+ (
62+ r"(\n\s*|;\s*)(with|use)(\s+[\w\.]+\s*;)" ,
63+ bygroups (Punctuation , Keyword .Reserved , Name .Namespace ),
64+ ),
5265 # Match procedure, package and function declarations
53- (r'end\s+(if|loop|record)' , Keyword ),
54- (r'(package(?:\s+body)?\s+|' + project_pattern +
55- r'function\s+|end\s+|procedure\s+)([\w\.]+)' ,
56- bygroups (Keyword , Name .Function )),
66+ (r"end\s+(if|loop|record)" , Keyword ),
67+ (
68+ r"(package(?:\s+body)?\s+|"
69+ + project_pattern
70+ + r"function\s+|end\s+|procedure\s+)([\w\.]+)" ,
71+ bygroups (Keyword , Name .Function ),
72+ ),
5773 # Ada 2012 standard attributes, GNAT specific ones and
5874 # Spark 2014 ones ('Update and 'Loop_Entry)
5975 # (reversed order to avoid having for
6076 # example Max before Max_Alignment_For_Allocation).
61- (r'\'(Write|Width|Wide_Width|Wide_Wide_Width|Wide_Wide_Value|'
62- r'Wide_Wide_Image|Wide_Value|Wide_Image|Word_Size|Wchar_T_Size|'
63- r'Version|Value_Size|Value|Valid_Scalars|VADS_Size|Valid|Val|'
64- r'Update|Unrestricted_Access|Universal_Literal_String|'
65- r'Unconstrained_Array|Unchecked_Access|Unbiased_Rounding|'
66- r'UET_Address|Truncation|Type_Class|To_Address|Tick|Terminated|'
67- r'Target_Name|Tag|System_Allocator_Alignment|Succ|Stub_Type|'
68- r'Stream_Size|Storage_Unit|Storage_Size|Storage_Pool|Small|Size|'
69- r'Simple_Storage_Pool|Signed_Zeros|Scaling|Scale|'
70- r'Scalar_Storage_Order|Safe_Last|Safe_Large|Safe_First|'
71- r'Safe_Emax|Rounding|Round|Result|Remainder|Ref|Read|'
72- r'Range_Length|Range|Priority|Pred|'
73- r'Position|Pos|Pool_Address|Passed_By_Reference|Partition_Id|'
74- r'Overlaps_Storage|Output|Old|Object_Size|Null_Parameter|Modulus|'
75- r'Model_Small|Model_Mantissa|Model_Epsilon|Model_Emin|Model|Mod|'
76- r'Min|Mechanism_Code|Maximum_Alignment|'
77- r'Max_Size_In_Storage_Elements|Max_Priority|'
78- r'Max_Interrupt_Priority|Max_Alignment_For_Allocation|'
79- r'Max|Mantissa|Machine_Size|Machine_Rounds|Machine_Rounding|'
80- r'Machine_Radix|Machine_Overflows|Machine_Mantissa|Machine_Emin|'
81- r'Machine_Emax|Machine|Loop_Entry|Length|Length|Leading_Part|'
82- r'Last_Valid|Last_Bit|Last|Large|Invalid_Value|Integer_Value|'
83- r'Input|Image|Img|Identity|Has_Same_Storage|Has_Discriminants|'
84- r'Has_Access_Values|Fraction|Fore|Floor|Fixed_Value|First_Valid|'
85- r'First_Bit|First|External_Tag|Exponent|Epsilon|Enum_Val|'
86- r'Enum_Rep|Enabled|Emax|Elaborated|Elab_Subp_Body|Elab_Spec|'
87- r'Elab_Body|Descriptor_Size|Digits|Denorm|Delta|Definite|'
88- r'Default_Bit_Order|Count|Copy_Sign|Constrained|'
89- r'Compose|Component_Size|Compiler_Version|Code_Address|Class|'
90- r'Ceiling|Caller|Callable|Body_Version|Bit_Order|Bit_Position|'
91- r'Bit|Base|Asm_Output|Asm_Input|Alignment|Aft|Adjacent|'
92- r'Address_Size|Address|Access|Abort_Signal|AST_Entry)' ,
93- Name .Attribute ),
77+ (
78+ r"\'(Write|Width|Wide_Width|Wide_Wide_Width|Wide_Wide_Value|"
79+ r"Wide_Wide_Image|Wide_Value|Wide_Image|Word_Size|Wchar_T_Size|"
80+ r"Version|Value_Size|Value|Valid_Scalars|VADS_Size|Valid|Val|"
81+ r"Update|Unrestricted_Access|Universal_Literal_String|"
82+ r"Unconstrained_Array|Unchecked_Access|Unbiased_Rounding|"
83+ r"UET_Address|Truncation|Type_Class|To_Address|Tick|Terminated|"
84+ r"Target_Name|Tag|System_Allocator_Alignment|Succ|Stub_Type|"
85+ r"Stream_Size|Storage_Unit|Storage_Size|Storage_Pool|Small|Size|"
86+ r"Simple_Storage_Pool|Signed_Zeros|Scaling|Scale|"
87+ r"Scalar_Storage_Order|Safe_Last|Safe_Large|Safe_First|"
88+ r"Safe_Emax|Rounding|Round|Result|Remainder|Ref|Read|"
89+ r"Range_Length|Range|Priority|Pred|"
90+ r"Position|Pos|Pool_Address|Passed_By_Reference|Partition_Id|"
91+ r"Overlaps_Storage|Output|Old|Object_Size|Null_Parameter|Modulus|"
92+ r"Model_Small|Model_Mantissa|Model_Epsilon|Model_Emin|Model|Mod|"
93+ r"Min|Mechanism_Code|Maximum_Alignment|"
94+ r"Max_Size_In_Storage_Elements|Max_Priority|"
95+ r"Max_Interrupt_Priority|Max_Alignment_For_Allocation|"
96+ r"Max|Mantissa|Machine_Size|Machine_Rounds|Machine_Rounding|"
97+ r"Machine_Radix|Machine_Overflows|Machine_Mantissa|Machine_Emin|"
98+ r"Machine_Emax|Machine|Loop_Entry|Length|Length|Leading_Part|"
99+ r"Last_Valid|Last_Bit|Last|Large|Invalid_Value|Integer_Value|"
100+ r"Input|Image|Img|Identity|Has_Same_Storage|Has_Discriminants|"
101+ r"Has_Access_Values|Fraction|Fore|Floor|Fixed_Value|First_Valid|"
102+ r"First_Bit|First|External_Tag|Exponent|Epsilon|Enum_Val|"
103+ r"Enum_Rep|Enabled|Emax|Elaborated|Elab_Subp_Body|Elab_Spec|"
104+ r"Elab_Body|Descriptor_Size|Digits|Denorm|Delta|Definite|"
105+ r"Default_Bit_Order|Count|Copy_Sign|Constrained|"
106+ r"Compose|Component_Size|Compiler_Version|Code_Address|Class|"
107+ r"Ceiling|Caller|Callable|Body_Version|Bit_Order|Bit_Position|"
108+ r"Bit|Base|Asm_Output|Asm_Input|Alignment|Aft|Adjacent|"
109+ r"Address_Size|Address|Access|Abort_Signal|AST_Entry)" ,
110+ Name .Attribute ,
111+ ),
94112 # All Ada2012 reserved words
95- (r'(abort|abstract|abs|accept|access|aliased|all|and|array|at|'
96- r'begin|body|case|constant|declare|delay|delta|digits|do|'
97- r'else|elsif|end|entry|exception|exit|for|function|generic|goto|'
98- r'if|interface|in|is|limited|loop|mod|new|not|null|'
99- r'of|or|others|out|overriding|' + project_pattern2 +
100- r'package|pragma|private|procedure|protected|'
101- r'raise|range|record|rem|renames|requeue|return|reverse|'
102- r'select|separate|some|subtype|synchronized|'
103- r'tagged|task|terminate|then|type|until|use|when|while|with|xor'
104- r')([\s;,])' ,
105- bygroups (Keyword .Reserved , Punctuation )),
113+ (
114+ r"(abort|abstract|abs|accept|access|aliased|all|and|array|at|"
115+ r"begin|body|case|constant|declare|delay|delta|digits|do|"
116+ r"else|elsif|end|entry|exception|exit|for|function|generic|goto|"
117+ r"if|interface|in|is|limited|loop|mod|new|not|null|"
118+ r"of|or|others|out|overriding|"
119+ + project_pattern2
120+ + r"package|pragma|private|procedure|protected|"
121+ r"raise|range|record|rem|renames|requeue|return|reverse|"
122+ r"select|separate|some|subtype|synchronized|"
123+ r"tagged|task|terminate|then|type|until|use|when|while|with|xor"
124+ r")([\s;,])" ,
125+ bygroups (Keyword .Reserved , Punctuation ),
126+ ),
106127 # Two characters operators
107- (r' =>|\.\.|\*\*|:=|/=|>=|<=|<<|>>|<>' , Operator ),
128+ (r" =>|\.\.|\*\*|:=|/=|>=|<=|<<|>>|<>" , Operator ),
108129 # One character operators
109- (r' &|\'|\(|\)|\*|\+|-|\.|/|:|<|=|>|\|' , Operator ),
110- (r' ,|;' , Punctuation ),
130+ (r" &|\'|\(|\)|\*|\+|-|\.|/|:|<|=|>|\|" , Operator ),
131+ (r" ,|;" , Punctuation ),
111132 # Spaces
112- (r' \s+' , Text ),
133+ (r" \s+" , Text ),
113134 # Builtin values
114- (r' False|True' , Keyword .Constant ),
135+ (r" False|True" , Keyword .Constant ),
115136 # Identifiers
116- (r'[\w\.]+' , Name ),
117- (r'.' , Text )]}
137+ (r"[\w\.]+" , Name ),
138+ (r"." , Text ),
139+ ]
140+ }
118141
119142 # Insert tag highlighting before identifiers
120143 if tag_highlighting :
121- result [' root' ].insert (- 1 , (r' \[[\w ]*\]' , Name .Tag ))
144+ result [" root" ].insert (- 1 , (r" \[[\w ]*\]" , Name .Tag ))
122145
123146 return result
124147
@@ -140,10 +163,11 @@ def setup(app):
140163 app.add_lexer('ada', gnatpython.ada_pygments.AdaLexer())
141164
142165 """
143- name = 'Ada'
144- aliases = ['ada' , 'ada83' , 'ada95' , 'ada2005' , 'ada2012' ]
145- filenames = ['*.adb' , '*.ads' , '*.ada' ]
146- mimetypes = ['text/x-ada' ]
166+
167+ name = "Ada"
168+ aliases = ["ada" , "ada83" , "ada95" , "ada2005" , "ada2012" ]
169+ filenames = ["*.adb" , "*.ads" , "*.ada" ]
170+ mimetypes = ["text/x-ada" ]
147171
148172 flags = re .MULTILINE | re .I # Ignore case
149173
@@ -161,8 +185,8 @@ class TaggedAdaLexer(AdaLexer):
161185 brackets.
162186 """
163187
164- name = ' TaggedAda'
165- aliases = [' tagged_ada' ]
188+ name = " TaggedAda"
189+ aliases = [" tagged_ada" ]
166190 tokens = get_lexer_tokens (True )
167191
168192
@@ -172,10 +196,11 @@ class GNATProjectLexer(RegexLexer):
172196 This is the same as the AdaLexer but with support of ``project``
173197 keyword.
174198 """
175- name = 'GPR'
176- aliases = ['gpr' ]
177- filenames = ['*.gpr' ]
178- mimetypes = ['text/x-gpr' ]
199+
200+ name = "GPR"
201+ aliases = ["gpr" ]
202+ filenames = ["*.gpr" ]
203+ mimetypes = ["text/x-gpr" ]
179204
180205 flags = re .MULTILINE | re .I # Ignore case
181206
0 commit comments