diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index d3b81cf..76987df 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -25,7 +25,7 @@ jobs: - name: Install MoonBit # if: ${{ matrix.os.name != 'windows-latest' }} run: | - curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s -- pre-release + curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s echo "$HOME/.moon/bin" >> $GITHUB_PATH - name: Run benchmark diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1065b81..aeebb7c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -14,11 +14,7 @@ jobs: matrix: os: - name: ubuntu-latest - path: ubuntu_x86_64_moon_setup - - name: macos-13 - path: mac_intel_moon_setup - name: macos-latest - path: mac_m1_moon_setup - name: windows-latest runs-on: ${{ matrix.os.name }} @@ -29,12 +25,10 @@ jobs: - name: install if: ${{ matrix.os.name != 'windows-latest' }} run: | - curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s -- pre-release + curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s echo "$HOME/.moon/bin" >> $GITHUB_PATH - name: install on windows - env: - MOONBIT_INSTALL_VERSION: pre-release if: ${{ matrix.os.name == 'windows-latest' }} run: | Set-ExecutionPolicy RemoteSigned -Scope CurrentUser; irm https://cli.moonbitlang.com/install/powershell.ps1 | iex @@ -48,7 +42,8 @@ jobs: - name: moon check run: | moon update - moon check --deny-warn + # moon check --deny-warn + moon check - name: moon info and moon fmt run: | @@ -64,8 +59,10 @@ jobs: moon test --target wasm --release moon test --target wasm-gc moon test --target wasm-gc --release - # moon test --target js - # moon test --target js --release + moon test --target js + moon test --target js --release + moon test --target native + moon test --target native --release coverage-check: runs-on: ubuntu-latest @@ -75,7 +72,7 @@ jobs: - name: install run: | - curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s -- pre-release + curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s echo "$HOME/.moon/bin" >> $GITHUB_PATH - name: moon test diff --git a/src/char/entities.mbt b/src/char/entities.mbt index 70659b8..565b2ea 100644 --- a/src/char/entities.mbt +++ b/src/char/entities.mbt @@ -1,4 +1,5 @@ -///| A collection of named entities in HTML, +///| +/// A collection of named entities in HTML, /// generated from . /// To regenerate, run `moon build`. let html_named_entities : Json = { diff --git a/src/char/pkg.generated.mbti b/src/char/pkg.generated.mbti new file mode 100644 index 0000000..ca2a5ed --- /dev/null +++ b/src/char/pkg.generated.mbti @@ -0,0 +1,60 @@ +// Generated using `moon info`, DON'T EDIT IT +package "rami3l/cmark/char" + +import( + "moonbitlang/core/string" +) + +// Values +fn ascii_digit_to_int(Char) -> Int + +fn ascii_hexdigit_to_int(Char) -> Int + +fn ascii_octdigit_to_int(Char) -> Int + +fn at_checked(@string.View, Int) -> Result[Char, Int] + +fn is_ascii_alphanum(Char) -> Bool + +fn is_ascii_blank(Char) -> Bool + +fn is_ascii_control(Char) -> Bool + +fn is_ascii_graphic(Char) -> Bool + +fn is_ascii_punctuation(Char) -> Bool + +fn is_ascii_whitespace(Char) -> Bool + +fn length_utf16(Int) -> Int + +fn length_utf32(Int) -> Int + +fn length_utf8(Int) -> Int + +fn next_char(@string.View, last~ : Int, after~ : Int) -> Char + +fn prev_char(@string.View, first~ : Int, before~ : Int) -> Char + +let rep : Char + +fn sub_includes(affix~ : String, String, first~ : Int, last~ : Int) -> Bool + +fn to_ascii_lower(Char) -> Char + +fn to_ascii_upper(Char) -> Char + +fn utf_16_clean_raw(pad? : Int, StringBuilder, String, first~ : Int, last~ : Int) -> String + +fn utf_16_clean_unesc_unref(StringBuilder, String, first~ : Int, last~ : Int) -> String + +fn utf_16_clean_unref(StringBuilder, String, first~ : Int, last~ : Int) -> String + +// Errors + +// Types and methods + +// Type aliases + +// Traits + diff --git a/src/char/text.mbt b/src/char/text.mbt index 03b2c5b..c48b10a 100644 --- a/src/char/text.mbt +++ b/src/char/text.mbt @@ -74,7 +74,7 @@ pub fn next_char(s : @string.View, last~ : Int, after~ : Int) -> Char { ///| pub fn utf_16_clean_raw( - pad~ : Int = 0, + pad? : Int = 0, buf : Buffer, s : String, first~ : Int, diff --git a/src/cmark/alias.mbt b/src/cmark/alias.mbt index 930c18b..4b1b14f 100644 --- a/src/cmark/alias.mbt +++ b/src/cmark/alias.mbt @@ -29,7 +29,7 @@ typealias @cmark_base.Span typealias @cmark_base.LineSpan ///| -priv struct Tokens(@deque.T[Token]) +priv struct Tokens(@deque.Deque[Token]) ///| impl Show for Tokens with output(self, logger) { @@ -58,7 +58,7 @@ fn Tokens::push(self : Tokens, t : Token) -> Unit { // } ///| -priv struct RevTokens(@deque.T[Token]) +priv struct RevTokens(@deque.Deque[Token]) ///| impl Show for RevTokens with output(self, logger) { diff --git a/src/cmark/block.mbt b/src/cmark/block.mbt index 79f93e2..5b77395 100644 --- a/src/cmark/block.mbt +++ b/src/cmark/block.mbt @@ -1,4 +1,5 @@ -///| A markdown block. +///| +/// A markdown block. pub(all) enum Block { BlankLine(Node[BlockBlankLine]) BlockQuote(Node[BlockQuote]) @@ -39,7 +40,8 @@ pub fn Block::meta(self : Block) -> Meta { } } -///| Normalize a block. +///| +/// Normalize a block. /// /// `b.normalize()` has the same content as `b` but is such that for any /// occurrence of `Blocks` in `b` the list of blocks `bs`: @@ -71,11 +73,12 @@ pub fn Block::normalize(self : Block) -> Block { } } -///| Collects the given `Block`'s link definitions (e.g. `LinkRefDefinition` +///| +/// Collects the given `Block`'s link definitions (e.g. `LinkRefDefinition` /// and `ExtFootnoteDefinition`) and adds them to `init` (defaults to an empty map). pub fn Block::defs( self : Block, - init~ : LabelDefs = LabelDefs::new(), + init? : LabelDefs = LabelDefs::new(), ) -> LabelDefs { match self { BlockQuote(bl) => bl.v.block.defs(init~) @@ -95,11 +98,13 @@ pub fn Block::defs( } } -///| The type for [blank lines](https://spec.commonmark.org/0.30/#blank-lines). +///| +/// The type for [blank lines](https://spec.commonmark.org/0.30/#blank-lines). /// These can be ignored during rendering, they are kept for layout. pub typealias Blanks as BlockBlankLine -///| The type for [block quotes](https://spec.commonmark.org/0.30/#block-quotes). +///| +/// The type for [block quotes](https://spec.commonmark.org/0.30/#block-quotes). pub(all) struct BlockQuote { /// The indentation to the block quote marker found on the first line. indent : Indent @@ -108,7 +113,7 @@ pub(all) struct BlockQuote { } derive(Show, ToJson) ///| -pub fn BlockQuote::new(indent~ : Int = 0, block : Block) -> BlockQuote { +pub fn BlockQuote::new(indent? : Int = 0, block : Block) -> BlockQuote { { indent, block } } @@ -125,7 +130,8 @@ pub fn BlockQuote::normalize_block(self : BlockQuote) -> BlockQuote { self.map_block(Block::normalize) } -///| The type for [indented](https://spec.commonmark.org/0.30/#indented-code-block) and +///| +/// The type for [indented](https://spec.commonmark.org/0.30/#indented-code-block) and /// [fenced](:https://spec.commonmark.org/0.30/#fenced-code-blocks) code blocks. pub(all) struct CodeBlock { layout : CodeBlockLayout @@ -153,8 +159,8 @@ pub fn CodeBlockFencedLayout::default() -> CodeBlockFencedLayout { ///| pub fn CodeBlock::new( - layout~ : CodeBlockLayout = Fenced(CodeBlockFencedLayout::default()), - info_string~ : StringNode? = None, + layout? : CodeBlockLayout = Fenced(CodeBlockFencedLayout::default()), + info_string? : StringNode? = None, code : Seq[StringNode], ) -> CodeBlock { let layout = match (info_string, layout) { @@ -165,7 +171,8 @@ pub fn CodeBlock::new( { layout, info_string, code } } -///| [make_fence cb] is a fence character and count suitable for [cb]. +///| +/// [make_fence cb] is a fence character and count suitable for [cb]. pub fn CodeBlock::make_fence(self : CodeBlock) -> (Char, Count) { let ch = if self.info_string is Some(info) && info.v.contains_char('`') { '~' @@ -186,7 +193,8 @@ pub fn CodeBlock::make_fence(self : CodeBlock) -> (Char, Count) { (ch, InlineCodeSpan::min_backticks(min=3, counts)) } -///| [language_of_info_string s] extracts a (non-empty) language, the first word of [s] and a trimmed remainder. +///| +/// [language_of_info_string s] extracts a (non-empty) language, the first word of [s] and a trimmed remainder. /// Assumes [s] is {!String.trim}ed which is what {!info_string} gives you. pub fn CodeBlock::language_of_info_string(s : String) -> (String, String)? { guard not(s.is_empty()) else { None } @@ -208,7 +216,8 @@ fn CodeBlock::is_math_block(s : String?) -> Bool { CodeBlock::language_of_info_string(s).map(fn(i) { i.0 }) == Some("math") } -///| The type for [ATX](https://spec.commonmark.org/0.30/#atx-headings) +///| +/// The type for [ATX](https://spec.commonmark.org/0.30/#atx-headings) /// and [Setext](https://spec.commonmark.org/0.30/#setext-headings) headings. pub(all) struct BlockHeading { layout : BlockHeadingLayout @@ -252,15 +261,16 @@ pub(all) enum BlockHeadingId { ///| pub fn BlockHeading::new( - id~ : BlockHeadingId? = None, - layout~ : BlockHeadingLayout = Atx(BlockHeadingAtxLayout::default()), + id? : BlockHeadingId? = None, + layout? : BlockHeadingLayout = Atx(BlockHeadingAtxLayout::default()), level~ : Int, inline : Inline, ) -> BlockHeading { { layout, level, inline, id } } -///| The type for [HTML blocks](https://spec.commonmark.org/0.30/#html-blocks). +///| +/// The type for [HTML blocks](https://spec.commonmark.org/0.30/#html-blocks). pub(all) struct HtmlBlock(Seq[StringNode]) derive(Show, ToJson) ///| @@ -277,9 +287,9 @@ pub typealias ListItem as ListItemBlock ///| pub fn ListItem::new( - before_marker~ : Indent = 0, - marker~ : StringNode = layout_empty, - after_marker~ : Indent = 1, + before_marker? : Indent = 0, + marker? : StringNode = layout_empty, + after_marker? : Indent = 1, ext_task_marker~ : Node[Char]?, block : Block, ) -> ListItem { @@ -314,7 +324,8 @@ pub fn ListTaskStatus::from_marker(marker : Char) -> ListTaskStatus { } } -///| The type for [lists](https://spec.commonmark.org/0.30/#lists). +///| +/// The type for [lists](https://spec.commonmark.org/0.30/#lists). pub(all) struct BlockList { ty : ListType tight : Bool @@ -334,7 +345,8 @@ pub fn BlockList::normalize_items(self : BlockList) -> BlockList { self.map_items(ListItem::normalize_block) } -///| The type for [paragraphs](https://spec.commonmark.org/0.30/#paragraphs). +///| +/// The type for [paragraphs](https://spec.commonmark.org/0.30/#paragraphs). pub(all) struct BlockParagraph { leading_indent : Indent inline : Inline @@ -343,14 +355,15 @@ pub(all) struct BlockParagraph { ///| pub fn BlockParagraph::new( - leading_indent~ : Indent = 0, - trailing_blanks~ : Blanks = "", + leading_indent? : Indent = 0, + trailing_blanks? : Blanks = "", inline : Inline, ) -> BlockParagraph { { leading_indent, inline, trailing_blanks } } -///| The type for [thematic breaks](https://spec.commonmark.org/0.30/#thematic-break). +///| +/// The type for [thematic breaks](https://spec.commonmark.org/0.30/#thematic-break). pub(all) struct BlockThematicBreak { indent : Indent layout : String @@ -358,8 +371,8 @@ pub(all) struct BlockThematicBreak { ///| pub fn BlockThematicBreak::new( - indent~ : Indent = 0, - layout~ : String = "---", + indent? : Indent = 0, + layout? : String = "---", ) -> BlockThematicBreak { { indent, layout } } @@ -376,7 +389,7 @@ pub(all) struct Footnote { ///| pub fn Footnote::new( - indent~ : Indent = 0, + indent? : Indent = 0, defined_label? : Label?, label : Label, block : Block, @@ -436,7 +449,7 @@ pub(all) struct TableCellLayout((Blanks, Blanks)) derive ( ///| pub fn Table::new( - indent~ : Indent = 0, + indent? : Indent = 0, rows : Seq[(Node[TableRow], Blanks)], ) -> Table { let mut col_count = 0 diff --git a/src/cmark/block_line.mbt b/src/cmark/block_line.mbt index 8197286..ca1fced 100644 --- a/src/cmark/block_line.mbt +++ b/src/cmark/block_line.mbt @@ -1,4 +1,5 @@ -///| Block lines. +///| +/// Block lines. /// /// In CommonMark blocks, a "line" does not necessarily correspond to /// a line in the source plain text. For example the lines of a @@ -24,14 +25,15 @@ pub fn BlockLine::list_text_loc(ls : Seq[BlockLine]) -> TextLoc { } } -///| Tight block lines: a block line with its initial blanks trimmed but kept for layout. +///| +/// Tight block lines: a block line with its initial blanks trimmed but kept for layout. pub(all) struct Tight { blanks : Blanks node : StringNode } derive(Eq, ToJson) ///| -pub fn Tight::empty(meta~ : Meta = Meta::none()) -> Tight { +pub fn Tight::empty(meta? : Meta = Meta::none()) -> Tight { { blanks: "", node: StringNode::empty(meta~) } } @@ -66,7 +68,7 @@ pub fn Tight::list_text_loc(ls : Seq[Tight]) -> TextLoc { ///| fn BlockLine::flush_tight( - meta~ : Meta = Meta::none(), + meta? : Meta = Meta::none(), s : String, start : Int, last : Int, diff --git a/src/cmark/block_struct.mbt b/src/cmark/block_struct.mbt index 0a78e50..d3668a6 100644 --- a/src/cmark/block_struct.mbt +++ b/src/cmark/block_struct.mbt @@ -69,7 +69,8 @@ fn Parser::accept_cols(self : Parser, count~ : Int) -> Unit { self.update_next_non_blank() } -///| https://spec.commonmark.org/current/#block-quote-marker +///| +/// https://spec.commonmark.org/current/#block-quote-marker fn Parser::match_and_accept_block_quote(self : Parser) -> Bool { if self.end_of_line() || self.i[self.curr_char] != '>' { return false @@ -85,7 +86,8 @@ fn Parser::match_and_accept_block_quote(self : Parser) -> Bool { true } -///| Returns min indent after marker for list item +///| +/// Returns min indent after marker for list item fn Parser::accept_list_marker_and_indent( self : Parser, marker_size~ : Int, @@ -103,7 +105,8 @@ fn Parser::accept_list_marker_and_indent( min_indent } -///| Returns padding for partially consumed tab and content first char +///| +/// Returns padding for partially consumed tab and content first char fn Parser::accept_code_indent( self : Parser, count~ : Int, @@ -123,7 +126,7 @@ fn Parser::accept_code_indent( // line spans. See: // https://spec.commonmark.org/current/#phase-1-block-structure -///| +///| /// Number of space characters to pad content with typealias Int as SpacePad @@ -387,7 +390,8 @@ fn Parser::table( // Link reference definition parsing // This is invoked when we close a paragraph and works on the paragraph lines. -///| Has no side effect on [p], parsing occurs on [lines] spans. +///| +/// Has no side effect on [p], parsing occurs on [lines] spans. /// https://spec.commonmark.org/current/#link-reference-definitions fn Parser::parse_link_ref_definition( self : Parser, @@ -683,7 +687,8 @@ fn Parser::end_doc(self : Parser, bs : Array[BlockStruct]) -> Unit { // Adding lines to blocks -///| Effects on [p]'s column advance +///| +/// Effects on [p]'s column advance fn Parser::match_line_type( self : Parser, no_setext~ : Bool, diff --git a/src/cmark/block_test.mbt b/src/cmark/block_test.mbt index d61e83e..9bbb84a 100644 --- a/src/cmark/block_test.mbt +++ b/src/cmark/block_test.mbt @@ -35,7 +35,8 @@ test "code block new with info string" { } } -///| Test CodeBlock::new with indented layout and info string +///| +/// Test CodeBlock::new with indented layout and info string test "code block with indented layout and info string" { let node = StringNode::empty() let code = Seq::from_array([node]) @@ -54,7 +55,8 @@ test "code block with indented layout and info string" { } } -///| Test for CodeBlock::make_fence +///| +/// Test for CodeBlock::make_fence test "code block make fence" { // Test when there are no backticks in any lines let node = Node::new("plain text") @@ -73,7 +75,8 @@ test "code block make fence" { inspect(count2, content="4") } -///| Test Block::normalize for BlockQuote +///| +/// Test Block::normalize for BlockQuote test "block normalize with block quote" { let blockQuote = @cmark.BlockQuote::new(@cmark.Block::empty()) let normalized = @cmark.Block::BlockQuote(@cmark.Node::new(blockQuote)).normalize() @@ -83,7 +86,8 @@ test "block normalize with block quote" { ) } -///| Test Block::normalize for List with Seq.empty() +///| +/// Test Block::normalize for List with Seq.empty() test "block normalize with list using Seq.empty" { let items = @cmark.Seq::empty() let list = @cmark.BlockList::{ @@ -98,7 +102,8 @@ test "block normalize with list using Seq.empty" { ) } -///| Tests to improve coverage for the block.mbt file +///| +/// Tests to improve coverage for the block.mbt file test "code block fenced layout default" { let layout = CodeBlockFencedLayout::default() inspect(layout.indent, content="0") @@ -139,7 +144,8 @@ test "block quote normalize_block" { inspect(normalized_quote.indent, content="0") } -///| Test the ListTaskStatus::from_marker with a custom marker +///| +/// Test the ListTaskStatus::from_marker with a custom marker test "list task status from marker with custom marker" { let status = ListTaskStatus::from_marker('?') match status { diff --git a/src/cmark/closer.mbt b/src/cmark/closer.mbt index 4974ef3..ed4238b 100644 --- a/src/cmark/closer.mbt +++ b/src/cmark/closer.mbt @@ -1,4 +1,5 @@ -///| Closer indexes. +///| +/// Closer indexes. /// /// They map closing delimiters to the position where they /// start. Shortcuts forward searches in inline parsing. See diff --git a/src/cmark/doc.mbt b/src/cmark/doc.mbt index b76dcc9..8f51e3a 100644 --- a/src/cmark/doc.mbt +++ b/src/cmark/doc.mbt @@ -1,4 +1,5 @@ -///| The type for CommonMark documents. +///| +/// The type for CommonMark documents. pub(all) struct Doc { nl : String block : Block @@ -7,8 +8,8 @@ pub(all) struct Doc { ///| pub fn Doc::new( - nl~ : String = "\n", - defs~ : LabelDefs = LabelDefs::new(), + nl? : String = "\n", + defs? : LabelDefs = LabelDefs::new(), block : Block, ) -> Doc { { nl, block, defs } @@ -21,14 +22,14 @@ pub fn Doc::empty() -> Doc { ///| pub fn Doc::from_string( - defs~ : LabelDefs = LabelDefs::new(), - resolver~ : LabelResolverFn = LabelContext::default_resolver, - nested_links~ : Bool = false, - heading_auto_ids~ : Bool = false, - layout~ : Bool = false, - locs~ : Bool = false, - file~ : FilePath = file_path_none, - strict~ : Bool = true, + defs? : LabelDefs = LabelDefs::new(), + resolver? : LabelResolverFn = LabelContext::default_resolver, + nested_links? : Bool = false, + heading_auto_ids? : Bool = false, + layout? : Bool = false, + locs? : Bool = false, + file? : FilePath = file_path_none, + strict? : Bool = true, s : String, ) -> Doc { let p = Parser::new( diff --git a/src/cmark/folder.mbt b/src/cmark/folder.mbt index 6dc1c33..274e015 100644 --- a/src/cmark/folder.mbt +++ b/src/cmark/folder.mbt @@ -12,7 +12,8 @@ pub(all) struct FoldFn[A, B]((Folder[B], B, A) -> B raise FolderError) ///| pub(all) struct FolderFn[A, B]((Folder[B], B, A) -> FolderResult[B]) -///| The type for folder results. +///| +/// The type for folder results. /// `Default` means doing the default fold. pub(all) enum FolderResult[A] { Default @@ -57,10 +58,10 @@ pub fn[A] Folder::block_ext_none( ///| pub fn[A] Folder::new( - inline_ext_default~ : FoldFn[Inline, A] = Folder::inline_ext_none, - block_ext_default~ : FoldFn[Block, A] = Folder::block_ext_none, - inline~ : FolderFn[Inline, A] = Folder::none, - block~ : FolderFn[Block, A] = Folder::none, + inline_ext_default? : FoldFn[Inline, A] = Folder::inline_ext_none, + block_ext_default? : FoldFn[Block, A] = Folder::block_ext_none, + inline? : FolderFn[Inline, A] = Folder::none, + block? : FolderFn[Block, A] = Folder::none, ) -> Folder[A] { { inline_ext_default, block_ext_default, inline, block } } diff --git a/src/cmark/inline.mbt b/src/cmark/inline.mbt index 644db07..32cd196 100644 --- a/src/cmark/inline.mbt +++ b/src/cmark/inline.mbt @@ -31,7 +31,8 @@ pub fn Inline::is_empty(self : Inline) -> Bool { } } -///| `meta(i)` is the metadata of `i`. +///| +/// `meta(i)` is the metadata of `i`. pub fn Inline::meta( self : Inline, // ext~ : (Inline) -> Meta!InvalidArgumentError = fn(_i) { @@ -54,7 +55,8 @@ pub fn Inline::meta( } } -///| `normalize(i)` has the same content as `i` but is such that for any +///| +/// `normalize(i)` has the same content as `i` but is such that for any /// occurence of `Inlines(is, _)` in `i` the list of inlines `is`: /// - `is` is not a singleton list. /// - Has no two consecutive `Text _` cases. If that occurs the texts are @@ -112,7 +114,8 @@ pub fn Inline::normalize(self : Inline) -> Inline { } } -///| `to_plain_text(i, break_on_soft~, acc~)` has the plain text of `i` +///| +/// `to_plain_text(i, break_on_soft~, acc~)` has the plain text of `i` /// as a sequence of lines represented by a list of strings to be /// concatenated. If `break_on_soft` is `true` soft line breaks /// are turned into hard line breaks. @@ -156,7 +159,7 @@ pub fn Inline::to_plain_text( ///| pub fn Inline::id( self : Inline, - buf~ : Buffer = Buffer::new(size_hint=256), + buf? : Buffer = Buffer::new(size_hint=256), ) -> String { let text = self.to_plain_text(break_on_soft=false) let s = text.inner().map(fn(l) { l.inner().join("") }).join("\n") @@ -231,8 +234,8 @@ pub(all) struct InlineBreak { ///| pub fn InlineBreak::new( - layout_before~ : BlanksNode = layout_empty, - layout_after~ : BlanksNode = layout_empty, + layout_before? : BlanksNode = layout_empty, + layout_after? : BlanksNode = layout_empty, ty : InlineBreakType, ) -> InlineBreak { { layout_before, ty, layout_after } @@ -244,7 +247,8 @@ pub(all) enum InlineBreakType { Soft } derive(Eq, Compare, Show, FromJson(style="flat"), ToJson(style="flat")) -///| The type for [code spans](https://spec.commonmark.org/0.30/#code-spans). +///| +/// The type for [code spans](https://spec.commonmark.org/0.30/#code-spans). pub(all) struct InlineCodeSpan { backticks : Count code_layout : Seq[Tight] @@ -261,7 +265,7 @@ pub fn InlineCodeSpan::new( ///| fn InlineCodeSpan::min_backticks( min~ : Count, - counts : @sorted_set.T[Count], + counts : @sorted_set.SortedSet[Count], ) -> Count { let mut min = min for c in counts { @@ -271,7 +275,8 @@ fn InlineCodeSpan::min_backticks( min } -///| `from_string(s)` is a code span for `s`. `s` can start with or +///| +/// `from_string(s)` is a code span for `s`. `s` can start with or /// include backticks; the appropriate minimal backtick count and /// possible needed leading and trailing space are computed /// accordingly. If `s` contains newlines, blanks after newlines @@ -279,7 +284,7 @@ fn InlineCodeSpan::min_backticks( /// the lines of the resulting code layout (see `code_layout`). /// the resulting code layout (see `code_layout`). pub fn InlineCodeSpan::from_string( - meta~ : Meta = Meta::none(), + meta? : Meta = Meta::none(), s : String, ) -> InlineCodeSpan { if s.is_empty() { @@ -322,7 +327,8 @@ pub fn InlineCodeSpan::from_string( { code_layout, backticks: InlineCodeSpan::min_backticks(min=1, bt_counts) } } -///| https://spec.commonmark.org/0.30/#code-spans +///| +/// https://spec.commonmark.org/0.30/#code-spans pub fn InlineCodeSpan::code(self : InlineCodeSpan) -> String { let s = self.code_layout.iter().map(Tight::to_string).to_array().join(" ") guard s != "" else { "" } @@ -332,7 +338,8 @@ pub fn InlineCodeSpan::code(self : InlineCodeSpan) -> String { s } -///| The type for emphasis and strong emphasis. +///| +/// The type for emphasis and strong emphasis. /// https://spec.commonmark.org/0.30/#emphasis-and-strong-emphasis pub(all) struct InlineEmphasis { delim : Char @@ -341,7 +348,7 @@ pub(all) struct InlineEmphasis { ///| pub fn InlineEmphasis::new( - delim~ : Char = '*', + delim? : Char = '*', inline : Inline, ) -> InlineEmphasis { { delim, inline } @@ -378,7 +385,8 @@ pub fn InlineLink::new(text : Inline, reference : ReferenceKind) -> InlineLink { { text, reference } } -///| `referenced_label(l)` is the label referenced by the label of `l`. +///| +/// `referenced_label(l)` is the label referenced by the label of `l`. /// This is the second label of `Ref(_)` or `None` on inline references. pub fn InlineLink::referenced_label(self : InlineLink) -> Label? { match self.reference { @@ -387,7 +395,8 @@ pub fn InlineLink::referenced_label(self : InlineLink) -> Label? { } } -///| `reference_definition(defs, l)` is the definition of `l`'s reference. +///| +/// `reference_definition(defs, l)` is the definition of `l`'s reference. /// If `l` is an `Inline` reference this returns its link definition /// wrapped in a `LinkDef`. If `l` is `Ref` this looks up the /// `referenced_label` in `defs`. @@ -401,7 +410,8 @@ pub fn InlineLink::reference_definition( } } -///| `is_unsafe(l)` is `true` if `l` is deemed unsafe. +///| +/// `is_unsafe(l)` is `true` if `l` is deemed unsafe. /// This is the case if `l` starts with a caseless match of /// `javascript:`, `vbscript:`, `file:` or `data:` except if /// `data:image/{gif,png,jpeg,webp}`. @@ -430,10 +440,12 @@ pub fn InlineLink::is_unsafe(l : String) -> Bool { (lower.has_prefix("data:") && not(allowed_data_url(l))) } -///| The type for [inline raw HTML](https://spec.commonmark.org/0.30/#raw-html) (can span multiple lines). +///| +/// The type for [inline raw HTML](https://spec.commonmark.org/0.30/#raw-html) (can span multiple lines). pub(all) struct InlineRawHtml(Seq[Tight]) derive(Eq, Show, ToJson) -///| The type for [textual content](https://spec.commonmark.org/0.30/#textual-content). +///| +/// The type for [textual content](https://spec.commonmark.org/0.30/#textual-content). /// /// Normally these strings should not contain newlines. This can /// however happen if the source had newlines as diff --git a/src/cmark/inline_struct.mbt b/src/cmark/inline_struct.mbt index aacea8f..cc9a6df 100644 --- a/src/cmark/inline_struct.mbt +++ b/src/cmark/inline_struct.mbt @@ -1,6 +1,7 @@ // Inline structure parsing -///| Tokens for parsing inlines. +///| +/// Tokens for parsing inlines. /// /// The list of tokens of a paragraph are the points to consider to /// parse it into inlines. Tokens gradually become `Inline` tokens @@ -176,7 +177,8 @@ fn make_closer_index(toks : Tokens) -> CloserIndex { cidx } -///| Used to make the text delimitation precise for nested inlines. +///| +/// Used to make the text delimitation precise for nested inlines. fn tokens_shorten_last_line(to_last~ : Int, toks : Tokens) -> Unit { let last = to_last for i = toks.inner().length() - 1; i >= 0; i = i - 1 { @@ -597,7 +599,8 @@ fn Parser::ext_math_span_token( // Parsers -///| https://spec.commonmark.org/current/#code-span +///| +/// https://spec.commonmark.org/current/#code-span /// Tries to push an inline code span to the `rev_toks` stack. /// If this function returns `Some((line_span, token))`, it means the stack has been modified. fn Parser::try_code( @@ -752,7 +755,8 @@ fn Parser::label_of_spans( { meta, key, text } } -///| https://spec.commonmark.org/current/#full-reference-link +///| +/// https://spec.commonmark.org/current/#full-reference-link /// If the function returns `Some(Some(_))`, it means the `rev_toks` stack has been modified. fn Parser::try_full_reflink_remainder( self : Parser, @@ -778,7 +782,8 @@ fn Parser::try_full_reflink_remainder( Some(Some((line, ReferenceKind::Ref(Full, ref_, def), last))) } -///| https://spec.commonmark.org/current/#shortcut-reference-link +///| +/// https://spec.commonmark.org/current/#shortcut-reference-link /// If the function returns `Some(Some(_))`, it means the `rev_toks` stack has been modified. fn Parser::try_shortcut_reflink( self : Parser, @@ -805,7 +810,8 @@ fn Parser::try_shortcut_reflink( Some((line, ReferenceKind::Ref(Shortcut, ref_, def), last)) } -///| https://spec.commonmark.org/current/#collapsed-reference-link +///| +/// https://spec.commonmark.org/current/#collapsed-reference-link /// If the function returns `Some()`, it means the `rev_toks` stack has been modified. fn Parser::try_collapsed_reflink( self : Parser, @@ -834,7 +840,8 @@ fn Parser::try_collapsed_reflink( Some((line, ReferenceKind::Ref(Collapsed, ref_, def), last)) } -///| https://spec.commonmark.org/current/#inline-link +///| +/// https://spec.commonmark.org/current/#inline-link /// If the function returns `Some(_)`, it means the `rev_toks` stack has been modified. fn Parser::try_inline_link_remainder( self : Parser, @@ -1136,7 +1143,8 @@ fn Parser::try_link( }) } -///| Parse inline atoms and links. +///| +/// Parse inline atoms and links. /// Links are parsed here otherwise link reference data gets parsed as atoms. fn Parser::first_pass( self : Parser, @@ -1414,7 +1422,7 @@ fn Parser::second_pass( // Last pass -///| +///| /// Only `Inline` and `Newline` tokens remain. We fold over them to /// convert them to `inline` values and `Break`s. `Text` inlines /// are created for data between them. diff --git a/src/cmark/inline_struct_wbtest.mbt b/src/cmark/inline_struct_wbtest.mbt index 26322b1..4b7ee07 100644 --- a/src/cmark/inline_struct_wbtest.mbt +++ b/src/cmark/inline_struct_wbtest.mbt @@ -1,8 +1,8 @@ ///| fn parse_only( txt : String, - strict~ : Bool = true, - polish~ : (Parser) -> Parser = fn(p) { p }, + strict? : Bool = true, + polish? : (Parser) -> Parser = fn(p) { p }, ) -> ((Col, String), Inline) { let p = Parser::new(txt, strict~) |> polish() let lines = txt.split("\n") @@ -24,7 +24,7 @@ fn parse_only( ///| fn tokenize_only( txt : String, - strict~ : Bool = true, + strict? : Bool = true, ) -> (CloserIndex, Tokens, LineSpan) { let p = Parser::new(txt, strict~) let lines = txt.split("\n") diff --git a/src/cmark/label.mbt b/src/cmark/label.mbt index fe53f83..e4d3a17 100644 --- a/src/cmark/label.mbt +++ b/src/cmark/label.mbt @@ -1,6 +1,7 @@ // Labels. -///| Labels are used by [reference links](https://spec.commonmark.org/0.30/#reference-link) to +///| +/// Labels are used by [reference links](https://spec.commonmark.org/0.30/#reference-link) to /// refer to the [definitions](#definitions) of /// [link reference definitions](https://spec.commonmark.org/0.30/#link-reference-definitions), /// [footnote definitions](#footnote-definitions) and your own @@ -11,14 +12,15 @@ pub(all) struct Label { text : Seq[Tight] } derive(Show, ToJson) -///| The type for label keys. These are +///| +/// The type for label keys. These are /// [link labels](https://spec.commonmark.org/0.30/#link-label) /// normalized for [matches](https://spec.commonmark.org/0.30/#matches). pub typealias String as LabelKey ///| pub fn Label::new( - meta~ : Meta = Meta::none(), + meta? : Meta = Meta::none(), key~ : String, text : Seq[Tight], ) -> Label { @@ -31,7 +33,7 @@ pub fn Label::text_loc(self : Label) -> TextLoc { } ///| -pub impl Eq for Label with op_equal(self, other) { +pub impl Eq for Label with equal(self, other) { self.key == other.key } @@ -49,7 +51,8 @@ pub(all) enum LabelDef { ///| pub typealias Map[LabelKey, LabelDef] as LabelDefs -///| `context` is: +///| +/// `context` is: /// - `Def (prev, current)` when we just hit a /// [link reference definition](https://spec.commonmark.org/0.30/#link-reference-definitions) /// or footnote definition that defines the label `current`. diff --git a/src/cmark/layout.mbt b/src/cmark/layout.mbt index 424c65f..1af4e51 100644 --- a/src/cmark/layout.mbt +++ b/src/cmark/layout.mbt @@ -1,5 +1,5 @@ ///| -pub fn layout_of_string(meta~ : Meta = Meta::none(), s : String) -> StringNode { +pub fn layout_of_string(meta? : Meta = Meta::none(), s : String) -> StringNode { { meta, v: s } } diff --git a/src/cmark/link_definition.mbt b/src/cmark/link_definition.mbt index 3f874ba..55d0543 100644 --- a/src/cmark/link_definition.mbt +++ b/src/cmark/link_definition.mbt @@ -13,11 +13,11 @@ pub(all) struct LinkDefinition { ///| pub fn LinkDefinition::new( - layout~ : LinkDefinitionLayout = LinkDefinitionLayout::default(), - label~ : Label? = None, - defined_label~ : Label? = None, - dest~ : StringNode? = None, - title~ : Seq[Tight]? = None, + layout? : LinkDefinitionLayout = LinkDefinitionLayout::default(), + label? : Label? = None, + defined_label? : Label? = None, + dest? : StringNode? = None, + title? : Seq[Tight]? = None, ) -> LinkDefinition { { layout, label, defined_label, dest, title } } diff --git a/src/cmark/mapper.mbt b/src/cmark/mapper.mbt index 0b3131f..f5b50b4 100644 --- a/src/cmark/mapper.mbt +++ b/src/cmark/mapper.mbt @@ -1,4 +1,5 @@ -///| Abstract syntax tree mappers. +///| +/// Abstract syntax tree mappers. /// /// Mappers help with pushing abstract syntax tree transformations in every /// node with a minimal amount of code by defaulting the cases you @@ -23,7 +24,8 @@ pub(all) struct MapFn[A]((Mapper, A) -> A? raise MapperError) ///| pub(all) struct MapperFn[A]((Mapper, A) -> MapperResult[A]) -///| The type for mapper results. +///| +/// The type for mapper results. /// `Default` means doing the default map. pub(all) enum MapperResult[A] { Default @@ -68,10 +70,10 @@ pub fn[A] Mapper::block_ext_none(self : Mapper, _a : A) -> A? raise MapperError ///| pub fn Mapper::new( - inline_ext_default~ : MapFn[Inline] = Mapper::inline_ext_none, - block_ext_default~ : MapFn[Block] = Mapper::block_ext_none, - inline~ : MapperFn[Inline] = Mapper::none, - block~ : MapperFn[Block] = Mapper::none, + inline_ext_default? : MapFn[Inline] = Mapper::inline_ext_none, + block_ext_default? : MapFn[Block] = Mapper::block_ext_none, + inline? : MapperFn[Inline] = Mapper::none, + block? : MapperFn[Block] = Mapper::none, ) -> Mapper { { inline_ext_default, block_ext_default, inline, block } } diff --git a/src/cmark/node.mbt b/src/cmark/node.mbt index e998a0d..2095dd3 100644 --- a/src/cmark/node.mbt +++ b/src/cmark/node.mbt @@ -5,7 +5,7 @@ pub(all) struct Node[A] { } derive(Eq) ///| -pub fn[A] Node::new(v : A, meta~ : Meta = Meta::none()) -> Node[A] { +pub fn[A] Node::new(v : A, meta? : Meta = Meta::none()) -> Node[A] { { v, meta } } @@ -41,6 +41,6 @@ pub typealias Node[String] as StringNode pub typealias Node[Blanks] as BlanksNode ///| -pub fn StringNode::empty(meta~ : Meta = Meta::none()) -> StringNode { +pub fn StringNode::empty(meta? : Meta = Meta::none()) -> StringNode { { v: "", meta } } diff --git a/src/cmark/parser.mbt b/src/cmark/parser.mbt index 3444c4a..bfb0e52 100644 --- a/src/cmark/parser.mbt +++ b/src/cmark/parser.mbt @@ -35,14 +35,14 @@ priv struct Parser { ///| fn Parser::new( - defs~ : LabelDefs = LabelDefs::new(), - resolver~ : LabelResolverFn = LabelContext::default_resolver, - nested_links~ : Bool = false, - heading_auto_ids~ : Bool = false, - layout~ : Bool = false, - locs~ : Bool = false, - file~ : FilePath = file_path_none, - strict~ : Bool = true, + defs? : LabelDefs = LabelDefs::new(), + resolver? : LabelResolverFn = LabelContext::default_resolver, + nested_links? : Bool = false, + heading_auto_ids? : Bool = false, + layout? : Bool = false, + locs? : Bool = false, + file? : FilePath = file_path_none, + strict? : Bool = true, i : String, ) -> Parser { { @@ -190,7 +190,7 @@ fn Parser::meta_of_metas(self : Parser, first~ : Meta, last~ : Meta) -> Meta { ///| fn Parser::clean_raw_span( self : Parser, - pad~ : Int = 0, + pad? : Int = 0, span : LineSpan, ) -> StringNode { { @@ -234,7 +234,7 @@ fn Parser::clean_unesc_unref_span(self : Parser, span : LineSpan) -> StringNode ///| fn Parser::layout_clean_raw_span( self : Parser, - pad~ : Int = 0, + pad? : Int = 0, span : LineSpan, ) -> StringNode { if self.no_layouts { @@ -249,7 +249,7 @@ fn Parser::layout_clean_raw_span( ///| fn Parser::layout_clean_raw_span1( self : Parser, - pad~ : Int = 0, + pad? : Int = 0, span : LineSpan, ) -> String { if self.no_layouts { diff --git a/src/cmark/pkg.generated.mbti b/src/cmark/pkg.generated.mbti new file mode 100644 index 0000000..0801280 --- /dev/null +++ b/src/cmark/pkg.generated.mbti @@ -0,0 +1,552 @@ +// Generated using `moon info`, DON'T EDIT IT +package "rami3l/cmark/cmark" + +import( + "moonbitlang/core/json" + "rami3l/cmark/cmark_base" +) + +// Values +let layout_empty : Node[String] + +fn layout_of_string(meta? : @cmark_base.Meta, String) -> Node[String] + +// Errors +pub(all) suberror FolderError String +impl Show for FolderError + +pub(all) suberror MapperError String +impl Show for MapperError + +// Types and methods +pub(all) enum Block { + BlankLine(Node[String]) + BlockQuote(Node[BlockQuote]) + Blocks(Node[Seq[Block]]) + CodeBlock(Node[CodeBlock]) + Heading(Node[BlockHeading]) + HtmlBlock(Node[HtmlBlock]) + LinkRefDefinition(Node[LinkDefinition]) + List(Node[BlockList]) + Paragraph(Node[BlockParagraph]) + ThematicBreak(Node[BlockThematicBreak]) + ExtMathBlock(Node[CodeBlock]) + ExtTable(Node[Table]) + ExtFootnoteDefinition(Node[Footnote]) +} +fn Block::defs(Self, init? : Map[String, LabelDef]) -> Map[String, LabelDef] +fn Block::empty() -> Self +fn Block::meta(Self) -> @cmark_base.Meta +fn Block::normalize(Self) -> Self +impl Show for Block +impl ToJson for Block + +pub(all) struct BlockHeading { + layout : BlockHeadingLayout + level : Int + inline : Inline + id : BlockHeadingId? +} +fn BlockHeading::new(id? : BlockHeadingId?, layout? : BlockHeadingLayout, level~ : Int, Inline) -> Self +impl Show for BlockHeading +impl ToJson for BlockHeading + +pub(all) struct BlockHeadingAtxLayout { + indent : Int + after_opening : String + closing : String +} +fn BlockHeadingAtxLayout::default() -> Self +impl Show for BlockHeadingAtxLayout +impl ToJson for BlockHeadingAtxLayout +impl @json.FromJson for BlockHeadingAtxLayout + +pub(all) enum BlockHeadingId { + Auto(String) + Id(String) +} +impl Show for BlockHeadingId +impl ToJson for BlockHeadingId +impl @json.FromJson for BlockHeadingId + +pub(all) enum BlockHeadingLayout { + Atx(BlockHeadingAtxLayout) + Setext(BlockHeadingSetextLayout) +} +impl Show for BlockHeadingLayout +impl ToJson for BlockHeadingLayout + +pub(all) struct BlockHeadingSetextLayout { + leading_indent : Int + trailing_blanks : String + underline_indent : Int + underline_count : Node[Int] + underline_blanks : String +} +impl Show for BlockHeadingSetextLayout +impl ToJson for BlockHeadingSetextLayout + +pub(all) struct BlockLine(Node[String]) +fn BlockLine::inner(Self) -> Node[String] +fn BlockLine::list_text_loc(Seq[Self]) -> @cmark_base.TextLoc +fn BlockLine::to_string(Self) -> String + +pub(all) struct BlockList { + ty : @cmark_base.ListType + tight : Bool + items : Seq[Node[ListItem]] +} +fn BlockList::map_items(Self, (ListItem) -> ListItem) -> Self +fn BlockList::normalize_items(Self) -> Self +impl Show for BlockList +impl ToJson for BlockList + +pub(all) struct BlockParagraph { + leading_indent : Int + inline : Inline + trailing_blanks : String +} +fn BlockParagraph::new(leading_indent? : Int, trailing_blanks? : String, Inline) -> Self +impl Show for BlockParagraph +impl ToJson for BlockParagraph + +pub(all) struct BlockQuote { + indent : Int + block : Block +} +fn BlockQuote::map_block(Self, (Block) -> Block) -> Self +fn BlockQuote::new(indent? : Int, Block) -> Self +fn BlockQuote::normalize_block(Self) -> Self +impl Show for BlockQuote +impl ToJson for BlockQuote + +pub(all) struct BlockThematicBreak { + indent : Int + layout : String +} +fn BlockThematicBreak::new(indent? : Int, layout? : String) -> Self +impl Show for BlockThematicBreak +impl ToJson for BlockThematicBreak +impl @json.FromJson for BlockThematicBreak + +pub(all) struct CodeBlock { + layout : CodeBlockLayout + info_string : Node[String]? + code : Seq[Node[String]] +} +fn CodeBlock::language_of_info_string(String) -> (String, String)? +fn CodeBlock::make_fence(Self) -> (Char, Int) +fn CodeBlock::new(layout? : CodeBlockLayout, info_string? : Node[String]?, Seq[Node[String]]) -> Self +impl Show for CodeBlock +impl ToJson for CodeBlock + +pub(all) struct CodeBlockFencedLayout { + indent : Int + opening_fence : Node[String] + closing_fence : Node[String]? +} +fn CodeBlockFencedLayout::default() -> Self +impl Show for CodeBlockFencedLayout +impl ToJson for CodeBlockFencedLayout + +pub(all) enum CodeBlockLayout { + Indented + Fenced(CodeBlockFencedLayout) +} +impl Show for CodeBlockLayout +impl ToJson for CodeBlockLayout + +pub(all) struct Doc { + nl : String + block : Block + defs : Map[String, LabelDef] +} +fn Doc::empty() -> Self +fn Doc::from_string(defs? : Map[String, LabelDef], resolver? : LabelResolverFn, nested_links? : Bool, heading_auto_ids? : Bool, layout? : Bool, locs? : Bool, file? : String, strict? : Bool, String) -> Self +fn Doc::new(nl? : String, defs? : Map[String, LabelDef], Block) -> Self +impl Show for Doc +impl ToJson for Doc + +pub(all) struct FoldFn[A, B]((Folder[B], B, A) -> B raise FolderError) +fn[A, B] FoldFn::inner(Self[A, B]) -> (Folder[B], B, A) -> B raise FolderError + +pub(all) struct Folder[A] { + inline_ext_default : FoldFn[Inline, A] + block_ext_default : FoldFn[Block, A] + inline : FolderFn[Inline, A] + block : FolderFn[Block, A] +} +fn[A] Folder::block_ext_none(Self[A], A, Block) -> A raise FolderError +fn[A] Folder::fold_block(Self[A], A, Block) -> A raise FolderError +fn[A] Folder::fold_doc(Self[A], A, Doc) -> A raise FolderError +fn[A] Folder::fold_inline(Self[A], A, Inline) -> A raise FolderError +fn[A] Folder::inline_ext_none(Self[A], A, Inline) -> A raise FolderError +fn[A] Folder::new(inline_ext_default? : FoldFn[Inline, A], block_ext_default? : FoldFn[Block, A], inline? : FolderFn[Inline, A], block? : FolderFn[Block, A]) -> Self[A] +fn[A, B] Folder::none(Self[A], A, B) -> FolderResult[A] +fn[A] Folder::ret(A) -> FolderResult[A] + +pub(all) struct FolderFn[A, B]((Folder[B], B, A) -> FolderResult[B]) +fn[A, B] FolderFn::inner(Self[A, B]) -> (Folder[B], B, A) -> FolderResult[B] + +pub(all) enum FolderResult[A] { + Default + Fold(A) +} +impl[A] Default for FolderResult[A] +impl[A : Eq] Eq for FolderResult[A] +impl[A : Show] Show for FolderResult[A] +impl[A : ToJson] ToJson for FolderResult[A] + +pub(all) struct Footnote { + indent : Int + label : Label + defined_label : Label? + block : Block +} +fn Footnote::map_block(Self, (Block) -> Block) -> Self +fn Footnote::new(indent? : Int, defined_label? : Label?, Label, Block) -> Self +fn Footnote::normalize_block(Self) -> Self +impl Show for Footnote +impl ToJson for Footnote + +pub(all) struct HtmlBlock(Seq[Node[String]]) +fn HtmlBlock::inner(Self) -> Seq[Node[String]] +impl Show for HtmlBlock +impl ToJson for HtmlBlock + +pub(all) enum Inline { + Autolink(Node[InlineAutolink]) + Break(Node[InlineBreak]) + CodeSpan(Node[InlineCodeSpan]) + Emphasis(Node[InlineEmphasis]) + Image(Node[InlineLink]) + Inlines(Node[Seq[Inline]]) + Link(Node[InlineLink]) + RawHtml(Node[InlineRawHtml]) + StrongEmphasis(Node[InlineEmphasis]) + Text(Node[String]) + ExtStrikethrough(Node[InlineStrikethrough]) + ExtMathSpan(Node[InlineMathSpan]) +} +fn Inline::empty() -> Self +fn Inline::id(Self, buf? : StringBuilder) -> String +fn Inline::is_empty(Self) -> Bool +fn Inline::meta(Self) -> @cmark_base.Meta +fn Inline::normalize(Self) -> Self +fn Inline::to_plain_text(Self, break_on_soft~ : Bool) -> Seq[Seq[String]] +impl Eq for Inline +impl Show for Inline +impl ToJson for Inline + +pub(all) struct InlineAutolink { + is_email : Bool + link : Node[String] +} +fn InlineAutolink::new(Node[String]) -> Self +impl Eq for InlineAutolink +impl Show for InlineAutolink +impl ToJson for InlineAutolink + +pub(all) struct InlineBreak { + layout_before : Node[String] + ty : InlineBreakType + layout_after : Node[String] +} +fn InlineBreak::new(layout_before? : Node[String], layout_after? : Node[String], InlineBreakType) -> Self +impl Eq for InlineBreak +impl Show for InlineBreak +impl ToJson for InlineBreak + +pub(all) enum InlineBreakType { + Hard + Soft +} +impl Compare for InlineBreakType +impl Eq for InlineBreakType +impl Show for InlineBreakType +impl ToJson for InlineBreakType +impl @json.FromJson for InlineBreakType + +pub(all) struct InlineCodeSpan { + backticks : Int + code_layout : Seq[Tight] +} +fn InlineCodeSpan::code(Self) -> String +fn InlineCodeSpan::from_string(meta? : @cmark_base.Meta, String) -> Self +fn InlineCodeSpan::new(backticks~ : Int, Seq[Tight]) -> Self +impl Eq for InlineCodeSpan +impl Show for InlineCodeSpan +impl ToJson for InlineCodeSpan + +pub(all) struct InlineEmphasis { + delim : Char + inline : Inline +} +fn InlineEmphasis::new(delim? : Char, Inline) -> Self +impl Eq for InlineEmphasis +impl Show for InlineEmphasis +impl ToJson for InlineEmphasis + +pub(all) struct InlineLink { + text : Inline + reference : ReferenceKind +} +fn InlineLink::is_unsafe(String) -> Bool +fn InlineLink::new(Inline, ReferenceKind) -> Self +fn InlineLink::reference_definition(Self, Map[String, LabelDef]) -> LabelDef? +fn InlineLink::referenced_label(Self) -> Label? +impl Eq for InlineLink +impl Show for InlineLink +impl ToJson for InlineLink + +pub(all) struct InlineMathSpan { + display : Bool + tex_layout : Seq[Tight] +} +fn InlineMathSpan::tex(Self) -> String +impl Eq for InlineMathSpan +impl Show for InlineMathSpan +impl ToJson for InlineMathSpan + +pub(all) struct InlineRawHtml(Seq[Tight]) +fn InlineRawHtml::inner(Self) -> Seq[Tight] +impl Eq for InlineRawHtml +impl Show for InlineRawHtml +impl ToJson for InlineRawHtml + +pub(all) struct InlineStrikethrough(Inline) +fn InlineStrikethrough::inner(Self) -> Inline +impl Eq for InlineStrikethrough +impl Show for InlineStrikethrough +impl ToJson for InlineStrikethrough + +pub(all) struct Label { + meta : @cmark_base.Meta + key : String + text : Seq[Tight] +} +fn Label::compare(Self, Self) -> Int +fn Label::new(meta? : @cmark_base.Meta, key~ : String, Seq[Tight]) -> Self +fn Label::text_loc(Self) -> @cmark_base.TextLoc +impl Eq for Label +impl Show for Label +impl ToJson for Label + +pub(all) enum LabelContext { + Def(Label?, Label) + Ref(LinkKind, Label, Label?) +} +fn LabelContext::default_resolver(Self) -> Label? + +pub(all) enum LabelDef { + LinkDef(Node[LinkDefinition]) + FootnoteDef(Node[Footnote]) +} +impl Show for LabelDef +impl ToJson for LabelDef + +pub(all) struct LabelResolverFn((LabelContext) -> Label?) +fn LabelResolverFn::inner(Self) -> (LabelContext) -> Label? + +pub(all) struct LinkDefinition { + layout : LinkDefinitionLayout + label : Label? + defined_label : Label? + dest : Node[String]? + title : Seq[Tight]? +} +fn LinkDefinition::new(layout? : LinkDefinitionLayout, label? : Label?, defined_label? : Label?, dest? : Node[String]?, title? : Seq[Tight]?) -> Self +impl Eq for LinkDefinition +impl Show for LinkDefinition +impl ToJson for LinkDefinition + +pub(all) struct LinkDefinitionLayout { + indent : Int + angled_dest : Bool + before_dest : Seq[Node[String]] + after_dest : Seq[Node[String]] + title_open_delim : Char + after_title : Seq[Node[String]] +} +fn LinkDefinitionLayout::default() -> Self +fn LinkDefinitionLayout::for_dest(String) -> Self +impl Eq for LinkDefinitionLayout +impl Show for LinkDefinitionLayout +impl ToJson for LinkDefinitionLayout + +pub(all) enum LinkKind { + Link + Image +} + +pub(all) struct ListItem { + before_marker : Int + marker : Node[String] + after_marker : Int + block : Block + ext_task_marker : Node[Char]? +} +fn ListItem::map_block(Self, (Block) -> Block) -> Self +fn ListItem::new(before_marker? : Int, marker? : Node[String], after_marker? : Int, ext_task_marker~ : Node[Char]?, Block) -> Self +fn ListItem::normalize_block(Self) -> Self +impl Show for ListItem +impl ToJson for ListItem + +pub(all) enum ListTaskStatus { + Cancelled + Checked + Unchecked + Other(Char) +} +fn ListTaskStatus::from_marker(Char) -> Self + +pub(all) struct MapFn[A]((Mapper, A) -> A? raise MapperError) +fn[A] MapFn::inner(Self[A]) -> (Mapper, A) -> A? raise MapperError + +pub(all) struct Mapper { + inline_ext_default : MapFn[Inline] + block_ext_default : MapFn[Block] + inline : MapperFn[Inline] + block : MapperFn[Block] +} +fn[A] Mapper::block_ext_none(Self, A) -> A? raise MapperError +fn[A] Mapper::delete() -> MapperResult[A] +fn[A] Mapper::inline_ext_none(Self, A) -> A? raise MapperError +fn Mapper::map_block(Self, Block) -> Block? +fn Mapper::map_doc(Self, Doc) -> Doc +fn Mapper::map_inline(Self, Inline) -> Inline? +fn Mapper::new(inline_ext_default? : MapFn[Inline], block_ext_default? : MapFn[Block], inline? : MapperFn[Inline], block? : MapperFn[Block]) -> Self +fn[A] Mapper::none(Self, A) -> MapperResult[A] +fn[A] Mapper::ret(A) -> MapperResult[A] + +pub(all) struct MapperFn[A]((Mapper, A) -> MapperResult[A]) +fn[A] MapperFn::inner(Self[A]) -> (Mapper, A) -> MapperResult[A] + +pub(all) enum MapperResult[A] { + Default + Map(A?) +} +impl[A] Default for MapperResult[A] +impl[A : Eq] Eq for MapperResult[A] +impl[A : Show] Show for MapperResult[A] +impl[A : ToJson] ToJson for MapperResult[A] + +pub(all) struct Node[A] { + v : A + meta : @cmark_base.Meta +} +fn Node::empty(meta? : @cmark_base.Meta) -> Self[String] +fn[A, B] Node::map(Self[A], (A) -> B) -> Self[B] +fn[A] Node::new(A, meta? : @cmark_base.Meta) -> Self[A] +impl[A : Eq] Eq for Node[A] +impl[A : Show] Show for Node[A] +impl[A : ToJson] ToJson for Node[A] + +pub(all) enum ReferenceKind { + Inline(Node[LinkDefinition]) + Ref(ReferenceLayout, Label, Label) +} +impl Eq for ReferenceKind +impl Show for ReferenceKind +impl ToJson for ReferenceKind + +pub(all) enum ReferenceLayout { + Collapsed + Full + Shortcut +} +impl Eq for ReferenceLayout +impl Show for ReferenceLayout +impl ToJson for ReferenceLayout +impl @json.FromJson for ReferenceLayout + +type Seq[A] +fn[A] Seq::empty() -> Self[A] +fn[A, B] Seq::fold(Self[A], init~ : B, (B, A) -> B) -> B +fn[A] Seq::from_array(Array[A]) -> Self[A] +fn[A] Seq::from_iter(Iter[A]) -> Self[A] +fn[A] Seq::get(Self[A], Int) -> A? +fn[A] Seq::is_empty(Self[A]) -> Bool +fn[A] Seq::iter(Self[A]) -> Iter[A] +fn[A] Seq::length(Self[A]) -> Int +fn[A, B] Seq::map(Self[A], (A) -> B) -> Self[B] +fn[A] Seq::op_get(Self[A], Int) -> A +fn[A] Seq::op_set(Self[A], Int, A) -> Unit +fn[A, B] Seq::rev_fold(Self[A], init~ : B, (B, A) -> B) -> B +fn[A] Seq::to_array(Self[A]) -> Array[A] +impl[A : Eq] Eq for Seq[A] +impl[A : Show] Show for Seq[A] +impl[A : ToJson] ToJson for Seq[A] + +pub(all) struct Table { + indent : Int + col_count : Int + rows : Seq[(Node[TableRow], String)] +} +fn Table::new(indent? : Int, Seq[(Node[TableRow], String)]) -> Self +impl Show for Table +impl ToJson for Table + +pub(all) enum TableAlign { + Left + Center + Right +} +impl Show for TableAlign +impl ToJson for TableAlign +impl @json.FromJson for TableAlign + +pub(all) struct TableCellLayout((String, String)) +fn TableCellLayout::inner(Self) -> (String, String) +impl Compare for TableCellLayout +impl Eq for TableCellLayout +impl Show for TableCellLayout +impl ToJson for TableCellLayout + +pub(all) enum TableRow { + Header(Seq[(Inline, TableCellLayout)]) + Sep(Seq[Node[TableSep]]) + Data(Seq[(Inline, TableCellLayout)]) +} +impl Show for TableRow +impl ToJson for TableRow + +pub(all) struct TableSep((TableAlign?, Int)) +fn TableSep::inner(Self) -> (TableAlign?, Int) +impl Show for TableSep +impl ToJson for TableSep + +pub(all) struct Tight { + blanks : String + node : Node[String] +} +fn Tight::empty(meta? : @cmark_base.Meta) -> Self +fn Tight::list_text_loc(Seq[Self]) -> @cmark_base.TextLoc +fn Tight::to_string(Self) -> String +impl Eq for Tight +impl Show for Tight +impl ToJson for Tight + +// Type aliases +pub typealias String as Blanks + +pub typealias Node[String] as BlanksNode + +pub typealias String as BlockBlankLine + +pub typealias Node[String] as BlockLineBlank + +pub typealias Int as Count + +pub typealias String as InlineText + +pub typealias Map[String, LabelDef] as LabelDefs + +pub typealias String as LabelKey + +pub typealias ListItem as ListItemBlock + +pub typealias Node[String] as StringNode + +// Traits + diff --git a/src/cmark_base/autolink.mbt b/src/cmark_base/autolink.mbt index 2296800..c3c07a8 100644 --- a/src/cmark_base/autolink.mbt +++ b/src/cmark_base/autolink.mbt @@ -1,6 +1,7 @@ -///| `autolink_email(s, last, start)` matches an email autolink starting at +///| +/// `autolink_email(s, last, start)` matches an email autolink starting at /// `start` in the range `[start;last]` (assumed on the same line). -pub fn autolink_email(s : String, last~ : Int = -1, start~ : Int = 0) -> Last? { +pub fn autolink_email(s : String, last? : Int = -1, start? : Int = 0) -> Last? { let last = if last < 0 { s.length() + last } else { last } fn char_is_alphanum_or_hyp(c) { @char.is_ascii_alphanum(c) || c == '-' @@ -44,9 +45,10 @@ pub fn autolink_email(s : String, last~ : Int = -1, start~ : Int = 0) -> Last? { } } -///| `autolink_uri(s, last, start)` matches an URI autolink starting at +///| +/// `autolink_uri(s, last, start)` matches an URI autolink starting at /// `start` in the range `[start;last]` (assumed on the same line). -pub fn autolink_uri(s : String, last~ : Int = -1, start~ : Int = 0) -> Last? { +pub fn autolink_uri(s : String, last? : Int = -1, start? : Int = 0) -> Last? { let last = if last < 0 { s.length() + last } else { last } let char_is_scheme = fn(c) { @char.is_ascii_alphanum(c) || c is ('+' | '-' | '.') diff --git a/src/cmark_base/leaf_blocks.mbt b/src/cmark_base/leaf_blocks.mbt index 55fdffd..635eee7 100644 --- a/src/cmark_base/leaf_blocks.mbt +++ b/src/cmark_base/leaf_blocks.mbt @@ -41,7 +41,8 @@ pub(all) enum LineType { Nomatch } derive(Show, ToJson(style="flat"), Eq) -///| https://spec.commonmark.org/current/#thematic-breaks +///| +/// https://spec.commonmark.org/current/#thematic-breaks pub fn LineType::thematic_break( s : String, last~ : CharCodePos, @@ -71,7 +72,8 @@ pub fn LineType::thematic_break( } } -///| https://spec.commonmark.org/current/#atx-headings +///| +/// https://spec.commonmark.org/current/#atx-headings pub fn LineType::atx_heading( s : String, last~ : CharCodePos, @@ -146,7 +148,8 @@ pub fn LineType::atx_heading( level(s, last, 1, start + 1) } -///| https://spec.commonmark.org/current/#setext-heading +///| +/// https://spec.commonmark.org/current/#setext-heading pub fn LineType::setext_heading_underline( s : String, last~ : CharCodePos, @@ -236,7 +239,8 @@ pub(all) enum FencedCodeBlockContinue { Code } derive(Show, ToJson(style="flat")) -///| `fenced_code_block_continue(fence, s, last, start)` indicates +///| +/// `fenced_code_block_continue(fence, s, last, start)` indicates /// whether the fence code continues or closes in the the range /// [start;last] given the opening `open` which indicates the /// indent, fence char and number of fence chars. @@ -356,7 +360,8 @@ fn LineType::html_block_start_7_close_tag( } } -///| https://spec.commonmark.org/current/#html-blocks +///| +/// https://spec.commonmark.org/current/#html-blocks pub fn LineType::html_block_start( s : String, last~ : CharCodePos, @@ -425,7 +430,8 @@ pub fn LineType::html_block_start( } } -///| https://spec.commonmark.org/current/#html-blocks end condition 1. +///| +/// https://spec.commonmark.org/current/#html-blocks end condition 1. fn LineType::html_block_end_cond_1( s : String, last~ : CharCodePos, diff --git a/src/cmark_base/link.mbt b/src/cmark_base/link.mbt index 64de7a3..7568d18 100644 --- a/src/cmark_base/link.mbt +++ b/src/cmark_base/link.mbt @@ -1,4 +1,5 @@ -///| `link_destination(s, last, start)` matches a link destination +///| +/// `link_destination(s, last, start)` matches a link destination /// starting at `start` in the range `start..=last` (assumed on /// the same line). This is `Some((delimited, first, last))` with the /// data in [first..=last] the destination data. `delimited` is @@ -66,7 +67,8 @@ pub fn link_destination( } } -///| `link_title(next_line, s, lines, line, last)` is a link title on line `line` starting at `start`. +///| +/// `link_title(next_line, s, lines, line, last)` is a link title on line `line` starting at `start`. /// Returns `Some((lines, last_line, spans, last))` with `lines` the lines after consuming the title, /// `last_line` the line where it stops, `spans` the byte ranges of `s` that make up the title in reverse /// order, `last` is on the closing delimiter and guaranteed to be on `last_line`. @@ -120,7 +122,8 @@ pub fn[A] link_title( } } -///| Matches a link label on `line` starting at `start`. +///| +/// Matches a link label on `line` starting at `start`. /// The byte ranges have the label's content, the string is the normalized label. /// `buf` is used as scratch space. /// diff --git a/src/cmark_base/meta.mbt b/src/cmark_base/meta.mbt index b808b55..97773d9 100644 --- a/src/cmark_base/meta.mbt +++ b/src/cmark_base/meta.mbt @@ -12,7 +12,7 @@ typealias Int as MetaId let curr_id : Ref[MetaId] = Ref::new(0) ///| -pub fn Meta::new(loc~ : TextLoc = text_loc_none) -> Meta { +pub fn Meta::new(loc? : TextLoc = text_loc_none) -> Meta { let res = { loc, id: curr_id.val, extra: None } curr_id.val += 1 res @@ -27,7 +27,7 @@ pub fn Meta::none() -> Meta { } ///| -pub impl Eq for Meta with op_equal(self, other) { +pub impl Eq for Meta with equal(self, other) { self.id == other.id } diff --git a/src/cmark_base/pkg.generated.mbti b/src/cmark_base/pkg.generated.mbti new file mode 100644 index 0000000..6b1eacd --- /dev/null +++ b/src/cmark_base/pkg.generated.mbti @@ -0,0 +1,196 @@ +// Generated using `moon info`, DON'T EDIT IT +package "rami3l/cmark/cmark_base" + +import( + "moonbitlang/core/json" +) + +// Values +fn autolink_email(String, last? : Int, start? : Int) -> Int? + +fn autolink_uri(String, last? : Int, start? : Int) -> Int? + +let char_code_pos_none : Int + +fn could_be_link_ref_definition(String, last~ : Int, start~ : Int) -> Bool + +fn ext_task_marker(String, last~ : Int, start~ : Int) -> (Char, Int)? + +let file_path_none : String + +fn first_non_blank(String, last~ : Int, start~ : Int) -> Int + +fn first_non_blank_in_span(String, LineSpan) -> Int + +fn[A] first_non_blank_over_nl(next_line~ : NextLineFn[A], String, A, line~ : LineSpan, start~ : Int) -> NextLineResult? + +fn first_non_escaped_char(Char, String, last~ : Int, start~ : Int) -> Int + +fn last_non_blank(String, first~ : Int, start~ : Int) -> Int + +let line_num_none : Int + +let line_pos_none : LinePos + +fn link_destination(String, last~ : Int, start~ : Int) -> (Bool, Int, Int)? + +fn[A] link_label(StringBuilder, next_line~ : NextLineFn[A], String, A, line~ : LineSpan, start~ : Int) -> (LineSpan, Array[Span], Int, String)? + +fn[A] link_title(next_line~ : NextLineFn[A], String, A, line~ : LineSpan, start~ : Int) -> (LineSpan, Array[Span], Int)? + +fn[A] raw_html(next_line~ : NextLineFn[A], String, A, line~ : LineSpan, start~ : Int) -> (LineSpan, Array[Span], Int)? + +fn rev_drop_spaces(String, first~ : Int, start~ : Int) -> Int + +fn run_of(char~ : Char, String, last~ : Int, start~ : Int) -> Int + +// Errors + +// Types and methods +pub(all) enum FencedCodeBlockContinue { + Close(Int, Int) + Code +} +fn FencedCodeBlockContinue::new(String, fence~ : (Char, Int), last~ : Int, start~ : Int) -> Self +impl Show for FencedCodeBlockContinue +impl ToJson for FencedCodeBlockContinue + +pub(all) enum HtmlBlockEndCond { + EndStr(String) + EndCond1 + EndBlank + EndBlank7 +} +impl Eq for HtmlBlockEndCond +impl Show for HtmlBlockEndCond +impl ToJson for HtmlBlockEndCond + +pub(all) struct LinePos(Int, Int) + +impl Compare for LinePos +impl Eq for LinePos +impl Show for LinePos +impl ToJson for LinePos +impl @json.FromJson for LinePos + +pub(all) struct LineSpan { + pos : LinePos + first : Int + last : Int +} +impl Compare for LineSpan +impl Eq for LineSpan +impl Show for LineSpan +impl ToJson for LineSpan + +pub(all) enum LineType { + AtxHeadingLine(Int, Int, Int, Int) + BlankLine + BlockQuoteLine + FencedCodeBlockLine(Int, Int, (Int, Int)?) + HtmlBlockLine(HtmlBlockEndCond) + IndentedCodeBlockLine + ListMarkerLine(ListType, Int) + ParagraphLine + SetextUnderlineLine(Int, Int) + ThematicBreakLine(Int) + ExtTableRow(Int) + ExtFootnoteLabel(Array[Span], Int, String) + Nomatch +} +fn LineType::atx_heading(String, last~ : Int, start~ : Int) -> Self +fn LineType::ext_footnote_label(StringBuilder, String, line_pos~ : LinePos, last~ : Int, start~ : Int) -> Self +fn LineType::ext_table_row(String, last~ : Int, start~ : Int) -> Self +fn LineType::fenced_code_block_start(String, last~ : Int, start~ : Int) -> Self +fn LineType::html_block_end(String, end_cond~ : HtmlBlockEndCond, last~ : Int, start~ : Int) -> Bool +fn LineType::html_block_start(String, last~ : Int, start~ : Int) -> Self +fn LineType::list_marker(String, last~ : Int, start~ : Int) -> Self +fn LineType::setext_heading_underline(String, last~ : Int, start~ : Int) -> Self +fn LineType::thematic_break(String, last~ : Int, start~ : Int) -> Self +impl Eq for LineType +impl Show for LineType +impl ToJson for LineType + +pub(all) enum ListType { + Unordered(Char) + Ordered(Int, Char) +} +fn ListType::is_same_type(Self, Self) -> Bool +impl Eq for ListType +impl Show for ListType +impl ToJson for ListType +impl @json.FromJson for ListType + +pub(all) struct Meta { + id : Int + loc : TextLoc + extra : Error? +} +fn Meta::compare(Self, Self) -> Int +fn Meta::is_none(Self) -> Bool +fn Meta::new(loc? : TextLoc) -> Self +fn Meta::none() -> Self +fn Meta::to_json(Self) -> Json +impl Eq for Meta +impl Show for Meta +impl ToJson for Meta + +pub(all) struct NextLineFn[A]((A) -> LineSpan?) +fn[A] NextLineFn::inner(Self[A]) -> (A) -> LineSpan? + +pub(all) enum NextLineResult { + ThisLine(Int) + NextLine(LineSpan, Int) +} +impl Show for NextLineResult +impl ToJson for NextLineResult + +pub(all) struct Span { + start : Int + span : LineSpan +} +impl Compare for Span +impl Eq for Span +impl Show for Span +impl ToJson for Span + +pub(all) struct TextLoc { + file : String + first_ccode : Int + last_ccode : Int + first_line : LinePos + last_line : LinePos +} +fn TextLoc::after(Self) -> Self +fn TextLoc::is_empty(Self) -> Bool +fn TextLoc::is_none(Self) -> Bool +fn TextLoc::none() -> Self +fn TextLoc::reloc(Self, Self) -> Self +fn TextLoc::span(Self, Self) -> Self +fn TextLoc::to_first(Self) -> Self +fn TextLoc::to_last(Self) -> Self +impl Compare for TextLoc +impl Eq for TextLoc +impl Show for TextLoc +impl ToJson for TextLoc +impl @json.FromJson for TextLoc + +// Type aliases +pub typealias Int as CharCodePos + +pub typealias String as FilePath + +pub typealias Int as First + +pub typealias Int as HeadingLevel + +pub typealias Int as Indent + +pub typealias Int as Last + +pub typealias Int as LineNum + +pub typealias Int as Next + +// Traits + diff --git a/src/cmark_base/raw_html.mbt b/src/cmark_base/raw_html.mbt index deab941..da37b31 100644 --- a/src/cmark_base/raw_html.mbt +++ b/src/cmark_base/raw_html.mbt @@ -1,5 +1,6 @@ -///| https://spec.commonmark.org/current/#tag-name -fn tag_name(s : String, last~ : Int = -1, start~ : Int = 0) -> Int? { +///| +/// https://spec.commonmark.org/current/#tag-name +fn tag_name(s : String, last? : Int = -1, start? : Int = 0) -> Int? { let last = if last < 0 { s.length() + last } else { last } for k = start + 1 { guard k <= last else { break Some(k - 1) } @@ -10,8 +11,9 @@ fn tag_name(s : String, last~ : Int = -1, start~ : Int = 0) -> Int? { } } -///| https://spec.commonmark.org/current/#attribute-name -fn attribute_name(s : String, last~ : Int = -1, start~ : Int = 0) -> Next? { +///| +/// https://spec.commonmark.org/current/#attribute-name +fn attribute_name(s : String, last? : Int = -1, start? : Int = 0) -> Next? { let last = if last < 0 { s.length() + last } else { last } fn char_is_start(c : Char) -> Bool { match c { @@ -38,7 +40,8 @@ fn attribute_name(s : String, last~ : Int = -1, start~ : Int = 0) -> Next? { } } -///| https://spec.commonmark.org/current/#attribute-value +///| +/// https://spec.commonmark.org/current/#attribute-value fn[A] attribute_value( next_line~ : NextLineFn[A], s : String, @@ -71,7 +74,8 @@ fn[A] attribute_value( } } -///| https://spec.commonmark.org/current/#attribute +///| +/// https://spec.commonmark.org/current/#attribute /// https://spec.commonmark.org/current/#attribute-value-specification fn[A] attribute( next_line~ : NextLineFn[A], @@ -111,7 +115,8 @@ fn[A] attribute( attribute_value(next_line~, s, lines, line~, spans.val, start~) } -///| https://spec.commonmark.org/current/#open-tag +///| +/// https://spec.commonmark.org/current/#open-tag fn[A] open_tag( next_line~ : NextLineFn[A], s : String, @@ -167,7 +172,8 @@ fn[A] open_tag( } } -///| Start is on ` (String) -> LineSpan? { fn(_) { None } } @@ -131,7 +132,8 @@ test "raw_html with invalid char after " // Tag name cannot start with a number let line_span = @cmark_base.LineSpan::{ @@ -170,7 +173,8 @@ test "raw_html_closing_tag_invalid_name" { ) } -///| Test raw_html with closing tag that has no closing bracket +///| +/// Test raw_html with closing tag that has no closing bracket test "raw_html_closing_tag_no_end" { let s = " let line_span = @cmark_base.LineSpan::{ @@ -188,7 +192,8 @@ test "raw_html_closing_tag_no_end" { inspect(result, content="None") } -///| Test raw_html with invalid open tag +///| +/// Test raw_html with invalid open tag test "raw_html_open_tag_invalid" { let s = "<.div>" // Tag name cannot start with a dot let line_span = @cmark_base.LineSpan::{ @@ -209,7 +214,8 @@ test "raw_html_open_tag_invalid" { ) } -///| Test raw_html with self-closing tag that has no closing bracket +///| +/// Test raw_html with self-closing tag that has no closing bracket test "raw_html_self_closing_tag_no_end" { let s = "
let line_span = @cmark_base.LineSpan::{ @@ -227,7 +233,8 @@ test "raw_html_self_closing_tag_no_end" { inspect(result, content="None") } -///| Test raw_html with attribute that has invalid name +///| +/// Test raw_html with attribute that has invalid name test "raw_html_attribute_invalid_name" { let s = "
" let line_span = @cmark_base.LineSpan::{ @@ -245,7 +252,8 @@ test "raw_html_attribute_invalid_name" { inspect(result, content="None") } -///| Test raw_html with attribute that has no value +///| +/// Test raw_html with attribute that has no value test "raw_html_attribute_no_value" { let s = "
" // Attribute without value is valid let line_span = @cmark_base.LineSpan::{ @@ -266,7 +274,8 @@ test "raw_html_attribute_no_value" { ) } -///| Test raw_html with unquoted attribute value +///| +/// Test raw_html with unquoted attribute value test "raw_html_attribute_unquoted_value" { let s = "
" // Unquoted attribute value is valid let line_span = @cmark_base.LineSpan::{ @@ -287,7 +296,8 @@ test "raw_html_attribute_unquoted_value" { ) } -///| Test raw_html with exclamation mark but invalid format +///| +/// Test raw_html with exclamation mark but invalid format test "raw_html_exclamation_invalid" { let s = "" // Invalid HTML comment let line_span = @cmark_base.LineSpan::{ @@ -359,7 +372,8 @@ test "raw_html_comment_invalid1" { inspect(result, content="None") } -///| Test HTML comment with invalid format 2 +///| +/// Test HTML comment with invalid format 2 test "raw_html_comment_invalid2" { let s = "" // Invalid HTML comment let line_span = @cmark_base.LineSpan::{ @@ -377,7 +391,8 @@ test "raw_html_comment_invalid2" { inspect(result, content="None") } -///| Test CDATA section with incomplete format +///| +/// Test CDATA section with incomplete format test "raw_html_cdata_incomplete" { let s = "" let result = tag_name(s, last=16, start=0) @@ -19,7 +20,8 @@ test "tag_name with invalid start condition" { inspect(result, content="Some(3)") } -///| Test for attribute_name +///| +/// Test for attribute_name test "attribute_name with valid start chars" { let s = "_attr:value" let result = attribute_name(s, last=9, start=0) diff --git a/src/cmark_base/runs.mbt b/src/cmark_base/runs.mbt index 11916a8..0aced18 100644 --- a/src/cmark_base/runs.mbt +++ b/src/cmark_base/runs.mbt @@ -1,4 +1,5 @@ -///| `run_of(char, s, last, start)` is the last position of a consecutive run of `char` +///| +/// `run_of(char, s, last, start)` is the last position of a consecutive run of `char` /// in the range `[start, last]` or `start - 1` if `start` is not `char`. pub fn run_of( char~ : Char, @@ -12,7 +13,8 @@ pub fn run_of( run_of(char~, s, last~, start=start + 1) } -///| `first_non_blank(s, last, start)` is the first position in the range `[start, last]` +///| +/// `first_non_blank(s, last, start)` is the first position in the range `[start, last]` /// that is not blank and `last + 1` if there is none. pub fn first_non_blank( s : String, @@ -25,12 +27,14 @@ pub fn first_non_blank( last + 1 } -///| `first_non_blank_in_span(s, span)` is `first_non_blank(s, last=span.last, start=span.first)`. +///| +/// `first_non_blank_in_span(s, span)` is `first_non_blank(s, last=span.last, start=span.first)`. pub fn first_non_blank_in_span(s : String, span : LineSpan) -> CharCodePos { first_non_blank(s, last=span.last, start=span.first) } -///| `last_non_blank(s, first, start)` is the last position in the range `[first, start]` +///| +/// `last_non_blank(s, first, start)` is the last position in the range `[first, start]` /// that is not blank and `first - 1` if there is none. pub fn last_non_blank( s : String, @@ -46,7 +50,8 @@ pub fn last_non_blank( } } -///| `rev_drop_spaces(s, first, start)` is the last position in the range `[first, start]` +///| +/// `rev_drop_spaces(s, first, start)` is the last position in the range `[first, start]` /// that is not U+0020 and `first - 1` if there is none. pub fn rev_drop_spaces( s : String, @@ -84,7 +89,8 @@ fn push_span( spans.push({ start: line.first, span: { ..line, first: first1, last: last1 } }) } -///| Includes final `char` in spans. +///| +/// Includes final `char` in spans. fn[A] accept_to( char~ : Char, next_line~ : NextLineFn[A], @@ -109,7 +115,8 @@ fn[A] accept_to( } } -///| Does not not include final `char` in spans and continues on backslashed `char`. +///| +/// Does not not include final `char` in spans and continues on backslashed `char`. fn[A] accept_upto( char~ : Char, next_line~ : NextLineFn[A], @@ -141,7 +148,8 @@ fn[A] accept_upto( } } -///| `first_non_blank_over_nl(next_line, s, lines, line, start)` is the first byte position starting with `start` +///| +/// `first_non_blank_over_nl(next_line, s, lines, line, start)` is the first byte position starting with `start` /// that is not blank in `line` or on the next line as determined by `next_line`. /// Returns `None` if there is no such position. pub fn[A] first_non_blank_over_nl( @@ -163,7 +171,8 @@ pub fn[A] first_non_blank_over_nl( Some(NextLine(new_line, nb)) } -///| Same as `first_non_blank_over_nl()` but pushes skipped data on `spans`. +///| +/// Same as `first_non_blank_over_nl()` but pushes skipped data on `spans`. fn[A] first_non_blank_over_nl1( next_line~ : NextLineFn[A], s : String, @@ -187,7 +196,8 @@ fn[A] first_non_blank_over_nl1( } } -///| `first_non_escaped_char(c, s, last, start)` is the first `CharCodePos` +///| +/// `first_non_escaped_char(c, s, last, start)` is the first `CharCodePos` /// in the range `[start, last]` that has `c` unescaped and `last + 1` if there is none. pub fn first_non_escaped_char( c : Char, diff --git a/src/cmark_html/html.mbt b/src/cmark_html/html.mbt index c15a76b..c51bc0b 100644 --- a/src/cmark_html/html.mbt +++ b/src/cmark_html/html.mbt @@ -28,7 +28,7 @@ test { } ///| -impl Eq for HtmlRenderFootnote with op_equal(self, other) { +impl Eq for HtmlRenderFootnote with equal(self, other) { self.id == other.id } @@ -63,7 +63,7 @@ fn backend_blocks(c : Context) -> Bool { ///| fn init_context( - backend_blocks~ : Bool = false, + backend_blocks? : Bool = false, safe~ : Bool, c : Context, _doc : Doc, @@ -392,7 +392,7 @@ fn link_dest_and_title( } ///| -fn image(c : Context, i : @cmark.InlineLink, close~ : String = " >") -> Unit { +fn image(c : Context, i : @cmark.InlineLink, close? : String = " >") -> Unit { match i.reference_definition(c.doc.defs) { Some(LinkDef({ v: ld, .. })) => { let (link, title) = link_dest_and_title(c, ld) @@ -918,7 +918,7 @@ fn doc(c : Context, d : Doc) -> Bool raise { ///| pub fn renderer( - backend_blocks~ : Bool = false, + backend_blocks? : Bool = false, safe~ : Bool, ) -> @cmark_renderer.Renderer { @cmark_renderer.Renderer::new( @@ -931,7 +931,7 @@ pub fn renderer( ///| pub fn xhtml_renderer( - backend_blocks~ : Bool = false, + backend_blocks? : Bool = false, safe~ : Bool, ) -> @cmark_renderer.Renderer { @cmark_renderer.Renderer::new( @@ -944,7 +944,7 @@ pub fn xhtml_renderer( ///| pub fn from_doc( - backend_blocks~ : Bool = false, + backend_blocks? : Bool = false, safe~ : Bool, doc : Doc, ) -> String raise { @@ -956,9 +956,9 @@ pub fn from_doc( /// /// For more parsing options, call `@cmark.Doc::from_string()` and `from_doc()` manually. pub fn render( - backend_blocks~ : Bool = false, - safe~ : Bool = false, - strict~ : Bool = true, + backend_blocks? : Bool = false, + safe? : Bool = false, + strict? : Bool = true, s : String, ) -> String raise { from_doc(backend_blocks~, safe~, @cmark.Doc::from_string(s, strict~)) diff --git a/src/cmark_html/html_test.mbt b/src/cmark_html/html_test.mbt index 5067c00..b838b50 100644 --- a/src/cmark_html/html_test.mbt +++ b/src/cmark_html/html_test.mbt @@ -222,7 +222,8 @@ test "spec" (it : @test.T) { it.snapshot(filename="spec.html") } -///| Test for raw HTML handling in safe mode +///| +/// Test for raw HTML handling in safe mode test "raw html in safe mode" (it : @test.T) { let doc = #|## Raw HTML in safe mode @@ -239,7 +240,8 @@ test "raw html in safe mode" (it : @test.T) { it.snapshot(filename="raw_html_safe_mode.html") } -///| Test for comments +///| +/// Test for comments test "html with comments" (it : @test.T) { let doc = #|## HTML with comments @@ -256,7 +258,8 @@ test "html with comments" (it : @test.T) { it.snapshot(filename="html_comments.html") } -///| Test for strict mode HTML +///| +/// Test for strict mode HTML test "strict mode html" (it : @test.T) { let doc = #|

This paragraph is valid HTML.

@@ -271,7 +274,8 @@ test "strict mode html" (it : @test.T) { it.snapshot(filename="strict_mode_html.html") } -///| Test XHTML rendering +///| +/// Test XHTML rendering test "xhtml rendering" (it : @test.T) { let doc = #|## Thematic breaks diff --git a/src/cmark_html/pkg.generated.mbti b/src/cmark_html/pkg.generated.mbti new file mode 100644 index 0000000..ad77329 --- /dev/null +++ b/src/cmark_html/pkg.generated.mbti @@ -0,0 +1,27 @@ +// Generated using `moon info`, DON'T EDIT IT +package "rami3l/cmark/cmark_html" + +import( + "rami3l/cmark/cmark" + "rami3l/cmark/cmark_renderer" +) + +// Values +fn from_doc(backend_blocks? : Bool, safe~ : Bool, @cmark.Doc) -> String raise + +fn render(backend_blocks? : Bool, safe? : Bool, strict? : Bool, String) -> String raise + +fn renderer(backend_blocks? : Bool, safe~ : Bool) -> @cmark_renderer.Renderer + +fn safe(@cmark_renderer.Context) -> Bool + +fn xhtml_renderer(backend_blocks? : Bool, safe~ : Bool) -> @cmark_renderer.Renderer + +// Errors + +// Types and methods + +// Type aliases + +// Traits + diff --git a/src/cmark_renderer/pkg.generated.mbti b/src/cmark_renderer/pkg.generated.mbti new file mode 100644 index 0000000..bf076ad --- /dev/null +++ b/src/cmark_renderer/pkg.generated.mbti @@ -0,0 +1,55 @@ +// Generated using `moon info`, DON'T EDIT IT +package "rami3l/cmark/cmark_renderer" + +import( + "rami3l/cmark/cmark" +) + +// Values + +// Errors +pub(all) suberror RenderError String +impl Show for RenderError + +// Types and methods +pub(all) struct BlockFn((Context, @cmark.Block) -> Bool raise) +fn BlockFn::inner(Self) -> (Context, @cmark.Block) -> Bool raise + +pub(all) struct Context { + renderer : Renderer + mut state : Error? + b : StringBuilder + mut doc : @cmark.Doc +} +fn Context::block(Self, @cmark.Block) -> Unit raise +fn Context::char(Self, Char) -> Unit +fn Context::doc(Self, @cmark.Doc) -> Unit raise +fn Context::init(Self, @cmark.Doc) -> Unit +fn Context::inline(Self, @cmark.Inline) -> Unit raise +fn Context::new(Renderer, StringBuilder) -> Self +fn Context::string(Self, String) -> Unit + +pub(all) struct DocFn((Context, @cmark.Doc) -> Bool raise) +fn DocFn::inner(Self) -> (Context, @cmark.Doc) -> Bool raise + +pub(all) struct InitContextFn((Context, @cmark.Doc) -> Unit) +fn InitContextFn::inner(Self) -> (Context, @cmark.Doc) -> Unit + +pub(all) struct InlineFn((Context, @cmark.Inline) -> Bool raise) +fn InlineFn::inner(Self) -> (Context, @cmark.Inline) -> Bool raise + +pub(all) struct Renderer { + init_context : InitContextFn + inline : InlineFn + block : BlockFn + doc : DocFn +} +fn Renderer::buffer_add_doc(Self, StringBuilder, @cmark.Doc) -> Unit raise +fn Renderer::compose(Self, Self) -> Self +fn Renderer::doc_to_string(Self, @cmark.Doc) -> String raise +fn Renderer::new(init_context? : InitContextFn, inline? : InlineFn, block? : BlockFn, doc? : DocFn) -> Self + +// Type aliases + +// Traits + diff --git a/src/cmark_renderer/renderer.mbt b/src/cmark_renderer/renderer.mbt index 48c607e..b9e6adf 100644 --- a/src/cmark_renderer/renderer.mbt +++ b/src/cmark_renderer/renderer.mbt @@ -1,4 +1,5 @@ -///| Renderer abstraction. +///| +/// Renderer abstraction. /// /// Stateful renderer abstraction to render documents in memory. pub(all) struct Renderer { @@ -10,10 +11,10 @@ pub(all) struct Renderer { ///| pub fn Renderer::new( - init_context~ : InitContextFn = fn(_c, _d) { }, - inline~ : InlineFn = fn(_c, _i) { false }, - block~ : BlockFn = fn(_c, _b) { false }, - doc~ : DocFn = fn(_c, _d) { false }, + init_context? : InitContextFn = fn(_c, _d) { }, + inline? : InlineFn = fn(_c, _i) { false }, + block? : BlockFn = fn(_c, _b) { false }, + doc? : DocFn = fn(_c, _d) { false }, ) -> Renderer { { init_context, inline, block, doc } }