-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathquantified_atom.go
More file actions
68 lines (56 loc) · 2.02 KB
/
Copy pathquantified_atom.go
File metadata and controls
68 lines (56 loc) · 2.02 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package quamina
import "fmt"
// represents the "atom [ quantifier ]" piece of the regexp grammar. Is kind of messy but
// faithful to the kind-of-messy regexp semantics. I blame Kleene.
type quantifiedAtom struct {
runes RuneRange
dotRunes bool // true if atom is "."
bigRuneRangeKey string // for the huge character_properties RuneRanges
quantMin int // 0 means ? or *
quantMax int // the value regexpQuantifierMax means + or *, no max
subtree regexpRoot // if non-nil, ()-enclosed subtree here
}
func (qa *quantifiedAtom) getSubtree() regexpRoot {
return qa.subtree
}
func (qa *quantifiedAtom) isDot() bool {
return qa.dotRunes
}
func (qa *quantifiedAtom) runeRangeCache() string {
return qa.bigRuneRangeKey
}
func (qa *quantifiedAtom) isQM() bool {
return qa.quantMin == 0 && qa.quantMax == 1
}
func (qa *quantifiedAtom) isPlus() bool {
return qa.quantMin == 1 && qa.quantMax == regexpQuantifierMax
}
func (qa *quantifiedAtom) isStar() bool {
return qa.quantMin == 0 && qa.quantMax == regexpQuantifierMax
}
func (qa *quantifiedAtom) hasMinMax() bool {
return qa.quantMax != regexpQuantifierMax && qa.quantMax != regexpMinimumOnly && qa.quantMax > 1
}
func (qa *quantifiedAtom) isNoOp() bool {
return qa.quantMax == 0
}
func (qa *quantifiedAtom) isMinimumOnly() bool {
return qa.quantMax == regexpMinimumOnly
}
func (qa *quantifiedAtom) makeFA(nextStep *faState, pp printer) smallTable {
var table smallTable
switch {
case qa.isDot():
table = makeDotFA(nextStep)
pp.labelTable(&table, "Dot")
case qa.getSubtree() != nil:
table = makeNFAFromBranches(qa.getSubtree(), nextStep, false, pp)
case qa.runeRangeCache() != "":
table = makeAndCacheRuneRangeFA(qa.runes, nextStep, qa.runeRangeCache(), pp)
default:
// if it's none of these other things, it has to boil down to a rune range
table = makeRuneRangeNFA(qa.runes, nextStep, pp)
pp.labelTable(&table, fmt.Sprintf("RR %x/%x, %d-%d", qa.runes[0].Lo, qa.runes[0].Hi, qa.quantMin, qa.quantMax))
}
return table
}