From 0a155d36309a30d93e9b823ca972e8851f4c45c9 Mon Sep 17 00:00:00 2001 From: Anton Edvinovich Pozharskiy Date: Mon, 19 Aug 2024 15:07:51 +0200 Subject: [PATCH] remove dead code --- sphinxcontrib/mat_parser.py | 88 ----------------------- sphinxcontrib/mat_types.py | 136 +----------------------------------- 2 files changed, 1 insertion(+), 223 deletions(-) delete mode 100644 sphinxcontrib/mat_parser.py diff --git a/sphinxcontrib/mat_parser.py b/sphinxcontrib/mat_parser.py deleted file mode 100644 index 55db502..0000000 --- a/sphinxcontrib/mat_parser.py +++ /dev/null @@ -1,88 +0,0 @@ -""" - sphinxcontrib.mat_parser - ~~~~~~~~~~~~~~~~~~~~~~~~ - - Functions for parsing MatlabLexer output. - - :copyright: Copyright 2023-2024 by the sphinxcontrib-matlabdomain team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" - -import re -import sphinx.util - -logger = sphinx.util.logging.getLogger("matlab-domain") - - -def remove_comment_header(code): - """ - Removes the comment header (if there is one) and empty lines from the - top of the current read code. - :param code: Current code string. - :type code: str - :returns: Code string without comments above a function, class or - procedure/script. - """ - # get the line number when the comment header ends (incl. empty lines) - ln_pos = 0 - for line in code.splitlines(True): - if re.match(r"[ \t]*(%|\n)", line): - ln_pos += 1 - else: - break - - if ln_pos > 0: - # remove the header block and empty lines from the top of the code - try: - code = code.split("\n", ln_pos)[ln_pos:][0] - except IndexError: - # only header and empty lines. - code = "" - - return code - - -def remove_line_continuations(code): - """ - Removes line continuations (...) from code as functions must be on a - single line - :param code: - :type code: str - :return: - """ - # pat = r"('.*)(\.\.\.)(.*')" - # code = re.sub(pat, r"\g<1>\g<3>", code, flags=re.MULTILINE) - - pat = r"^([^%'\"\n]*)(\.\.\..*\n)" - code = re.sub(pat, r"\g<1>", code, flags=re.MULTILINE) - return code - - -def fix_function_signatures(code): - """ - Transforms function signatures with line continuations to a function - on a single line with () appended. Required because pygments cannot - handle this situation correctly. - - :param code: - :type code: str - :return: Code string with functions on single line - """ - pat = r"""^[ \t]*function[ \t.\n]* # keyword (function) - (\[?[\w, \t.\n]*\]?) # outputs: group(1) - [ \t.\n]*=[ \t.\n]* # punctuation (eq) - (\w+)[ \t.\n]* # name: group(2) - \(?([\w, \t.\n]*)\)?""" # args: group(3) - pat = re.compile(pat, re.X | re.MULTILINE) # search start of every line - - # replacement function - def repl(m): - retv = m.group(0) - # if no args and doesn't end with parentheses, append "()" - if not (m.group(3) or m.group(0).endswith("()")): - retv = retv.replace(m.group(2), m.group(2) + "()") - return retv - - code = pat.sub(repl, code) # search for functions and apply replacement - - return code diff --git a/sphinxcontrib/mat_types.py b/sphinxcontrib/mat_types.py index 1701663..c4ba86e 100644 --- a/sphinxcontrib/mat_types.py +++ b/sphinxcontrib/mat_types.py @@ -46,14 +46,6 @@ "MatApplication", ] -# MATLAB keywords that increment keyword-end pair count -MATLAB_KEYWORD_REQUIRES_END = list( - zip( - (Token.Keyword,) * 7, - ("arguments", "for", "if", "switch", "try", "while", "parfor"), - ) -) - # MATLAB attribute type dictionaries. @@ -114,12 +106,6 @@ "TestTags": list, } - -MATLAB_FUNC_BRACES_BEGIN = tuple(zip((Token.Punctuation,) * 2, ("(", "{"))) -MATLAB_FUNC_BRACES_END = tuple(zip((Token.Punctuation,) * 2, (")", "}"))) -MATLAB_PROP_BRACES_BEGIN = tuple(zip((Token.Punctuation,) * 3, ("(", "{", "["))) -MATLAB_PROP_BRACES_END = tuple(zip((Token.Punctuation,) * 3, (")", "}", "]"))) - # Dictionary containing all MATLAB entities that are found in `matlab_src_dir`. # The dictionary keys are both the full dotted path, relative to the root. # Further, "short names" are added. Example: @@ -733,126 +719,6 @@ def getter(self, name, *defargs): return entity -class MatMixin(object): - """ - Methods to comparing and manipulating tokens in :class:`MatFunction` and - :class:`MatClass`. - """ - - def _tk_eq(self, idx, token): - """ - Returns ``True`` if token keys are the same and values are equal. - - :param idx: Index of token in :class:`MatObject`. - :type idx: int - :param token: Comparison token. - :type token: tuple - """ - return self.tokens[idx][0] is token[0] and self.tokens[idx][1] == token[1] - - def _tk_ne(self, idx, token): - """ - Returns ``True`` if token keys are not the same or values are not - equal. - - :param idx: Index of token in :class:`MatObject`. - :type idx: int - :param token: Comparison token. - :type token: tuple - """ - return self.tokens[idx][0] is not token[0] or self.tokens[idx][1] != token[1] - - def _eotk(self, idx): - """ - Returns ``True`` if end of tokens is reached. - """ - return idx >= len(self.tokens) - - def _blanks(self, idx): - """ - Returns number of blank text tokens. - - :param idx: Token index. - :type idx: int - """ - # idx0 = idx # original index - # while self._tk_eq(idx, (Token.Text, ' ')): idx += 1 - # return idx - idx0 # blanks - return self._indent(idx) - - def _whitespace(self, idx): - """ - Returns number of whitespaces text tokens, including blanks, newline - and tabs. - - :param idx: Token index. - :type idx: int - """ - idx0 = idx # original index - while ( - self.tokens[idx][0] is Token.Text - or self.tokens[idx][0] is Token.Text.Whitespace - ) and self.tokens[idx][1] in [" ", "\n", "\t"]: - idx += 1 - return idx - idx0 # whitespace - - def _indent(self, idx): - """ - Returns indentation tabs or spaces. No indentation is zero. - - :param idx: Token index. - :type idx: int - """ - idx0 = idx # original index - while self.tokens[idx][0] is Token.Text and self.tokens[idx][1] in [" ", "\t"]: - idx += 1 - return idx - idx0 # indentation - - def _propspec(self, idx): - """ - Returns number of "property" specification tokens - - :param idx: Token index. - :type idx: int - """ - idx0 = idx # original index - while ( - self._tk_eq(idx, (Token.Punctuation, "@")) - or self._tk_eq(idx, (Token.Punctuation, "(")) - or self._tk_eq(idx, (Token.Punctuation, ")")) - or self._tk_eq(idx, (Token.Punctuation, ",")) - or self._tk_eq(idx, (Token.Punctuation, ":")) - or self.tokens[idx][0] == Token.Literal.Number.Integer - or self._tk_eq(idx, (Token.Punctuation, "{")) - or self._tk_eq(idx, (Token.Punctuation, "}")) - or self._tk_eq(idx, (Token.Punctuation, "[")) - or self._tk_eq(idx, (Token.Punctuation, "]")) - or self._tk_eq(idx, (Token.Punctuation, ".")) - or self.tokens[idx][0] == Token.Literal.String - or self.tokens[idx][0] == Token.Name - or (self.tokens[idx][0] == Token.Text and self.tokens[idx][1] != "\n") - ): - idx += 1 - return idx - idx0 # property spec count. - - def _is_newline(self, idx): - """Returns true if the token at index is a newline""" - return ( - self.tokens[idx][0] in (Token.Text, Token.Text.Whitespace) - and self.tokens[idx][1] == "\n" - ) - - -def skip_whitespace(tks): - """Eats whitespace from list of tokens""" - while tks and ( - tks[-1][0] == Token.Text.Whitespace - or tks[-1][0] == Token.Text - and tks[-1][1] in [" ", "\t"] - ): - tks.pop() - - class MatFunction(MatObject): """ A MATLAB function. @@ -902,7 +768,7 @@ def getter(self, name, *defargs): super(MatFunction, self).getter(name, *defargs) -class MatClass(MatMixin, MatObject): +class MatClass(MatObject): """ A MATLAB class definition.