diff options
Diffstat (limited to 'gettext-tools/src/format-python-brace.c')
-rw-r--r-- | gettext-tools/src/format-python-brace.c | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/gettext-tools/src/format-python-brace.c b/gettext-tools/src/format-python-brace.c index a212707..c76088c 100644 --- a/gettext-tools/src/format-python-brace.c +++ b/gettext-tools/src/format-python-brace.c @@ -140,42 +140,49 @@ parse_directive (struct spec *spec, return false; } - c = *format; - if (c == '.') + /* Parse '.' (getattr) or '[..]' (getitem) operators followed by a + name. If must not recurse, but can be specifed in a chain, such + as "foo.bar.baz[0]". */ + for (;;) { - format++; - if (!parse_named_field (spec, &format, translated, fdi, - invalid_reason)) - { - *invalid_reason = - xasprintf (_("In the directive number %u, '%c' cannot start a getattr argument."), spec->directives, *format); - FDI_SET (format, FMTDIR_ERROR); - return false; - } c = *format; - } - else if (c == '[') - { - format++; - if (!parse_named_field (spec, &format, translated, fdi, - invalid_reason) - && !parse_numeric_field (spec, &format, translated, fdi, - invalid_reason)) + + if (c == '.') { - *invalid_reason = - xasprintf (_("In the directive number %u, '%c' cannot start a getitem argument."), spec->directives, *format); - FDI_SET (format, FMTDIR_ERROR); - return false; + format++; + if (!parse_named_field (spec, &format, translated, fdi, + invalid_reason)) + { + *invalid_reason = + xasprintf (_("In the directive number %u, '%c' cannot start a getattr argument."), spec->directives, *format); + FDI_SET (format, FMTDIR_ERROR); + return false; + } } - - c = *format++; - if (c != ']') + else if (c == '[') { - *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); - FDI_SET (format, FMTDIR_ERROR); - return false; + format++; + if (!parse_named_field (spec, &format, translated, fdi, + invalid_reason) + && !parse_numeric_field (spec, &format, translated, fdi, + invalid_reason)) + { + *invalid_reason = + xasprintf (_("In the directive number %u, '%c' cannot start a getitem argument."), spec->directives, *format); + FDI_SET (format, FMTDIR_ERROR); + return false; + } + + c = *format++; + if (c != ']') + { + *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE (); + FDI_SET (format, FMTDIR_ERROR); + return false; + } } - c = *format; + else + break; } if (c == ':') |