use a single yyParser instance only, and reuse initialized parser
This commit is contained in:
parent
221075269e
commit
071bf92c4f
19
markdown.go
19
markdown.go
@ -22,6 +22,7 @@ package markdown
|
||||
import (
|
||||
"strings"
|
||||
"bytes"
|
||||
"log"
|
||||
)
|
||||
|
||||
// Markdown Extensions:
|
||||
@ -37,6 +38,10 @@ func Parse(text string, extFlags int) *Doc {
|
||||
d := new(Doc)
|
||||
d.syntaxExtensions = extFlags
|
||||
|
||||
d.parser = new(yyParser)
|
||||
d.parser.Doc = d
|
||||
d.parser.Init()
|
||||
|
||||
s := preformat(text)
|
||||
|
||||
d.parseRule(ruleReferences, s)
|
||||
@ -49,21 +54,17 @@ func Parse(text string, extFlags int) *Doc {
|
||||
}
|
||||
|
||||
func (d *Doc) parseRule(rule int, s string) {
|
||||
m := new(yyParser)
|
||||
m.Doc = d
|
||||
m.Init()
|
||||
m.Buffer = s
|
||||
m := d.parser
|
||||
if m.ResetBuffer(s) != "" {
|
||||
log.Exitf("Buffer not empty")
|
||||
}
|
||||
if !m.Parse(rule) {
|
||||
m.PrintError()
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Doc) parseMarkdown(text string) *element {
|
||||
m := new(yyParser)
|
||||
m.Doc = d
|
||||
m.Init()
|
||||
m.Buffer = text
|
||||
m.Parse(ruleDoc)
|
||||
d.parseRule(ruleDoc, text)
|
||||
return d.tree
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,8 @@ const (
|
||||
)
|
||||
|
||||
type Doc struct {
|
||||
parser *yyParser
|
||||
|
||||
tree *element /* Results of parse. */
|
||||
references *element /* List of link references found. */
|
||||
notes *element /* List of footnotes found. */
|
||||
|
Loading…
Reference in New Issue
Block a user