diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-08-17 13:42:39 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-08-17 13:42:39 +0200 |
commit | c768ef603eeaae25d4115b9c741b79e524954648 (patch) | |
tree | faa8e56aef13ffbfc1f991bab48beb20250790f9 /auto-auto-complete.py | |
parent | shell option do not need to be first (diff) | |
download | auto-auto-complete-c768ef603eeaae25d4115b9c741b79e524954648.tar.gz auto-auto-complete-c768ef603eeaae25d4115b9c741b79e524954648.tar.bz2 auto-auto-complete-c768ef603eeaae25d4115b9c741b79e524954648.tar.xz |
implement variables
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'auto-auto-complete.py')
-rwxr-xr-x | auto-auto-complete.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/auto-auto-complete.py b/auto-auto-complete.py index ac0993e..0c05f5f 100755 --- a/auto-auto-complete.py +++ b/auto-auto-complete.py @@ -153,6 +153,7 @@ class Parser: ''' @staticmethod def simplify(tree): + global variables program = tree[0] stack = [tree] while len(stack) > 0: @@ -172,6 +173,17 @@ class Parser: new.append(alt[1]) break edited = True + elif item[0] == 'value': + variable = item[1] + if variable in variables: + for value in variables[variable]: + new.append(value) + else: + if len(item) == 2: + abort('Undefined variable: ' + variable) + for value in item[2:]: + new.append(value) + edited = True else: new.append(item) else: @@ -778,13 +790,14 @@ def main(shell, output, source): mane! ''' if __name__ == '__main__': - if len(sys.argv) == 0: - print("USAGE: auto-auto-complete SHELL --output OUTPUT_FILE --source SOURCE_FILE") + if len(sys.argv) < 4: + print("USAGE: auto-auto-complete SHELL --output OUTPUT_FILE --source SOURCE_FILE [VARIABLE=VALUE...]") exit(2) shell = None output = None source = None + variables = {} option = None aliases = {'-o' : '--output', @@ -794,9 +807,14 @@ if __name__ == '__main__': def useopt(option, arg): global source global output + global variables old = None if option == '--output': old = output; output = arg elif option == '--source': old = source; source = arg + elif not option.startswith('-'): + if option not in variables: + variables[option] = [] + variables[option].append(arg) else: abort('Unrecognised option: ' + option) if old is not None: @@ -812,7 +830,7 @@ if __name__ == '__main__': shell = arg else: if '=' in arg: - useopt(arg[:index('=')], arg[index('=') + 1:]) + useopt(arg[:arg.index('=')], arg[arg.index('=') + 1:]) else: option = arg |