From 4aaf28cc905bebf757b02ad911a6eed78714cac7 Mon Sep 17 00:00:00 2001 From: Maxime Dénès Date: Fri, 10 Feb 2017 15:52:24 +0100 Subject: Integration of a sphinx-based documentation generator. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The original contribution is from Clément Pit-Claudel. I updated his code and integrated it with the Coq build system. Many improvements by Paul Steckler (MIT). This commit adds the infrastructure but no content. --- doc/tools/coqrst/__init__.py | 10 + doc/tools/coqrst/checkdeps.py | 39 + doc/tools/coqrst/coqdoc/__init__.py | 10 + doc/tools/coqrst/coqdoc/main.py | 86 +++ doc/tools/coqrst/coqdomain.py | 816 +++++++++++++++++++++ doc/tools/coqrst/notations/Makefile | 27 + doc/tools/coqrst/notations/TacticNotations.g | 30 + doc/tools/coqrst/notations/TacticNotations.tokens | 8 + doc/tools/coqrst/notations/TacticNotationsLexer.py | 60 ++ .../coqrst/notations/TacticNotationsLexer.tokens | 8 + .../coqrst/notations/TacticNotationsParser.py | 519 +++++++++++++ .../coqrst/notations/TacticNotationsVisitor.py | 53 ++ doc/tools/coqrst/notations/UbuntuMono-B.ttf | Bin 0 -> 191400 bytes doc/tools/coqrst/notations/UbuntuMono-Square.ttf | Bin 0 -> 38200 bytes doc/tools/coqrst/notations/__init__.py | 0 doc/tools/coqrst/notations/fontsupport.py | 81 ++ doc/tools/coqrst/notations/html.py | 65 ++ doc/tools/coqrst/notations/parsing.py | 37 + doc/tools/coqrst/notations/plain.py | 50 ++ doc/tools/coqrst/notations/regexp.py | 57 ++ doc/tools/coqrst/notations/sphinx.py | 77 ++ doc/tools/coqrst/repl/__init__.py | 0 doc/tools/coqrst/repl/ansicolors.py | 99 +++ doc/tools/coqrst/repl/coqtop.py | 98 +++ 24 files changed, 2230 insertions(+) create mode 100644 doc/tools/coqrst/__init__.py create mode 100644 doc/tools/coqrst/checkdeps.py create mode 100644 doc/tools/coqrst/coqdoc/__init__.py create mode 100644 doc/tools/coqrst/coqdoc/main.py create mode 100644 doc/tools/coqrst/coqdomain.py create mode 100644 doc/tools/coqrst/notations/Makefile create mode 100644 doc/tools/coqrst/notations/TacticNotations.g create mode 100644 doc/tools/coqrst/notations/TacticNotations.tokens create mode 100644 doc/tools/coqrst/notations/TacticNotationsLexer.py create mode 100644 doc/tools/coqrst/notations/TacticNotationsLexer.tokens create mode 100644 doc/tools/coqrst/notations/TacticNotationsParser.py create mode 100644 doc/tools/coqrst/notations/TacticNotationsVisitor.py create mode 100644 doc/tools/coqrst/notations/UbuntuMono-B.ttf create mode 100644 doc/tools/coqrst/notations/UbuntuMono-Square.ttf create mode 100644 doc/tools/coqrst/notations/__init__.py create mode 100755 doc/tools/coqrst/notations/fontsupport.py create mode 100644 doc/tools/coqrst/notations/html.py create mode 100644 doc/tools/coqrst/notations/parsing.py create mode 100644 doc/tools/coqrst/notations/plain.py create mode 100644 doc/tools/coqrst/notations/regexp.py create mode 100644 doc/tools/coqrst/notations/sphinx.py create mode 100644 doc/tools/coqrst/repl/__init__.py create mode 100644 doc/tools/coqrst/repl/ansicolors.py create mode 100644 doc/tools/coqrst/repl/coqtop.py (limited to 'doc/tools') diff --git a/doc/tools/coqrst/__init__.py b/doc/tools/coqrst/__init__.py new file mode 100644 index 000000000..2dda7d921 --- /dev/null +++ b/doc/tools/coqrst/__init__.py @@ -0,0 +1,10 @@ +########################################################################## +## # The Coq Proof Assistant / The Coq Development Team ## +## v # INRIA, CNRS and contributors - Copyright 1999-2018 ## +## ", "<-", "<->", "=>", "<=", ">=", "<>", "~", "/\\", "\\/", "|-", "*", "forall", "exists"] +COQDOC_HEADER = "".join("(** remove printing {} *)".format(s) for s in COQDOC_SYMBOLS) + +def coqdoc(coq_code, coqdoc_bin = os.path.join(os.getenv("COQBIN"),"coqdoc")): + """Get the output of coqdoc on coq_code.""" + fd, filename = mkstemp(prefix="coqdoc-", suffix=".v") + try: + os.write(fd, COQDOC_HEADER.encode("utf-8")) + os.write(fd, coq_code.encode("utf-8")) + os.close(fd) + return check_output([coqdoc_bin] + COQDOC_OPTIONS + [filename], timeout = 2).decode("utf-8") + finally: + os.remove(filename) + +def is_whitespace_string(elem): + return isinstance(elem, NavigableString) and elem.strip() == "" + +def strip_soup(soup, pred): + """Strip elements maching pred from front and tail of soup.""" + while soup.contents and pred(soup.contents[-1]): + soup.contents.pop() + + skip = 0 + for elem in soup.contents: + if not pred(elem): + break + skip += 1 + + soup.contents[:] = soup.contents[skip:] + +def lex(source): + """Convert source into a stream of (css_classes, token_string).""" + coqdoc_output = coqdoc(source) + soup = BeautifulSoup(coqdoc_output, "html.parser") + root = soup.find(class_='code') + strip_soup(root, is_whitespace_string) + for elem in root.children: + if isinstance(elem, NavigableString): + yield [], elem + elif elem.name == "span": + cls = "coqdoc-{}".format(elem['title']) + yield [cls], elem.string + elif elem.name == 'br': + pass + else: + raise ValueError(elem) + +def main(): + """Lex stdin (for testing purposes)""" + import sys + for classes, text in lex(sys.stdin.read()): + print(repr(text) + "\t" ' '.join(classes)) + +if __name__ == '__main__': + main() diff --git a/doc/tools/coqrst/coqdomain.py b/doc/tools/coqrst/coqdomain.py new file mode 100644 index 000000000..18f32d7a8 --- /dev/null +++ b/doc/tools/coqrst/coqdomain.py @@ -0,0 +1,816 @@ +########################################################################## +## # The Coq Proof Assistant / The Coq Development Team ## +## v # INRIA, CNRS and contributors - Copyright 1999-2018 ## +##