|
1 | 1 | # designs.py -- Convert MPS design documents into sources for the MPS manual |
2 | | -# $Id$ |
3 | 2 | # |
4 | | -# This was originally done in the Makefile, but moved to Python in the hope |
5 | | -# that readthedocs.org would be able to generate the manual. However, they |
6 | | -# (sensibly) don't run extensions, so we can't use them. Processing the |
7 | | -# designs here still seems like a good idea, though. |
| 3 | +# Copyright (c) 2013-2023 Ravenbrook Limited. See end of file for license. |
| 4 | +# |
| 5 | +# This code converts the MPS design documents (in plain |
| 6 | +# reStructuredText) for use in the manual (in Sphinx extended |
| 7 | +# reStructuredText) and so implements design.mps.doc.fmt. |
8 | 8 | # |
| 9 | +# TODO: It's a shame that the regexps we convert from (near the start |
| 10 | +# of the file) are a log way from the strings we convert to (in |
| 11 | +# ``convert_file``). |
9 | 12 |
|
10 | 13 | from __future__ import unicode_literals |
11 | 14 |
|
|
43 | 46 | ''' |
44 | 47 |
|
45 | 48 | mode = re.compile(r'\.\. mode: .*\n') |
| 49 | + |
| 50 | +# design.mps.doc.metadata.tag |
46 | 51 | prefix = re.compile(r'^:Tag: ([a-z][a-z.0-9-]*[a-z0-9])$', re.MULTILINE) |
| 52 | + |
47 | 53 | rst_tag = re.compile(r'^:(?:Author|Date|Status|Revision|Copyright|Organization|Format|Index terms|Readership):.*?$\n', re.MULTILINE | re.IGNORECASE) |
| 54 | + |
| 55 | +# design.mps.doc.fmt.tag |
48 | 56 | mps_tag = re.compile(r'_`\.([a-z][A-Za-z.0-9_-]*[A-Za-z0-9])`:') |
| 57 | + |
| 58 | +# design.mps.doc.fmt.ref |
49 | 59 | mps_ref = re.compile(r'`(\.[a-z][A-Za-z.0-9_-]*[A-Za-z0-9])`_(?: )?') |
| 60 | + |
| 61 | +# design.mps.doc.fmt.function-decl |
50 | 62 | funcdef = re.compile(r'^``([^`]*\([^`]*\))``$', re.MULTILINE) |
| 63 | + |
| 64 | +# design.mps.doc.fmt.macro-decl |
51 | 65 | macrodef = re.compile(r'^``((?:[A-Z][A-Z0-9_]+|{})(?:\([^`]*\))?)``$' |
52 | 66 | .format('|'.join(map(re.escape, MACROS.split()))), re.MULTILINE) |
| 67 | +# design.mps.doc.fmt.macro |
53 | 68 | macro = re.compile(r'``([A-Z][A-Z0-9_]+)``(?: )?') |
| 69 | + |
| 70 | +# design.mps.doc.fmt.type-def |
54 | 71 | typedef = re.compile(r'^``typedef ([^`]*)``$', re.MULTILINE) |
| 72 | + |
| 73 | +# design.mps.doc.fmt.function-ref |
55 | 74 | func = re.compile(r'``([A-Za-z][A-Za-z0-9_]+\(\))``') |
| 75 | + |
| 76 | +# design.mps.doc.fmt.type-ref |
56 | 77 | typename = re.compile(r'``({0}|[A-Z][A-Za-z0-9_]*' |
57 | 78 | r'(?:Class|Function|Method|Struct|Union)|' |
58 | 79 | r'mps_[a-z_]+_[stu])``(?: )?' |
59 | 80 | .format('|'.join(map(re.escape, TYPES.split())))) |
| 81 | + |
| 82 | +# Tags referencing other design documents |
60 | 83 | design_ref = re.compile(r'^( *\.\. _design\.mps\.(?:[^:\n]+): (?:[^#:\n]+))$', re.MULTILINE) |
61 | 84 | design_frag_ref = re.compile(r'^( *\.\. _design\.mps\.([^:\n]+)\.([^:\n]+): (?:[^#:\n]+))#(.+)$', re.MULTILINE) |
| 85 | + |
62 | 86 | relative_link = re.compile(r'^( *\.\. _[\w\.]+: +\.\./)', re.MULTILINE) |
63 | 87 | history = re.compile(r'^Document History\n.*', |
64 | 88 | re.MULTILINE | re.IGNORECASE | re.DOTALL) |
|
69 | 93 | def secnum_sub(m): |
70 | 94 | return m.group(1) + '\n' + m.group(3) * len(m.group(1)) |
71 | 95 |
|
72 | | -# Convert Ravenbrook style citations into MPS Manual style citations. |
| 96 | +# Convert Ravenbrook style citations into MPS Manual style citations |
| 97 | +# (design.mps.doc.fmt.citation) |
| 98 | +# |
73 | 99 | # Example citations transformation, from: |
74 | 100 | # .. [THVV_1995] "Structure Marking"; Tom Van Vleck; 1995; |
75 | 101 | # <http://www.multicians.org/thvv/marking.html>. |
@@ -157,18 +183,66 @@ def newer(src, target): |
157 | 183 | logger = logging.getLogger(__name__) |
158 | 184 |
|
159 | 185 | # Mini-make |
| 186 | +# |
| 187 | +# This uses app.srcdir (the directory of the manual sources) to find |
| 188 | +# the root of the MPS tree (two directories above) and so find the |
| 189 | +# design documents to convert. |
| 190 | + |
160 | 191 | def convert_updated(app): |
161 | 192 | logger.info(bold('converting MPS design documents')) |
162 | | - for design in glob.iglob('../design/*.txt'): |
| 193 | + for design in glob.iglob(os.path.join(app.srcdir, '../../design/*.txt')): |
163 | 194 | name = os.path.splitext(os.path.basename(design))[0] |
164 | 195 | if name == 'index': continue |
165 | | - converted = 'source/design/%s.rst' % name |
| 196 | + converted = os.path.join(app.srcdir, 'design/%s.rst' % name) |
166 | 197 | if newer(design, converted): |
167 | 198 | logger.info('converting design %s' % name) |
168 | 199 | convert_file(name, design, converted) |
169 | | - diagrams = chain(*[glob.iglob('../design/*.' + ext) |
| 200 | + diagrams = chain(*[glob.iglob(os.path.join(app.srcdir, '../../design/*.' + ext)) |
170 | 201 | for ext in 'png svg'.split()]) |
171 | 202 | for diagram in diagrams: |
172 | | - target = os.path.join('source/design/', os.path.basename(diagram)) |
| 203 | + target = os.path.join(app.srcdir, 'design/', os.path.basename(diagram)) |
173 | 204 | if newer(diagram, target): |
174 | 205 | shutil.copyfile(diagram, target) |
| 206 | + |
| 207 | + |
| 208 | +# A. REFERENCES |
| 209 | +# |
| 210 | +# [GDR-2018-09-18] "Documentation"; Gareth Rees; 2018-09-18; design.mps.doc. |
| 211 | +# |
| 212 | +# |
| 213 | +# B. DOCUMENT HISTORY |
| 214 | +# |
| 215 | +# 2013-06-01 RB Created. |
| 216 | +# 2023-02-15 RB Updated with copyright, licence, and document history. |
| 217 | +# |
| 218 | +# |
| 219 | +# C. COPYRIGHT AND LICENSE |
| 220 | +# |
| 221 | +# Copyright (C) 2023 Ravenbrook Limited <https://www.ravenbrook.com/>. |
| 222 | +# |
| 223 | +# Redistribution and use in source and binary forms, with or without |
| 224 | +# modification, are permitted provided that the following conditions are |
| 225 | +# met: |
| 226 | +# |
| 227 | +# 1. Redistributions of source code must retain the above copyright |
| 228 | +# notice, this list of conditions and the following disclaimer. |
| 229 | +# |
| 230 | +# 2. Redistributions in binary form must reproduce the above copyright |
| 231 | +# notice, this list of conditions and the following disclaimer in the |
| 232 | +# documentation and/or other materials provided with the |
| 233 | +# distribution. |
| 234 | +# |
| 235 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 236 | +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 237 | +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 238 | +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 239 | +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 240 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 241 | +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 242 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 243 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 244 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 245 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 246 | +# |
| 247 | +# |
| 248 | +# $Id$ |
0 commit comments