MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
fences.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3"""Doxygen input filter: wraps every Mim and EBNF listing in a `<lang>-code` div.
4
5Doxygen discards the language of a fenced code block, so `docs/mim.js` and `docs/ebnf.js` need the wrapper to tell such a listing from any other verbatim block.
6"""
7
8import re
9import sys
10
11WRAP = re.compile(r'^([ \t]*)(?:```(mim|ebnf)\n.*?^[ \t]*```|\\include "[^"]*\.(mim)")$', re.M | re.S)
12
13
14def wrap(match):
15 indent, lang = match.group(1), match.group(2) or match.group(3)
16 return f'{indent}<div class="{lang}-code">\n\n{match.group(0)}\n\n{indent}</div>'
17
18
19def main():
20 with open(sys.argv[1], encoding='utf-8') as file:
21 sys.stdout.write(WRAP.sub(wrap, file.read()))
22
23
24if __name__ == '__main__':
25 main()
wrap(match)
Definition fences.py:14
main()
Definition fences.py:19