예제 #1
0
def parse(content, root=None, filename=''):
    """
    Parse a hit tree from a *content* string and return a `pyhit.Node` object.

    The returned object is the root of the loaded tree. The *root* input can provide a node object
    for the tree to populate; if it is given this same node is returned. The *filename*, if provided,
    will be used for error reporting when manipulating the tree.
    """
    hit_node = hit.parse(filename, content)
    hit.explode(hit_node)
    return _parse_hit(Node(root, hit_node), hit_node, filename)
예제 #2
0
def parse(content, root=None, filename=''):
    """
    Parse a hit tree from a string.

    Inputs:
       content[str]: string to process
       root[Node]: (Optional) root node of the tree
       filename[str]: (Optional) filename for error reporting

    """
    hit_node = hit.parse(filename, content)
    hit.explode(hit_node)
    root = Node(root, hit_node) if root is not None else Node(None, hit_node)
    _parse_hit(root, hit_node, filename)
    return root
예제 #3
0
 def readInputData(self, data, filename):
     try:
         self.filename = os.path.abspath(filename)
         root = hit.parse(os.path.abspath(filename), data)
         hit.explode(root)
         w = DupWalker(os.path.abspath(filename))
         root.walk(w, hit.NodeType.Field)
         if w.errors:
             for err in w.errors:
                 mooseutils.mooseWarning(err)
             raise PeacockException("Parser errors")
         self.original_text = data
         self.root_node = root
         self.changed = False
     except PeacockException as e:
         msg = "Failed to parse input file %s:\n%s\n" % (filename, e)
         mooseutils.mooseWarning(msg)
         raise e
예제 #4
0
    def getInputFileFormat(self, extra=[]):
        """
        Does a dump and uses the GetPotParser to parse the output.
        """
        args = ["--disable-refcount-printing", "--dump"] + extra
        output = run_app(args)
        self.assertIn("### START DUMP DATA ###\n", output)
        self.assertIn("### END DUMP DATA ###\n", output)

        output = output.split('### START DUMP DATA ###\n')[1]
        output = output.split('### END DUMP DATA ###')[0]

        self.assertNotEqual(len(output), 0)
        root = hit.parse("dump.i", output)
        hit.explode(root)
        w = DupWalker("dump.i")
        root.walk(w, hit.NodeType.All)
        if w.errors:
            print("\n".join(w.errors))
        self.assertEqual(len(w.errors), 0)
        return root
예제 #5
0
파일: test_json.py 프로젝트: FHilty/moose
    def getInputFileFormat(self, extra=[]):
        """
        Does a dump and uses the GetPotParser to parse the output.
        """
        args = ["--disable-refcount-printing", "--dump"] + extra
        output = run_app(args)
        self.assertIn("### START DUMP DATA ###\n", output)
        self.assertIn("### END DUMP DATA ###\n", output)

        output = output.split('### START DUMP DATA ###\n')[1]
        output = output.split('### END DUMP DATA ###')[0]

        self.assertNotEqual(len(output), 0)
        root = hit.parse("dump.i", output)
        hit.explode(root)
        w = DupWalker("dump.i")
        root.walk(w, hit.NodeType.All)
        if w.errors:
            print("\n".join(w.errors))
        self.assertEqual(len(w.errors), 0)
        return root