Create an org heading builder

This commit is contained in:
Florian Schroedl
2022-05-04 17:00:00 +02:00
parent bec4953a97
commit 722e66cf85
10 changed files with 342 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
import std/sugar
import results
import std/collections/sequtils
import ./org_types
import ../parser/parser_types
## Inline Blocks
type OrgInlineBuilderT* = OrgInlineBlock
type OrgInlineBuilder* = Builder[OrgInlineBuilderT]
type OrgInlineBuilderResult* = BuilderResult[OrgInlineBuilderT]
@@ -28,3 +30,25 @@ func rawTextTokenizer*(kind: orgInlineBlockKind): string -> OrgInlineBuilderT =
kind: kind,
content: content,
)
## Blocks
type OrgBuilderT* = OrgBlock
type OrgBuilder* = Builder[OrgBuilderT]
type OrgBuilderResult* = BuilderResult[OrgBuilderT]
func initOrgBuilder*(content: string): OrgBuilderResult =
return OrgBuilderResult.ok(OrgBuilder((
parser: initParser(content),
tree: newSeq[OrgBuilderT](),
)))
# proc orgBuilderConcat*(typeInfo: OrgBuilderT, concatFn: (ParserToken, OrgBuilderT) -> OrgBuilderT):
# (seq[ParserToken], OrgBuilderT) -> OrgBuilderT =
# return proc(xs: seq[ParserToken], builder: OrgBuilderT): OrgBuilderT =
# return xs.foldl(concatFn(b, a), typeInfo)
proc orgBuilderApply*(concatFn: (ParserToken, OrgBuilderT) -> OrgBuilderT):
(seq[ParserToken], OrgBuilderT) -> OrgBuilderT =
return proc(tokens: seq[ParserToken], builder: OrgBuilderT): OrgBuilderT =
tokens.foldl(concatFn(b, a), builder)