-
Notifications
You must be signed in to change notification settings - Fork 15
/
regexp.go
31 lines (26 loc) · 1.23 KB
/
regexp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package rivescript
import "regexp"
// Commonly used regular expressions.
var (
reWeight = regexp.MustCompile(`\s*\{weight=(\d+)\}\s*`)
reInherits = regexp.MustCompile(`\{inherits=(\d+)\}`)
reMeta = regexp.MustCompile(`[\<>]+`)
reSymbols = regexp.MustCompile(`[.?,!;:@#$%^&*()]+`)
reNasties = regexp.MustCompile(`[^A-Za-z0-9 ]`)
reZerowidthstar = regexp.MustCompile(`^\*$`)
reOptional = regexp.MustCompile(`\[(.+?)\]`)
reArray = regexp.MustCompile(`@(.+?)\b`)
reReplyArray = regexp.MustCompile(`\(@([A-Za-z0-9_]+)\)`)
reBotvars = regexp.MustCompile(`<bot (.+?)>`)
reUservars = regexp.MustCompile(`<get (.+?)>`)
reRandom = regexp.MustCompile(`\{random\}(.+?)\{/random\}`)
// Self-contained tags like <set> that contain no nested tag.
reAnytag = regexp.MustCompile(`<([^<]+?)>`)
reTopic = regexp.MustCompile(`\{topic=(.+?)\}`)
reRedirect = regexp.MustCompile(`\{@(.+?)\}`)
reCall = regexp.MustCompile(`<call>(.+?)</call>`)
reCondition = regexp.MustCompile(`^(.+?)\s+(==|eq|!=|ne|<>|<|<=|>|>=)\s+(.*?)$`)
reSet = regexp.MustCompile(`<set (.+?)=(.+?)>`)
// Placeholders used during substitutions.
rePlaceholder = regexp.MustCompile(`\x00(\d+)\x00`)
)