From c768ef603eeaae25d4115b9c741b79e524954648 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 17 Aug 2013 13:42:39 +0200 Subject: implement variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- auto-auto-complete.py | 24 +++++++++++++++++++++--- example | 2 +- 2 files changed, 22 insertions(+), 4 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 diff --git a/example b/example index fb42bc6..6212c06 100644 --- a/example +++ b/example @@ -1,4 +1,4 @@ -(ponysay +((value command ponysay) (default (arg MESSAGE) (files -0) (suggest message) (desc 'Message spoken by the pony')) (multiple unargumented -- cgit v1.2.3-70-g09d2