def _unparse_visit_identifier(node: ParseTreeNode, result: parse_primitives.ObjectToStringResult, arg_map: parse_primitives.ObjectNodeArgMap): arg_name = node.value if not arg_map.is_argname_present(arg_name): raise UnparseError(f"Arg {arg_name} is not present") result.add_argname_tostring(arg_name)
def unparse_visitor(node: ParseTreeNode, result: parse_primitives.ObjectToStringResult, arg_map: parse_primitives.ObjectNodeArgMap): if node.rule_name == "arg_identifier": _unparse_visit_identifier(node, result, arg_map) elif node.rule_name == "str_match": result.add_string(node.value[1:-1]) elif node.rule_name == "sufix": _unparse_visit_suffix(node, result, arg_map) else: if isinstance(node, arpeggio.NonTerminal): for child in node: unparse_visitor(child, result, arg_map)
def unparser(arg_map: parse_primitives.ObjectNodeArgMap, result: parse_primitives.ObjectToStringResult): if allow_modifier: result.add_argname_tostring(WORD_PART_MODIFIER_ARG_NAME) else: result.add_string(symb) result.add_argname_tostring(WORD_PART_NEXT_ARG_NAME)
def CmdSeqUnparser( arg_map: parse_primitives.ObjectNodeArgMap, result: parse_primitives.ObjectToStringResult ): if arg_map.is_argname_present("ProgramArg"): result.add_argname_tostring("ProgramArg") if arg_map.is_argname_present("CompoundOp"): result.add_string(" ") result.add_argname_tostring("CompoundOp")
def _unparse_visit_suffix(node: ParseTreeNode, result: parse_primitives.ObjectToStringResult, arg_map: parse_primitives.ObjectNodeArgMap): snapshot = result.make_snapshot() try: unparse_visitor(node[0], result, arg_map) except UnparseError as e: if len(node) > 1: suffix = node[1] if suffix == OPTIONAL: snapshot.restore() else: raise ValueError(f"Unimplemented suffix {suffix}") else: raise
def ProgramObjectUnparser( arg_map: parse_primitives.ObjectNodeArgMap, result: parse_primitives.ObjectToStringResult ): had_prev_args = False # First add in all the flag args for arg in arg_map.implementation.children: if not arg_map.is_argname_present(arg.name): continue if POSITION in arg.arg_data: continue if had_prev_args: result.add_string(" ") arg_flag = _get_flag_for_arg_unparse(arg) result.add_string(arg_flag) if arg.type is not None: result.add_string(" ") result.add_arg_tostring(arg) had_prev_args = True # Now do all the positional args in order for arg in get_all_positional_args(arg_map.implementation.children): if not arg_map.is_argname_present(arg.name): continue if had_prev_args: result.add_string(" ") result.add_arg_tostring(arg) had_prev_args = True
def unparser(arg_map: parse_primitives.ObjectNodeArgMap, result: parse_primitives.ObjectToStringResult): result.add_arg_tostring(parts)