MCPcopy Create free account
hub / github.com/Vespa314/cflow / Parse

Method Parse

plugin/gomark/parser/code_block.go:56–79  ·  view source on GitHub ↗
(tokens []*tokenizer.Token)

Source from the content-addressed store, hash-verified

54}
55
56func (p *CodeBlockParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
57 size, ok := p.Match(tokens)
58 if size == 0 || !ok {
59 return nil, errors.New("not matched")
60 }
61
62 languageToken := tokens[3]
63 contentStart, contentEnd := 5, size-4
64 if languageToken.Type == tokenizer.Newline {
65 languageToken = nil
66 contentStart = 4
67 }
68 if tokens[size-1].Type == tokenizer.Newline {
69 contentEnd = size - 5
70 }
71
72 codeBlock := &ast.CodeBlock{
73 Content: tokenizer.Stringify(tokens[contentStart:contentEnd]),
74 }
75 if languageToken != nil {
76 codeBlock.Language = languageToken.String()
77 }
78 return codeBlock, nil
79}

Callers

nothing calls this directly

Calls 3

MatchMethod · 0.95
StringifyFunction · 0.92
StringMethod · 0.65

Tested by

no test coverage detected