Fixed comments.

This commit is contained in:
Franco Masotti 2022-04-02 18:09:33 +02:00
parent a5bbc275dd
commit ab9c35a12a
Signed by: frnmst
GPG Key ID: 24116ED85666780A
10 changed files with 81 additions and 57 deletions

View File

@ -26,6 +26,10 @@ import sys
from .buffer_h import _cmark_CMARK_BUF_INIT, _cmarkCmarkStrbuf
from .cmark_h import _cmarkCmarkMem
# License E applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
# 0.29, 0.30
def _cmark_cmark_strbuf_init(mem: _cmarkCmarkMem, buf: _cmarkCmarkStrbuf, initial_size: int):

View File

@ -22,6 +22,10 @@ r"""A cmark implementation file."""
from .cmark_h import _cmarkCmarkMem
# License E applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
class _cmarkCmarkStrbuf:
def __init__(self):

View File

@ -24,23 +24,24 @@ import copy
from ..constants import parser as md_parser
# License E applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
class _cmarkCmarkChunk:
r"""See chunk.h file."""
# license E applies here. See docs/copyright_license.rst
def __init__(self, data: str = None, length: int = 0, alloc: int = 0):
self.data: str = data
self.length: int = length
# Returns 1 if c is a "whitespace" character as defined by the spec.
# Returns 1 if c is a "whitespace" character as defined by the spec.
# int cmark_isspace(char c) { return cmark_ctype_class[(uint8_t)c] == 1; }
# The only defined whitespaces in the spec are Unicode whitespaces.
# 0.30
def _cmark_cmark_chunk_rtrim(c: _cmarkCmarkChunk):
# license E applies here. See docs/copyright_license.rst
while c.length > 0:
# if (!cmark_isspace(c->data[c->len - 1]))
if not c.data[c.length - 1] in md_parser['cmark']['pseudo-re']['UWC']:
@ -51,7 +52,6 @@ def _cmark_cmark_chunk_rtrim(c: _cmarkCmarkChunk):
# 0.30
def _cmark_cmark_chunk_literal(data: str) -> _cmarkCmarkChunk:
# license E applies here. See docs/copyright_license.rst
length: int
c: _cmarkCmarkChunk
@ -66,6 +66,9 @@ def _cmark_cmark_chunk_literal(data: str) -> _cmarkCmarkChunk:
# 0.29, 0.30
def _cmark_cmark_chunk_dup(ch: _cmarkCmarkChunk, pos: int, length: int) -> str:
# license E applies here. See docs/copyright_license.rst
c = _cmarkCmarkChunk(copy.deepcopy(ch.data[pos: pos + length]), length)
return c
if __name__ == '__main__':
pass

View File

@ -22,13 +22,20 @@ r"""The cmark implementation file."""
from ..constants import parser as md_parser
# License C applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
# Return True if c is an ascii punctuation character.
# 0.29, 0.30
def _cmark_cmark_ispunct(char: int, parser: str = 'github') -> bool:
r"""Return True if c is an ascii punctuation character."""
# license C applies here. See docs/copyright_license.rst.
value = False
if chr(char) in md_parser[parser]['pseudo-re']['APC']:
value = True
return value
if __name__ == '__main__':
pass

View File

@ -20,15 +20,18 @@
#
r"""A cmark implementation file."""
# License C applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
# /** Defines the memory allocation functions to be used by CMark
# * when parsing and allocating a document tree
# */
# typedef struct cmark_mem {
# void *(*calloc)(size_t, size_t);
# void *(*realloc)(void *, size_t);
# void (*free)(void *);
# } cmark_mem;
# Defines the memory allocation functions to be used by CMark
# when parsing and allocating a document tree
# typedef struct cmark_mem {
# void *(*calloc)(size_t, size_t);
# void *(*realloc)(void *, size_t);
# void (*free)(void *);
# } cmark_mem;
class _cmarkCmarkMem:
pass

View File

@ -22,6 +22,10 @@ r"""The cmark implementation file."""
from ..generic import _noop
# License C applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
class _cmarkCmarkReference:
def __init__(self):
@ -53,3 +57,7 @@ class _cmarkCmarkReferenceMap:
_noop(size)
_noop(ref_size)
_noop(max_ref_size)
if __name__ == '__main__':
pass

View File

