File: vl_sphinx_extract

package info (click to toggle)
verilator 5.038-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 162,552 kB
  • sloc: cpp: 139,204; python: 20,931; ansic: 10,222; yacc: 6,000; lex: 1,925; makefile: 1,260; sh: 494; perl: 282; fortran: 22
file content (58 lines) | stat: -rwxr-xr-x 2,117 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# pylint: disable=C0112,C0114,C0115,C0116,C0209,C0301,R0903
# -*- Python -*- See copyright, etc below
######################################################################

import argparse
import re

#######################################################################


class VlSphinxExtract:
    debug = 0
    SkipBasenames = {}

    def process(self, filename):
        with open(filename, "r", encoding="utf8") as fhr:
            fhw = None
            for line in fhr:
                # =for VL_SPHINX_EXTRACT "file_to_write_to"
                match = re.search(r'VL_SPHINX_EXTRACT +"([^"]+)"', line)
                if match:
                    outname = match.group(1)
                    print("Writing %s" % outname)
                    fhw = open(outname, "w", encoding="utf8")  # pylint: disable=consider-using-with
                    fhw.write(".. comment: generated by vl_sphinx_extract from " + filename + "\n")
                    fhw.write(".. code-block::\n")
                elif re.match(r'^[=a-zA-Z0-9_]', line):
                    fhw = None
                elif fhw:
                    fhw.write(line)


#######################################################################

parser = argparse.ArgumentParser(
    allow_abbrev=False,
    formatter_class=argparse.RawDescriptionHelpFormatter,
    description="""Read a file and extract documentation data.""",
    epilog=""" Copyright 2021-2025 by Wilson Snyder.  This package is free software;
you can redistribute it and/or modify it under the terms of either the GNU
Lesser General Public License Version 3 or the Perl Artistic License
Version 2.0.

SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0""")

parser.add_argument('--debug', action='store_const', const=9, help='enable debug')
parser.add_argument('path', help='path to extract from')
Args = parser.parse_args()

o = VlSphinxExtract()
o.debug = Args.debug
o.process(Args.path)

######################################################################
# Local Variables:
# compile-command: "./vl_sphinx_extract --debug ../../bin/verilator"
# End: