File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -107,6 +107,48 @@ func (e Speices) Match(
107107 }
108108}
109109
110+ func (e Speices ) MatchS (s struct {
111+ onHuman func ()
112+ onElf func ()
113+ onOrc func ()
114+ onDwarf func ()
115+ onGnome func ()
116+ onHalfling func ()
117+ onHalfElf func ()
118+ onHalfOrc func ()
119+ onDragonborn func ()
120+ onTiefling func ()
121+ onGnoll func ()
122+ onGoblin func ()
123+ }) {
124+ switch e {
125+ case Speices_Human :
126+ s .onHuman ()
127+ case Speices_Elf :
128+ s .onElf ()
129+ case Speices_Orc :
130+ s .onOrc ()
131+ case Speices_Dwarf :
132+ s .onDwarf ()
133+ case Speices_Gnome :
134+ s .onGnome ()
135+ case Speices_Halfling :
136+ s .onHalfling ()
137+ case Speices_HalfElf :
138+ s .onHalfElf ()
139+ case Speices_HalfOrc :
140+ s .onHalfOrc ()
141+ case Speices_Dragonborn :
142+ s .onDragonborn ()
143+ case Speices_Tiefling :
144+ s .onTiefling ()
145+ case Speices_Gnoll :
146+ s .onGnoll ()
147+ case Speices_Goblin :
148+ s .onGoblin ()
149+ }
150+ }
151+
110152type ItemType uint8
111153
112154const (
@@ -142,6 +184,21 @@ func (e ItemType) Match(
142184 }
143185}
144186
187+ func (e ItemType ) MatchS (s struct {
188+ onWeapon func ()
189+ onArmor func ()
190+ onPotion func ()
191+ }) {
192+ switch e {
193+ case ItemType_Weapon :
194+ s .onWeapon ()
195+ case ItemType_Armor :
196+ s .onArmor ()
197+ case ItemType_Potion :
198+ s .onPotion ()
199+ }
200+ }
201+
145202type Coordinate []byte
146203
147204func (s Coordinate ) X () int64 {
Original file line number Diff line number Diff line change @@ -38,5 +38,18 @@ func writeEnums(w io.Writer, i *ir.IR) {
3838 }
3939 fmt .Fprintf (w , "}\n " )
4040 fmt .Fprintf (w , "}\n \n " )
41+
42+ fmt .Fprintf (w , "func (e %s) MatchS(s struct {\n " , NameConv (e .Name ))
43+ for _ , o := range e .Options {
44+ fmt .Fprintf (w , "on%s func()\n " , NameConv (o ))
45+ }
46+ fmt .Fprintf (w , "}) {\n " )
47+ fmt .Fprintf (w , "switch e {\n " )
48+ for _ , o := range e .Options {
49+ fmt .Fprintf (w , "case %s_%s:\n " , NameConv (e .Name ), NameConv (o ))
50+ fmt .Fprintf (w , "s.on%s()\n " , NameConv (o ))
51+ }
52+ fmt .Fprintf (w , "}\n " )
53+ fmt .Fprintf (w , "}\n \n " )
4154 }
4255}
You can’t perform that action at this time.
0 commit comments