-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
flag.go
82 lines (69 loc) · 1.28 KB
/
flag.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package flag
import (
"fmt"
)
type Type int
const (
EOF Type = iota
Eol
Keyword
QuotedString
Variable
BlockStart
BlockEnd
Semicolon
Comment
Illegal
Regex
)
var (
FlagName = map[Type]string{
QuotedString: "QuotedString",
EOF: "Eof",
Keyword: "Keyword",
Variable: "Variable",
BlockStart: "BlockStart",
BlockEnd: "BlockEnd",
Semicolon: "Semicolon",
Comment: "Comment",
Illegal: "Illegal",
Regex: "Regex",
}
)
func (tt Type) String() string {
return FlagName[tt]
}
type Flag struct {
Type Type
Literal string
Line int
Column int
}
func (t Flag) String() string {
return fmt.Sprintf("{Type:%s,Literal:\"%s\",Line:%d,Column:%d}", t.Type, t.Literal, t.Line, t.Column)
}
func (t Flag) Lit(literal string) Flag {
t.Literal = literal
return t
}
func (t Flag) EqualTo(t2 Flag) bool {
return t.Type == t2.Type && t.Literal == t2.Literal
}
type Flags []Flag
func (fs Flags) EqualTo(flags Flags) bool {
if len(fs) != len(flags) {
return false
}
for i, t := range fs {
if !t.EqualTo(flags[i]) {
return false
}
}
return true
}
func (t Flag) Is(typ Type) bool {
return t.Type == typ
}
func (t Flag) IsParameterEligible() bool {
return t.Is(Keyword) || t.Is(QuotedString) || t.Is(Variable) || t.Is(Regex)
}