-
Notifications
You must be signed in to change notification settings - Fork 667
/
parser.py
2964 lines (2058 loc) · 68.5 KB
/
parser.py
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2004-2019 Tom Rothamel <pytom@bishoujo.us>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# This module contains the parser for the Ren'Py script language. It's
# called when parsing is necessary, and creates an AST from the script.
from __future__ import division, absolute_import, with_statement, print_function, unicode_literals
from renpy.compat import *
import codecs
import re
import os
import time
import contextlib
import renpy.display
import renpy.test
import renpy.ast as ast
import renpy.sl2
# A list of parse error messages.
parse_errors = [ ]
from renpy.parsersupport import match_logical_word
class ParseError(Exception):
def __init__(self, filename, number, msg, line=None, pos=None, first=False):
message = u"File \"%s\", line %d: %s" % (unicode_filename(filename), number, msg)
if line:
if isinstance(line, list):
line = "".join(line)
lines = line.split('\n')
if len(lines) > 1:
open_string = None
i = 0
while i < len(lines[0]):
c = lines[0][i]
if c == "\\":
i += 1
elif c == open_string:
open_string = None
elif open_string:
pass
elif c == '`' or c == '\'' or c == '"':
open_string = c
i += 1
if open_string:
message += "\n(Perhaps you left out a %s at the end of the first line.)" % open_string
for l in lines:
message += "\n " + l
if pos is not None:
if pos <= len(l):
message += "\n " + " " * pos + "^"
pos = None
else:
pos -= len(l)
if first:
break
self.message = message
Exception.__init__(self, message)
def __unicode__(self):
return self.message
# Something to hold the expected line number.
class LineNumberHolder(object):
"""
Holds the expected line number.
"""
def __init__(self):
self.line = 0
def unicode_filename(fn):
"""
Converts the supplied filename to unicode.
"""
if isinstance(fn, str):
return fn
# Windows.
try:
return fn.decode("mbcs")
except:
pass
# Mac and (sane) Unix
try:
return fn.decode("utf-8")
except:
pass
# Insane systems, mojibake.
return fn.decode("latin-1")
# Matches either a word, or something else. Most magic is taken care of
# before this.
lllword = re.compile(r'__(\w+)|\w+| +|.', re.S)
def munge_filename(fn):
# The prefix that's used when __ is found in the file.
rv = os.path.basename(fn)
rv = os.path.splitext(rv)[0]
rv = rv.replace(" ", "_")
def munge_char(m):
return hex(ord(m.group(0)))
rv = re.sub(r'[^a-zA-Z0-9_]', munge_char, rv)
return "_m1_" + rv + "__"
def elide_filename(fn):
"""
Returns a version of fn that is either relative to the base directory,
or relative to the Ren'Py directory.
"""
ofn = fn
fn = os.path.abspath(fn)
basedir = os.path.abspath(renpy.config.basedir)
renpy_base = os.path.abspath(renpy.config.renpy_base)
if fn.startswith(basedir):
return os.path.relpath(fn, basedir).replace("\\", "/")
elif fn.startswith(renpy_base):
return os.path.relpath(fn, renpy_base).replace("\\", "/")
else:
return ofn.replace("\\", "/")
def unelide_filename(fn):
fn1 = os.path.join(renpy.config.basedir, fn)
if os.path.exists(fn1):
return fn1
fn2 = os.path.join(renpy.config.renpy_base, fn)
if os.path.exists(fn2):
return fn2
return fn
# The filename that the start and end positions are relative to.
original_filename = ""
def list_logical_lines(filename, filedata=None, linenumber=1, add_lines=False):
"""
Reads `filename`, and divides it into logical lines.
Returns a list of (filename, line number, line text) triples.
If `filedata` is given, it should be a unicode string giving the file
contents. In that case, `filename` need not exist.
"""
def munge_string(m):
brackets = m.group(1)
if (len(brackets) & 1) == 0:
return m.group(0)
if "__" in m.group(2):
return m.group(0)
return brackets + prefix + m.group(2)
global original_filename
original_filename = filename
if filedata:
data = filedata
else:
f = open(filename, "rb")
data = f.read().decode("utf-8")
f.close()
filename = elide_filename(filename)
prefix = munge_filename(filename)
# Add some newlines, to fix lousy editors.
data += "\n\n"
# The result.
rv = []
# The line number in the physical file.
number = linenumber
# The current position we're looking at in the buffer.
pos = 0
# Are we looking at a triple-quoted string?
# Skip the BOM, if any.
if len(data) and data[0] == u'\ufeff':
pos += 1
if add_lines or renpy.game.context().init_phase:
lines = renpy.scriptedit.lines
else:
lines = { }
len_data = len(data)
renpy.scriptedit.files.add(filename)
# Looping over the lines in the file.
while pos < len_data:
# The line number of the start of this logical line.
start_number = number
# The line that we're building up.
line = [ ]
# The number of open parenthesis there are right now.
parendepth = 0
loc = (filename, start_number)
lines[loc] = renpy.scriptedit.Line(original_filename, start_number, pos)
endpos = None
while pos < len_data:
startpos = pos
c = data[pos]
if c == u'\t':
raise ParseError(filename, number, "Tab characters are not allowed in Ren'Py scripts.")
if c == u'\n' and not parendepth:
line = ''.join(line)
# If not blank...
if not re.match(u"^\s*$", line):
# Add to the results.
rv.append((filename, start_number, line))
if endpos is None:
endpos = pos
lines[loc].end_delim = endpos + 1
while data[endpos - 1] in u' \r':
endpos -= 1
lines[loc].end = endpos
lines[loc].text = data[lines[loc].start:lines[loc].end]
lines[loc].full_text = data[lines[loc].start:lines[loc].end_delim]
pos += 1
number += 1
endpos = None
# This helps out error checking.
line = [ ]
break
if c == u'\n':
number += 1
endpos = None
if c == u"\r":
pos += 1
continue
# Backslash/newline.
if c == u"\\" and data[pos + 1] == u"\n":
pos += 2
number += 1
line.append(u"\\\n")
continue
# Parenthesis.
if c in u'([{':
parendepth += 1
if (c in u'}])') and parendepth:
parendepth -= 1
# Comments.
if c == u'#':
endpos = pos
while data[pos] != u'\n':
pos += 1
continue
# Strings.
if c in u'"\'`':
delim = c
line.append(c)
pos += 1
escape = False
triplequote = False
if (pos < len_data - 1) and (data[pos] == delim) and (data[pos + 1] == delim):
line.append(delim)
line.append(delim)
pos += 2
triplequote = True
s = [ ]
while pos < len_data:
c = data[pos]
if c == u'\n':
number += 1
if c == u'\r':
pos += 1
continue
if escape:
escape = False
pos += 1
s.append(c)
continue
if c == delim:
if not triplequote:
pos += 1
s.append(c)
break
if (pos < len_data - 2) and (data[pos + 1] == delim) and (data[pos + 2] == delim):
pos += 3
s.append(delim)
s.append(delim)
s.append(delim)
break
if c == u'\\':
escape = True
s.append(c)
pos += 1
continue
s = "".join(s)
if "[__" in s:
# Munge substitutions.
s = re.sub(r'(\.|\[+)__(\w+)', munge_string, s)
line.append(s)
continue
word, magic, end = match_logical_word(data, pos)
if magic:
rest = word[2:]
if u"__" not in rest:
word = prefix + rest
line.append(word)
pos = end
if (pos - startpos) > 65536:
raise ParseError(filename, start_number, "Overly long logical line. (Check strings and parenthesis.)", line=line, first=True)
if line:
raise ParseError(filename, start_number, "is not terminated with a newline. (Check strings and parenthesis.)", line=line, first=True)
return rv
def group_logical_lines(lines):
"""
This takes as input the list of logical line triples output from
list_logical_lines, and breaks the lines into blocks. Each block
is represented as a list of (filename, line number, line text,
block) triples, where block is a block list (which may be empty if
no block is associated with this line.)
"""
# Returns the depth of a line, and the rest of the line.
def depth_split(l):
depth = 0
index = 0
while True:
if l[index] == ' ':
depth += 1
index += 1
continue
# if l[index] == '\t':
# index += 1
# depth = depth + 8 - (depth % 8)
# continue
break
return depth, l[index:]
# i, min_depth -> block, new_i
def gll_core(i, min_depth):
rv = []
depth = None
while i < len(lines):
filename, number, text = lines[i]
line_depth, rest = depth_split(text)
# This catches a block exit.
if line_depth < min_depth:
break
if depth is None:
depth = line_depth
if depth != line_depth:
raise ParseError(filename, number, "indentation mismatch.")
# Advance to the next line.
i += 1
# Try parsing a block associated with this line.
block, i = gll_core(i, depth + 1)
rv.append((filename, number, rest, block))
return rv, i
return gll_core(0, 0)[0]
# A list of keywords which should not be parsed as names, because
# there is a huge chance of confusion.
#
# Note: We need to be careful with what's in here, because these
# are banned in simple_expressions, where we might want to use
# some of them.
KEYWORDS = set([
'$',
'as',
'at',
'behind',
'call',
'expression',
'hide',
'if',
'in',
'image',
'init',
'jump',
'menu',
'onlayer',
'python',
'return',
'scene',
'show',
'with',
'while',
'zorder',
'transform',
])
OPERATORS = [
'<>',
'<<',
'<=',
'<',
'>>',
'>=',
'>',
'!=',
'==',
'|',
'^',
'&',
'+',
'-',
'**',
'*',
'//',
'/',
'%',
'~',
]
ESCAPED_OPERATORS = [
r'\bor\b',
r'\band\b',
r'\bnot\b',
r'\bin\b',
r'\bis\b',
]
operator_regexp = "|".join([ re.escape(i) for i in OPERATORS ] + ESCAPED_OPERATORS)
word_regexp = r'[a-zA-Z_\u00a0-\ufffd][0-9a-zA-Z_\u00a0-\ufffd]*'
image_word_regexp = r'[-0-9a-zA-Z_\u00a0-\ufffd][-0-9a-zA-Z_\u00a0-\ufffd]*'
class SubParse(object):
"""
This represents the information about a subparse that can be provided to
a creator-defined statement.
"""
def __init__(self, block):
self.block = block
def __repr__(self):
if not self.block:
return "<SubParse empty>"
else:
return "<SubParse {}:{}>".format(self.block[0].filename, self.block[0].linenumber)
class Lexer(object):
"""
The lexer that is used to lex script files. This works on the idea
that we want to lex each line in a block individually, and use
sub-lexers to lex sub-blocks.
"""
def __init__(self, block, init=False, init_offset=0, global_label=None, monologue_delimiter="\n\n", subparses=None):
# Are we underneath an init block?
self.init = init
# The priority of auto-defined init statements.
self.init_offset = init_offset
self.block = block
self.eob = False
self.line = -1
# These are set by advance.
self.filename = ""
self.text = ""
self.number = 0
self.subblock = [ ]
self.global_label = global_label
self.pos = 0
self.word_cache_pos = -1
self.word_cache_newpos = -1
self.word_cache = ""
self.monologue_delimiter = monologue_delimiter
self.subparses = subparses
def advance(self):
"""
Advances this lexer to the next line in the block. The lexer
starts off before the first line, so advance must be called
before any matching can be done. Returns True if we've
successfully advanced to a line in the block, or False if we
have advanced beyond all lines in the block. In general, once
this method has returned False, the lexer is in an undefined
state, and it doesn't make sense to call any method other than
advance (which will always return False) on the lexer.
"""
self.line += 1
if self.line >= len(self.block):
self.eob = True
return False
self.filename, self.number, self.text, self.subblock = self.block[self.line]
self.pos = 0
self.word_cache_pos = -1
return True
def unadvance(self):
"""
Puts the parsing point at the end of the previous line. This is used
after renpy_statement to prevent the advance that Ren'Py statements
do.
"""
self.line -= 1
self.eob = False
self.filename, self.number, self.text, self.subblock = self.block[self.line]
self.pos = len(self.text)
self.word_cache_pos = -1
def match_regexp(self, regexp):
"""
Tries to match the given regexp at the current location on the
current line. If it succeds, it returns the matched text (if
any), and updates the current position to be after the
match. Otherwise, returns None and the position is unchanged.
"""
if self.eob:
return None
if self.pos == len(self.text):
return None
m = re.compile(regexp, re.DOTALL).match(self.text, self.pos)
if not m:
return None
self.pos = m.end()
return m.group(0)
def skip_whitespace(self):
"""
Advances the current position beyond any contiguous whitespace.
"""
# print self.text[self.pos].encode('unicode_escape')
self.match_regexp(r"(\s+|\\\n)+")
def match(self, regexp):
"""
Matches something at the current position, skipping past
whitespace. Even if we can't match, the current position is
still skipped past the leading whitespace.
"""
self.skip_whitespace()
return self.match_regexp(regexp)
def keyword(self, word):
"""
Matches a keyword at the current position. A keyword is a word
that is surrounded by things that aren't words, like
whitespace. (This prevents a keyword from matching a prefix.)
"""
oldpos = self.pos
if self.word() == word:
return word
self.pos = oldpos
return ''
@contextlib.contextmanager
def catch_error(self):
"""
Catches errors, then causes the line to advance if it hasn't been
advanced already.
"""
try:
yield
except ParseError as e:
parse_errors.append(e.message)
def error(self, msg):
"""
Convenience function for reporting a parse error at the current
location.
"""
raise ParseError(self.filename, self.number, msg, self.text, self.pos)
def eol(self):
"""
Returns True if, after skipping whitespace, the current
position is at the end of the end of the current line, or
False otherwise.
"""
self.skip_whitespace()
return self.pos >= len(self.text)
def expect_eol(self):
"""
If we are not at the end of the line, raise an error.
"""
if not self.eol():
self.error('end of line expected.')
def expect_noblock(self, stmt):
"""
Called to indicate this statement does not expect a block.
If a block is found, raises an error.
"""
if self.subblock:
ll = self.subblock_lexer()
ll.advance()
ll.error("Line is indented, but the preceding %s statement does not expect a block. Please check this line's indentation." % stmt)
def expect_block(self, stmt):
"""
Called to indicate that the statement requires that a non-empty
block is present.
"""
if not self.subblock:
self.error('%s expects a non-empty block.' % stmt)
def has_block(self):
"""
Called to check if the current line has a non-empty block.
"""
return bool(self.subblock)
def subblock_lexer(self, init=False):
"""
Returns a new lexer object, equiped to parse the block
associated with this line.
"""
init = self.init or init
return Lexer(self.subblock, init=init, init_offset=self.init_offset, global_label=self.global_label, monologue_delimiter=self.monologue_delimiter, subparses=self.subparses)
def string(self):
"""
Lexes a string, and returns the string to the user, or None if
no string could be found. This also takes care of expanding
escapes and collapsing whitespace.
Be a little careful, as this can return an empty string, which is
different than None.
"""
s = self.match(r'r?"([^\\"]|\\.)*"')
if s is None:
s = self.match(r"r?'([^\\']|\\.)*'")
if s is None:
s = self.match(r"r?`([^\\`]|\\.)*`")
if s is None:
return None
if s[0] == 'r':
raw = True
s = s[1:]
else:
raw = False
# Strip off delimiters.
s = s[1:-1]
def dequote(m):
c = m.group(1)
if c == "{":
return "{{"
elif c == "[":
return "[["
elif c == "%":
return "%%"
elif c == "n":
return "\n"
elif c[0] == 'u':
group2 = m.group(2)
if group2:
return chr(int(m.group(2), 16))
else:
return c
if not raw:
# Collapse runs of whitespace into single spaces.
s = re.sub(r'\s+', ' ', s)
s = re.sub(r'\\(u([0-9a-fA-F]{1,4})|.)', dequote, s)
return s
def triple_string(self):
"""
Lexes a triple quoted string, intended for use with monologue mode.
This is about the same as the double-quoted strings, except that
runs of whitespace with multiple newlines are turned into a single
newline.
"""
s = self.match(r'r?"""([^\\"]|\\.)*"""')
if s is None:
s = self.match(r"r?'''([^\\']|\\.)*'''")
if s is None:
s = self.match(r"r?```([^\\`]|\\.)*```")
if s is None:
return None
if s[0] == 'r':
raw = True
s = s[1:]
else:
raw = False
# Strip off delimiters.
s = s[3:-3]
def dequote(m):
c = m.group(1)
if c == "{":
return "{{"
elif c == "[":
return "[["
elif c == "%":
return "%%"
elif c == "n":
return "\n"
elif c[0] == 'u':
group2 = m.group(2)
if group2:
return chr(int(m.group(2), 16))
else:
return c
if not raw:
# Collapse runs of whitespace into single spaces.
s = re.sub(r' *\n *', '\n', s)
rv = [ ]
for s in s.split(self.monologue_delimiter):
s = s.strip()
if not s:
continue
s = re.sub(r'\s+', ' ', s)
s = re.sub(r'\\(u([0-9a-fA-F]{1,4})|.)', dequote, s)
rv.append(s)
return rv
return s
def integer(self):
"""
Tries to parse an integer. Returns a string containing the
integer, or None.
"""
return self.match(r'(\+|\-)?\d+')
def float(self): # @ReservedAssignment
"""
Tries to parse a number (float). Returns a string containing the
number, or None.
"""
return self.match(r'(\+|\-)?(\d+\.?\d*|\.\d+)([eE][-+]?\d+)?')
def hash(self):
"""
Matches the characters in an md5 hash, and then some.
"""
return self.match(r'\w+')
def word(self):
"""
Parses a name, which may be a keyword or not.
"""
if self.pos == self.word_cache_pos:
self.pos = self.word_cache_newpos
return self.word_cache
self.word_cache_pos = self.pos
rv = self.match(word_regexp)
self.word_cache = rv
self.word_cache_newpos = self.pos
return rv
def name(self):
"""
This tries to parse a name. Returns the name or None.
"""
oldpos = self.pos
rv = self.word()
if (rv == "r") or (rv == "u"):
if self.text[self.pos:self.pos + 1] in ('"', "'", "`"):
self.pos = oldpos
return None
if rv in KEYWORDS:
self.pos = oldpos
return None
return rv
def set_global_label(self, label):
"""
Set current global_label, which is used for label_name calculations.
label can be any valid label or None, but this has only effect if label
has global part.
"""
if label and label[0] != '.':
self.global_label = label.split('.')[0]
def label_name(self, declare=False):
"""
Try to parse label name. Returns name in form of "global.local" if local
is present, "global" otherwise; or None if it doesn't parse.
If declare is True, allow only such names that are valid for declaration
(e.g. forbid global name mismatch)
"""
old_pos = self.pos
local_name = None
global_name = self.name()
if not global_name:
# .local label
if not self.match('\.') or not self.global_label:
self.pos = old_pos
return None
global_name = self.global_label
local_name = self.name()
if not local_name:
self.pos = old_pos
return None
else:
if self.match('\.'):
# full global.local name
if declare and global_name != self.global_label:
self.pos = old_pos
return None
local_name = self.name()
if not local_name:
self.pos = old_pos