-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathliquid.go
27 lines (24 loc) · 1.38 KB
/
liquid.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
package liquid
// based on revision 3146d5c of github.com:shopify/liquid.git
import (
"fmt"
"regexp"
)
// Regular Expressions for parsing liquid tags
var (
filterSeparatorRegexp = regexp.MustCompile(`\|`)
tagStartRegexp = regexp.MustCompile(`\{\%`)
tagEndRegexp = regexp.MustCompile(`\%\}`)
variableSignatureRegexp = regexp.MustCompile(`\(?[\w\-\.\[\]]\)?`)
variableSegmentRegexp = regexp.MustCompile(`[\w\-]`)
variableStartRegexp = regexp.MustCompile(`\{\{`)
variableEndRegexp = regexp.MustCompile(`\}\}`)
variableIncompleteEndRegexp = regexp.MustCompile(`\}\}?`)
quotedStringRegexp = regexp.MustCompile(`"[^"]*"|'[^']*'`)
quotedFragmentRegexp = regexp.MustCompile(fmt.Sprintf(`%v|(?:[^\s,\|'"]|%v)+`, quotedStringRegexp, quotedStringRegexp))
tagAttributesRegexp = regexp.MustCompile(fmt.Sprintf(`(\w+)\s*\:\s*(%v)`, quotedFragmentRegexp))
anyStartingTagRegexp = regexp.MustCompile(`\{\{|\{\%`)
partialTemplateParserRegexp = regexp.MustCompile(fmt.Sprintf(`(?ms)%v.*?%v|%v.*?%v`, tagStartRegexp, tagEndRegexp, variableStartRegexp, variableIncompleteEndRegexp))
templateParserRegexp = regexp.MustCompile(fmt.Sprintf(`(?ms)(%v|%v)`, partialTemplateParserRegexp, anyStartingTagRegexp))
variableParserRegexp = regexp.MustCompile(fmt.Sprintf(`\[[^\]]+\]|%v+\??`, variableSegmentRegexp))
)