########################################################################## ## # The Rocq Prover / The Rocq Development Team ## ## v # Copyright INRIA, CNRS and contributors ## ## <O___,, # (see version control and CREDITS file for authors & dates) ## ## \VV/ ############################################################### ## // # This file is distributed under the terms of the ## ## # GNU Lesser General Public License Version 2.1 ## ## # (see LICENSE file for the text of the license) ## ########################################################################## """A visitor for ANTLR notation ASTs, producing Sphinx nodes.
Unlike the HTML visitor, this produces Sphinx-friendly nodes that can be used by
all backends. If you just want HTML output, use the HTML visitor. """
from .parsing import parse from .TacticNotationsParser import TacticNotationsParser from .TacticNotationsVisitor import TacticNotationsVisitor
from docutils import nodes from sphinx import addnodes
class TacticNotationsToSphinxVisitor(TacticNotationsVisitor): def defaultResult(self): return []
def aggregateResult(self, aggregate, nextResult): if nextResult:
aggregate.extend(nextResult) return aggregate
@staticmethod def is_alternative(node): return isinstance(node, nodes.inline) and node['classes'] == ['alternative']
def visitRepeat(self, ctx:TacticNotationsParser.RepeatContext): # Uses inline nodes instead of subscript and superscript to ensure that # we get the right customization hooks at the LaTeX level
separator = ctx.ATOM() or ctx.PIPE() # I wanted to have 2 independent classes "repeat-wrapper" and "with-sub" here, # but that breaks the latex build (invalid .tex file)
classes = 'repeat-wrapper-with-sub'if separator else'repeat-wrapper'
wrapper = nodes.inline('', '', classes=[classes])
children = self.visitChildren(ctx) if len(children) == 1 and self.is_alternative(children[0]): # Use a custom style if an alternative is nested in a repeat. # (We could detect this in CSS, but it's much harder in LaTeX.)
def sphinxify(notation): """Translate a notation into a Sphinx document tree."""
vs = TacticNotationsToSphinxVisitor() return vs.visit(parse(notation))
def main():
print(sphinxify("a := {+, b {+ c}}"))
if __name__ == '__main__':
main()
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.