Give Sphinx configuration domains access to grammar
This commit is contained in:
@@ -34,6 +34,8 @@ from sphinx.util import logging
|
||||
from sphinx.util.docutils import SphinxDirective
|
||||
from sphinx.util.nodes import make_refnode
|
||||
|
||||
import checkgrammar
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -50,7 +52,7 @@ def split_csv(argument, required):
|
||||
|
||||
|
||||
# pylint: disable=too-many-statements
|
||||
def domain_factory(domainname, domainlabel, todolist):
|
||||
def domain_factory(domainname, domainlabel, todolist, grammar):
|
||||
"""
|
||||
Return parametrized Sphinx domain object.
|
||||
@param domainname Name used when referencing domain in .rst: e.g. namedconf
|
||||
@@ -148,6 +150,14 @@ def domain_factory(domainname, domainlabel, todolist):
|
||||
|
||||
indices = {} # no custom indicies
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.grammar = grammar
|
||||
self.statement_blocks = checkgrammar.statement2block(grammar, ["_top"])
|
||||
self.statement_grammar_groups = checkgrammar.diff_statements(
|
||||
self.grammar, self.statement_blocks
|
||||
)
|
||||
|
||||
def get_objects(self):
|
||||
"""
|
||||
Sphinx API:
|
||||
@@ -388,12 +398,12 @@ class DictToDocutilsTableBuilder:
|
||||
return self.table
|
||||
|
||||
|
||||
def setup(app, domainname, confname, docutilsplaceholder):
|
||||
def setup(app, domainname, confname, docutilsplaceholder, grammar):
|
||||
"""
|
||||
Install new parametrized Sphinx domain.
|
||||
"""
|
||||
|
||||
Conf = domain_factory(domainname, confname, docutilsplaceholder)
|
||||
Conf = domain_factory(domainname, confname, docutilsplaceholder, grammar)
|
||||
app.add_domain(Conf)
|
||||
app.connect("doctree-resolved", Conf.process_statementlist_nodes)
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from . import parsegrammar
|
||||
import parsegrammar
|
||||
|
||||
|
||||
def read_zone():
|
||||
|
||||
@@ -18,6 +18,7 @@ Sphinx domain "namedconf". See iscconf.py for details.
|
||||
from docutils import nodes
|
||||
|
||||
import iscconf
|
||||
import mergegrammar
|
||||
|
||||
|
||||
class ToBeReplacedStatementList(nodes.General, nodes.Element):
|
||||
@@ -28,4 +29,7 @@ class ToBeReplacedStatementList(nodes.General, nodes.Element):
|
||||
|
||||
|
||||
def setup(app):
|
||||
return iscconf.setup(app, "namedconf", "named.conf", ToBeReplacedStatementList)
|
||||
grammar = mergegrammar.combine()
|
||||
return iscconf.setup(
|
||||
app, "namedconf", "named.conf", ToBeReplacedStatementList, grammar
|
||||
)
|
||||
|
||||
@@ -18,6 +18,7 @@ Sphinx domain "rndcconf". See iscconf.py for details.
|
||||
from docutils import nodes
|
||||
|
||||
import iscconf
|
||||
import parsegrammar
|
||||
|
||||
|
||||
class ToBeReplacedStatementList(nodes.General, nodes.Element):
|
||||
@@ -28,4 +29,8 @@ class ToBeReplacedStatementList(nodes.General, nodes.Element):
|
||||
|
||||
|
||||
def setup(app):
|
||||
return iscconf.setup(app, "rndcconf", "rndc.conf", ToBeReplacedStatementList)
|
||||
with open("../misc/rndc.grammar", encoding="utf-8") as filein:
|
||||
grammar = parsegrammar.parse_mapbody(filein)
|
||||
return iscconf.setup(
|
||||
app, "rndcconf", "rndc.conf", ToBeReplacedStatementList, grammar
|
||||
)
|
||||
|
||||
@@ -104,6 +104,7 @@ def setup(app):
|
||||
# documentation root, make it absolute.
|
||||
#
|
||||
sys.path.append(str(Path(__file__).resolve().parent / "_ext"))
|
||||
sys.path.append(str(Path(__file__).resolve().parent.parent / "misc"))
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user