Created
August 19, 2019 02:03
-
-
Save kaymccormick/bf68b4e7a399fe5825d2ead08ba1896a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Py from "../src/Py"; | |
let __docformat__: any; | |
let sys: any; | |
let re: any; | |
let FunctionType: any; | |
let MethodType: any; | |
let nodes: any; | |
let statemachine: any; | |
let utils: any; | |
let ApplicationError: any; | |
let DataError: any; | |
let StateMachineWS: any; | |
let StateWS: any; | |
let normalize_name: any; | |
let whitespace_normalize_name: any; | |
let docutils: any; | |
let directives: any; | |
let languages: any; | |
let tableparser: any; | |
let roles: any; | |
let _fallback_language_module: any; | |
let escape2null: any; | |
let unescape: any; | |
let column_width: any; | |
let punctuation_chars: any; | |
let roman: any; | |
let urischemes: any; | |
let split_escaped_whitespace: any; | |
let state_classes: any; | |
__docformat__ = new Py.PyStr("reStructuredText"); | |
class MarkupError extends DataError { | |
} | |
class UnknownInterpretedRoleError extends DataError { | |
} | |
class InterpretedRoleNotImplementedError extends DataError { | |
} | |
class ParserError extends ApplicationError { | |
} | |
class MarkupMismatch extends Error { | |
} | |
class Struct { | |
public constructor() { | |
this.__dict__.update(keywordargs); | |
} | |
} | |
class RSTStateMachine extends StateMachineWS { | |
public results: any; | |
public node: any; | |
public reporter: any; | |
public document: any; | |
public memo: any; | |
public inliner: any; | |
public match_titles: any; | |
public language: any; | |
public run(input_lines, document, input_offset, match_titles, inliner): void { | |
let results; | |
this.language = languages.get_language(document.settings.language_code); | |
this.match_titles = match_titles; | |
if (inliner) { | |
inliner = Inliner(); | |
} | |
inliner.init_customizations(document.settings); | |
this.memo = Struct(); | |
this.document = document; | |
this.attach_observer(document.note_source); | |
this.reporter = this.memo.reporter; | |
this.node = document; | |
results = StateMachineWS.run(this, input_lines, input_offset); | |
this.memo = this.node = undefined; | |
} | |
} | |
class NestedStateMachine extends StateMachineWS { | |
public results: any; | |
public node: any; | |
public language: any; | |
public reporter: any; | |
public document: any; | |
public memo: any; | |
public match_titles: any; | |
public run(input_lines, input_offset, memo, node, match_titles): any { | |
let results; | |
this.match_titles = match_titles; | |
this.memo = memo; | |
this.document = memo.document; | |
this.attach_observer(this.document.note_source); | |
this.reporter = memo.reporter; | |
this.language = memo.language; | |
this.node = node; | |
results = StateMachineWS.run(this, input_lines, input_offset); | |
return results; | |
} | |
} | |
class RSTState extends StateWS { | |
public lineno: any; | |
public nodes: any; | |
public p: any; | |
public messages: any; | |
public literalnext: any; | |
public text: any; | |
public data: any; | |
public newabsoffset: any; | |
public absoffset: any; | |
public offset: any; | |
public name: any; | |
public titlenode: any; | |
public title_messages: any; | |
public textnodes: any; | |
public section_node: any; | |
public error: any; | |
public level: any; | |
public mylevel: any; | |
public title_styles: any; | |
public blank_finish: any; | |
public blank_finish_state: any; | |
public new_offset: any; | |
public state_machine: any; | |
public block_length: any; | |
public state_machine_kwargs: any; | |
public state_machine_class: any; | |
public use_default: any; | |
public parent: any; | |
public document: any; | |
public inliner: any; | |
public reporter: any; | |
public memo: any; | |
public nested_sm_kwargs: any; | |
public nested_sm_cache: any = new Py.PyArray(); | |
public nested_sm: any = NestedStateMachine; | |
public constructor(state_machine, debug) { | |
this.nested_sm_kwargs = new Py.PyDict({ | |
"state_classes": state_classes, | |
"initial_state": new Py.PyStr("Body") | |
}); | |
StateWS.__init__(this, state_machine, debug); | |
} | |
public runtime_init(): void { | |
let memo; | |
StateWS.runtime_init(this); | |
memo = this.state_machine.memo; | |
this.memo = memo; | |
this.reporter = memo.reporter; | |
this.inliner = memo.inliner; | |
this.document = memo.document; | |
this.parent = this.state_machine.node; | |
if (!Py.hasattr(this.reporter, new Py.PyStr("get_source_and_line"))) { | |
this.reporter.get_source_and_line = this.state_machine.get_source_and_line; | |
} | |
} | |
public goto_line(abs_line_offset): void { | |
try { | |
this.state_machine.goto_line(abs_line_offset); | |
} | |
catch (___error) { | |
if (___error instanceof EOFError) { } | |
} | |
} | |
public no_match(context, transitions): PyTuple<any> { | |
this.reporter.severe(new Py.PyStr("Internal error: no transition pattern match. State: \"%s\"; transitions: %s; context: %s; current line: %r.") % new Py.PyTuple(this.__class__.__name__, transitions, context, this.state_machine.line)); | |
return new Py.PyTuple(context, undefined, new Py.PyArray()); | |
} | |
public bof(context): PyTuple<PyArray<unknown>> { | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyArray()); | |
} | |
public nested_parse(block, input_offset, node, match_titles, state_machine_class, state_machine_kwargs): any { | |
let use_default; | |
let block_length; | |
let state_machine; | |
let new_offset; | |
use_default = 0; | |
if (state_machine_class) { | |
state_machine_class = this.nested_sm; | |
} | |
if (state_machine_kwargs) { | |
state_machine_kwargs = this.nested_sm_kwargs; | |
} | |
block_length = Py.len(block); | |
state_machine = undefined; | |
if (use_default) { | |
try { | |
state_machine = this.nested_sm_cache.pop(); | |
} | |
catch (___error) { | |
if (___error instanceof IndexError) { } | |
} | |
} | |
if (!state_machine) { | |
state_machine = state_machine_class(); | |
} | |
state_machine.run(block, input_offset); | |
if (use_default) { | |
this.nested_sm_cache.append(state_machine); | |
} | |
else { | |
state_machine.unlink(); | |
} | |
new_offset = state_machine.abs_line_offset(); | |
if (block.parent && Py.len(block) - block_length) { | |
this.state_machine.next_line(Py.len(block) - block_length); | |
} | |
return new_offset; | |
} | |
public nested_list_parse(block, input_offset, node, initial_state, blank_finish, blank_finish_state, extra_settings, match_titles, state_machine_class, state_machine_kwargs): PyTuple<any> { | |
let state_machine; | |
let key; | |
let value; | |
if (state_machine_class) { | |
state_machine_class = this.nested_sm; | |
} | |
if (state_machine_kwargs) { | |
state_machine_kwargs = this.nested_sm_kwargs.copy(); | |
} | |
state_machine_kwargs[new Py.PyStr("initial_state")] = initial_state; | |
state_machine = state_machine_class(); | |
if (blank_finish_state) { | |
blank_finish_state = initial_state; | |
} | |
state_machine.states[blank_finish_state].blank_finish = blank_finish; | |
for ([key, value] of Py.list(extra_settings.items())) { | |
Py.setattr(state_machine.states[initial_state], key, value); | |
} | |
state_machine.run(block, input_offset); | |
blank_finish = state_machine.states[blank_finish_state].blank_finish; | |
state_machine.unlink(); | |
return new Py.PyTuple(state_machine.abs_line_offset(), blank_finish); | |
} | |
public section(title, source, style, lineno, messages): void { | |
if (this.check_subsection(source, style, lineno)) { | |
this.new_subsection(title, lineno, messages); | |
} | |
} | |
public check_subsection(source, style, lineno): number { | |
let memo; | |
let title_styles; | |
let mylevel; | |
let level; | |
memo = this.memo; | |
title_styles = memo.title_styles; | |
mylevel = memo.section_level; | |
try { | |
level = title_styles.index(style) + 1; | |
} | |
catch (___error) { | |
if (___error instanceof ValueError) { | |
if (Py.len(title_styles)) { | |
title_styles.append(style); | |
return 1; | |
} | |
else { | |
return undefined; | |
} | |
} | |
} | |
if (level) { | |
memo.section_level = level; | |
if (Py.len(style)) { | |
memo.section_bubble_up_kludge = true; | |
} | |
this.state_machine.previous_line(Py.len(style) + 1); | |
throw EOFError; | |
} | |
if (level) { | |
return 1; | |
} | |
else { | |
return undefined; | |
} | |
} | |
public title_inconsistent(sourcetext, lineno): any { | |
let error; | |
error = this.reporter.severe(new Py.PyStr("Title level inconsistent:"), nodes.literal_block(new Py.PyStr(""), sourcetext)); | |
return error; | |
} | |
public new_subsection(title, lineno, messages): void { | |
let memo; | |
let mylevel; | |
let section_node; | |
let textnodes; | |
let title_messages; | |
let titlenode; | |
let name; | |
let offset; | |
let absoffset; | |
let newabsoffset; | |
memo = this.memo; | |
mylevel = memo.section_level; | |
section_node = nodes.section(); | |
this.inline_text(title, lineno); | |
titlenode = nodes.title(title, new Py.PyStr(""), ...textnodes); | |
name = normalize_name(titlenode.astext()); | |
section_node[new Py.PyStr("names")].append(name); | |
this.document.note_implicit_target(section_node, section_node); | |
offset = this.state_machine.line_offset + 1; | |
absoffset = this.state_machine.abs_line_offset() + 1; | |
newabsoffset = this.nested_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(newabsoffset); | |
if (memo.section_level) { | |
throw EOFError; | |
} | |
memo.section_level = mylevel; | |
} | |
public paragraph(lines, lineno): PyTuple<any> { | |
let data; | |
let text; | |
let literalnext; | |
let textnodes; | |
let messages; | |
let p; | |
data = new Py.PyStr("\n").join(lines).rstrip(); | |
if (re.search(new Py.PyStr("(?<!\\\\)(\\\\\\\\)*::$"), data)) { | |
if (Py.len(data)) { | |
return new Py.PyTuple(new Py.PyArray(), 1); | |
} | |
else { | |
if (data[data.length + -3]) { | |
text = data.slice(undefined, -3).rstrip(); | |
} | |
else { | |
text = data.slice(undefined, -1); | |
} | |
} | |
literalnext = 1; | |
} | |
else { | |
text = data; | |
literalnext = 0; | |
} | |
this.inline_text(text, lineno); | |
p = nodes.paragraph(data, new Py.PyStr(""), ...textnodes); | |
p.source = p.line = this.state_machine.get_source_and_line(lineno); | |
return new Py.PyTuple(new Py.PyArray(p) + messages, literalnext); | |
} | |
public inline_text(text, lineno): PyTuple<any> { | |
let nodes; | |
let messages; | |
this.inliner.parse(text, lineno, this.memo, this.parent); | |
return new Py.PyTuple(nodes, messages); | |
} | |
public unindent_warning(node_name): any { | |
let lineno; | |
lineno = this.state_machine.abs_line_number() + 1; | |
return this.reporter.warning(new Py.PyStr("%s ends without a blank line; unexpected unindent.") % node_name); | |
} | |
} | |
function build_regexp(definition, compile) { | |
let name: any; | |
let prefix: any; | |
let suffix: any; | |
let parts: any; | |
let part_strings: any; | |
let part: any; | |
let or_group: any; | |
let regexp: any; | |
name = prefix = suffix = parts = definition; | |
part_strings = new Py.PyArray(); | |
for (part of parts) { | |
if (Py.type(part)) { | |
part_strings.append(build_regexp(part, undefined)); | |
} | |
else { | |
part_strings.append(part); | |
} | |
} | |
or_group = new Py.PyStr("|").join(part_strings); | |
regexp = new Py.PyStr("%(prefix)s(?P<%(name)s>%(or_group)s)%(suffix)s") % Py.locals(); | |
if (compile) { | |
return re.compile(regexp, re.UNICODE); | |
} | |
else { | |
return regexp; | |
} | |
} | |
class Inliner { | |
public rfcnum: any; | |
public rfc_url: any = new Py.PyStr("rfc%d.html"); | |
public ref: any; | |
public pepnum: any; | |
public unescaped: any; | |
public addscheme: any; | |
public referencenode: any; | |
public referencename: any; | |
public refnode: any; | |
public label: any; | |
public reference_node: any; | |
public subref_text: any; | |
public subref_node: any; | |
public name: any; | |
public messages2: any; | |
public nodes: any; | |
public role_fn: any; | |
public node_list: any; | |
public reference: any; | |
public refname: any; | |
public alias_parts: any; | |
public target: any; | |
public alias: any; | |
public aliastype: any; | |
public underscore_escaped: any; | |
public rawaliastext: any; | |
public aliastext: any; | |
public rawtext: any; | |
public nodelist: any; | |
public escaped: any; | |
public position: any; | |
public role: any; | |
public rolestart: any; | |
public end_pattern: any; | |
public endstring: any; | |
public prbid: any; | |
public problematic: any; | |
public msgid: any; | |
public prb: any; | |
public msg: any; | |
public node: any; | |
public rawsource: any; | |
public textend: any; | |
public text: any; | |
public _text: any; | |
public endmatch: any; | |
public matchend: any; | |
public matchstart: any; | |
public poststart: any; | |
public prestart: any; | |
public start: any; | |
public string: any; | |
public email_pattern: any = new Py.PyStr("\n %(emailc)s+(?:\\.%(emailc)s+)* # name\n (?<!\\x00)@ # at\n %(emailc)s+(?:\\.%(emailc)s*)* # host\n %(uri_end)s # final URI char\n "); | |
public emailc: any = new Py.PyStr("[-_!~*'{|}/#?^`&=+$%a-zA-Z0-9\\x00]"); | |
public uri_end: any = new Py.PyStr("(?:%(urilast)s|%(uric)s(?=%(uri_end_delim)s))") % Py.locals(); | |
public urilast: any = new Py.PyStr("[_~*/=+a-zA-Z0-9]"); | |
public uri_end_delim: any = new Py.PyStr("[>]"); | |
public uric: any = new Py.PyStr("[-_.!~*'()[\\];/:@&=+$,%a-zA-Z0-9\\x00]"); | |
public simplename: any = new Py.PyStr("(?:(?!_)\\w)+(?:[-._+:](?:(?!_)\\w)+)*"); | |
public non_whitespace_after: any = new Py.PyStr("(?!\\s)"); | |
public non_unescaped_whitespace_escape_before: any = new Py.PyStr("(?<!(?<!\\x00)[\\s\\x00])"); | |
public non_whitespace_escape_before: any = new Py.PyStr("(?<![\\s\\x00])"); | |
public non_whitespace_before: any = new Py.PyStr("(?<!\\s)"); | |
public sysmessages: any; | |
public inlines: any; | |
public before: any; | |
public method: any; | |
public groups: any; | |
public match: any; | |
public messages: any; | |
public unprocessed: any; | |
public processed: any; | |
public remaining: any; | |
public dispatch: any = new Py.PyDict({ | |
"*": emphasis, | |
"**": strong, | |
"`": interpreted_or_phrase_ref, | |
"``": literal, | |
"_`": inline_internal_target, | |
"]_": footnote_reference, | |
"|": substitution_reference, | |
"_": reference, | |
"__": anonymous_reference | |
}); | |
public pattern_search: any; | |
public parent: any; | |
public language: any; | |
public document: any; | |
public reporter: any; | |
public patterns: any; | |
public parts: any; | |
public args: any; | |
public end_string_suffix: any; | |
public start_string_prefix: any; | |
public implicit_dispatch: any; | |
public constructor() { | |
this.implicit_dispatch = new Py.PyArray(); | |
} | |
public init_customizations(settings): void { | |
let start_string_prefix; | |
let end_string_suffix; | |
let args; | |
let parts; | |
if (Py.getattr(settings, new Py.PyStr("character_level_inline_markup"), false)) { | |
start_string_prefix = new Py.PyStr("(^|(?<!\u0000))"); | |
end_string_suffix = new Py.PyStr(""); | |
} | |
else { | |
start_string_prefix = new Py.PyStr("(^|(?<=\\s|[%s%s]))") % new Py.PyTuple(punctuation_chars.openers, punctuation_chars.delimiters); | |
end_string_suffix = new Py.PyStr("($|(?=\\s|[\u0000%s%s%s]))") % new Py.PyTuple(punctuation_chars.closing_delimiters, punctuation_chars.delimiters, punctuation_chars.closers); | |
} | |
args = Py.locals().copy(); | |
args.update(Py.vars(this.__class__)); | |
parts = new Py.PyTuple(new Py.PyStr("initial_inline"), start_string_prefix, new Py.PyStr(""), new Py.PyArray(new Py.PyTuple(new Py.PyStr("start"), new Py.PyStr(""), this.non_whitespace_after, new Py.PyArray(new Py.PyStr("\\*\\*"), new Py.PyStr("\\*(?!\\*)"), new Py.PyStr("``"), new Py.PyStr("_`"), new Py.PyStr("\\|(?!\\|)"))), new Py.PyTuple(new Py.PyStr("whole"), new Py.PyStr(""), end_string_suffix, new Py.PyArray(new Py.PyStr("(?P<refname>%s)(?P<refend>__?)") % this.simplename, new Py.PyTuple(new Py.PyStr("footnotelabel"), new Py.PyStr("\\["), new Py.PyStr("(?P<fnend>\\]_)"), new Py.PyArray(new Py.PyStr("[0-9]+"), new Py.PyStr("\\#(%s)?") % this.simplename, new Py.PyStr("\\*"), new Py.PyStr("(?P<citationlabel>%s)") % this.simplename)))), new Py.PyTuple(new Py.PyStr("backquote"), new Py.PyStr("(?P<role>(:%s:)?)") % this.simplename, this.non_whitespace_after, new Py.PyArray(new Py.PyStr("`(?!`)"))))); | |
this.start_string_prefix = start_string_prefix; | |
this.end_string_suffix = end_string_suffix; | |
this.parts = parts; | |
this.patterns = Struct(); | |
this.implicit_dispatch.append(new Py.PyTuple(this.patterns.uri, this.standalone_uri)); | |
if (settings.pep_references) { | |
this.implicit_dispatch.append(new Py.PyTuple(this.patterns.pep, this.pep_reference)); | |
} | |
if (settings.rfc_references) { | |
this.implicit_dispatch.append(new Py.PyTuple(this.patterns.rfc, this.rfc_reference)); | |
} | |
} | |
public parse(text, lineno, memo, parent): PyTuple<any> { | |
let pattern_search; | |
let dispatch; | |
let remaining; | |
let processed; | |
let unprocessed; | |
let messages; | |
let match; | |
let groups; | |
let method; | |
let before; | |
let inlines; | |
let sysmessages; | |
this.reporter = memo.reporter; | |
this.document = memo.document; | |
this.language = memo.language; | |
this.parent = parent; | |
pattern_search = this.patterns.initial.search; | |
dispatch = this.dispatch; | |
remaining = escape2null(text); | |
processed = new Py.PyArray(); | |
unprocessed = new Py.PyArray(); | |
messages = new Py.PyArray(); | |
remaining = new Py.PyStr("").join(unprocessed) + remaining; | |
if (remaining) { } | |
return new Py.PyTuple(processed, messages); | |
} | |
public quoted_start(match): any { | |
let string; | |
let start; | |
let prestart; | |
let poststart; | |
string = match.string; | |
start = match.start(); | |
if (start) { | |
return false; | |
} | |
prestart = string[start - 1]; | |
try { | |
poststart = string[match.end()]; | |
} | |
catch (___error) { | |
if (___error instanceof IndexError) { | |
return true; | |
} | |
} | |
return punctuation_chars.match_chars(prestart, poststart); | |
} | |
public inline_obj(match, lineno, end_pattern, nodeclass, restore_backslashes): PyTuple<any> { | |
let string; | |
let matchstart; | |
let matchend; | |
let endmatch; | |
let _text; | |
let text; | |
let textend; | |
let rawsource; | |
let node; | |
let msg; | |
let prb; | |
string = match.string; | |
matchstart = match.start(new Py.PyStr("start")); | |
matchend = match.end(new Py.PyStr("start")); | |
if (this.quoted_start(match)) { | |
return new Py.PyTuple(string.slice(undefined, matchend), new Py.PyArray(), string.slice(matchend, undefined), new Py.PyArray(), new Py.PyStr("")); | |
} | |
endmatch = end_pattern.search(string.slice(matchend, undefined)); | |
if (endmatch && endmatch.start(1)) { | |
_text = endmatch.string.slice(undefined, endmatch.start(1)); | |
text = unescape(_text, restore_backslashes); | |
textend = matchend + endmatch.end(1); | |
rawsource = unescape(string.slice(matchstart, textend), true); | |
node = nodeclass(rawsource, text); | |
node[0].rawsource = unescape(_text, true); | |
return new Py.PyTuple(string.slice(undefined, matchstart), new Py.PyArray(node), string.slice(textend, undefined), new Py.PyArray(), endmatch.group(1)); | |
} | |
msg = this.reporter.warning(new Py.PyStr("Inline %s start-string without end-string.") % nodeclass.__name__); | |
text = unescape(string.slice(matchstart, matchend), true); | |
rawsource = unescape(string.slice(matchstart, matchend), true); | |
prb = this.problematic(text, rawsource, msg); | |
return new Py.PyTuple(string.slice(undefined, matchstart), new Py.PyArray(prb), string.slice(matchend, undefined), new Py.PyArray(msg), new Py.PyStr("")); | |
} | |
public problematic(text, rawsource, message): any { | |
let msgid; | |
let problematic; | |
let prbid; | |
msgid = this.document.set_id(message, this.parent); | |
problematic = nodes.problematic(rawsource, text); | |
prbid = this.document.set_id(problematic); | |
message.add_backref(prbid); | |
return problematic; | |
} | |
public emphasis(match, lineno): PyTuple<any> { | |
let before; | |
let inlines; | |
let remaining; | |
let sysmessages; | |
let endstring; | |
this.inline_obj(match, lineno, this.patterns.emphasis, nodes.emphasis); | |
return new Py.PyTuple(before, inlines, remaining, sysmessages); | |
} | |
public strong(match, lineno): PyTuple<any> { | |
let before; | |
let inlines; | |
let remaining; | |
let sysmessages; | |
let endstring; | |
this.inline_obj(match, lineno, this.patterns.strong, nodes.strong); | |
return new Py.PyTuple(before, inlines, remaining, sysmessages); | |
} | |
public interpreted_or_phrase_ref(match, lineno): PyTuple<any> { | |
let end_pattern; | |
let string; | |
let matchstart; | |
let matchend; | |
let rolestart; | |
let role; | |
let position; | |
let endmatch; | |
let textend; | |
let msg; | |
let text; | |
let prb; | |
let escaped; | |
let rawsource; | |
let nodelist; | |
let messages; | |
end_pattern = this.patterns.interpreted_or_phrase_ref; | |
string = match.string; | |
matchstart = match.start(new Py.PyStr("backquote")); | |
matchend = match.end(new Py.PyStr("backquote")); | |
rolestart = match.start(new Py.PyStr("role")); | |
role = match.group(new Py.PyStr("role")); | |
position = new Py.PyStr(""); | |
if (role) { | |
role = role.slice(1, -1); | |
position = new Py.PyStr("prefix"); | |
} | |
else { | |
if (this.quoted_start(match)) { | |
return new Py.PyTuple(string.slice(undefined, matchend), new Py.PyArray(), string.slice(matchend, undefined), new Py.PyArray()); | |
} | |
} | |
endmatch = end_pattern.search(string.slice(matchend, undefined)); | |
if (endmatch && endmatch.start(1)) { | |
textend = matchend + endmatch.end(); | |
if (endmatch.group(new Py.PyStr("role"))) { | |
if (role) { | |
msg = this.reporter.warning(new Py.PyStr("Multiple roles in interpreted text (both prefix and suffix present; only one allowed).")); | |
text = unescape(string.slice(rolestart, textend), true); | |
prb = this.problematic(text, text, msg); | |
return new Py.PyTuple(string.slice(undefined, rolestart), new Py.PyArray(prb), string.slice(textend, undefined), new Py.PyArray(msg)); | |
} | |
role = endmatch.group(new Py.PyStr("suffix")).slice(1, -1); | |
position = new Py.PyStr("suffix"); | |
} | |
escaped = endmatch.string.slice(undefined, endmatch.start(1)); | |
rawsource = unescape(string.slice(matchstart, textend), true); | |
if (rawsource.slice(-1, undefined)) { | |
if (role) { | |
msg = this.reporter.warning(new Py.PyStr("Mismatch: both interpreted text role %s and reference suffix.") % position); | |
text = unescape(string.slice(rolestart, textend), true); | |
prb = this.problematic(text, text, msg); | |
return new Py.PyTuple(string.slice(undefined, rolestart), new Py.PyArray(prb), string.slice(textend, undefined), new Py.PyArray(msg)); | |
} | |
return this.phrase_ref(string.slice(undefined, matchstart), string.slice(textend, undefined), rawsource, escaped, unescape(escaped)); | |
} | |
else { | |
rawsource = unescape(string.slice(rolestart, textend), true); | |
this.interpreted(rawsource, escaped, role, lineno); | |
return new Py.PyTuple(string.slice(undefined, rolestart), nodelist, string.slice(textend, undefined), messages); | |
} | |
} | |
msg = this.reporter.warning(new Py.PyStr("Inline interpreted text or phrase reference start-string without end-string.")); | |
text = unescape(string.slice(matchstart, matchend), true); | |
prb = this.problematic(text, text, msg); | |
return new Py.PyTuple(string.slice(undefined, matchstart), new Py.PyArray(prb), string.slice(matchend, undefined), new Py.PyArray(msg)); | |
} | |
public phrase_ref(before, after, rawsource, escaped, text): PyTuple<any> { | |
let match; | |
let rawtext; | |
let aliastext; | |
let rawaliastext; | |
let underscore_escaped; | |
let aliastype; | |
let alias; | |
let target; | |
let alias_parts; | |
let refname; | |
let reference; | |
let node_list; | |
match = this.patterns.embedded_link.search(escaped); | |
if (match) { | |
text = unescape(escaped.slice(undefined, match.start(0))); | |
rawtext = unescape(escaped.slice(undefined, match.start(0)), true); | |
aliastext = unescape(match.group(2)); | |
rawaliastext = unescape(match.group(2), true); | |
underscore_escaped = rawaliastext.endswith(new Py.PyStr("\\_")); | |
if (aliastext.endswith(new Py.PyStr("_")) && !(underscore_escaped || this.patterns.uri.match(aliastext))) { | |
aliastype = new Py.PyStr("name"); | |
alias = normalize_name(aliastext.slice(undefined, -1)); | |
target = nodes.target(match.group(1)); | |
target.indirect_reference_name = aliastext.slice(undefined, -1); | |
} | |
else { | |
aliastype = new Py.PyStr("uri"); | |
alias_parts = split_escaped_whitespace(match.group(2)); | |
alias = new Py.PyStr(" ").join(alias_parts.map(part => new Py.PyStr("").join(unescape(part).split()))); | |
alias = this.adjust_uri(alias); | |
if (alias.endswith(new Py.PyStr("\\_"))) { | |
alias = alias.slice(undefined, -2) + new Py.PyStr("_"); | |
} | |
target = nodes.target(match.group(1)); | |
target.referenced = 1; | |
} | |
if (!aliastext) { | |
throw ApplicationError(new Py.PyStr("problem with embedded link: %r") % aliastext); | |
} | |
if (!text) { | |
text = alias; | |
rawtext = rawaliastext; | |
} | |
} | |
else { | |
target = undefined; | |
rawtext = unescape(escaped, true); | |
} | |
refname = normalize_name(text); | |
reference = nodes.reference(rawsource, text); | |
reference[0].rawsource = rawtext; | |
node_list = new Py.PyArray(reference); | |
if (rawsource.slice(-2, undefined)) { | |
if (target && aliastype) { | |
reference[new Py.PyStr("refname")] = alias; | |
this.document.note_refname(reference); | |
} | |
else { | |
if (target && aliastype) { | |
reference[new Py.PyStr("refuri")] = alias; | |
} | |
else { | |
reference[new Py.PyStr("anonymous")] = 1; | |
} | |
} | |
} | |
else { | |
if (target) { | |
target[new Py.PyStr("names")].append(refname); | |
if (aliastype) { | |
reference[new Py.PyStr("refname")] = alias; | |
this.document.note_indirect_target(target); | |
this.document.note_refname(reference); | |
} | |
else { | |
reference[new Py.PyStr("refuri")] = alias; | |
this.document.note_explicit_target(target, this.parent); | |
} | |
node_list.append(target); | |
} | |
else { | |
reference[new Py.PyStr("refname")] = refname; | |
this.document.note_refname(reference); | |
} | |
} | |
return new Py.PyTuple(before, node_list, after, new Py.PyArray()); | |
} | |
public adjust_uri(uri): any { | |
let match; | |
match = this.patterns.email.match(uri); | |
if (match) { | |
return new Py.PyStr("mailto:") + uri; | |
} | |
else { | |
return uri; | |
} | |
} | |
public interpreted(rawsource, text, role, lineno): PyTuple<any> { | |
let role_fn; | |
let messages; | |
let nodes; | |
let messages2; | |
let msg; | |
roles.role(role, this.language, lineno, this.reporter); | |
if (role_fn) { | |
role_fn(role, rawsource, text, lineno, this); | |
try { | |
nodes[0][0].rawsource = unescape(text, true); | |
} | |
catch (___error) { | |
if (___error instanceof IndexError) { } | |
} | |
return new Py.PyTuple(nodes, messages + messages2); | |
} | |
else { | |
msg = this.reporter.error(new Py.PyStr("Unknown interpreted text role \"%s\".") % role); | |
return new Py.PyTuple(new Py.PyArray(this.problematic(rawsource, rawsource, msg)), messages + new Py.PyArray(msg)); | |
} | |
} | |
public literal(match, lineno): PyTuple<any> { | |
let before; | |
let inlines; | |
let remaining; | |
let sysmessages; | |
let endstring; | |
this.inline_obj(match, lineno, this.patterns.literal, nodes.literal); | |
return new Py.PyTuple(before, inlines, remaining, sysmessages); | |
} | |
public inline_internal_target(match, lineno): PyTuple<any> { | |
let before; | |
let inlines; | |
let remaining; | |
let sysmessages; | |
let endstring; | |
let target; | |
let name; | |
this.inline_obj(match, lineno, this.patterns.target, nodes.target); | |
if (inlines && Py.isinstance(inlines[0], nodes.target)) { | |
target = inlines[0]; | |
name = normalize_name(target.astext()); | |
target[new Py.PyStr("names")].append(name); | |
this.document.note_explicit_target(target, this.parent); | |
} | |
return new Py.PyTuple(before, inlines, remaining, sysmessages); | |
} | |
public substitution_reference(match, lineno): PyTuple<any> { | |
let before; | |
let inlines; | |
let remaining; | |
let sysmessages; | |
let endstring; | |
let subref_node; | |
let subref_text; | |
let reference_node; | |
this.inline_obj(match, lineno, this.patterns.substitution_ref, nodes.substitution_reference); | |
if (Py.len(inlines)) { | |
subref_node = inlines[0]; | |
if (Py.isinstance(subref_node, nodes.substitution_reference)) { | |
subref_text = subref_node.astext(); | |
this.document.note_substitution_ref(subref_node, subref_text); | |
if (endstring.slice(-1, undefined)) { | |
reference_node = nodes.reference(new Py.PyStr("|%s%s") % new Py.PyTuple(subref_text, endstring), new Py.PyStr("")); | |
if (endstring.slice(-2, undefined)) { | |
reference_node[new Py.PyStr("anonymous")] = 1; | |
} | |
else { | |
reference_node[new Py.PyStr("refname")] = normalize_name(subref_text); | |
this.document.note_refname(reference_node); | |
} | |
inlines = new Py.PyArray(reference_node); | |
} | |
} | |
} | |
return new Py.PyTuple(before, inlines, remaining, sysmessages); | |
} | |
public footnote_reference(match, lineno): PyTuple<any> { | |
let label; | |
let refname; | |
let string; | |
let before; | |
let remaining; | |
let refnode; | |
label = match.group(new Py.PyStr("footnotelabel")); | |
refname = normalize_name(label); | |
string = match.string; | |
before = string.slice(undefined, match.start(new Py.PyStr("whole"))); | |
remaining = string.slice(match.end(new Py.PyStr("whole")), undefined); | |
if (match.group(new Py.PyStr("citationlabel"))) { | |
refnode = nodes.citation_reference(new Py.PyStr("[%s]_") % label); | |
this.document.note_citation_ref(refnode); | |
} | |
else { | |
refnode = nodes.footnote_reference(new Py.PyStr("[%s]_") % label); | |
if (refname[0]) { | |
refname = refname.slice(1, undefined); | |
refnode[new Py.PyStr("auto")] = 1; | |
this.document.note_autofootnote_ref(refnode); | |
} | |
else { | |
if (refname) { | |
refname = new Py.PyStr(""); | |
refnode[new Py.PyStr("auto")] = new Py.PyStr("*"); | |
this.document.note_symbol_footnote_ref(refnode); | |
} | |
} | |
if (refname) { | |
refnode[new Py.PyStr("refname")] = refname; | |
this.document.note_footnote_ref(refnode); | |
} | |
if (utils.get_trim_footnote_ref_space(this.document.settings)) { | |
before = before.rstrip(); | |
} | |
} | |
return new Py.PyTuple(before, new Py.PyArray(refnode), remaining, new Py.PyArray()); | |
} | |
public reference(match, lineno, anonymous): PyTuple<any> { | |
let referencename; | |
let refname; | |
let referencenode; | |
let string; | |
let matchstart; | |
let matchend; | |
referencename = match.group(new Py.PyStr("refname")); | |
refname = normalize_name(referencename); | |
referencenode = nodes.reference(referencename + match.group(new Py.PyStr("refend")), referencename); | |
referencenode[0].rawsource = referencename; | |
if (anonymous) { | |
referencenode[new Py.PyStr("anonymous")] = 1; | |
} | |
else { | |
referencenode[new Py.PyStr("refname")] = refname; | |
this.document.note_refname(referencenode); | |
} | |
string = match.string; | |
matchstart = match.start(new Py.PyStr("whole")); | |
matchend = match.end(new Py.PyStr("whole")); | |
return new Py.PyTuple(string.slice(undefined, matchstart), new Py.PyArray(referencenode), string.slice(matchend, undefined), new Py.PyArray()); | |
} | |
public anonymous_reference(match, lineno): any { | |
return this.reference(match, lineno); | |
} | |
public standalone_uri(match, lineno): PyArray<any> { | |
let addscheme; | |
let text; | |
let unescaped; | |
let rawsource; | |
let reference; | |
if (!match.group(new Py.PyStr("scheme")) || match.group(new Py.PyStr("scheme")).lower()) { | |
if (match.group(new Py.PyStr("email"))) { | |
addscheme = new Py.PyStr("mailto:"); | |
} | |
else { | |
addscheme = new Py.PyStr(""); | |
} | |
text = match.group(new Py.PyStr("whole")); | |
unescaped = unescape(text); | |
rawsource = unescape(text, true); | |
reference = nodes.reference(rawsource, unescaped); | |
reference[0].rawsource = rawsource; | |
return new Py.PyArray(reference); | |
} | |
else { | |
throw MarkupMismatch; | |
} | |
} | |
public pep_reference(match, lineno): PyArray<any> { | |
let text; | |
let pepnum; | |
let ref; | |
let unescaped; | |
text = match.group(0); | |
if (text.startswith(new Py.PyStr("pep-"))) { | |
pepnum = Py.int(match.group(new Py.PyStr("pepnum1"))); | |
} | |
else { | |
if (text.startswith(new Py.PyStr("PEP"))) { | |
pepnum = Py.int(match.group(new Py.PyStr("pepnum2"))); | |
} | |
else { | |
throw MarkupMismatch; | |
} | |
} | |
ref = this.document.settings.pep_base_url + this.document.settings.pep_file_url_template % pepnum; | |
unescaped = unescape(text); | |
return new Py.PyArray(nodes.reference(unescape(text, true), unescaped)); | |
} | |
public rfc_reference(match, lineno): PyArray<any> { | |
let text; | |
let rfcnum; | |
let ref; | |
let unescaped; | |
text = match.group(0); | |
if (text.startswith(new Py.PyStr("RFC"))) { | |
rfcnum = Py.int(match.group(new Py.PyStr("rfcnum"))); | |
ref = this.document.settings.rfc_base_url + this.rfc_url % rfcnum; | |
} | |
else { | |
throw MarkupMismatch; | |
} | |
unescaped = unescape(text); | |
return new Py.PyArray(nodes.reference(unescape(text, true), unescaped)); | |
} | |
public implicit_inline(text, lineno): any { | |
let pattern; | |
let method; | |
let match; | |
if (!text) { | |
return new Py.PyArray(); | |
} | |
for ([pattern, method] of this.implicit_dispatch) { | |
match = pattern.search(text); | |
if (match) { | |
try { | |
return this.implicit_inline(text.slice(undefined, match.start()), lineno) + method(match, lineno) + this.implicit_inline(text.slice(match.end(), undefined), lineno); | |
} | |
catch (___error) { | |
if (___error instanceof MarkupMismatch) { } | |
} | |
} | |
} | |
return new Py.PyArray(nodes.Text(unescape(text))); | |
} | |
} | |
function _loweralpha_to_int(s, _zero) { | |
return Py.ord(s) - _zero; | |
} | |
function _upperalpha_to_int(s, _zero) { | |
return Py.ord(s) - _zero; | |
} | |
function _lowerroman_to_int(s) { | |
return roman.fromRoman(s.upper()); | |
} | |
class Body extends RSTState { | |
public expmatch: any; | |
public errors: any; | |
public arg_text: any; | |
public optional: any; | |
public required: any; | |
public success: any; | |
public opt_block: any; | |
public arg_block: any; | |
public has_content: any; | |
public option_spec: any; | |
public msg_node: any; | |
public directive_instance: any; | |
public content_offset: any; | |
public content: any; | |
public ___arguments: any; | |
public block_text: any; | |
public initial_line_offset: any; | |
public directive: any; | |
public directive_class: any; | |
public type_name: any; | |
public pformat: any; | |
public new_abs_offset: any; | |
public substitution_node: any; | |
public subname: any; | |
public subdefmatch: any; | |
public uri: any; | |
public ref_parts: any; | |
public refname: any; | |
public reference: any; | |
public target_type: any; | |
public target: any; | |
public targetmatch: any; | |
public blockindex: any; | |
public escaped: any; | |
public blocktext: any; | |
public pattern: any; | |
public citation: any; | |
public footnote: any; | |
public label: any; | |
public explicit: any = Struct(); | |
public entry: any; | |
public attributes: any; | |
public cellblock: any; | |
public morecols: any; | |
public morerows: any; | |
public row: any; | |
public tbody: any; | |
public thead: any; | |
public colspec: any; | |
public tgroup: any; | |
public bodyrows: any; | |
public headrows: any; | |
public colwidths: any; | |
public error: any; | |
public startline: any; | |
public message: any; | |
public extra: any; | |
public end: any; | |
public found_at: any; | |
public found: any; | |
public pattern_match: any; | |
public toplen: any; | |
public limit: any; | |
public lines: any; | |
public start: any; | |
public width: any; | |
public table: any; | |
public tableline: any; | |
public tabledata: any; | |
public parser: any; | |
public nodelist: any; | |
public new_block: any; | |
public new_items: any; | |
public least: any; | |
public indents: any; | |
public text_nodes: any; | |
public block: any; | |
public data: any; | |
public option: any; | |
public firstopt: any; | |
public delimiter: any; | |
public tokens: any; | |
public optionstrings: any; | |
public optlist: any; | |
public option_list_item: any; | |
public description: any; | |
public option_group: any; | |
public options: any; | |
public optionlist: any; | |
public field_body: any; | |
public name_messages: any; | |
public name_nodes: any; | |
public field_node: any; | |
public srcline: any; | |
public src: any; | |
public name: any; | |
public field: any; | |
public field_list: any; | |
public formatinfo: any; | |
public enumerator: any; | |
public auto_enumerator: any; | |
public next_enumerator: any; | |
public result: any; | |
public next_line: any; | |
public groupdict: any; | |
public newline_offset: any; | |
public msg: any; | |
public enumlist: any; | |
public ordinal: any; | |
public sequence: any; | |
public format: any; | |
public listitem: any; | |
public offset: any; | |
public bulletlist: any; | |
public node: any; | |
public textnodes: any; | |
public lineno: any; | |
public text: any; | |
public i: any; | |
public a_lines: any; | |
public attribution_end: any; | |
public match: any; | |
public line: any; | |
public nonblank_seen: any; | |
public blank: any; | |
public attribution_pattern: any = re.compile(new Py.PyStr("(---?(?!-)|—) *(?=[^ \\n])"), re.UNICODE); | |
public messages: any; | |
public attribution: any; | |
public blockquote: any; | |
public new_line_offset: any; | |
public attribution_offset: any; | |
public attribution_lines: any; | |
public blockquote_lines: any; | |
public elements: any; | |
public blank_finish: any; | |
public line_offset: any; | |
public indent: any; | |
public indented: any; | |
public initial_transitions: any = new Py.PyTuple(new Py.PyStr("bullet"), new Py.PyStr("enumerator"), new Py.PyStr("field_marker"), new Py.PyStr("option_marker"), new Py.PyStr("doctest"), new Py.PyStr("line_block"), new Py.PyStr("grid_table_top"), new Py.PyStr("simple_table_top"), new Py.PyStr("explicit_markup"), new Py.PyStr("anonymous"), new Py.PyStr("line"), new Py.PyStr("text")); | |
public patterns: any = new Py.PyDict({ | |
"bullet": new Py.PyStr("[-+*•‣⁃]( +|$)"), | |
"enumerator": new Py.PyStr("(%(parens)s|%(rparen)s|%(period)s)( +|$)") % pats, | |
"field_marker": new Py.PyStr(":(?![: ])([^:\\\\]|\\\\.|:(?!([ `]|$)))*(?<! ):( +|$)"), | |
"option_marker": new Py.PyStr("%(option)s(, %(option)s)*( +| ?$)") % pats, | |
"doctest": new Py.PyStr(">>>( +|$)"), | |
"line_block": new Py.PyStr("\\|( +|$)"), | |
"grid_table_top": grid_table_top_pat, | |
"simple_table_top": simple_table_top_pat, | |
"explicit_markup": new Py.PyStr("\\.\\.( +|$)"), | |
"anonymous": new Py.PyStr("__( +|$)"), | |
"line": new Py.PyStr("(%(nonalphanum7bit)s)\\1* *$") % pats, | |
"text": new Py.PyStr("") | |
}); | |
public pats: any = new Py.PyDict({}); | |
public simple_table_border_pat: any = re.compile(new Py.PyStr("=+[ =]*$")); | |
public simple_table_top_pat: any = re.compile(new Py.PyStr("=+( +=+)+ *$")); | |
public grid_table_top_pat: any = re.compile(new Py.PyStr("\\+-[-+]+-\\+ *$")); | |
public enum: any = Struct(); | |
public double_width_pad_char: any = tableparser.TableParser.double_width_pad_char; | |
for(sequence, of): any { } | |
} | |
enum { | |
} | |
sequences; | |
{ | |
enum { | |
} | |
sequenceregexps[sequence] = re.compile(); | |
enum { | |
} | |
sequencepats[sequence] + new Py.PyStr("$"), re.UNICODE; | |
; | |
} | |
for (format of ) | |
enum { | |
} | |
formats; | |
{ | |
pats[format] = new Py.PyStr("(?P<%s>%s%s%s)") % new Py.PyTuple(format, re.escape()); | |
enum { | |
} | |
formatinfo[format].prefix; | |
pats[new Py.PyStr("enum")], | |
re.escape(); | |
enum { | |
} | |
formatinfo[format].suffix; | |
; | |
} | |
indent(match, context, next_state); | |
{ | |
let indented: any; | |
let indent: any; | |
let line_offset: any; | |
let blank_finish: any; | |
let elements: any; | |
this.state_machine.get_indented(); | |
elements = this.block_quote(indented, line_offset); | |
if (!blank_finish) { } | |
return new Py.PyTuple(context, next_state, new Py.PyArray()); | |
} | |
block_quote(indented, line_offset); | |
{ | |
let elements: any; | |
let blockquote_lines: any; | |
let attribution_lines: any; | |
let attribution_offset: any; | |
let new_line_offset: any; | |
let blockquote: any; | |
let attribution: any; | |
let messages: any; | |
elements = new Py.PyArray(); | |
return elements; | |
} | |
split_attribution(indented, line_offset); | |
{ | |
let blank: any; | |
let nonblank_seen: any; | |
let i: any; | |
let line: any; | |
let match: any; | |
let attribution_end: any; | |
let indent: any; | |
let a_lines: any; | |
blank = undefined; | |
nonblank_seen = false; | |
for (i of Py.range(Py.len(indented))) { | |
line = indented[i].rstrip(); | |
if (line) { | |
if (nonblank_seen && blank) { | |
match = this.attribution_pattern.match(line); | |
if (match) { | |
this.check_attribution(indented, i); | |
if (attribution_end) { | |
a_lines = indented.slice(i, attribution_end); | |
a_lines.trim_left(match.end()); | |
a_lines.trim_left(indent); | |
return new Py.PyTuple(indented.slice(undefined, i), a_lines, i, indented.slice(attribution_end, undefined), line_offset + attribution_end); | |
} | |
} | |
} | |
nonblank_seen = true; | |
} | |
else { | |
blank = i; | |
} | |
} | |
} | |
check_attribution(indented, attribution_start); | |
{ | |
let indent: any; | |
let i: any; | |
let line: any; | |
indent = undefined; | |
i = attribution_start + 1; | |
for (i of Py.range(attribution_start + 1, Py.len(indented))) { | |
line = indented[i].rstrip(); | |
if (!line) { } | |
if (indent) { | |
indent = Py.len(line) - Py.len(line.lstrip()); | |
} | |
else { | |
if (Py.len(line) - Py.len(line.lstrip())) { | |
return new Py.PyTuple(undefined, undefined); | |
} | |
} | |
} | |
return new Py.PyTuple(i, indent || 0); | |
} | |
parse_attribution(indented, line_offset); | |
{ | |
let text: any; | |
let lineno: any; | |
let textnodes: any; | |
let messages: any; | |
let node: any; | |
text = new Py.PyStr("\n").join(indented).rstrip(); | |
lineno = this.state_machine.abs_line_number() + line_offset; | |
this.inline_text(text, lineno); | |
node = nodes.attribution(text, new Py.PyStr(""), ...textnodes); | |
node.source = node.line = this.state_machine.get_source_and_line(lineno); | |
return new Py.PyTuple(node, messages); | |
} | |
bullet(match, context, next_state); | |
{ | |
let bulletlist: any; | |
let i: any; | |
let blank_finish: any; | |
let offset: any; | |
let new_line_offset: any; | |
bulletlist = nodes.bullet_list(); | |
bulletlist.source = bulletlist.line = this.state_machine.get_source_and_line(); | |
bulletlist[new Py.PyStr("bullet")] = match.string[0]; | |
this.list_item(match.end()); | |
offset = this.state_machine.line_offset + 1; | |
this.nested_list_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(new_line_offset); | |
if (!blank_finish) { } | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
list_item(indent); | |
{ | |
let indented: any; | |
let line_offset: any; | |
let blank_finish: any; | |
let listitem: any; | |
if (this.state_machine.line.slice(indent, undefined)) { | |
this.state_machine.get_known_indented(indent); | |
} | |
else { | |
this.state_machine.get_first_known_indented(indent); | |
} | |
listitem = nodes.list_item(new Py.PyStr("\n").join(indented)); | |
if (indented) { | |
this.nested_parse(indented); | |
} | |
return new Py.PyTuple(listitem, blank_finish); | |
} | |
enumerator(match, context, next_state); | |
{ | |
let format: any; | |
let sequence: any; | |
let text: any; | |
let ordinal: any; | |
let enumlist: any; | |
let msg: any; | |
let listitem: any; | |
let blank_finish: any; | |
let offset: any; | |
let newline_offset: any; | |
this.parse_enumerator(match); | |
if (!this.is_enumerated_list_item(ordinal, sequence, format)) { | |
throw statemachine.TransitionCorrection(new Py.PyStr("text")); | |
} | |
enumlist = nodes.enumerated_list(); | |
if (sequence) { | |
enumlist[new Py.PyStr("enumtype")] = new Py.PyStr("arabic"); | |
} | |
else { | |
enumlist[new Py.PyStr("enumtype")] = sequence; | |
} | |
enumlist[new Py.PyStr("prefix")] = this.enum.formatinfo[format].prefix; | |
enumlist[new Py.PyStr("suffix")] = this.enum.formatinfo[format].suffix; | |
if (ordinal) { | |
enumlist[new Py.PyStr("start")] = ordinal; | |
msg = this.reporter.info(new Py.PyStr("Enumerated list start value not ordinal-1: \"%s\" (ordinal %s)") % new Py.PyTuple(text, ordinal)); | |
} | |
this.list_item(match.end()); | |
offset = this.state_machine.line_offset + 1; | |
this.nested_list_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(newline_offset); | |
if (!blank_finish) { } | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
parse_enumerator(match, expected_sequence); | |
{ | |
let groupdict: any; | |
let sequence: any; | |
let format: any; | |
let text: any; | |
let ordinal: any; | |
groupdict = match.groupdict(); | |
sequence = new Py.PyStr(""); | |
for (format of this.enum.formats) { | |
if (groupdict[format]) { } | |
} | |
text = groupdict[format].slice(this.enum.formatinfo[format].start, this.enum.formatinfo[format].end); | |
if (text) { | |
sequence = new Py.PyStr("#"); | |
} | |
else { | |
if (expected_sequence) { | |
try { | |
if (this.enum.sequenceregexps[expected_sequence].match(text)) { | |
sequence = expected_sequence; | |
} | |
} | |
catch (___error: any) { | |
if (___error instanceof KeyError) { | |
throw ParserError(new Py.PyStr("unknown enumerator sequence: %s") % sequence); | |
} | |
} | |
} | |
else { | |
if (text) { | |
sequence = new Py.PyStr("lowerroman"); | |
} | |
else { | |
if (text) { | |
sequence = new Py.PyStr("upperroman"); | |
} | |
} | |
} | |
} | |
if (!sequence) { | |
for (sequence of this.enum.sequences) { | |
if (this.enum.sequenceregexps[sequence].match(text)) { } | |
} | |
} | |
if (sequence) { | |
ordinal = 1; | |
} | |
else { | |
try { | |
ordinal = this.enum.converters[sequence](text); | |
} | |
catch (___error: any) { | |
if (___error instanceof roman.InvalidRomanNumeralError) { | |
ordinal = undefined; | |
} | |
} | |
} | |
return new Py.PyTuple(format, sequence, text, ordinal); | |
} | |
is_enumerated_list_item(ordinal, sequence, format); | |
{ | |
let next_line: any; | |
let result: any; | |
let next_enumerator: any; | |
let auto_enumerator: any; | |
if (ordinal) { | |
return undefined; | |
} | |
try { | |
next_line = this.state_machine.next_line(); | |
} | |
catch (___error: any) { | |
if (___error instanceof EOFError) { | |
this.state_machine.previous_line(); | |
return 1; | |
} | |
} | |
if (!next_line.slice(undefined, 1).strip()) { | |
return 1; | |
} | |
result = this.make_enumerator(ordinal + 1, sequence, format); | |
if (result) { | |
result; | |
try { | |
if (next_line.startswith(next_enumerator) || next_line.startswith(auto_enumerator)) { | |
return 1; | |
} | |
} | |
catch (___error: any) { | |
if (___error instanceof TypeError) { } | |
} | |
} | |
return undefined; | |
} | |
make_enumerator(ordinal, sequence, format); | |
{ | |
let enumerator: any; | |
let formatinfo: any; | |
let next_enumerator: any; | |
let auto_enumerator: any; | |
if (sequence) { | |
enumerator = new Py.PyStr("#"); | |
} | |
else { | |
if (sequence) { | |
enumerator = Py.str(ordinal); | |
} | |
else { | |
if (sequence.endswith(new Py.PyStr("alpha"))) { | |
if (ordinal) { | |
return undefined; | |
} | |
enumerator = Py.chr(ordinal + Py.ord(new Py.PyStr("a")) - 1); | |
} | |
else { | |
if (sequence.endswith(new Py.PyStr("roman"))) { | |
try { | |
enumerator = roman.toRoman(ordinal); | |
} | |
catch (___error: any) { | |
if (___error instanceof roman.RomanError) { | |
return undefined; | |
} | |
} | |
} | |
else { | |
throw ParserError(new Py.PyStr("unknown enumerator sequence: \"%s\"") % sequence); | |
} | |
} | |
if (sequence.startswith(new Py.PyStr("lower"))) { | |
enumerator = enumerator.lower(); | |
} | |
else { | |
if (sequence.startswith(new Py.PyStr("upper"))) { | |
enumerator = enumerator.upper(); | |
} | |
else { | |
throw ParserError(new Py.PyStr("unknown enumerator sequence: \"%s\"") % sequence); | |
} | |
} | |
} | |
} | |
formatinfo = this.enum.formatinfo[format]; | |
next_enumerator = formatinfo.prefix + enumerator + formatinfo.suffix + new Py.PyStr(" "); | |
auto_enumerator = formatinfo.prefix + new Py.PyStr("#") + formatinfo.suffix + new Py.PyStr(" "); | |
return new Py.PyTuple(next_enumerator, auto_enumerator); | |
} | |
field_marker(match, context, next_state); | |
{ | |
let field_list: any; | |
let field: any; | |
let blank_finish: any; | |
let offset: any; | |
let newline_offset: any; | |
field_list = nodes.field_list(); | |
this.field(match); | |
offset = this.state_machine.line_offset + 1; | |
this.nested_list_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(newline_offset); | |
if (!blank_finish) { } | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
field(match); | |
{ | |
let name: any; | |
let src: any; | |
let srcline: any; | |
let lineno: any; | |
let indented: any; | |
let indent: any; | |
let line_offset: any; | |
let blank_finish: any; | |
let field_node: any; | |
let name_nodes: any; | |
let name_messages: any; | |
let field_body: any; | |
name = this.parse_field_marker(match); | |
this.state_machine.get_source_and_line(); | |
lineno = this.state_machine.abs_line_number(); | |
this.state_machine.get_first_known_indented(match.end()); | |
field_node = nodes.field(); | |
field_node.source = src; | |
field_node.line = srcline; | |
this.inline_text(name, lineno); | |
field_body = nodes.field_body(new Py.PyStr("\n").join(indented), ...name_messages); | |
if (indented) { | |
this.parse_field_body(indented, line_offset, field_body); | |
} | |
return new Py.PyTuple(field_node, blank_finish); | |
} | |
parse_field_marker(match); | |
{ | |
let field: any; | |
field = match.group().slice(1, undefined); | |
field = field.slice(undefined, field.rfind(new Py.PyStr(":"))); | |
return field; | |
} | |
parse_field_body(indented, offset, node); | |
{ | |
this.nested_parse(indented); | |
} | |
option_marker(match, context, next_state); | |
{ | |
let optionlist: any; | |
let listitem: any; | |
let blank_finish: any; | |
let error: any; | |
let msg: any; | |
let indented: any; | |
let indent: any; | |
let line_offset: any; | |
let elements: any; | |
let offset: any; | |
let newline_offset: any; | |
optionlist = nodes.option_list(); | |
optionlist.source = optionlist.line = this.state_machine.get_source_and_line(); | |
try { | |
this.option_list_item(match); | |
} | |
catch (___error: any) { | |
if (___error instanceof MarkupError) { | |
error = ___error; | |
msg = this.reporter.error(new Py.PyStr("Invalid option list marker: %s") % error); | |
this.state_machine.get_first_known_indented(match.end()); | |
elements = this.block_quote(indented, line_offset); | |
if (!blank_finish) { } | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
} | |
offset = this.state_machine.line_offset + 1; | |
this.nested_list_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(newline_offset); | |
if (!blank_finish) { } | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
option_list_item(match); | |
{ | |
let offset: any; | |
let options: any; | |
let indented: any; | |
let indent: any; | |
let line_offset: any; | |
let blank_finish: any; | |
let option_group: any; | |
let description: any; | |
let option_list_item: any; | |
offset = this.state_machine.abs_line_offset(); | |
options = this.parse_option_marker(match); | |
this.state_machine.get_first_known_indented(match.end()); | |
if (!indented) { | |
this.goto_line(offset); | |
throw statemachine.TransitionCorrection(new Py.PyStr("text")); | |
} | |
option_group = nodes.option_group(new Py.PyStr(""), ...options); | |
description = nodes.description(new Py.PyStr("\n").join(indented)); | |
option_list_item = nodes.option_list_item(new Py.PyStr(""), option_group, description); | |
if (indented) { | |
this.nested_parse(indented); | |
} | |
return new Py.PyTuple(option_list_item, blank_finish); | |
} | |
parse_option_marker(match); | |
{ | |
let optlist: any; | |
let optionstrings: any; | |
let optionstring: any; | |
let tokens: any; | |
let delimiter: any; | |
let firstopt: any; | |
let option: any; | |
optlist = new Py.PyArray(); | |
optionstrings = match.group().rstrip().split(new Py.PyStr(", ")); | |
for (optionstring of optionstrings) { | |
tokens = optionstring.split(); | |
delimiter = new Py.PyStr(" "); | |
firstopt = tokens[0].split(new Py.PyStr("="), 1); | |
if (Py.len(firstopt)) { | |
tokens.slice(undefined, 1) = firstopt; | |
delimiter = new Py.PyStr("="); | |
} | |
else { | |
if (Py.len(tokens[0]) && (tokens[0].startswith(new Py.PyStr("-")) && !tokens[0].startswith(new Py.PyStr("--")) || tokens[0].startswith(new Py.PyStr("+")))) { | |
tokens.slice(undefined, 1) = new Py.PyArray(tokens[0].slice(undefined, 2), tokens[0].slice(2, undefined)); | |
delimiter = new Py.PyStr(""); | |
} | |
} | |
if (Py.len(tokens) && (tokens[1].startswith(new Py.PyStr("<")) && tokens[tokens.length + -1].endswith(new Py.PyStr(">")))) { | |
tokens.slice(1, undefined) = new Py.PyArray(new Py.PyStr(" ").join(tokens.slice(1, undefined))); | |
} | |
if (0) { | |
option = nodes.option(optionstring); | |
if (Py.len(tokens)) { } | |
optlist.append(option); | |
} | |
else { | |
throw MarkupError(new Py.PyStr("wrong number of option tokens (=%s), should be 1 or 2: \"%s\"") % new Py.PyTuple(Py.len(tokens), optionstring)); | |
} | |
} | |
return optlist; | |
} | |
doctest(match, context, next_state); | |
{ | |
let data: any; | |
data = new Py.PyStr("\n").join(this.state_machine.get_text_block()); | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
line_block(match, context, next_state); | |
{ | |
let block: any; | |
let lineno: any; | |
let line: any; | |
let messages: any; | |
let blank_finish: any; | |
let offset: any; | |
let new_line_offset: any; | |
block = nodes.line_block(); | |
lineno = this.state_machine.abs_line_number(); | |
this.line_block_line(match, lineno); | |
if (!blank_finish) { | |
offset = this.state_machine.line_offset + 1; | |
this.nested_list_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(new_line_offset); | |
} | |
if (!blank_finish) { } | |
if (Py.len(block)) { | |
if (block[0].indent) { | |
block[0].indent = 0; | |
} | |
this.nest_line_block_lines(block); | |
} | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
line_block_line(match, lineno); | |
{ | |
let indented: any; | |
let indent: any; | |
let line_offset: any; | |
let blank_finish: any; | |
let text: any; | |
let text_nodes: any; | |
let messages: any; | |
let line: any; | |
this.state_machine.get_first_known_indented(match.end()); | |
text = new Py.PyStr("\n").join(indented); | |
this.inline_text(text, lineno); | |
line = nodes.line(text, new Py.PyStr(""), ...text_nodes); | |
if (match.string.rstrip()) { | |
line.indent = Py.len(match.group(1)) - 1; | |
} | |
return new Py.PyTuple(line, messages, blank_finish); | |
} | |
nest_line_block_lines(block); | |
{ | |
let index: any; | |
for (index of Py.range(1, Py.len(block))) { | |
if (Py.getattr(block[index], new Py.PyStr("indent"), undefined)) { | |
block[index].indent = block[index - 1].indent; | |
} | |
} | |
this.nest_line_block_segment(block); | |
} | |
nest_line_block_segment(block); | |
{ | |
let indents: any; | |
let least: any; | |
let new_items: any; | |
let new_block: any; | |
let item: any; | |
indents = block.map(item => item.indent); | |
least = Py.min(indents); | |
new_items = new Py.PyArray(); | |
new_block = nodes.line_block(); | |
for (item of block) { | |
if (item.indent) { | |
new_block.append(item); | |
} | |
else { | |
if (Py.len(new_block)) { | |
this.nest_line_block_segment(new_block); | |
new_items.append(new_block); | |
new_block = nodes.line_block(); | |
} | |
new_items.append(item); | |
} | |
} | |
if (Py.len(new_block)) { | |
this.nest_line_block_segment(new_block); | |
new_items.append(new_block); | |
} | |
block.slice(undefined, undefined) = new_items; | |
} | |
grid_table_top(match, context, next_state); | |
{ | |
return this.table_top(match, context, next_state, this.isolate_grid_table, tableparser.GridTableParser); | |
} | |
simple_table_top(match, context, next_state); | |
{ | |
return this.table_top(match, context, next_state, this.isolate_simple_table, tableparser.SimpleTableParser); | |
} | |
table_top(match, context, next_state, isolate_function, parser_class); | |
{ | |
let nodelist: any; | |
let blank_finish: any; | |
let msg: any; | |
this.table(isolate_function, parser_class); | |
if (!blank_finish) { | |
msg = this.reporter.warning(new Py.PyStr("Blank line required after table.")); | |
} | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
table(isolate_function, parser_class); | |
{ | |
let block: any; | |
let messages: any; | |
let blank_finish: any; | |
let parser: any; | |
let tabledata: any; | |
let tableline: any; | |
let table: any; | |
let nodelist: any; | |
let err: any; | |
isolate_function(); | |
if (block) { | |
try { | |
parser = parser_class(); | |
tabledata = parser.parse(block); | |
tableline = this.state_machine.abs_line_number() - Py.len(block) + 1; | |
table = this.build_table(tabledata, tableline); | |
nodelist = new Py.PyArray(table) + messages; | |
} | |
catch (___error: any) { | |
if (___error instanceof tableparser.TableMarkupError) { | |
err = ___error; | |
nodelist = this.malformed_table(block, new Py.PyStr(" ").join(err.args)) + messages; | |
} | |
} | |
} | |
else { | |
nodelist = messages; | |
} | |
return new Py.PyTuple(nodelist, blank_finish); | |
} | |
isolate_grid_table(); | |
{ | |
let messages: any; | |
let blank_finish: any; | |
let block: any; | |
let err: any; | |
let src: any; | |
let srcline: any; | |
let width: any; | |
let i: any; | |
messages = new Py.PyArray(); | |
blank_finish = 1; | |
try { | |
block = this.state_machine.get_text_block(); | |
} | |
catch (___error: any) { | |
if (___error instanceof statemachine.UnexpectedIndentationError) { | |
err = ___error; | |
err.args; | |
messages.append(this.reporter.error(new Py.PyStr("Unexpected indentation."))); | |
blank_finish = 0; | |
} | |
} | |
block.disconnect(); | |
block.pad_double_width(this.double_width_pad_char); | |
width = Py.len(block[0].strip()); | |
for (i of Py.range(Py.len(block))) { | |
block[i] = block[i].strip(); | |
if (block[i][0]) { | |
blank_finish = 0; | |
this.state_machine.previous_line(Py.len(block) - i); | |
} | |
} | |
if (!this.grid_table_top_pat.match(block[block.length + -1])) { | |
blank_finish = 0; | |
for (i of Py.range(Py.len(block) - 2, 1, -1)) { | |
if (this.grid_table_top_pat.match(block[i])) { | |
this.state_machine.previous_line(Py.len(block) - i + 1); | |
} | |
} | |
} | |
for (i of Py.range(Py.len(block))) { | |
if (Py.len(block[i]) || block[i][block[i].length + -1]) { | |
messages.extend(this.malformed_table(block)); | |
return new Py.PyTuple(new Py.PyArray(), messages, blank_finish); | |
} | |
} | |
return new Py.PyTuple(block, messages, blank_finish); | |
} | |
isolate_simple_table(); | |
{ | |
let start: any; | |
let lines: any; | |
let limit: any; | |
let toplen: any; | |
let pattern_match: any; | |
let found: any; | |
let found_at: any; | |
let i: any; | |
let line: any; | |
let match: any; | |
let messages: any; | |
let end: any; | |
let extra: any; | |
let block: any; | |
start = this.state_machine.line_offset; | |
lines = this.state_machine.input_lines; | |
limit = Py.len(lines) - 1; | |
toplen = Py.len(lines[start].strip()); | |
pattern_match = this.simple_table_border_pat.match; | |
found = 0; | |
found_at = undefined; | |
i = start + 1; | |
this.state_machine.next_line(end - start); | |
block = lines.slice(start, end + 1); | |
block.pad_double_width(this.double_width_pad_char); | |
return new Py.PyTuple(block, new Py.PyArray(), end || !lines[end + 1].strip()); | |
} | |
malformed_table(block, detail, offset); | |
{ | |
let data: any; | |
let message: any; | |
let startline: any; | |
let error: any; | |
block.replace(this.double_width_pad_char, new Py.PyStr("")); | |
data = new Py.PyStr("\n").join(block); | |
message = new Py.PyStr("Malformed table."); | |
startline = this.state_machine.abs_line_number() - Py.len(block) + 1; | |
if (detail) { } | |
error = this.reporter.error(message, nodes.literal_block(data, data)); | |
return new Py.PyArray(error); | |
} | |
build_table(tabledata, tableline, stub_columns, widths); | |
{ | |
let colwidths: any; | |
let headrows: any; | |
let bodyrows: any; | |
let table: any; | |
let tgroup: any; | |
let colwidth: any; | |
let colspec: any; | |
let thead: any; | |
let row: any; | |
let tbody: any; | |
tabledata; | |
table = nodes.table(); | |
if (widths) { } | |
else { | |
if (widths) { } | |
} | |
tgroup = nodes.tgroup(); | |
for (colwidth of colwidths) { | |
colspec = nodes.colspec(); | |
if (stub_columns) { | |
colspec.attributes[new Py.PyStr("stub")] = 1; | |
} | |
} | |
if (headrows) { | |
thead = nodes.thead(); | |
for (row of headrows) { } | |
} | |
tbody = nodes.tbody(); | |
for (row of bodyrows) { } | |
return table; | |
} | |
build_table_row(rowdata, tableline); | |
{ | |
let row: any; | |
let cell: any; | |
let morerows: any; | |
let morecols: any; | |
let offset: any; | |
let cellblock: any; | |
let attributes: any; | |
let entry: any; | |
row = nodes.row(); | |
for (cell of rowdata) { | |
if (cell) { } | |
cell; | |
attributes = new Py.PyDict({}); | |
if (morerows) { | |
attributes[new Py.PyStr("morerows")] = morerows; | |
} | |
if (morecols) { | |
attributes[new Py.PyStr("morecols")] = morecols; | |
} | |
entry = nodes.entry(); | |
if (new Py.PyStr("").join(cellblock)) { | |
this.nested_parse(cellblock); | |
} | |
} | |
return row; | |
} | |
footnote(match); | |
{ | |
let src: any; | |
let srcline: any; | |
let indented: any; | |
let indent: any; | |
let offset: any; | |
let blank_finish: any; | |
let label: any; | |
let name: any; | |
let footnote: any; | |
this.state_machine.get_source_and_line(); | |
this.state_machine.get_first_known_indented(match.end()); | |
label = match.group(1); | |
name = normalize_name(label); | |
footnote = nodes.footnote(new Py.PyStr("\n").join(indented)); | |
footnote.source = src; | |
footnote.line = srcline; | |
if (name[0]) { | |
name = name.slice(1, undefined); | |
footnote[new Py.PyStr("auto")] = 1; | |
if (name) { | |
footnote[new Py.PyStr("names")].append(name); | |
} | |
this.document.note_autofootnote(footnote); | |
} | |
else { | |
if (name) { | |
name = new Py.PyStr(""); | |
footnote[new Py.PyStr("auto")] = new Py.PyStr("*"); | |
this.document.note_symbol_footnote(footnote); | |
} | |
else { | |
footnote[new Py.PyStr("names")].append(name); | |
this.document.note_footnote(footnote); | |
} | |
} | |
if (name) { | |
this.document.note_explicit_target(footnote, footnote); | |
} | |
else { | |
this.document.set_id(footnote, footnote); | |
} | |
if (indented) { | |
this.nested_parse(indented); | |
} | |
return new Py.PyTuple(new Py.PyArray(footnote), blank_finish); | |
} | |
citation(match); | |
{ | |
let src: any; | |
let srcline: any; | |
let indented: any; | |
let indent: any; | |
let offset: any; | |
let blank_finish: any; | |
let label: any; | |
let name: any; | |
let citation: any; | |
this.state_machine.get_source_and_line(); | |
this.state_machine.get_first_known_indented(match.end()); | |
label = match.group(1); | |
name = normalize_name(label); | |
citation = nodes.citation(new Py.PyStr("\n").join(indented)); | |
citation.source = src; | |
citation.line = srcline; | |
citation[new Py.PyStr("names")].append(name); | |
this.document.note_citation(citation); | |
this.document.note_explicit_target(citation, citation); | |
if (indented) { | |
this.nested_parse(indented); | |
} | |
return new Py.PyTuple(new Py.PyArray(citation), blank_finish); | |
} | |
hyperlink_target(match); | |
{ | |
let pattern: any; | |
let lineno: any; | |
let block: any; | |
let indent: any; | |
let offset: any; | |
let blank_finish: any; | |
let blocktext: any; | |
let escaped: any; | |
let blockindex: any; | |
let targetmatch: any; | |
let target: any; | |
pattern = this.explicit.patterns.target; | |
lineno = this.state_machine.abs_line_number(); | |
this.state_machine.get_first_known_indented(match.end()); | |
blocktext = match.string.slice(undefined, match.end()) + new Py.PyStr("\n").join(block); | |
block = block.map(line => escape2null(line)); | |
escaped = block[0]; | |
blockindex = 0; | |
block[0] = (block[0] + new Py.PyStr(" ")).slice(targetmatch.end() - Py.len(escaped) - 1, undefined).strip(); | |
target = this.make_target(block, blocktext, lineno, targetmatch.group(new Py.PyStr("name"))); | |
return new Py.PyTuple(new Py.PyArray(target), blank_finish); | |
} | |
make_target(block, block_text, lineno, target_name); | |
{ | |
let target_type: any; | |
let data: any; | |
let target: any; | |
this.parse_target(block, block_text, lineno); | |
if (target_type) { | |
target = nodes.target(block_text, new Py.PyStr("")); | |
target.indirect_reference_name = data; | |
this.add_target(target_name, new Py.PyStr(""), target, lineno); | |
this.document.note_indirect_target(target); | |
return target; | |
} | |
else { | |
if (target_type) { | |
target = nodes.target(block_text, new Py.PyStr("")); | |
this.add_target(target_name, data, target, lineno); | |
return target; | |
} | |
else { | |
return data; | |
} | |
} | |
} | |
parse_target(block, block_text, lineno); | |
{ | |
let reference: any; | |
let refname: any; | |
let ref_parts: any; | |
if (block && block[block.length + -1].strip().slice(-1, undefined)) { | |
reference = new Py.PyStr(" ").join(block.map(line => line.strip())); | |
refname = this.is_reference(reference); | |
if (refname) { | |
return new Py.PyTuple(new Py.PyStr("refname"), refname); | |
} | |
} | |
ref_parts = split_escaped_whitespace(new Py.PyStr(" ").join(block)); | |
reference = new Py.PyStr(" ").join(ref_parts.map(part => new Py.PyStr("").join(unescape(part).split()))); | |
return new Py.PyTuple(new Py.PyStr("refuri"), reference); | |
} | |
is_reference(reference); | |
{ | |
let match: any; | |
match = this.explicit.patterns.reference.match(whitespace_normalize_name(reference)); | |
if (!match) { | |
return undefined; | |
} | |
return unescape(match.group(new Py.PyStr("simple")) || match.group(new Py.PyStr("phrase"))); | |
} | |
add_target(targetname, refuri, target, lineno); | |
{ | |
let name: any; | |
let uri: any; | |
target.line = lineno; | |
if (targetname) { | |
name = normalize_name(unescape(targetname)); | |
target[new Py.PyStr("names")].append(name); | |
if (refuri) { | |
uri = this.inliner.adjust_uri(refuri); | |
if (uri) { | |
target[new Py.PyStr("refuri")] = uri; | |
} | |
else { | |
throw ApplicationError(new Py.PyStr("problem with URI: %r") % refuri); | |
} | |
} | |
this.document.note_explicit_target(target, this.parent); | |
} | |
else { | |
if (refuri) { | |
target[new Py.PyStr("refuri")] = refuri; | |
} | |
target[new Py.PyStr("anonymous")] = 1; | |
this.document.note_anonymous_target(target); | |
} | |
} | |
substitution_def(match); | |
{ | |
let pattern: any; | |
let src: any; | |
let srcline: any; | |
let block: any; | |
let indent: any; | |
let offset: any; | |
let blank_finish: any; | |
let blocktext: any; | |
let escaped: any; | |
let blockindex: any; | |
let subdefmatch: any; | |
let subname: any; | |
let substitution_node: any; | |
let msg: any; | |
let new_abs_offset: any; | |
let i: any; | |
let node: any; | |
let pformat: any; | |
pattern = this.explicit.patterns.substitution; | |
this.state_machine.get_source_and_line(); | |
this.state_machine.get_first_known_indented(match.end()); | |
blocktext = match.string.slice(undefined, match.end()) + new Py.PyStr("\n").join(block); | |
block.disconnect(); | |
escaped = escape2null(block[0].rstrip()); | |
blockindex = 0; | |
block[0] = (block[0].strip() + new Py.PyStr(" ")).slice(subdefmatch.end() - Py.len(escaped) - 1, -1); | |
if (!block[0]) { } | |
subname = subdefmatch.group(new Py.PyStr("name")); | |
substitution_node = nodes.substitution_definition(blocktext); | |
substitution_node.source = src; | |
substitution_node.line = srcline; | |
if (!block) { | |
msg = this.reporter.warning(new Py.PyStr("Substitution definition \"%s\" missing contents.") % subname, nodes.literal_block(blocktext, blocktext)); | |
return new Py.PyTuple(new Py.PyArray(msg), blank_finish); | |
} | |
block[0] = block[0].strip(); | |
substitution_node[new Py.PyStr("names")].append(nodes.whitespace_normalize_name(subname)); | |
this.nested_list_parse(block); | |
i = 0; | |
for (node of substitution_node.slice(undefined, undefined)) { | |
if (!(Py.isinstance(node, nodes.Inline) || Py.isinstance(node, nodes.Text))) { } | |
} | |
for (node of substitution_node.traverse(nodes.Element)) { | |
if (this.disallowed_inside_substitution_definitions(node)) { | |
pformat = nodes.literal_block(new Py.PyStr(""), node.pformat().rstrip()); | |
msg = this.reporter.error(new Py.PyStr("Substitution definition contains illegal element <%s>:") % node.tagname, pformat, nodes.literal_block(blocktext, blocktext)); | |
return new Py.PyTuple(new Py.PyArray(msg), blank_finish); | |
} | |
} | |
if (Py.len(substitution_node)) { | |
msg = this.reporter.warning(new Py.PyStr("Substitution definition \"%s\" empty or invalid.") % subname, nodes.literal_block(blocktext, blocktext)); | |
return new Py.PyTuple(new Py.PyArray(msg), blank_finish); | |
} | |
this.document.note_substitution_def(substitution_node, subname, this.parent); | |
return new Py.PyTuple(new Py.PyArray(substitution_node), blank_finish); | |
} | |
disallowed_inside_substitution_definitions(node); | |
{ | |
if (node[new Py.PyStr("ids")] || Py.isinstance(node, nodes.reference) && node.get(new Py.PyStr("anonymous")) || Py.isinstance(node, nodes.footnote_reference) && node.get(new Py.PyStr("auto"))) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
directive(match); | |
{ | |
let type_name: any; | |
let directive_class: any; | |
let messages: any; | |
type_name = match.group(1); | |
directives.directive(type_name, this.memo.language, this.document); | |
if (directive_class) { | |
return this.run_directive(directive_class, match, type_name, option_presets); | |
} | |
else { | |
return this.unknown_directive(type_name); | |
} | |
} | |
run_directive(directive, match, type_name, option_presets); | |
{ | |
let convert_directive_function: any; | |
let lineno: any; | |
let initial_line_offset: any; | |
let indented: any; | |
let indent: any; | |
let line_offset: any; | |
let blank_finish: any; | |
let block_text: any; | |
let _Body___arguments: any; | |
let options: any; | |
let content: any; | |
let content_offset: any; | |
let detail: any; | |
let error: any; | |
let directive_instance: any; | |
let result: any; | |
let msg_node: any; | |
let i: any; | |
if (Py.isinstance(directive, new Py.PyTuple(FunctionType, MethodType))) { | |
directive = convert_directive_function(directive); | |
} | |
lineno = this.state_machine.abs_line_number(); | |
initial_line_offset = this.state_machine.line_offset; | |
this.state_machine.get_first_known_indented(match.end()); | |
block_text = new Py.PyStr("\n").join(this.state_machine.input_lines.slice(initial_line_offset, this.state_machine.line_offset + 1)); | |
try { | |
this.parse_directive_block(indented, line_offset, directive, option_presets); | |
} | |
catch (___error: any) { | |
if (___error instanceof MarkupError) { | |
detail = ___error; | |
error = this.reporter.error(new Py.PyStr("Error in \"%s\" directive:\n%s.") % new Py.PyTuple(type_name, new Py.PyStr(" ").join(detail.args)), nodes.literal_block(block_text, block_text)); | |
return new Py.PyTuple(new Py.PyArray(error), blank_finish); | |
} | |
} | |
directive_instance = directive(type_name, ___arguments, options, content, lineno, content_offset, block_text, this, this.state_machine); | |
try { | |
result = directive_instance.run(); | |
} | |
catch (___error: any) { | |
if (___error instanceof docutils.parsers.rst.DirectiveError) { | |
error = ___error; | |
msg_node = this.reporter.system_message(error.level, error.msg); | |
result = new Py.PyArray(msg_node); | |
} | |
} | |
for (i of Py.range(Py.len(result))) { } | |
return new Py.PyTuple(result, blank_finish || this.state_machine.is_next_line_blank()); | |
} | |
parse_directive_block(indented, line_offset, directive, option_presets); | |
{ | |
let option_spec: any; | |
let has_content: any; | |
let i: any; | |
let line: any; | |
let arg_block: any; | |
let content: any; | |
let content_offset: any; | |
let options: any; | |
let _Body___arguments: any; | |
option_spec = directive.option_spec; | |
has_content = directive.has_content; | |
if (indented && !indented[0].strip()) { | |
indented.trim_start(); | |
} | |
if (indented && (directive.required_arguments || directive.optional_arguments || option_spec)) { | |
for ([i, line] of Py.enumerate(indented)) { | |
if (!line.strip()) { } | |
} | |
arg_block = indented.slice(undefined, i); | |
content = indented.slice(i + 1, undefined); | |
content_offset = line_offset + i + 1; | |
} | |
else { | |
content = indented; | |
content_offset = line_offset; | |
arg_block = new Py.PyArray(); | |
} | |
if (option_spec) { | |
this.parse_directive_options(option_presets, option_spec, arg_block); | |
} | |
else { | |
options = new Py.PyDict({}); | |
} | |
if (arg_block && !(directive.required_arguments || directive.optional_arguments)) { | |
content = arg_block + indented.slice(i, undefined); | |
content_offset = line_offset; | |
arg_block = new Py.PyArray(); | |
} | |
if (directive.required_arguments || directive.optional_arguments) { | |
___arguments = this.parse_directive_arguments(directive, arg_block); | |
} | |
else { | |
___arguments = new Py.PyArray(); | |
} | |
if (content && !has_content) { | |
throw MarkupError(new Py.PyStr("no content permitted")); | |
} | |
return new Py.PyTuple(___arguments, options, content, content_offset); | |
} | |
parse_directive_options(option_presets, option_spec, arg_block); | |
{ | |
let options: any; | |
let i: any; | |
let line: any; | |
let opt_block: any; | |
let success: any; | |
let data: any; | |
options = option_presets.copy(); | |
for ([i, line] of Py.enumerate(arg_block)) { | |
if (re.match(Body.patterns[new Py.PyStr("field_marker")], line)) { | |
opt_block = arg_block.slice(i, undefined); | |
arg_block = arg_block.slice(undefined, i); | |
} | |
} | |
if (opt_block) { | |
this.parse_extension_options(option_spec, opt_block); | |
if (success) { | |
options.update(data); | |
} | |
else { | |
throw MarkupError(data); | |
} | |
} | |
return new Py.PyTuple(options, arg_block); | |
} | |
parse_directive_arguments(directive, arg_block); | |
{ | |
let required: any; | |
let optional: any; | |
let arg_text: any; | |
let _Body___arguments: any; | |
required = directive.required_arguments; | |
optional = directive.optional_arguments; | |
arg_text = new Py.PyStr("\n").join(arg_block); | |
___arguments = arg_text.split(); | |
if (Py.len(___arguments)) { | |
throw MarkupError(new Py.PyStr("%s argument(s) required, %s supplied") % new Py.PyTuple(required, Py.len(___arguments))); | |
} | |
else { | |
if (Py.len(___arguments)) { | |
if (directive.final_argument_whitespace) { | |
___arguments = arg_text.split(undefined, required + optional - 1); | |
} | |
else { | |
throw MarkupError(new Py.PyStr("maximum %s argument(s) allowed, %s supplied") % new Py.PyTuple(required + optional, Py.len(___arguments))); | |
} | |
} | |
} | |
return ___arguments; | |
} | |
parse_extension_options(option_spec, datalines); | |
{ | |
let node: any; | |
let newline_offset: any; | |
let blank_finish: any; | |
let options: any; | |
let detail: any; | |
node = nodes.field_list(); | |
this.nested_list_parse(datalines, 0, node); | |
if (newline_offset) { | |
return new Py.PyTuple(0, new Py.PyStr("invalid option block")); | |
} | |
try { | |
options = utils.extract_extension_options(node, option_spec); | |
} | |
catch (___error: any) { | |
if (___error instanceof KeyError) { | |
detail = ___error; | |
return new Py.PyTuple(0, new Py.PyStr("unknown option: \"%s\"") % detail.args[0]); | |
} | |
else if (___error instanceof new Py.PyTuple(ValueError, TypeError)) { | |
detail = ___error; | |
return new Py.PyTuple(0, new Py.PyStr("invalid option value: %s") % new Py.PyStr(" ").join(detail.args)); | |
} | |
else if (___error instanceof utils.ExtensionOptionError) { | |
detail = ___error; | |
return new Py.PyTuple(0, new Py.PyStr("invalid option data: %s") % new Py.PyStr(" ").join(detail.args)); | |
} | |
} | |
if (blank_finish) { | |
return new Py.PyTuple(1, options); | |
} | |
else { | |
return new Py.PyTuple(0, new Py.PyStr("option data incompletely parsed")); | |
} | |
} | |
unknown_directive(type_name); | |
{ | |
let lineno: any; | |
let indented: any; | |
let indent: any; | |
let offset: any; | |
let blank_finish: any; | |
let text: any; | |
let error: any; | |
lineno = this.state_machine.abs_line_number(); | |
this.state_machine.get_first_known_indented(0); | |
text = new Py.PyStr("\n").join(indented); | |
error = this.reporter.error(new Py.PyStr("Unknown directive type \"%s\".") % type_name, nodes.literal_block(text, text)); | |
return new Py.PyTuple(new Py.PyArray(error), blank_finish); | |
} | |
comment(match); | |
{ | |
let indented: any; | |
let indent: any; | |
let offset: any; | |
let blank_finish: any; | |
let text: any; | |
if (!match.string.slice(match.end(), undefined).strip() && this.state_machine.is_next_line_blank()) { | |
return new Py.PyTuple(new Py.PyArray(nodes.comment()), 1); | |
} | |
this.state_machine.get_first_known_indented(match.end()); | |
text = new Py.PyStr("\n").join(indented); | |
return new Py.PyTuple(new Py.PyArray(nodes.comment(text, text)), blank_finish); | |
} | |
explicit_markup(match, context, next_state); | |
{ | |
let nodelist: any; | |
let blank_finish: any; | |
this.explicit_construct(match); | |
this.explicit_list(blank_finish); | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
explicit_construct(match); | |
{ | |
let errors: any; | |
let method: any; | |
let pattern: any; | |
let expmatch: any; | |
let error: any; | |
let lineno: any; | |
let message: any; | |
let nodelist: any; | |
let blank_finish: any; | |
errors = new Py.PyArray(); | |
for ([method, pattern] of this.explicit.constructs) { | |
expmatch = pattern.match(match.string); | |
if (expmatch) { | |
try { | |
return method(this, expmatch); | |
} | |
catch (___error: any) { | |
if (___error instanceof MarkupError) { | |
error = ___error; | |
lineno = this.state_machine.abs_line_number(); | |
message = new Py.PyStr(" ").join(error.args); | |
errors.append(this.reporter.warning(message)); | |
} | |
} | |
} | |
} | |
this.comment(match); | |
return new Py.PyTuple(nodelist + errors, blank_finish); | |
} | |
explicit_list(blank_finish); | |
{ | |
let offset: any; | |
let newline_offset: any; | |
offset = this.state_machine.line_offset + 1; | |
this.nested_list_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(newline_offset); | |
if (!blank_finish) { } | |
} | |
anonymous(match, context, next_state); | |
{ | |
let nodelist: any; | |
let blank_finish: any; | |
this.anonymous_target(match); | |
this.explicit_list(blank_finish); | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
anonymous_target(match); | |
{ | |
let lineno: any; | |
let block: any; | |
let indent: any; | |
let offset: any; | |
let blank_finish: any; | |
let blocktext: any; | |
let target: any; | |
lineno = this.state_machine.abs_line_number(); | |
this.state_machine.get_first_known_indented(match.end()); | |
blocktext = match.string.slice(undefined, match.end()) + new Py.PyStr("\n").join(block); | |
block = block.map(line => escape2null(line)); | |
target = this.make_target(block, blocktext, lineno, new Py.PyStr("")); | |
return new Py.PyTuple(new Py.PyArray(target), blank_finish); | |
} | |
line(match, context, next_state); | |
{ | |
let msg: any; | |
let blocktext: any; | |
if (this.state_machine.match_titles) { | |
return new Py.PyTuple(new Py.PyArray(match.string), new Py.PyStr("Line"), new Py.PyArray()); | |
} | |
else { | |
if (match.string.strip()) { | |
throw statemachine.TransitionCorrection(new Py.PyStr("text")); | |
} | |
else { | |
if (Py.len(match.string.strip())) { | |
msg = this.reporter.info(new Py.PyStr("Unexpected possible title overline or transition.\nTreating it as ordinary text because it's so short.")); | |
throw statemachine.TransitionCorrection(new Py.PyStr("text")); | |
} | |
else { | |
blocktext = this.state_machine.line; | |
msg = this.reporter.severe(new Py.PyStr("Unexpected section title or transition."), nodes.literal_block(blocktext, blocktext)); | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
} | |
} | |
} | |
text(match, context, next_state); | |
{ | |
return new Py.PyTuple(new Py.PyArray(match.string), new Py.PyStr("Text"), new Py.PyArray()); | |
} | |
class RFC2822Body extends Body { | |
public fieldbody: any; | |
public fieldnode: any; | |
public line_offset: any; | |
public indent: any; | |
public indented: any; | |
public name: any; | |
public newline_offset: any; | |
public offset: any; | |
public blank_finish: any; | |
public field: any; | |
public fieldlist: any; | |
public initial_transitions: any = Body.initial_transitions.map(name => new Py.PyTuple(name, new Py.PyStr("Body"))); | |
public patterns: any = Body.patterns.copy(); | |
initial_transitions: any; | |
insert(): any { } | |
} | |
-1, new Py.PyTuple(new Py.PyStr("rfc2822"), new Py.PyStr("Body")); | |
; | |
rfc2822(match, context, next_state); | |
{ | |
let fieldlist: any; | |
let field: any; | |
let blank_finish: any; | |
let offset: any; | |
let newline_offset: any; | |
fieldlist = nodes.field_list(); | |
this.rfc2822_field(match); | |
offset = this.state_machine.line_offset + 1; | |
this.nested_list_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(newline_offset); | |
if (!blank_finish) { } | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
rfc2822_field(match); | |
{ | |
let name: any; | |
let indented: any; | |
let indent: any; | |
let line_offset: any; | |
let blank_finish: any; | |
let fieldnode: any; | |
let fieldbody: any; | |
name = match.string.slice(undefined, match.string.find(new Py.PyStr(":"))); | |
this.state_machine.get_first_known_indented(match.end()); | |
fieldnode = nodes.field(); | |
fieldbody = nodes.field_body(new Py.PyStr("\n").join(indented)); | |
if (indented) { | |
this.nested_parse(indented); | |
} | |
return new Py.PyTuple(fieldnode, blank_finish); | |
} | |
class SpecializedBody extends Body { | |
public text: any = invalid_input; | |
public line: any = invalid_input; | |
public anonymous: any = invalid_input; | |
public explicit_markup: any = invalid_input; | |
public simple_table_top: any = invalid_input; | |
public grid_table_top: any = invalid_input; | |
public line_block: any = invalid_input; | |
public doctest: any = invalid_input; | |
public option_marker: any = invalid_input; | |
public field_marker: any = invalid_input; | |
public enumerator: any = invalid_input; | |
public bullet: any = invalid_input; | |
public indent: any = invalid_input; | |
public invalid_input(match, context, next_state): void { | |
this.state_machine.previous_line(); | |
throw EOFError; | |
} | |
} | |
class BulletList extends SpecializedBody { | |
public blank_finish: any; | |
public listitem: any; | |
public bullet(match, context, next_state): PyTuple<any> { | |
let listitem; | |
let blank_finish; | |
if (match.string[0]) { | |
this.invalid_input(); | |
} | |
this.list_item(match.end()); | |
this.blank_finish = blank_finish; | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
} | |
class DefinitionList extends SpecializedBody { | |
public text(match, context, next_state): PyTuple<PyArray<any>> { | |
return new Py.PyTuple(new Py.PyArray(match.string), new Py.PyStr("Definition"), new Py.PyArray()); | |
} | |
} | |
class EnumeratedList extends SpecializedBody { | |
public lastordinal: any; | |
public blank_finish: any; | |
public listitem: any; | |
public auto: any; | |
public ordinal: any; | |
public text: any; | |
public sequence: any; | |
public format: any; | |
public enumerator(match, context, next_state): PyTuple<any> { | |
let format; | |
let sequence; | |
let text; | |
let ordinal; | |
let listitem; | |
let blank_finish; | |
this.parse_enumerator(match, this.parent[new Py.PyStr("enumtype")]); | |
if (format || sequence && (sequence || this.auto || ordinal) || !this.is_enumerated_list_item(ordinal, sequence, format)) { | |
this.invalid_input(); | |
} | |
if (sequence) { | |
this.auto = 1; | |
} | |
this.list_item(match.end()); | |
this.blank_finish = blank_finish; | |
this.lastordinal = ordinal; | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
} | |
class FieldList extends SpecializedBody { | |
public blank_finish: any; | |
public field: any; | |
public field_marker(match, context, next_state): PyTuple<any> { | |
let field; | |
let blank_finish; | |
this.field(match); | |
this.blank_finish = blank_finish; | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
} | |
class OptionList extends SpecializedBody { | |
public blank_finish: any; | |
public option_list_item: any; | |
public option_marker(match, context, next_state): PyTuple<any> { | |
let option_list_item; | |
let blank_finish; | |
try { | |
this.option_list_item(match); | |
} | |
catch (___error) { | |
if (___error instanceof MarkupError) { | |
this.invalid_input(); | |
} | |
} | |
this.blank_finish = blank_finish; | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
} | |
class RFC2822List extends SpecializedBody { | |
public blank: any = SpecializedBody.invalid_input; | |
public blank_finish: any; | |
public field: any; | |
public initial_transitions: any = RFC2822Body.initial_transitions; | |
public patterns: any = RFC2822Body.patterns; | |
public rfc2822(match, context, next_state): PyTuple<PyArray<unknown>> { | |
let field; | |
let blank_finish; | |
this.rfc2822_field(match); | |
this.blank_finish = blank_finish; | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("RFC2822List"), new Py.PyArray()); | |
} | |
} | |
class ExtensionOptions extends FieldList { | |
public text: any; | |
public lines: any; | |
public parse_field_body(indented, offset, node): void { | |
let lines; | |
let line; | |
let text; | |
lines = new Py.PyArray(); | |
for (line of Py.list(indented) + new Py.PyArray(new Py.PyStr(""))) { | |
if (line.strip()) { | |
lines.append(line); | |
} | |
else { | |
if (lines) { | |
text = new Py.PyStr("\n").join(lines); | |
lines = new Py.PyArray(); | |
} | |
} | |
} | |
} | |
} | |
class LineBlock extends SpecializedBody { | |
public blank_finish: any; | |
public messages: any; | |
public line: any; | |
public lineno: any; | |
public blank: any = SpecializedBody.invalid_input; | |
public line_block(match, context, next_state): PyTuple<any> { | |
let lineno; | |
let line; | |
let messages; | |
let blank_finish; | |
lineno = this.state_machine.abs_line_number(); | |
this.line_block_line(match, lineno); | |
this.blank_finish = blank_finish; | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
} | |
class Explicit extends SpecializedBody { | |
public blank: any = SpecializedBody.invalid_input; | |
public blank_finish: any; | |
public nodelist: any; | |
public explicit_markup(match, context, next_state): PyTuple<any> { | |
let nodelist; | |
let blank_finish; | |
this.explicit_construct(match); | |
this.blank_finish = blank_finish; | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
public anonymous(match, context, next_state): PyTuple<any> { | |
let nodelist; | |
let blank_finish; | |
this.anonymous_target(match); | |
this.blank_finish = blank_finish; | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
} | |
class SubstitutionDef extends Body { | |
public blank_finish: any; | |
public nodelist: any; | |
public initial_transitions: any = new Py.PyArray(new Py.PyStr("embedded_directive"), new Py.PyStr("text")); | |
public patterns: any = new Py.PyDict({ | |
"embedded_directive": re.compile(new Py.PyStr("(%s)::( +|$)") % Inliner.simplename, re.UNICODE), | |
"text": new Py.PyStr("") | |
}); | |
public embedded_directive(match, context, next_state): void { | |
let nodelist; | |
let blank_finish; | |
this.directive(match); | |
if (!this.state_machine.at_eof()) { | |
this.blank_finish = blank_finish; | |
} | |
throw EOFError; | |
} | |
public text(match, context, next_state): void { | |
if (!this.state_machine.at_eof()) { | |
this.blank_finish = this.state_machine.is_next_line_blank(); | |
} | |
throw EOFError; | |
} | |
} | |
class Text extends RSTState { | |
public textnode: any; | |
public text: any; | |
public parts: any; | |
public node: any; | |
public node_list: any; | |
public term_node: any; | |
public text_nodes: any; | |
public classifier_delimiter: any = re.compile(new Py.PyStr(" +: +")); | |
public definition: any; | |
public termlist: any; | |
public itemnode: any; | |
public line_offset: any; | |
public new_abs_offset: any; | |
public parent_node: any; | |
public abs_line_offset: any; | |
public nodelist: any; | |
public literal_block: any; | |
public data: any; | |
public indent: any; | |
public indented: any; | |
public lines: any; | |
public block: any; | |
public startline: any; | |
public style: any; | |
public srcline: any; | |
public src: any; | |
public blocktext: any; | |
public msg: any; | |
public messages: any; | |
public source: any; | |
public underline: any; | |
public title: any; | |
public lineno: any; | |
public newline_offset: any; | |
public offset: any; | |
public blank_finish: any; | |
public definitionlistitem: any; | |
public definitionlist: any; | |
public literalnext: any; | |
public paragraph: any; | |
public initial_transitions: any = new Py.PyArray(new Py.PyTuple(new Py.PyStr("underline"), new Py.PyStr("Body")), new Py.PyTuple(new Py.PyStr("text"), new Py.PyStr("Body"))); | |
public patterns: any = new Py.PyDict({ | |
"underline": Body.patterns[new Py.PyStr("line")], | |
"text": new Py.PyStr("") | |
}); | |
public blank(match, context, next_state): PyTuple<PyArray<unknown>> { | |
let paragraph; | |
let literalnext; | |
this.paragraph(context, this.state_machine.abs_line_number() - 1); | |
if (literalnext) { } | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("Body"), new Py.PyArray()); | |
} | |
public eof(context): PyArray<unknown> { | |
if (context) { | |
this.blank(undefined, context, undefined); | |
} | |
return new Py.PyArray(); | |
} | |
public indent(match, context, next_state): PyTuple<PyArray<unknown>> { | |
let definitionlist; | |
let definitionlistitem; | |
let blank_finish; | |
let offset; | |
let newline_offset; | |
definitionlist = nodes.definition_list(); | |
this.definition_list_item(context); | |
offset = this.state_machine.line_offset + 1; | |
this.nested_list_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(newline_offset); | |
if (!blank_finish) { } | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("Body"), new Py.PyArray()); | |
} | |
public underline(match, context, next_state): PyTuple<any> { | |
let lineno; | |
let title; | |
let underline; | |
let source; | |
let messages; | |
let msg; | |
let blocktext; | |
let src; | |
let srcline; | |
let style; | |
lineno = this.state_machine.abs_line_number(); | |
title = context[0].rstrip(); | |
underline = match.string.rstrip(); | |
source = title + new Py.PyStr("\n") + underline; | |
messages = new Py.PyArray(); | |
if (column_width(title)) { | |
if (Py.len(underline)) { | |
if (this.state_machine.match_titles) { | |
msg = this.reporter.info(new Py.PyStr("Possible title underline, too short for the title.\nTreating it as ordinary text because it's so short.")); | |
} | |
throw statemachine.TransitionCorrection(new Py.PyStr("text")); | |
} | |
else { | |
blocktext = context[0] + new Py.PyStr("\n") + this.state_machine.line; | |
msg = this.reporter.warning(new Py.PyStr("Title underline too short."), nodes.literal_block(blocktext, blocktext)); | |
messages.append(msg); | |
} | |
} | |
if (!this.state_machine.match_titles) { | |
blocktext = context[0] + new Py.PyStr("\n") + this.state_machine.line; | |
this.state_machine.get_source_and_line(); | |
msg = this.reporter.severe(new Py.PyStr("Unexpected section title."), nodes.literal_block(blocktext, blocktext)); | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
style = underline[0]; | |
context.slice(undefined, undefined) = new Py.PyArray(); | |
this.section(title, source, style, lineno - 1, messages); | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
public text(match, context, next_state): PyTuple<any> { | |
let startline; | |
let msg; | |
let block; | |
let err; | |
let src; | |
let srcline; | |
let lines; | |
let paragraph; | |
let literalnext; | |
startline = this.state_machine.abs_line_number() - 1; | |
msg = undefined; | |
try { | |
block = this.state_machine.get_text_block(); | |
} | |
catch (___error) { | |
if (___error instanceof statemachine.UnexpectedIndentationError) { | |
err = ___error; | |
err.args; | |
msg = this.reporter.error(new Py.PyStr("Unexpected indentation.")); | |
} | |
} | |
lines = context + Py.list(block); | |
this.paragraph(lines, startline); | |
if (literalnext) { | |
try { | |
this.state_machine.next_line(); | |
} | |
catch (___error) { | |
if (___error instanceof EOFError) { } | |
} | |
} | |
return new Py.PyTuple(new Py.PyArray(), next_state, new Py.PyArray()); | |
} | |
public literal_block(): any { | |
let indented; | |
let indent; | |
let offset; | |
let blank_finish; | |
let data; | |
let literal_block; | |
let nodelist; | |
this.state_machine.get_indented(); | |
if (!indented) { | |
return this.quoted_literal_block(); | |
} | |
data = new Py.PyStr("\n").join(indented); | |
literal_block = nodes.literal_block(data, data); | |
literal_block.source = literal_block.line = this.state_machine.get_source_and_line(offset + 1); | |
nodelist = new Py.PyArray(literal_block); | |
if (!blank_finish) { | |
nodelist.append(this.unindent_warning(new Py.PyStr("Literal block"))); | |
} | |
return nodelist; | |
} | |
public quoted_literal_block(): any { | |
let abs_line_offset; | |
let offset; | |
let parent_node; | |
let new_abs_offset; | |
abs_line_offset = this.state_machine.abs_line_offset(); | |
offset = this.state_machine.line_offset; | |
parent_node = nodes.Element(); | |
new_abs_offset = this.nested_parse(this.state_machine.input_lines.slice(offset, undefined)); | |
this.goto_line(new_abs_offset); | |
return parent_node.children; | |
} | |
public definition_list_item(termline): PyTuple<any> { | |
let indented; | |
let indent; | |
let line_offset; | |
let blank_finish; | |
let itemnode; | |
let lineno; | |
let termlist; | |
let messages; | |
let definition; | |
this.state_machine.get_indented(); | |
itemnode = nodes.definition_list_item(new Py.PyStr("\n").join(termline + Py.list(indented))); | |
lineno = this.state_machine.abs_line_number() - 1; | |
itemnode.source = itemnode.line = this.state_machine.get_source_and_line(lineno); | |
this.term(termline, lineno); | |
definition = nodes.definition(new Py.PyStr(""), ...messages); | |
if (termline[0].slice(-2, undefined)) { } | |
this.nested_parse(indented); | |
return new Py.PyTuple(itemnode, blank_finish); | |
} | |
public term(lines, lineno): PyTuple<any> { | |
let text_nodes; | |
let messages; | |
let term_node; | |
let node_list; | |
let i; | |
let node; | |
let parts; | |
let text; | |
let textnode; | |
let part; | |
this.inline_text(lines[0], lineno); | |
term_node = nodes.term(lines[0]); | |
term_node.source = term_node.line = this.state_machine.get_source_and_line(lineno); | |
node_list = new Py.PyArray(term_node); | |
for (i of Py.range(Py.len(text_nodes))) { | |
node = text_nodes[i]; | |
if (Py.isinstance(node, nodes.Text)) { | |
parts = this.classifier_delimiter.split(node); | |
if (Py.len(parts)) { } | |
else { | |
text = parts[0].rstrip(); | |
textnode = nodes.Text(utils.unescape(text, true)); | |
for (part of parts.slice(1, undefined)) { | |
node_list.append(nodes.classifier(unescape(part, true), part)); | |
} | |
} | |
} | |
} | |
return new Py.PyTuple(node_list, messages); | |
} | |
} | |
class SpecializedText extends Text { | |
public text: any = invalid_input; | |
public underline: any = invalid_input; | |
public indent: any = invalid_input; | |
public blank: any = invalid_input; | |
public eof(context): PyArray<unknown> { | |
return new Py.PyArray(); | |
} | |
public invalid_input(match, context, next_state): void { | |
throw EOFError; | |
} | |
} | |
class Definition extends SpecializedText { | |
public blank_finish: any; | |
public itemnode: any; | |
public eof(context): PyArray<unknown> { | |
this.state_machine.previous_line(2); | |
return new Py.PyArray(); | |
} | |
public indent(match, context, next_state): PyTuple<PyArray<unknown>> { | |
let itemnode; | |
let blank_finish; | |
this.definition_list_item(context); | |
this.blank_finish = blank_finish; | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("DefinitionList"), new Py.PyArray()); | |
} | |
} | |
class Line extends SpecializedText { | |
public indent: any = text; | |
public style: any; | |
public messages: any; | |
public source: any; | |
public msg: any; | |
public blocktext: any; | |
public underline: any; | |
public title: any; | |
public overline: any; | |
public srcline: any; | |
public src: any; | |
public transition: any; | |
public lineno: any; | |
public marker: any; | |
public eofcheck: any; | |
public eof(context): PyArray<unknown> { | |
let marker; | |
let lineno; | |
let transition; | |
marker = context[0].strip(); | |
if (this.memo.section_bubble_up_kludge) { | |
this.memo.section_bubble_up_kludge = false; | |
} | |
else { | |
if (Py.len(marker)) { | |
this.state_correction(context); | |
} | |
} | |
if (this.eofcheck) { | |
lineno = this.state_machine.abs_line_number() - 1; | |
transition = nodes.transition(); | |
transition.line = lineno; | |
} | |
this.eofcheck = 1; | |
return new Py.PyArray(); | |
} | |
public blank(match, context, next_state): PyTuple<PyArray<unknown>> { | |
let src; | |
let srcline; | |
let marker; | |
let transition; | |
this.state_machine.get_source_and_line(); | |
marker = context[0].strip(); | |
if (Py.len(marker)) { | |
this.state_correction(context); | |
} | |
transition = nodes.transition(); | |
transition.source = src; | |
transition.line = srcline - 1; | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("Body"), new Py.PyArray()); | |
} | |
public text(match, context, next_state): PyTuple<PyArray<unknown>> { | |
let lineno; | |
let overline; | |
let title; | |
let underline; | |
let blocktext; | |
let msg; | |
let source; | |
let messages; | |
let style; | |
lineno = this.state_machine.abs_line_number() - 1; | |
overline = context[0]; | |
title = match.string; | |
underline = new Py.PyStr(""); | |
try { | |
underline = this.state_machine.next_line(); | |
} | |
catch (___error) { | |
if (___error instanceof EOFError) { | |
blocktext = overline + new Py.PyStr("\n") + title; | |
if (Py.len(overline.rstrip())) { | |
this.short_overline(context, blocktext, lineno, 2); | |
} | |
else { | |
msg = this.reporter.severe(new Py.PyStr("Incomplete section title."), nodes.literal_block(blocktext, blocktext)); | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("Body"), new Py.PyArray()); | |
} | |
} | |
} | |
source = new Py.PyStr("%s\n%s\n%s") % new Py.PyTuple(overline, title, underline); | |
overline = overline.rstrip(); | |
underline = underline.rstrip(); | |
if (!this.transitions[new Py.PyStr("underline")][0].match(underline)) { | |
blocktext = overline + new Py.PyStr("\n") + title + new Py.PyStr("\n") + underline; | |
if (Py.len(overline.rstrip())) { | |
this.short_overline(context, blocktext, lineno, 2); | |
} | |
else { | |
msg = this.reporter.severe(new Py.PyStr("Missing matching underline for section title overline."), nodes.literal_block(source, source)); | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("Body"), new Py.PyArray()); | |
} | |
} | |
else { | |
if (overline) { | |
blocktext = overline + new Py.PyStr("\n") + title + new Py.PyStr("\n") + underline; | |
if (Py.len(overline.rstrip())) { | |
this.short_overline(context, blocktext, lineno, 2); | |
} | |
else { | |
msg = this.reporter.severe(new Py.PyStr("Title overline & underline mismatch."), nodes.literal_block(source, source)); | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("Body"), new Py.PyArray()); | |
} | |
} | |
} | |
title = title.rstrip(); | |
messages = new Py.PyArray(); | |
if (column_width(title)) { | |
blocktext = overline + new Py.PyStr("\n") + title + new Py.PyStr("\n") + underline; | |
if (Py.len(overline.rstrip())) { | |
this.short_overline(context, blocktext, lineno, 2); | |
} | |
else { | |
msg = this.reporter.warning(new Py.PyStr("Title overline too short."), nodes.literal_block(source, source)); | |
messages.append(msg); | |
} | |
} | |
style = new Py.PyTuple(overline[0], underline[0]); | |
this.eofcheck = 0; | |
this.section(title.lstrip(), source, style, lineno + 1, messages); | |
this.eofcheck = 1; | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("Body"), new Py.PyArray()); | |
} | |
public underline(match, context, next_state): PyTuple<PyArray<unknown>> { | |
let overline; | |
let blocktext; | |
let lineno; | |
let msg; | |
overline = context[0]; | |
blocktext = overline + new Py.PyStr("\n") + this.state_machine.line; | |
lineno = this.state_machine.abs_line_number() - 1; | |
if (Py.len(overline.rstrip())) { | |
this.short_overline(context, blocktext, lineno, 1); | |
} | |
msg = this.reporter.error(new Py.PyStr("Invalid section title or transition marker."), nodes.literal_block(blocktext, blocktext)); | |
return new Py.PyTuple(new Py.PyArray(), new Py.PyStr("Body"), new Py.PyArray()); | |
} | |
public short_overline(context, blocktext, lineno, lines): void { | |
let msg; | |
msg = this.reporter.info(new Py.PyStr("Possible incomplete section title.\nTreating the overline as ordinary text because it's so short.")); | |
this.state_correction(context, lines); | |
} | |
public state_correction(context, lines): void { | |
this.state_machine.previous_line(lines); | |
context.slice(undefined, undefined) = new Py.PyArray(); | |
throw statemachine.StateCorrection(new Py.PyStr("Body"), new Py.PyStr("text")); | |
} | |
} | |
class QuotedLiteralBlock extends RSTState { | |
public pattern: any; | |
public quote: any; | |
public literal_block: any; | |
public text: any; | |
public srcline: any; | |
public src: any; | |
public initial_lineno: any; | |
public messages: any; | |
public initial_transitions: any = new Py.PyTuple(new Py.PyStr("initial_quoted"), new Py.PyStr("text")); | |
public patterns: any = new Py.PyDict({ | |
"initial_quoted": new Py.PyStr("(%(nonalphanum7bit)s)") % Body.pats, | |
"text": new Py.PyStr("") | |
}); | |
public constructor(state_machine, debug) { | |
RSTState.__init__(this, state_machine, debug); | |
this.messages = new Py.PyArray(); | |
this.initial_lineno = undefined; | |
} | |
public blank(match, context, next_state): PyTuple<any> { | |
if (context) { | |
throw EOFError; | |
} | |
else { | |
return new Py.PyTuple(context, next_state, new Py.PyArray()); | |
} | |
} | |
public eof(context): PyArray<unknown> { | |
let src; | |
let srcline; | |
let text; | |
let literal_block; | |
if (context) { | |
this.state_machine.get_source_and_line(this.initial_lineno); | |
text = new Py.PyStr("\n").join(context); | |
literal_block = nodes.literal_block(text, text); | |
literal_block.source = src; | |
literal_block.line = srcline; | |
} | |
else { | |
this.state_machine.previous_line(); | |
} | |
return new Py.PyArray(); | |
} | |
public indent(match, context, next_state): void { | |
this.messages.append(this.reporter.error(new Py.PyStr("Unexpected indentation."))); | |
this.state_machine.previous_line(); | |
throw EOFError; | |
} | |
public initial_quoted(match, context, next_state): PyTuple<any> { | |
let quote; | |
let pattern; | |
this.remove_transition(new Py.PyStr("initial_quoted")); | |
quote = match.string[0]; | |
pattern = re.compile(re.escape(quote), re.UNICODE); | |
this.add_transition(new Py.PyStr("quoted"), new Py.PyTuple(pattern, this.quoted, this.__class__.__name__)); | |
this.initial_lineno = this.state_machine.abs_line_number(); | |
return new Py.PyTuple(new Py.PyArray(match.string), next_state, new Py.PyArray()); | |
} | |
public quoted(match, context, next_state): PyTuple<any> { | |
context.append(match.string); | |
return new Py.PyTuple(context, next_state, new Py.PyArray()); | |
} | |
public text(match, context, next_state): void { | |
if (context) { | |
this.messages.append(this.reporter.error(new Py.PyStr("Inconsistent literal block quoting."))); | |
this.state_machine.previous_line(); | |
} | |
throw EOFError; | |
} | |
} | |
state_classes = new Py.PyTuple(Body, BulletList, DefinitionList, EnumeratedList, FieldList, OptionList, LineBlock, ExtensionOptions, Explicit, Text, Definition, Line, SubstitutionDef, RFC2822Body, RFC2822List); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment