@@ -96,6 +96,70 @@ local all_lines_before_are_all_comments =
9696 " ^%s*$" ,
9797 }
9898
99+ --- @param shortcut string
100+ --- @return string ?
101+ local function quick_type (shortcut )
102+ -- v = std::vector, 1
103+ -- i = int32_t, 0
104+ -- s = std::string, 0
105+ -- u = uint32_t, 0
106+ -- m = absl::flat_hash_map, 2
107+ -- t = std::tuple, *
108+ --- @param s string
109+ --- @return string ?, string ?
110+ local function expect_typename (s )
111+ local first , rest = s :match (" ^(%l)(.*)$" )
112+ if first == nil then
113+ return nil , nil
114+ end
115+ if first == " v" then
116+ local typename , sub_rest = expect_typename (rest )
117+ if typename == nil then
118+ return " std::vector" , rest
119+ else
120+ return (" std::vector<%s>" ):format (typename ), sub_rest
121+ end
122+ elseif first == " i" then
123+ return " int32_t" , rest
124+ elseif first == " s" then
125+ return " std::string" , rest
126+ elseif first == " u" then
127+ return " uint32_t" , rest
128+ elseif first == " m" then
129+ local key_type , key_rest = expect_typename (rest )
130+ if key_type == nil or key_rest == nil then
131+ return " absl::flat_hash_map" , rest
132+ end
133+ local value_type , value_rest = expect_typename (key_rest )
134+ if value_type == nil or value_rest == nil then
135+ return " absl::flat_hash_map" , rest
136+ end
137+ return (" absl::flat_hash_map<%s, %s>" ):format (key_type , value_type ),
138+ value_rest
139+ elseif first == " t" then
140+ local parameters = {}
141+ while # rest > 0 do
142+ local typename , sub_rest = expect_typename (rest )
143+ if typename == nil or sub_rest == nil then
144+ if # parameters == 0 then
145+ return " std::tuple" , rest
146+ end
147+ return (" std::tuple<%s>" ):format (table.concat (parameters , " , " )), rest
148+ end
149+ parameters [# parameters + 1 ] = typename
150+ rest = sub_rest
151+ end
152+ return (" std::tuple<%s>" ):format (table.concat (parameters , " , " )), rest
153+ end
154+ end
155+
156+ local result , rest = expect_typename (shortcut )
157+ if rest and # rest > 0 then
158+ print ((" After QET eval, rest not empty: %s" ):format (rest ))
159+ end
160+ return result
161+ end
162+
99163return {
100164 cpo_snippet ,
101165
@@ -123,4 +187,25 @@ return {
123187 int_type_snippet (32 , false ),
124188 int_type_snippet (64 , true ),
125189 int_type_snippet (64 , false ),
190+
191+ -- quick expand, expand stl types
192+ -- v = std::vector
193+ -- i = int32_t
194+ -- s = std::string
195+ -- u = uint32_t
196+ -- m = absl::flat_hash_map
197+ -- t = std::tuple
198+ ls .s ({
199+ trig = " t(%l+)!" ,
200+ wordTrig = true ,
201+ regTrig = true ,
202+ snippetType = " autosnippet" ,
203+ name = " (t) Quick types" ,
204+ desc = " Expands to a type" ,
205+ }, {
206+ f (function (_ , snip )
207+ local shortcut = snip .captures [1 ]
208+ return quick_type (shortcut )
209+ end ),
210+ }),
126211}
0 commit comments