aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mparser.py
diff options
context:
space:
mode:
authorMathieu Duponchelle <mathieu@centricular.com>2018-05-20 22:02:08 +0200
committerMathieu Duponchelle <mathieu@centricular.com>2018-05-20 22:36:18 +0200
commit195c356f918d9d617ec8705cd459732ff1418650 (patch)
tree39beac8758a64cfd2d5d5f4b69a9e52abba8fba2 /mesonbuild/mparser.py
parentbd519fc75ed364f3f1082081ed39b1314d0da990 (diff)
downloadmeson-195c356f918d9d617ec8705cd459732ff1418650.zip
meson-195c356f918d9d617ec8705cd459732ff1418650.tar.gz
meson-195c356f918d9d617ec8705cd459732ff1418650.tar.bz2
dict: address review comments
Diffstat (limited to 'mesonbuild/mparser.py')
-rw-r--r--mesonbuild/mparser.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index fb1058c..18ee701 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -642,21 +642,22 @@ class Parser:
while not isinstance(s, EmptyNode):
potential = self.current
- if self.accept('comma'):
- a.commas.append(potential)
- a.append(s)
- elif self.accept('colon'):
+ if self.accept('colon'):
if not isinstance(s, StringNode):
raise ParseException('Key must be a string.',
self.getline(), s.lineno, s.colno)
+ if s.value in a.kwargs:
+ # + 1 to colno to point to the actual string, not the opening quote
+ raise ParseException('Duplicate dictionary key: {}'.format(s.value),
+ self.getline(), s.lineno, s.colno + 1)
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
+ raise ParseException('Only key:value pairs are valid in dict construction.',
+ self.getline(), s.lineno, s.colno)
s = self.statement()
return a
@@ -671,7 +672,7 @@ class Parser:
a.append(s)
elif self.accept('colon'):
if not isinstance(s, IdNode):
- raise ParseException('Keyword argument must be a plain identifier.',
+ raise ParseException('Dictionary key must be a plain identifier.',
self.getline(), s.lineno, s.colno)
a.set_kwarg(s.value, self.statement())
potential = self.current
@@ -708,7 +709,7 @@ class Parser:
varname = t
varnames = [t]
- if (self.accept('comma')):
+ if self.accept('comma'):
t = self.current
self.expect('id')
varnames.append(t)