aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpp.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gpp.py48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/gpp.py b/src/gpp.py
index b14e538..5828a7b 100644
--- a/src/gpp.py
+++ b/src/gpp.py
@@ -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)