diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-10-09 10:47:24 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-10-09 10:47:24 +0200 |
commit | 646274a0abeafe9f65ace6fc70da3235b82a75ab (patch) | |
tree | 9c41f3c2b346da8d185a1fb1c6dd7b4a065f9bc9 | |
parent | derp (diff) | |
download | gpp-646274a0abeafe9f65ace6fc70da3235b82a75ab.tar.gz gpp-646274a0abeafe9f65ace6fc70da3235b82a75ab.tar.bz2 gpp-646274a0abeafe9f65ace6fc70da3235b82a75ab.tar.xz |
error fixes
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/gpp.py | 48 |
1 files changed, 24 insertions, 24 deletions
@@ -23,25 +23,7 @@ def pp(line): dollar = False quote = [] for c in line: - if len(quote) > 0: - if esc: - esc = False - elif dollar: - dollar = False - if c == '(': - quote.append(')') - elif c == '{': - quote.append('}') - elif c == quote[-1]: - quote[:] = quote[:-1] - elif (quote[-1] in ')}') and (c in '\'"`'): - quote.append(c) - elif (c == '\\') and (quote[-1] != "'"): - esc = True - elif c == '$': - dollar = True - rc += c - elif brackets > 0: + if brackets > 0: if esc: esc = False elif (c == ')') or (c == '}'): @@ -56,13 +38,31 @@ def pp(line): rc += c elif symb: symb = False - if c == symbol: + if (c == '(') or (c == '{'): + brackets += 1 + rc += '\'"$' + c + else: rc += c elif c == symbol: symb = True - elif (c == '(') or (c == '{'): - brackets += 1 - rc += '\'"$' + c + elif len(quote) > 0: + if esc: + esc = False + elif dollar: + dollar = False + if c == '(': + quote.append(')') + elif c == '{': + quote.append('}') + elif c == quote[-1]: + quote[:] = quote[:-1] + elif (quote[-1] in ')}') and (c in '\'"`'): + quote.append(c) + elif (c == '\\') and (quote[-1] != "'"): + esc = True + elif c == '$': + dollar = True + rc += c elif (c == '"') or (c == "'") or (c == '`'): quote.append(c) rc += c @@ -82,7 +82,7 @@ for lineno in range(len(data)): bashed.append(line) else: line = '\'%s\'' % line.replace('\'', '\'\\\'\'') - bashed.append('echo $\'\\e%i\\e\' %s' % (lineno, pp(line))) + bashed.append('echo $\'\\e%i\\e\'%s' % (lineno, pp(line))) bashed = '\n'.join(bashed).encode(encoding) bash = Popen(["bash"], stdin = PIPE, stdout = PIPE, stderr = sys.stderr) |