aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-11-20 02:59:08 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2016-11-20 03:11:58 +0200
commitf111a0b82601ae4ed01e49069030eabeb2c5c008 (patch)
tree7382135a1cbddf5dba46802f207fdf9e3a237187
parent805847c4a0b081779fc376930f16c0c51032d9ce (diff)
downloadmeson-f111a0b82601ae4ed01e49069030eabeb2c5c008.zip
meson-f111a0b82601ae4ed01e49069030eabeb2c5c008.tar.gz
meson-f111a0b82601ae4ed01e49069030eabeb2c5c008.tar.bz2
Track comma spans in arguments.
-rw-r--r--mesonbuild/astinterpreter.py15
-rw-r--r--mesonbuild/mparser.py5
2 files changed, 17 insertions, 3 deletions
diff --git a/mesonbuild/astinterpreter.py b/mesonbuild/astinterpreter.py
index 29a7932..dabd1ba 100644
--- a/mesonbuild/astinterpreter.py
+++ b/mesonbuild/astinterpreter.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]))
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index ec5778d..51ba9a6 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -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