def main(): parser = argparse.ArgumentParser(prefix_chars='-') parser.add_argument('--print-tokens', action='store_true', help='Prints the tokenizer output.') parser.add_argument('--print-tree-transducer-outputs', action='store_true', help='Prints the output of each transducer in the chain.') parser.add_argument('--print-arrangement-outputs', action='store_true', help='Prints the output of each arrangement within each arrangement-based transducer in the chain.') parser.add_argument('--print-parse', action='store_true', help='Prints the outcome of parsing the written code (the forms, seqs, etc).') parser.add_argument('--print-macro-expanded-code', action='store_true', help='Prints the code after macro-expansion.') parser.add_argument('--print-python-ast', action='store_true', help='Prints the generated Python AST.') parser.add_argument('--print-python-code', action='store_true', help='Prints the generated Python source.') parser.add_argument('--skip-transducing', action='store_true', help='Stops the compiler immediately after tokenization.') parser.add_argument('--skip-macroexpansion', action='store_true', help='Stops the compiler immediately after parsing.') parser.add_argument('--skip-codegen', action='store_true', help='Stops the compiler immediately after macro-expansion.') parser.add_argument('--stdout', action='store_true') parser.add_argument('-I', '--include', help='A colon-separated list of source paths where to search for imported modules.') parser.add_argument('-E', '--toggle-exec', action='store_true', help='Executes the compiled code even in non-interactive mode, and does not execute in interactive mode.') parser.add_argument('-CP', '--compile-to-python', action='store_true', help='Compiles to Python, outputing the result into a .py file on the same path.') parser.add_argument('--version', action='version', version='Anoky α.1') parser.add_argument('file', nargs='*') parse = parser.parse_args() options = Record() options.print_tokens = parse.print_tokens if parse.print_tree_transducer_outputs: G.Options.PRINT_TREE_TRANSDUCER_OUTPUTS = True if parse.print_arrangement_outputs: G.Options.PRINT_ARRANGEMENT_OUTPUTS = True options.print_parse = parse.print_parse options.print_macro_expanded_code = parse.print_macro_expanded_code options.include_dirs = parse.include.split(':') if parse.include else ['.'] if len(parse.file) > 1: raise NotImplementedError() elif len(parse.file) == 0: options.interactive = True options.compile_to_python = False options.execute = not parse.toggle_exec else: options.interactive = False options.filename = parse.file[0] options.compile_to_python = parse.compile_to_python options.execute = parse.toggle_exec options.arrange_tokens = not parse.skip_transducing if not options.arrange_tokens: options.print_tokens = True options.expand_macros = not parse.skip_macroexpansion and not parse.skip_transducing if not options.expand_macros: options.print_parse = True options.generate_code = not parse.skip_macroexpansion and not parse.skip_transducing and not parse.skip_codegen if not options.generate_code: options.print_macro_expanded_code = True options.print_python_code = parse.print_python_code or not options.execute options.print_python_ast = parse.print_python_ast if parse.stdout: options.output = '<stdout>' else: options.output = '.' if options.interactive: interactive_anoky(options) else: non_interactive_anoky(options)
def parse_args(argv): options = Record({'verbose': False, 'execute': False},) args = SysArgsParser(argv) while args.next() is not None: arg = args() if arg == '--verbose': options.verbose = True Options.PRINT_TREE_TRANSDUCER_OUTPUTS = True Options.PRINT_ARRANGEMENT_OUTPUTS = True elif arg == '--binary': options.binary = True options.encoder = msgpack.packb elif arg == '--lex': if 'encoder' not in options: options.binary = False options.encoder = unicode_encoder if args.peek() is None or args.peek().startswith("--"): options.output = sys.stdout.buffer else: output_name = args.next() if output_name == 'stdout': options.output = sys.stdout.buffer if output_name == 'stderr': options.output = sys.stderr.buffer else: options.output = open(output_name, "wb") elif arg.lower().endswith('.aky'): if 'filename' in options: print("Multiple filenames found!") exit(-1) options['filename'] = arg elif arg == '--execute': options.execute = True else: print("Unexpected option, '%s'" % arg) exit(-1) return options
def main(): parser = argparse.ArgumentParser(prefix_chars='-') parser.add_argument('--print-tokens', action='store_true', help='Prints the tokenizer output.') parser.add_argument( '--print-tree-transducer-outputs', action='store_true', help='Prints the output of each transducer in the chain.') parser.add_argument( '--print-arrangement-outputs', action='store_true', help= 'Prints the output of each arrangement within each arrangement-based transducer in the chain.' ) parser.add_argument( '--print-parse', action='store_true', help= 'Prints the outcome of parsing the written code (the forms, seqs, etc).' ) parser.add_argument('--print-macro-expanded-code', action='store_true', help='Prints the code after macro-expansion.') parser.add_argument('--print-python-ast', action='store_true', help='Prints the generated Python AST.') parser.add_argument('--print-python-code', action='store_true', help='Prints the generated Python source.') parser.add_argument( '--skip-transducing', action='store_true', help='Stops the compiler immediately after tokenization.') parser.add_argument('--skip-macroexpansion', action='store_true', help='Stops the compiler immediately after parsing.') parser.add_argument( '--skip-codegen', action='store_true', help='Stops the compiler immediately after macro-expansion.') parser.add_argument('--stdout', action='store_true') parser.add_argument( '-I', '--include', help= 'A colon-separated list of source paths where to search for imported modules.' ) parser.add_argument( '-E', '--toggle-exec', action='store_true', help= 'Executes the compiled code even in non-interactive mode, and does not execute in interactive mode.' ) parser.add_argument( '-CP', '--compile-to-python', action='store_true', help= 'Compiles to Python, outputing the result into a .py file on the same path.' ) parser.add_argument('--version', action='version', version='Anoky α.1') parser.add_argument('file', nargs='*') parse = parser.parse_args() options = Record() options.print_tokens = parse.print_tokens if parse.print_tree_transducer_outputs: G.Options.PRINT_TREE_TRANSDUCER_OUTPUTS = True if parse.print_arrangement_outputs: G.Options.PRINT_ARRANGEMENT_OUTPUTS = True options.print_parse = parse.print_parse options.print_macro_expanded_code = parse.print_macro_expanded_code options.include_dirs = parse.include.split(':') if parse.include else ['.'] if len(parse.file) > 1: raise NotImplementedError() elif len(parse.file) == 0: options.interactive = True options.compile_to_python = False options.execute = not parse.toggle_exec else: options.interactive = False options.filename = parse.file[0] options.compile_to_python = parse.compile_to_python options.execute = parse.toggle_exec options.arrange_tokens = not parse.skip_transducing if not options.arrange_tokens: options.print_tokens = True options.expand_macros = not parse.skip_macroexpansion and not parse.skip_transducing if not options.expand_macros: options.print_parse = True options.generate_code = not parse.skip_macroexpansion and not parse.skip_transducing and not parse.skip_codegen if not options.generate_code: options.print_macro_expanded_code = True options.print_python_code = parse.print_python_code or not options.execute options.print_python_ast = parse.print_python_ast if parse.stdout: options.output = '<stdout>' else: options.output = '.' if options.interactive: interactive_anoky(options) else: non_interactive_anoky(options)