def parse_options(node): """Parse options according to the description in CoqtopDirective.""" options = node['coqtop_options'] # Behavior options opt_reset = 'reset' in options opt_fail = 'fail' in options opt_restart = 'restart' in options opt_abort = 'abort' in options options = options - set(('reset', 'fail', 'restart', 'abort')) unexpected_options = list(options - set(('all', 'none', 'in', 'out'))) if unexpected_options: loc = get_node_location(node) raise ExtensionError("{}: Unexpected options for .. coqtop:: {}".format(loc,unexpected_options)) # Display options if len(options) != 1: loc = get_node_location(node) raise ExtensionError("{}: Exactly one display option must be passed to .. coqtop::".format(loc)) opt_all = 'all' in options opt_none = 'none' in options opt_input = 'in' in options opt_output = 'out' in options return { 'reset': opt_reset, 'fail': opt_fail, 'restart': opt_restart, 'abort': opt_abort, 'input': opt_input or opt_all, 'output': opt_output or opt_all }
def parse_options(node): """Parse options according to the description in CoqtopDirective.""" options = node['coqtop_options'] # Behavior options opt_reset = 'reset' in options opt_fail = 'fail' in options opt_warn = 'warn' in options opt_restart = 'restart' in options opt_abort = 'abort' in options options = options - {'reset', 'fail', 'warn', 'restart', 'abort'} unexpected_options = list(options - {'all', 'none', 'in', 'out'}) if unexpected_options: loc = get_node_location(node) raise ExtensionError( "{}: Unexpected options for .. coqtop:: {}".format( loc, unexpected_options)) # Display options if len(options) != 1: loc = get_node_location(node) raise ExtensionError( "{}: Exactly one display option must be passed to .. coqtop::". format(loc)) opt_all = 'all' in options opt_none = 'none' in options opt_input = 'in' in options opt_output = 'out' in options return { 'reset': opt_reset, 'fail': opt_fail, # if errors are allowed, then warnings too # and they should be displayed as warnings, not errors 'warn': opt_warn or opt_fail, 'restart': opt_restart, 'abort': opt_abort, 'input': opt_input or opt_all, 'output': opt_output or opt_all }
def handle_signature(self, signature, signode): parts = signature.split(maxsplit=1) if parts[0].strip() == "|" and len(parts) == 2: lhs = "" op = "|" rhs = parts[1].strip() else: nsplits = 2 parts = signature.split(maxsplit=nsplits) if len(parts) != 3: loc = os.path.basename(get_node_location(signode)) raise ExtensionError(ProductionObject.SIG_ERROR.format(loc, signature)) else: lhs, op, rhs = (part.strip() for part in parts) if op not in ["::=", "+="]: loc = os.path.basename(get_node_location(signode)) raise ExtensionError(ProductionObject.SIG_ERROR.format(loc, signature)) self.signatures.append((lhs, op, rhs)) return ('token', lhs) if op == '::=' else None
def handle_signature(self, signature, signode): nsplits = 2 parts = signature.split(maxsplit=nsplits) if len(parts) != 3: loc = os.path.basename(get_node_location(signode)) raise ExtensionError(ProductionObject.SIG_ERROR.format(loc)) lhs, op, rhs = (part.strip() for part in parts) if op not in ["::=", "+="]: loc = os.path.basename(get_node_location(signode)) raise ExtensionError(ProductionObject.SIG_ERROR.format(loc)) self._render_annotation(signode) lhs_op = '{} {} '.format(lhs, op) lhs_node = nodes.literal(lhs_op, lhs_op) position = self.state_machine.get_source_and_line(self.lineno) rhs_node = notation_to_sphinx(rhs, *position) signode += addnodes.desc_name(signature, '', lhs_node, rhs_node) return ('token', lhs) if op == '::=' else None
def parse_options(node): """Parse options according to the description in CoqtopDirective.""" options = node['coqtop_options'] # Behavior options opt_reset = 'reset' in options opt_fail = 'fail' in options opt_warn = 'warn' in options opt_restart = 'restart' in options opt_abort = 'abort' in options options = options - {'reset', 'fail', 'warn', 'restart', 'abort'} unexpected_options = list(options - {'all', 'none', 'in', 'out'}) if unexpected_options: loc = get_node_location(node) raise ExtensionError("{}: Unexpected options for .. coqtop:: {}".format(loc,unexpected_options)) # Display options if len(options) != 1: loc = get_node_location(node) raise ExtensionError("{}: Exactly one display option must be passed to .. coqtop::".format(loc)) opt_all = 'all' in options opt_none = 'none' in options opt_input = 'in' in options opt_output = 'out' in options return { 'reset': opt_reset, 'fail': opt_fail, # if errors are allowed, then warnings too # and they should be displayed as warnings, not errors 'warn': opt_warn or opt_fail, 'restart': opt_restart, 'abort': opt_abort, 'input': opt_input or opt_all, 'output': opt_output or opt_all }
def test_get_node_location_abspath(): # Ensure that node locations are reported as an absolute path, # even if the source attribute is a relative path. relative_filename = os.path.join('relative', 'path.txt') absolute_filename = osutil.abspath(relative_filename) n = nodes.Node() n.source = relative_filename location = logging.get_node_location(n) assert location == absolute_filename + ':'
def add_coqtop_output(self): """Add coqtop's responses to a Sphinx AST Finds nodes to process using is_coqtop_block.""" with CoqTop(color=True) as repl: repl.send_initial_options() for node in self.document.traverse(CoqtopBlocksTransform.is_coqtop_block): try: self.add_coq_output_1(repl, node) except CoqTopError as err: import textwrap MSG = ("{}: Error while sending the following to coqtop:\n{}" + "\n coqtop output:\n{}" + "\n Full error text:\n{}") indent = " " loc = get_node_location(node) le = textwrap.indent(str(err.last_sentence), indent) bef = textwrap.indent(str(err.before), indent) fe = textwrap.indent(str(err.err), indent) raise ExtensionError(MSG.format(loc, le, bef, fe))