@ -37,18 +37,19 @@ from .utf8_c import (_cmark_cmark_utf8proc_is_punctuation,
_cmark_cmark_utf8proc_is_space,
_cmark_cmark_utf8proc_iterate)
# License C applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
# 0.29, 0.30
def _cmark_make_linebreak(mem):
# license C applies here. See docs/copyright_license.rst
_cmark_make_simple(mem, md_parser['cmark']['cmark_node_type']['CMARK_NODE_LINEBREAK'])
class _cmarkDelimiter:
r"""A list node with attributes useful for processing emphasis."""
# license C applies here. See docs/copyright_license.rst
def __init__(self, delim_char: str, length: int):
self.previous = None
self.next = None
@ -96,7 +97,6 @@ class _cmarkDelimiter:
class _cmarkBracket:
# license C applies here. See docs/copyright_license.rst
def __init__(self):
self.previous = None
self.previous_delimiter = None
@ -113,8 +113,6 @@ class _cmarkBracket:
class _cmarkSubject:
r"""A double linked list useful for processing emphasis."""
# license C applies here. See docs/copyright_license.rst
def __init__(self):
# cmark_mem
self.mem = None
@ -199,13 +197,11 @@ class _cmarkSubject:
# 0.30
def _cmark_S_is_line_end_char(c: str) -> bool:
# license C applies here. See docs/copyright_license.rst
return c == '\n' or c == '\r'
# 0.29, 0.30
def _cmark_make_literal(subj: _cmarkSubject, t: int, start_column: int, end_column: int) -> _cmarkCmarkNode:
# license C applies here. See docs/copyright_license.rst
r"""Create an inline with a literal string value."""
e = _cmarkCmarkNode()
@ -221,7 +217,6 @@ def _cmark_make_literal(subj: _cmarkSubject, t: int, start_column: int, end_colu
# 0.29, 0.30
def _cmark_make_simple(mem, t: int) -> _cmarkCmarkNode:
# license C applies here. See docs/copyright_license.rst
e = _cmarkCmarkNode()
e.mem = copy.deepcopy(mem)
e.type = t
@ -230,7 +225,6 @@ def _cmark_make_simple(mem, t: int) -> _cmarkCmarkNode:
# 0.29, 0.30
def _cmark_make_str(subj: _cmarkSubject, sc: int, ec: int, s: _cmarkCmarkChunk) -> _cmarkCmarkNode:
# license C applies here. See docs/copyright_license.rst
# s = char
# sc = start column
# ec = end cloumn
@ -253,7 +247,6 @@ def _cmark_make_str(subj: _cmarkSubject, sc: int, ec: int, s: _cmarkCmarkChunk)
def _cmark_subject_from_buf(mem, line_number: int,
block_offset: int, e: _cmarkSubject, chunk: _cmarkCmarkChunk,
refmap: _cmarkCmarkReferenceMap):
# license C applies here. See docs/copyright_license.rst
i: int
e.mem = mem
e.input = chunk
@ -282,7 +275,6 @@ def _cmark_isbacktick(c: int) -> int:
# 0.29, 0.30
def _cmark_peek_char(subj: _cmarkSubject) -> int:
# license C applies here. See docs/copyright_license.rst
# Instead of using assert just raise a ValueError
if subj.pos < subj.input.length and ord(subj.input.data[subj.pos]) == 0:
raise ValueError
@ -295,27 +287,23 @@ def _cmark_peek_char(subj: _cmarkSubject) -> int:
# 0.29, 0.30
def _cmark_peek_at(subj: _cmarkSubject, pos: int) -> int:
# license C applies here. See docs/copyright_license.rst
return ord(subj.input.data[pos])
# 0.30
def _cmark_is_eof(subj: _cmarkSubject):
r"""Return true if there are more characters in the subject."""
# license C applies here. See docs/copyright_license.rst.
return subj.pos >= subj.input.length
# 0.29, 0.30
def _cmark_advance(subj: _cmarkSubject):
# license C applies here. See docs/copyright_license.rst.
# Advance the subject. Doesn't check for eof.
subj.pos += 1
# 0.29, 0.30
def _cmark_skip_line_end(subj: _cmarkSubject) -> bool:
# license C applies here. See docs/copyright_license.rst
seen_line_end_char: bool = False
if _cmark_peek_char(subj) == '\r':
@ -328,9 +316,9 @@ def _cmark_skip_line_end(subj: _cmarkSubject) -> bool:
# Take characters while a predicate holds, and return a string.
# Get backtick spanning.
# 0.29, 0.30
def _cmark_take_while(subj: _cmarkSubject) -> _cmarkCmarkChunk:
r"""Get backtick spanning."""
c: int
startpos: int = subj.pos
len: int = 0
@ -498,7 +486,6 @@ def _cmark_handle_backticks(subj: _cmarkSubject, options: int) -> _cmarkCmarkNod
# 0.29, 0.30
def _cmark_scan_delims(subj: _cmarkSubject, c: str) -> tuple:
# license C applies here. See docs/copyright_license.rst
numdelims: int = 0
before_char_pos: int = 0
after_char: int = 0
@ -571,7 +558,6 @@ def _cmark_scan_delims(subj: _cmarkSubject, c: str) -> tuple:
# 0.30
def _cmark_pop_bracket(subj: _cmarkSubject):
# license C applies here. See docs/copyright_license.rst
b: _cmarkBracket
if subj.last_bracket is None:
return
@ -585,7 +571,6 @@ def _cmark_pop_bracket(subj: _cmarkSubject):
# 0.29, 0.30
def _cmark_push_delimiter(subj: _cmarkSubject, c: str, can_open: bool,
can_close: bool, inl_text: _cmarkCmarkNode):
# license C applies here. See docs/copyright_license.rst
delim = _cmarkDelimiter(c, inl_text.length)
delim.can_open = can_open
delim.can_close = can_close
@ -596,7 +581,6 @@ def _cmark_push_delimiter(subj: _cmarkSubject, c: str, can_open: bool,
# 0.29, 0.30
def _cmark_push_bracket(subj: _cmarkSubject, image: bool, inl_text: _cmarkCmarkNode):
# license C applies here. See docs/copyright_license.rst
b = _cmarkBracket()
if subj.last_bracket is not None:
subj.last_bracket.bracket_after = True
@ -613,7 +597,6 @@ def _cmark_push_bracket(subj: _cmarkSubject, image: bool, inl_text: _cmarkCmarkN
# Assumes the subject has a c at the current position.
# 0.29, 0.30
def _cmark_handle_delim(subj: _cmarkSubject, c: str, smart: bool = False) -> _cmarkCmarkNode:
# license C applies here. See docs/copyright_license.rst
numdelims: int
can_open: bool
can_close: bool
@ -642,7 +625,6 @@ def _cmark_handle_delim(subj: _cmarkSubject, c: str, smart: bool = False) -> _cm
# 0.29, 0.30
def _cmark_process_emphasis(subj: _cmarkSubject, stack_bottom: _cmarkDelimiter, ignore: list) -> list:
# license C applies here. See docs/copyright_license.rst
closer: _cmarkDelimiter = subj.last_delim
opener: _cmarkDelimiter
openers_bottom_index: int = 0
@ -718,7 +700,6 @@ def _cmark_process_emphasis(subj: _cmarkSubject, stack_bottom: _cmarkDelimiter,
# 0.29, 0.30
def _cmark_remove_emph(subj: _cmarkSubject, opener: _cmarkDelimiter, closer: _cmarkDelimiter, ignore: list):
# license C applies here. See docs/copyright_license.rst
# This function refers to S_insert_emph()
delim: _cmarkDelimiter
tmp_delim: _cmarkDelimiter
@ -797,10 +778,9 @@ def _cmark_remove_emph(subj: _cmarkSubject, opener: _cmarkDelimiter, closer: _cm
return closer
# Parse backslash-escape or just a backslash, returning an inline.
# 0.29, 0.30
def _cmark_handle_backslash(subj: _cmarkSubject):
r"""Parse backslash-escape or just a backslash, returning an inline."""
# license C applies here. See docs/copyright_license.rst
_cmark_advance(subj)
nextchar: str = _cmark_peek_char(subj)
@ -816,7 +796,6 @@ def _cmark_handle_backslash(subj: _cmarkSubject):
# 0.29, 0.30
def _cmark_subject_find_special_char(subj: _cmarkSubject, options: int) -> int:
# license C applies here. See docs/copyright_license.rst
# "\r\n\\`&_*[]<!"
SPECIAL_CHARS: list = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -868,10 +847,9 @@ def _cmark_subject_find_special_char(subj: _cmarkSubject, options: int) -> int:
# Parse an inline, advancing subject, and add it as a child of parent.
# Return 0 if no inline can be parsed, 1 otherwise.
# Handle all the different elements of a string.
# 0.29, 0.30
def _cmark_parse_inline(subj: _cmarkSubject, parent: _cmarkCmarkNode, options: int = 0) -> int:
r"""Handle all the different elements of a string."""
# license C applies here. See docs/copyright_license.rst
new_inl: _cmarkCmarkNode = None
contents: str
c: int
@ -919,11 +897,10 @@ def _cmark_parse_inline(subj: _cmarkSubject, parent: _cmarkCmarkNode, options: i
# Parse inlines from parent's string_content, adding as children of parent.
# Get the ignore list.
# 0.30
def _cmark_cmark_parse_inlines(mem, parent: _cmarkCmarkNode,
refmap: _cmarkCmarkReferenceMap, options: int) -> list:
r"""Get the ignore list."""
# license C applies here. See docs/copyright_license.rst
subj: _cmarkSubject
content: _cmarkCmarkChunk = _cmarkCmarkChunk(parent.data, parent.length)
subj = _cmarkSubject()
@ -944,3 +921,7 @@ def _cmark_cmark_parse_inlines(mem, parent: _cmarkCmarkNode,
_cmark_pop_bracket(subj)
return ignore
if __name__ == '__main__':
pass

View File

@ -26,10 +26,13 @@ from ..constants import parser as md_parser
from ..generic import _noop
from .node_h import _cmarkCmarkNode
# License C applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
# 0.30
def _cmark_S_free_nodes(e: _cmarkCmarkNode):
# license C applies here. See docs/copyright_license.rst
mem = e.mem
next: _cmarkCmarkNode
_noop(mem)
@ -51,7 +54,6 @@ def _cmark_S_free_nodes(e: _cmarkCmarkNode):
# 0.30
def _cmark_cmark_node_free(node: _cmarkCmarkNode):
# license C applies here. See docs/copyright_license.rst
_cmark_S_node_unlink(node)
node.next = None
_cmark_S_free_nodes(node)
@ -59,7 +61,6 @@ def _cmark_cmark_node_free(node: _cmarkCmarkNode):
# 0.30
def _cmark_cmark_set_cstr(mem, dst: str, src: str) -> int:
# license C applies here. See docs/copyright_license.rst
old: str = dst
length: int
@ -83,7 +84,6 @@ def _cmark_cmark_set_cstr(mem, dst: str, src: str) -> int:
# 0.30
def _cmark_cmark_node_set_literal(node: _cmarkCmarkNode, content: str) -> int:
# license C applies here. See docs/copyright_license.rst
if node is None:
return 0
@ -103,7 +103,6 @@ def _cmark_cmark_node_set_literal(node: _cmarkCmarkNode, content: str) -> int:
# 0.30
# Unlink a node without adjusting its next, prev, and parent pointers.
def _cmark_S_node_unlink(node: _cmarkCmarkNode):
# license C applies here. See docs/copyright_license.rst
if node is None:
return
@ -120,3 +119,7 @@ def _cmark_S_node_unlink(node: _cmarkCmarkNode):
parent.first_child = node.next
if parent.last_child == node:
parent.last_child = node.prev
if __name__ == '__main__':
pass

View File

@ -20,9 +20,12 @@
#
r"""A cmark implementation file."""
# License C applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
class _cmarkCmarkNode:
# license C applies here. See docs/copyright_license.rst
def __init__(self):
# cmark_strbuf
@ -67,3 +70,7 @@ class _cmarkCmarkNode:
else:
# Also set first_child if node previously had no children.
self.first_child = child
if __name__ == '__main__':
pass

View File

@ -24,10 +24,13 @@ from ..constants import parser as md_parser
from ..exceptions import CannotTreatUnicodeString
from .cmark_ctype_c import _cmark_cmark_ispunct
# License D applies to this file except for non derivative code:
# in that case the license header at the top of the file applies.
# See docs/copyright_license.rst
# 0.29, 0.30
def _cmark_cmark_utf8proc_charlen(line: str, line_length: int) -> int:
# license D applies here. See docs/copyright_license.rst
length: int
i: int
@ -63,7 +66,6 @@ def _cmark_cmark_utf8proc_charlen(line: str, line_length: int) -> int:
# 0.29, 0.30
def _cmark_cmark_utf8proc_iterate(line: str, line_len: int) -> tuple:
# license D applies here. See docs/copyright_license.rst
length: int = 0
uc: int = -1
dst: int = -1
@ -99,7 +101,6 @@ def _cmark_cmark_utf8proc_iterate(line: str, line_len: int) -> tuple:
# 0.29, 0.30
def _cmark_cmark_utf8proc_is_space(char: int, parser: str = 'github') -> bool:
r"""Match anything in the Zs class, plus LF, CR, TAB, FF."""
# license D applies here. See docs/copyright_license.rst.
value = False
if chr(char) in md_parser[parser]['pseudo-re']['UWC']:
value = True
@ -110,9 +111,12 @@ def _cmark_cmark_utf8proc_is_space(char: int, parser: str = 'github') -> bool:
# 0.29, 0.30
def _cmark_cmark_utf8proc_is_punctuation(char: int, parser: str = 'github') -> bool:
r"""Match anything in the P[cdefios] classes."""
# license C applies here. See docs/copyright_license.rst.
value = False
if (char < 128 and _cmark_cmark_ispunct(char)) or chr(char) in md_parser[parser]['pseudo-re']['UPC']:
value = True
return value
if __name__ == '__main__':
pass