-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathideas.gigo
133 lines (115 loc) · 2.76 KB
/
ideas.gigo
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
// other ideas
// keyword to: forbid dereference of a pointer
// https://groups.google.com/forum/#!topic/golang-nuts/zlGzLYMGRPo
//
// pointer keyword would say that the new type should always be a pointer
// and never dereferenced.
type xx pointer struct {
xx *myType // that must not be dereferenced
}
// There might be cases where it is desirable to dereference,
// what are they ?
// the goal of this question is to udnerstand if
// the sytem should emit error or warning on bad usage detection.
// trait ?
// type Formatter interface{
// Format(f State, c rune)
// }
/*
*/
template Dumper trait {
}
func (s Dumper) Format(f State, c rune) {
<range $p := $.Props>
<.Name>
<end>
io.WriteString(os.Stdout, "build a pretty printed string of s")
}
type PrettyTodos implements<Dumper .Todo>
type MyType implements<Mutexed (Slice .PrettyTodos "Name")> {
}
// <:if modifier>
/*
*/
<:if .Implements fmt.Stringer> func (s <:.Name>Slice) Something(item <:.Name>) string {
return ""
}
<:else if .Implements fmt.Whatever> func (s <:.Name>Slice) Something(item <:.Name>) string {
return "somehow different"
}
/*
*/
// define a template func
<define> func nameInTemplate(a astThing, w out, args ...string)error {
}
// define new keywords
// - to open a resource
f, err := open os.Open(...)
// translate to
f, err := os.Open(...)
defer f.Close()
// - must keyword
f := must open os.Open(...)
// translate to
f, err := os.Open(...)
if err != nil {
... // this depends of the context,
// if the method does not return arguments => panic
// if the method returns arguments => return ...
}
defer f.Close()
// - the ... keyword in return ...err
// where it declares default value for
// out values with ..., insert provided err appropriately
func p() (int, bool, *A, B){
return ...
}
// translate to
func p() (int, bool, *A, B){
return 0, false, nil, B{}
}
// - the or keyword in must call() or smting
f := must os.Open(...) or panic
// translate to
f, err := os.Open(...)
if err != nil {
panic(err)
}
//-
f, err := must os.Open(...) or return ...err
// translate to
f, err := os.Open(...)
if err != nil {
return err
}
//- going further
f, err := must open os.Open(...) or
return ...log.log("file", "open", err)
// translate to
f, err := os.Open(...)
if err != nil {
return log.log("file", "open", err)
}
defer f.Close()
// - interface combiner
func p(value SomePusher+Committer) {}
// which would translate into a new interface declaration such as
type genXXXer interface {
SomePusher
Committer
}
// and translate the func signature to
func p(value genXXXer) {}
// - const name
const (
numberToken lexer.TokenType = iota
wsToken
)
var xName = constname(numberToken)
// translate to
const (
numberToken lexer.TokenType = iota
wsToken
)
var xName = "numberToken"