Example #1
0
def test_implicit_references_structure_is_resolved():
    root = Root().insert(
        nodes.Namespace("n").insert(
            Archive("A").insert(
                res.Vector("r1"), res.Vector("r2"),
                res.BoundResource("b").insert(
                    refs.ResourceReference("A.r1"),
                    refs.ResourceReference("A.r2")))))
    resolve_references(root)
    assert_equal("@@n@A@r1", root.find('.n.A.b').children[0].name)
    assert_equal("@@n@A@r2", root.find('.n.A.b').children[1].name)
Example #2
0
def _build_node_tree(definition):
    if not definition:
        return Root()

    try:
        parsed = flatdata_grammar.parseString(definition,
                                              parseAll=True).flatdata
    except (ParseException, ParseSyntaxException) as err:
        raise ParsingError(err)

    roots = []

    for namespace in parsed.namespace:
        root_namespace, target_namespace = _create_nested_namespaces(
            namespace.name)

        parsed_items = [(namespace.constants, nodes.Constant),
                        (namespace.structures, nodes.Structure),
                        (namespace.enumerations, nodes.Enumeration),
                        (namespace.archives, Archive)]

        for collection, cls in parsed_items:
            for item in collection:
                target_namespace.insert(
                    cls.create(properties=item, definition=definition))

        roots.append(root_namespace)

    return _merge_roots(roots)
Example #3
0
def _create_tree_resource_to_archive():
    root = Root().insert(
        nodes.Namespace(name="ns").insert(
            Archive(name="RefArchive"),
            Archive(name="Archive").insert(
                res.Archive(name="resource").insert(
                    refs.ArchiveReference(name="RefArchive")))))
    return SyntaxTree(root)
Example #4
0
def _create_tree_resource_to_struct_with_extra_folding(actual, reference):
    root = Root().insert(
        nodes.Namespace(name="ns").insert(
            nodes.Namespace(name="fold").insert(nodes.Structure(name=actual)),
            Archive(name="Archive").insert(
                res.Vector(name="resource").insert(
                    refs.StructureReference(name=reference)))))
    return SyntaxTree(root)
Example #5
0
def _create_tree_with_two_struct_references():
    root = Root().insert(
        nodes.Namespace(name="ns").insert(
            nodes.Structure(name="S1"), nodes.Structure(name="S2"),
            Archive(name="Archive").insert(
                res.Multivector(name="resource").insert(
                    refs.StructureReference(name="S1"),
                    refs.StructureReference(name="S2")))))
    return SyntaxTree(root)
Example #6
0
def _merge_roots(roots):
    result = Root()
    for root in roots:
        innermost = _innermost_namespace(root)
        target = _ensure_namespace(result,
                                   Node.PATH_SEPARATOR + innermost.path)
        for child in innermost.children:
            target.insert(child.detach())
    return result
Example #7
0
def _create_tree_with_explicit_reference(name):
    root = Root().insert(
        nodes.Namespace(name="ns").insert(
            nodes.Structure(name="Struct").insert(nodes.Field(name="Field")),
            Archive(name="Archive").insert(
                res.Vector(name="resource").insert(
                    refs.FieldReference(name="Struct.Field"),
                    refs.ResourceReference(name=name)),
                res.Vector(name="resource2"))))
    return SyntaxTree(root)