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 (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Markdown Extensions:
|
// Markdown Extensions:
|
||||||
@ -37,6 +38,10 @@ func Parse(text string, extFlags int) *Doc {
|
|||||||
d := new(Doc)
|
d := new(Doc)
|
||||||
d.syntaxExtensions = extFlags
|
d.syntaxExtensions = extFlags
|
||||||
|
|
||||||
|
d.parser = new(yyParser)
|
||||||
|
d.parser.Doc = d
|
||||||
|
d.parser.Init()
|
||||||
|
|
||||||
s := preformat(text)
|
s := preformat(text)
|
||||||
|
|
||||||
d.parseRule(ruleReferences, s)
|
d.parseRule(ruleReferences, s)
|
||||||
@ -49,21 +54,17 @@ func Parse(text string, extFlags int) *Doc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Doc) parseRule(rule int, s string) {
|
func (d *Doc) parseRule(rule int, s string) {
|
||||||
m := new(yyParser)
|
m := d.parser
|
||||||
m.Doc = d
|
if m.ResetBuffer(s) != "" {
|
||||||
m.Init()
|
log.Exitf("Buffer not empty")
|
||||||
m.Buffer = s
|
}
|
||||||
if !m.Parse(rule) {
|
if !m.Parse(rule) {
|
||||||
m.PrintError()
|
m.PrintError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Doc) parseMarkdown(text string) *element {
|
func (d *Doc) parseMarkdown(text string) *element {
|
||||||
m := new(yyParser)
|
d.parseRule(ruleDoc, text)
|
||||||
m.Doc = d
|
|
||||||
m.Init()
|
|
||||||
m.Buffer = text
|
|
||||||
m.Parse(ruleDoc)
|
|
||||||
return d.tree
|
return d.tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Doc struct {
|
type Doc struct {
|
||||||
|
parser *yyParser
|
||||||
|
|
||||||
tree *element /* Results of parse. */
|
tree *element /* Results of parse. */
|
||||||
references *element /* List of link references found. */
|
references *element /* List of link references found. */
|
||||||
notes *element /* List of footnotes found. */
|
notes *element /* List of footnotes found. */
|
||||||
|
Loading…
Reference in New Issue
Block a user