use a single yyParser instance only, and reuse initialized parser

This commit is contained in:
Michael Teichgräber 2010-11-24 19:36:10 +01:00
parent 221075269e
commit 071bf92c4f
2 changed files with 12 additions and 9 deletions

View File

@ -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
}

View File

@ -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. */