3 pygments.lexers.stata |
3 pygments.lexers.stata |
4 ~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexer for Stata |
6 Lexer for Stata |
7 |
7 |
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 from pygments.lexer import RegexLexer, include, words |
13 from pygments.lexer import RegexLexer, default, include, words |
14 from pygments.token import Comment, Keyword, Name, Number, \ |
14 from pygments.token import Comment, Keyword, Name, Number, \ |
15 String, Text, Operator |
15 String, Text, Operator |
16 |
16 |
17 from pygments.lexers._stata_builtins import builtins_base, builtins_functions |
17 from pygments.lexers._stata_builtins import builtins_base, builtins_functions |
18 |
18 |
116 # `' is a local. |
116 # `' is a local. |
117 # |
117 # |
118 # A global is more restricted, so we do follow rules. Note only |
118 # A global is more restricted, so we do follow rules. Note only |
119 # locals explicitly enclosed ${} can be nested. |
119 # locals explicitly enclosed ${} can be nested. |
120 'macros': [ |
120 'macros': [ |
121 (r'\$(\{|(?=[\$`]))', Name.Variable.Global, 'macro-global-nested'), |
121 (r'\$(\{|(?=[$`]))', Name.Variable.Global, 'macro-global-nested'), |
122 (r'\$', Name.Variable.Global, 'macro-global-name'), |
122 (r'\$', Name.Variable.Global, 'macro-global-name'), |
123 (r'`', Name.Variable, 'macro-local'), |
123 (r'`', Name.Variable, 'macro-local'), |
124 ], |
124 ], |
125 'macro-local': [ |
125 'macro-local': [ |
126 (r'`', Name.Variable, '#push'), |
126 (r'`', Name.Variable, '#push'), |
127 (r"'", Name.Variable, '#pop'), |
127 (r"'", Name.Variable, '#pop'), |
128 (r'\$(\{|(?=[\$`]))', Name.Variable.Global, 'macro-global-nested'), |
128 (r'\$(\{|(?=[$`]))', Name.Variable.Global, 'macro-global-nested'), |
129 (r'\$', Name.Variable.Global, 'macro-global-name'), |
129 (r'\$', Name.Variable.Global, 'macro-global-name'), |
130 (r'.', Name.Variable), # fallback |
130 (r'.', Name.Variable), # fallback |
131 ], |
131 ], |
132 'macro-global-nested': [ |
132 'macro-global-nested': [ |
133 (r'\$(\{|(?=[\$`]))', Name.Variable.Global, '#push'), |
133 (r'\$(\{|(?=[$`]))', Name.Variable.Global, '#push'), |
134 (r'\}', Name.Variable.Global, '#pop'), |
134 (r'\}', Name.Variable.Global, '#pop'), |
135 (r'\$', Name.Variable.Global, 'macro-global-name'), |
135 (r'\$', Name.Variable.Global, 'macro-global-name'), |
136 (r'`', Name.Variable, 'macro-local'), |
136 (r'`', Name.Variable, 'macro-local'), |
137 (r'\w', Name.Variable.Global), # fallback |
137 (r'\w', Name.Variable.Global), # fallback |
138 (r'(?!\w)', Name.Variable.Global, '#pop'), |
138 default('#pop'), |
139 ], |
139 ], |
140 'macro-global-name': [ |
140 'macro-global-name': [ |
141 (r'\$(\{|(?=[\$`]))', Name.Variable.Global, 'macro-global-nested', '#pop'), |
141 (r'\$(\{|(?=[$`]))', Name.Variable.Global, 'macro-global-nested', '#pop'), |
142 (r'\$', Name.Variable.Global, 'macro-global-name', '#pop'), |
142 (r'\$', Name.Variable.Global, 'macro-global-name', '#pop'), |
143 (r'`', Name.Variable, 'macro-local', '#pop'), |
143 (r'`', Name.Variable, 'macro-local', '#pop'), |
144 (r'\w{1,32}', Name.Variable.Global, '#pop'), |
144 (r'\w{1,32}', Name.Variable.Global, '#pop'), |
145 ], |
145 ], |
146 # Built in functions and statements |
146 # Built in functions and statements |