diff --git a/src/org/org_builder.nim b/src/org/org_builder.nim index a507c19..b102e51 100644 --- a/src/org/org_builder.nim +++ b/src/org/org_builder.nim @@ -3,28 +3,28 @@ import results import ./org_types import ../parser/parser_types -type OrgBuilderT* = OrgElement -type OrgBuilder* = Builder[OrgBuilderT] -type OrgBuilderResult* = BuilderResult[OrgBuilderT] +type OrgInlineBuilderT* = OrgInlineBlock +type OrgInlineBuilder* = Builder[OrgInlineBuilderT] +type OrgInlineBuilderResult* = BuilderResult[OrgInlineBuilderT] -func initOrgBuilder*(content: string): OrgBuilderResult = - return OrgBuilderResult.ok(OrgBuilder(( +func initOrgInlineBuilder*(content: string): OrgInlineBuilderResult = + return OrgInlineBuilderResult.ok(OrgInlineBuilder(( parser: initParser(content), - tree: newSeq[OrgBuilderT](), + tree: newSeq[OrgInlineBuilderT](), ))) -func textTokenizer*(kind: orgElementKind): seq[ParserToken] -> seq[OrgBuilderT] = - return func(tokens: seq[ParserToken]): seq[OrgBuilderT] = +func textTokenizer*(kind: orgInlineBlockKind): seq[ParserToken] -> seq[OrgInlineBuilderT] = + return func(tokens: seq[ParserToken]): seq[OrgInlineBuilderT] = return @[ - OrgBuilderT( + OrgInlineBuilderT( kind: kind, content: tokens.tokensToString(), ) ] -func rawTextTokenizer*(kind: orgElementKind): string -> OrgBuilderT = - return func(content: string): OrgBuilderT = - return OrgBuilderT( +func rawTextTokenizer*(kind: orgInlineBlockKind): string -> OrgInlineBuilderT = + return func(content: string): OrgInlineBuilderT = + return OrgInlineBuilderT( kind: kind, content: content, ) diff --git a/src/org/org_text_delimiter.nim b/src/org/org_text_delimiter.nim index 0cb8365..9d641cb 100644 --- a/src/org/org_text_delimiter.nim +++ b/src/org/org_text_delimiter.nim @@ -39,7 +39,7 @@ let orgStyledTextBuilders = @[ (linkParser, linkTokenizerSeq), ] -proc makeRawTokenOrEmpty(tokens: seq[ParserToken]): seq[OrgBuilderT] = +proc makeRawTokenOrEmpty(tokens: seq[ParserToken]): seq[OrgInlineBuilderT] = ## Merge all parser `tokens` into a string to tokenize for the builder. ## Unless the string is empty, in this case return an empty list. let str = tokens.foldl(a & b.tokenStringValue(), "") @@ -47,10 +47,10 @@ proc makeRawTokenOrEmpty(tokens: seq[ParserToken]): seq[OrgBuilderT] = else: @[rawTokenizer(str)] when isMainModule: - let test = initOrgBuilder( + let test = initOrgInlineBuilder( "Regular *bold* [[https://some.url]] /italic/ _underline_ =verbatim= ~code~ +strikethrough+ [[https://some.url][title]]" ) - .flatMap((builder: OrgBuilder) => tryParseBuild( + .flatMap((builder: OrgInlineBuilder) => tryParseBuild( builder = builder, builderFns = orgStyledTextBuilders, defaultBuilderFn = makeRawTokenOrEmpty, diff --git a/src/org/org_text_link.nim b/src/org/org_text_link.nim index 3062e9e..b048f00 100644 --- a/src/org/org_text_link.nim +++ b/src/org/org_text_link.nim @@ -43,17 +43,17 @@ proc linkStringifier*(linkUrl: string, linkDescription: Maybe[string]): string = of (@linkUrl, None()): return &"[[{linkUrl}]]" -func linkTokenizer*(parserTokens: seq[ParserToken]): OrgBuilderT = +func linkTokenizer*(parserTokens: seq[ParserToken]): OrgInlineBuilderT = [@linkUrl, @linkDescription] := parserTokens.map(tokenStringValue) let maybeLinkDescription = linkDescription.just().notEmpty() - return OrgBuilderT( + return OrgInlineBuilderT( kind: orgLink, content: linkStringifier(linkUrl, maybeLinkDescription), linkUrl: linkUrl, linkDescription: maybeLinkDescription, ) -let linkTokenizerSeq* = proc(parserTokens: seq[ParserToken]): seq[OrgBuilderT] {.closure.} = +let linkTokenizerSeq* = proc(parserTokens: seq[ParserToken]): seq[OrgInlineBuilderT] {.closure.} = return @[linkTokenizer(parserTokens)] when isMainModule: @@ -61,6 +61,6 @@ when isMainModule: echo initParser("[[https://florianschroedl.com][My blog]]") .linkParser() .foldTokens( - onError = (x) => newSeq[OrgBuilderT](), - onSuccess = proc(xs: seq[ParserToken]): seq[OrgBuilderT] = linkTokenizerSeq(xs), + onError = (x) => newSeq[OrgInlineBuilderT](), + onSuccess = proc(xs: seq[ParserToken]): seq[OrgInlineBuilderT] = linkTokenizerSeq(xs), ) diff --git a/src/org/org_types.nim b/src/org/org_types.nim index b67a764..9deeb66 100644 --- a/src/org/org_types.nim +++ b/src/org/org_types.nim @@ -4,7 +4,7 @@ import std/strutils import fp/maybe type - orgElementKind* = enum + orgInlineBlockKind* = enum orgRawText, orgText, @@ -18,11 +18,11 @@ type # Links orgLink, - OrgElement* = ref object - children*: seq[OrgElement] + OrgInlineBlock* = ref object + children*: seq[OrgInlineBlock] content*: string - case kind*: orgElementKind + case kind*: orgInlineBlockKind of orgRawText: discard of orgText: discard @@ -39,7 +39,7 @@ type linkUrl*: string linkDescription*: Maybe[string] -proc `$`*(x: orgElementKind): string = +proc `$`*(x: orgInlineBlockKind): string = case x: of orgRawText: "Text (Raw)" of orgText: "Text" @@ -55,7 +55,7 @@ proc `$`*(x: orgElementKind): string = # Links of orgLink: "Link" -func stringifySpecialFields(x: OrgElement): string = +func stringifySpecialFields(x: OrgInlineBlock): string = let specialFields = case x.kind: of orgLink: &"""linkUrl: "{x.linkUrl}"""" & @@ -69,8 +69,8 @@ func stringifySpecialFields(x: OrgElement): string = .map(x => "\n" & x & "\n") .getOrElse("") -proc `$`*(x: OrgElement): string = - &"""OrgElement( +proc `$`*(x: OrgInlineBlock): string = + &"""OrgInlineBlock( content: "{x.content}" kind: {x.kind}""" & stringifySpecialFields(x) & diff --git a/src/types.nim b/src/types.nim index a7484f7..cd786ff 100644 --- a/src/types.nim +++ b/src/types.nim @@ -1,23 +1,23 @@ import print type - orgElementContent = string - orgElementChildren = seq[OrgElement] + orgInlineBlockContent = string + orgInlineBlockChildren = seq[OrgInlineBlock] - OrgElementKind = enum + OrgInlineBlockKind = enum orgDocument, orgHeadline, orgText, - OrgElement* = ref object - children*: orgElementChildren + OrgInlineBlock* = ref object + children*: orgInlineBlockChildren id*: string - case kind*: OrgElementKind + case kind*: OrgInlineBlockKind of orgHeadline: level*: int of orgText: - content: orgElementContent + content: orgInlineBlockContent of orgDocument: discard -let emptyChildrenSeq: orgElementChildren = newSeq[OrgElement]() +let emptyChildrenSeq: orgInlineBlockChildren = newSeq[OrgInlineBlock]()