Create an org heading builder
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user