mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 15:48:21 +00:00
Improve +processpre directive parsing to include #warning
This commit is contained in:
parent
d5b83d50c4
commit
13e48ff956
1 changed files with 21 additions and 14 deletions
|
@ -427,12 +427,15 @@ class parser(object):
|
||||||
if directive[len(directive)-1:] == '\\':
|
if directive[len(directive)-1:] == '\\':
|
||||||
raise EParseInvalidBackslash(self)
|
raise EParseInvalidBackslash(self)
|
||||||
|
|
||||||
|
# compile the RE lazily, to avoid penalizing programs not using it
|
||||||
if self.parse_directive_re is None:
|
if self.parse_directive_re is None:
|
||||||
self.parse_directive_re = re.compile(
|
self.parse_directive_re = re.compile(
|
||||||
r'^#\s*(?:'
|
r'^#\s*(?:'
|
||||||
r'(?:line)?\s+(\d+)(?:\s+("(?:\\.|[^"])*")(?:\s+\d+)*)?'
|
r'(?:line)?\s+(\d+)(?:\s+("(?:\\.|[^"])*")(?:\s+\d+)*)?'
|
||||||
r'|'
|
r'|'
|
||||||
r'([a-z0-9_]+)\s+([a-z0-9_]+)\s+([-+,a-z0-9_]+)'
|
r'(?:pragma)\s+(?:OPT)\s+([-+,a-z0-9_]+)'
|
||||||
|
r'|'
|
||||||
|
r'([a-z0-9_]+)(?:\s+(.*)?)' # others
|
||||||
r')\s*$'
|
r')\s*$'
|
||||||
, re.I
|
, re.I
|
||||||
)
|
)
|
||||||
|
@ -460,25 +463,29 @@ class parser(object):
|
||||||
actlinenum = self.script.count('\n', 0, self.pos)
|
actlinenum = self.script.count('\n', 0, self.pos)
|
||||||
self.linedir.append((actlinenum, reflinenum, filename))
|
self.linedir.append((actlinenum, reflinenum, filename))
|
||||||
del actlinenum, reflinenum, filename
|
del actlinenum, reflinenum, filename
|
||||||
else:
|
elif match.group(3): # '#pragma OPT <options>' found
|
||||||
assert match.group(3) is not None
|
opts = match.group(3).lower().split(',')
|
||||||
if match.group(3).lower() == 'pragma' and match.group(4) == 'OPT':
|
for opt in opts:
|
||||||
opts = match.group(5).lower().split(',')
|
if opt != '':
|
||||||
for opt in opts:
|
if opt[0] == '-':
|
||||||
if opt != '':
|
self.SetOpt(opt[1:], False)
|
||||||
if opt[0] == '-':
|
elif opt[0] == '+':
|
||||||
self.SetOpt(opt[1:], False)
|
self.SetOpt(opt[1:], True)
|
||||||
elif opt[0] == '+':
|
else:
|
||||||
self.SetOpt(opt[1:], True)
|
self.SetOpt(opt, True)
|
||||||
else:
|
elif match.group(4) == 'warning':
|
||||||
self.SetOpt(opt, True)
|
if match.group(5):
|
||||||
|
warning("Warning: #warning " + match.group(5))
|
||||||
|
else:
|
||||||
|
warning("Warning: #warning")
|
||||||
|
# else ignore
|
||||||
|
|
||||||
def GetToken(self):
|
def GetToken(self):
|
||||||
"""Lexer"""
|
"""Lexer"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while self.pos < self.length:
|
while self.pos < self.length:
|
||||||
# If an error occurs, it will happen at the start of this token.
|
# In case of error, report it at the start of this token.
|
||||||
self.errorpos = self.pos
|
self.errorpos = self.pos
|
||||||
|
|
||||||
c = self.script[self.pos]
|
c = self.script[self.pos]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue