gosuki/parsing/parse.go

59 lines
1.2 KiB
Go
Raw Normal View History

2018-11-09 17:25:50 +00:00
package parsing
2017-10-20 10:51:56 +00:00
import (
2020-11-06 17:50:36 +00:00
"git.sp4ke.xyz/sp4ke/gomark/logging"
"git.sp4ke.xyz/sp4ke/gomark/tree"
"regexp"
"time"
2017-10-20 10:51:56 +00:00
)
2018-11-09 17:25:50 +00:00
type Node = tree.Node
var log = logging.GetLogger("PARSE")
const (
2017-11-30 15:08:12 +00:00
// First group is tag
// TODO: use named groups
// [named groups](https://github.com/StefanSchroeder/Golang-Regex-Tutorial/blob/master/01-chapter2.markdown)
// Regex matching tests:
//#start test2 #test3 elol
//#start word with #end
//word in the #middle of sentence
//tags with a #dot.caracter
//this is a end of sentence #tag
2018-11-09 17:25:50 +00:00
ReTags = "\\B#(?P<tag>\\w+\\.?\\w+)"
)
2017-10-20 10:51:56 +00:00
2018-11-09 17:25:50 +00:00
type Stats struct {
2018-11-13 16:11:16 +00:00
LastFullTreeParseTime time.Duration
LastWatchRunTime time.Duration
LastNodeCount int
LastURLCount int
CurrentNodeCount int
CurrentUrlCount int
2017-11-17 18:06:34 +00:00
}
2017-10-20 10:51:56 +00:00
2018-11-09 17:25:50 +00:00
type Hook func(node *Node)
2017-11-20 18:07:15 +00:00
2017-11-30 15:08:12 +00:00
func ParseTags(node *Node) {
2017-11-20 18:07:15 +00:00
2017-11-30 15:08:12 +00:00
var regex = regexp.MustCompile(ReTags)
2017-11-20 18:07:15 +00:00
2017-11-30 15:08:12 +00:00
matches := regex.FindAllStringSubmatch(node.Name, -1)
for _, m := range matches {
2018-05-27 15:36:03 +00:00
node.Tags = append(node.Tags, m[1])
2017-11-30 15:08:12 +00:00
}
//res := regex.FindAllStringSubmatch(bk.Metadata, -1)
2018-11-09 17:25:50 +00:00
if len(node.Tags) > 0 {
log.Debugf("[in title] found following tags: %s", node.Tags)
2017-11-20 18:07:15 +00:00
}
}
2018-11-09 17:25:50 +00:00
func S(value interface{}) string {
return string(value.([]byte))
}