Beispiel #1
0
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
Beispiel #2
0
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 test_unparse_str_and_arg(mobject):
    instance = create_object_parser_from_grammar(MagicMock(), "FooParser",
                                                 '"Hello" FooArg')
    foo_arg = mobject.get_arg_by_name("FooArg")
    args = ObjectNodeArgMap(mobject, {"FooArg": True})
    result = instance.to_string(args)
    assert result.unparse_seq == ["Hello", ArgToStringDelegation(foo_arg)]
Beispiel #4
0
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 test_unparse_juststr(mobject):
    instance = create_object_parser_from_grammar(MagicMock(), "FooParser",
                                                 '"Hello"')
    args = ObjectNodeArgMap(mobject, {})
    result = instance.to_string(args)
    assert result.unparse_seq == [
        "Hello",
    ]
Beispiel #6
0
    def _obj_node_to_arg_map(self, node: ObjectNode) -> ObjectNodeArgMap:
        is_present_map = {}
        for arg in node.implementation.children:
            chosen = node.get_choice_node_for_arg(arg.name)
            is_present_map[arg.name] = chosen.copy_was_chosen or \
                                       arg.required or \
                                       chosen.get_chosen_impl_name() != arg.not_present_object.name

        return ObjectNodeArgMap(implenetation=node.implementation,
                                is_present_map=is_present_map)
Beispiel #7
0
def test_prog_object_tostring_basic_with_type(type_context):
    a_arg = AInixArgument(type_context,
                          "a",
                          "Program",
                          arg_data={"short_name": "a"},
                          parent_object_name="sdf")
    onearg = AInixObject(type_context, "FooProgram", "Program", [a_arg])
    parser = type_context.get_object_parser_by_name("ProgramObjectParser")
    # Unparse
    unparse = parser.to_string(ObjectNodeArgMap(onearg, {"a": True}))
    assert unparse.unparse_seq == ["-a", " ", ArgToStringDelegation(a_arg)]
def test_unparse_twoarg_fail(mobject):
    instance = create_object_parser_from_grammar(MagicMock(), "FooParser",
                                                 '"Hey" FooArg " " BarArg')
    args = ObjectNodeArgMap(mobject, {"FooArg": True, "BarArg": False})
    with pytest.raises(UnparseError):
        instance.to_string(args)
def test_unparse_paren_fail(mobject):
    instance = create_object_parser_from_grammar(
        MagicMock(), "FooParser", '"Hey" ("9" FooArg "d")? "!"')
    args = ObjectNodeArgMap(mobject, {"FooArg": False})
    result = instance.to_string(args)
    assert result.unparse_seq == ["Hey", "!"]