2017-07-15 21:49:08 +02:00
|
|
|
package treerack
|
2017-06-25 17:51:08 +02:00
|
|
|
|
|
|
|
type charParser struct {
|
|
|
|
name string
|
2017-07-15 21:49:08 +02:00
|
|
|
id int
|
2017-06-25 17:51:08 +02:00
|
|
|
not bool
|
|
|
|
chars []rune
|
|
|
|
ranges [][]rune
|
2017-07-27 01:48:16 +02:00
|
|
|
includedBy []int
|
2017-06-25 17:51:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func newChar(
|
|
|
|
name string,
|
2017-06-25 23:38:32 +02:00
|
|
|
not bool,
|
2017-06-25 17:51:08 +02:00
|
|
|
chars []rune,
|
|
|
|
ranges [][]rune,
|
|
|
|
) *charParser {
|
|
|
|
return &charParser{
|
|
|
|
name: name,
|
|
|
|
not: not,
|
|
|
|
chars: chars,
|
|
|
|
ranges: ranges,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-01 02:43:46 +01:00
|
|
|
func (p *charParser) nodeName() string { return p.name }
|
|
|
|
func (p *charParser) setNodeName(n string) { p.name = n }
|
|
|
|
func (p *charParser) nodeID() int { return p.id }
|
|
|
|
func (p *charParser) setID(id int) { p.id = id }
|
|
|
|
func (p *charParser) commitType() CommitType { return Alias }
|
|
|
|
func (p *charParser) setCommitType(ct CommitType) {}
|
|
|
|
func (p *charParser) validate(*registry) error { return nil }
|
|
|
|
func (p *charParser) init(*registry) {}
|
|
|
|
|
2017-11-01 03:54:53 +01:00
|
|
|
func (p *charParser) setIncludedBy(includedBy int) {
|
2017-11-01 02:43:46 +01:00
|
|
|
if intsContain(p.includedBy, includedBy) {
|
|
|
|
return
|
2017-06-25 23:38:32 +02:00
|
|
|
}
|
|
|
|
|
2017-11-01 02:43:46 +01:00
|
|
|
p.includedBy = append(p.includedBy, includedBy)
|
|
|
|
}
|
|
|
|
|
2017-11-01 03:54:53 +01:00
|
|
|
func (p *charParser) parser() parser { return p }
|
|
|
|
func (p *charParser) builder() builder { return p }
|
2017-06-25 17:51:08 +02:00
|
|
|
|
2017-10-31 21:53:09 +01:00
|
|
|
func matchChars(chars []rune, ranges [][]rune, not bool, char rune) bool {
|
|
|
|
for _, ci := range chars {
|
|
|
|
if ci == char {
|
|
|
|
return !not
|
2017-06-25 17:51:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 21:53:09 +01:00
|
|
|
for _, ri := range ranges {
|
|
|
|
if char >= ri[0] && char <= ri[1] {
|
|
|
|
return !not
|
2017-06-25 17:51:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 21:53:09 +01:00
|
|
|
return not
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *charParser) match(t rune) bool {
|
|
|
|
return matchChars(p.chars, p.ranges, p.not, t)
|
2017-06-25 17:51:08 +02:00
|
|
|
}
|
|
|
|
|
2017-10-31 21:09:30 +01:00
|
|
|
func (p *charParser) parse(c *context) {
|
2017-07-17 04:23:29 +02:00
|
|
|
if tok, ok := c.token(); !ok || !p.match(tok) {
|
2017-06-25 17:51:08 +02:00
|
|
|
c.fail(c.offset)
|
|
|
|
return
|
|
|
|
}
|
2017-07-17 04:23:29 +02:00
|
|
|
|
|
|
|
for _, includedBy := range p.includedBy {
|
2017-11-02 20:49:49 +01:00
|
|
|
c.results.setMatch(c.offset, includedBy, c.offset+1)
|
2017-07-17 04:23:29 +02:00
|
|
|
}
|
2017-11-01 00:19:29 +01:00
|
|
|
|
|
|
|
c.success(c.offset + 1)
|
2017-06-25 17:51:08 +02:00
|
|
|
}
|
2017-07-29 16:25:17 +02:00
|
|
|
|
|
|
|
func (p *charParser) build(c *context) ([]*Node, bool) {
|
2017-07-30 03:08:45 +02:00
|
|
|
panic("called char build")
|
2017-07-29 16:25:17 +02:00
|
|
|
}
|