Track comma spans in arguments.

pull/1103/head
Jussi Pakkanen 8 years ago
parent 805847c4a0
commit f111a0b826
  1. 15
      mesonbuild/astinterpreter.py
  2. 5
      mesonbuild/mparser.py

@ -188,11 +188,20 @@ class AstInterpreter(interpreterbase.InterpreterBase):
for i in range(len(args)):
if self.filename == args[i]:
namespan = node.args.arguments[i].bytespan
# SUPER HACK! Should track bytespans of commas instead.
namespan = (namespan[0]-2, namespan[1])
# Usually remove the comma after this item but if it is
# the last argument, we need to remove the one before.
if i >= len(node.args.commas):
i -= 1
if i < 0:
commaspan = (0, 0) # Removed every entry in the list.
else:
commaspan = node.args.commas[i].bytespan
if commaspan[0] < namespan[0]:
commaspan, namespan = namespan, commaspan
buildfilename = os.path.join(self.source_root, self.subdir, environment.build_filename)
raw_data = open(buildfilename, 'r').read()
updated = raw_data[0:namespan[0]] + raw_data[namespan[1]:]
intermediary = raw_data[0:commaspan[0]] + raw_data[commaspan[1]:]
updated = intermediary[0:namespan[0]] + intermediary[namespan[1]:]
open(buildfilename, 'w').write(updated)
sys.exit(0)
sys.exit('Could not find source %s in target %s.' % (self.filename, args[0]))

@ -301,6 +301,7 @@ class ArgumentNode():
self.lineno = token.lineno
self.colno = token.colno
self.arguments = []
self.commas = []
self.kwargs = {}
self.order_error = False
@ -520,15 +521,19 @@ class Parser:
a = ArgumentNode(s)
while not isinstance(s, EmptyNode):
potential = self.current
if self.accept('comma'):
a.commas.append(potential)
a.append(s)
elif self.accept('colon'):
if not isinstance(s, IdNode):
raise ParseException('Keyword argument must be a plain identifier.',
s.lineno, s.colno)
a.set_kwarg(s.value, self.statement())
potential = self.current
if not self.accept('comma'):
return a
a.commas.append(potential)
else:
a.append(s)
return a

Loading…
Cancel
Save