@@ -126,13 +126,23 @@ If you pass more than one such search filter, separated by commas Loogle will re
126
126
🔍 Real.sin, \" two\" , tsum, _ * _, _ ^ _, |- _ < _ → _
127
127
woould find all lemmas which mention the constants Real.sin and tsum, have \" two\" as a substring of the lemma name, include a product and a power somewhere in the type, and have a hypothesis of the form _ < _ (if there were any such lemmas). Metavariables (?a) are assigned independently in each filter."
128
128
129
+ /-- The turnstyle uesd bin `#find`, unicode or ascii allowed -/
130
+ syntax turnstyle := patternIgnore("⊢ " <|> "|- " )
131
+ /-- a single `#find` filter. The `term` can also be an ident or a strlit,
132
+ these are distinguished in `parseFindFilters` -/
133
+ syntax loogle_filter := (turnstyle term) <|> term
134
+
135
+ /-- The argument to `#find`, a list of filters -/
136
+ syntax loogle_filters := loogle_filter,*
137
+
129
138
open Command
130
- syntax (name := loogle_cmd) "#loogle" str "go" : command
139
+ syntax (name := loogle_cmd) "#loogle" loogle_filters "go" : command
131
140
@[command_elab loogle_cmd] def loogleCmdImpl : CommandElab := fun stx =>
132
141
Command.liftTermElabM do
133
142
match stx with
134
- | `(command| #loogle $s go) =>
135
- let s := s.getString
143
+ | `(command| #loogle $args:loogle_filters go) =>
144
+ let s := (← PrettyPrinter.ppCategory ``loogle_filters args).pretty
145
+ logInfo s
136
146
let result ← getLoogleQueryJson s
137
147
match result with
138
148
| LoogleResult.success xs =>
@@ -149,28 +159,27 @@ syntax (name := loogle_cmd) "#loogle" str "go" : command
149
159
| some suggestions =>
150
160
let suggestions : List TryThis.Suggestion :=
151
161
suggestions.map fun s =>
152
- let s := s.replace "\" " "\\\" "
153
162
{suggestion := .string s! "#loogle \" { s} \" go" }
154
163
unless suggestions.isEmpty do
155
164
TryThis.addSuggestions stx suggestions.toArray (header := s! "Did you maybe mean" )
156
165
| none => pure ()
157
166
| _ => throwUnsupportedSyntax
158
167
159
- -- #loogle " List ?a → ?b" go
168
+ -- #loogle List ?a → ?b go
160
169
161
- -- #loogle " nonsense" go
170
+ -- #loogle nonsense go
162
171
163
- -- #loogle " ?a → ?b" go
172
+ -- #loogle ?a → ?b go
164
173
165
- -- #loogle " sin" go
174
+ -- #loogle sin go
166
175
167
176
168
- syntax (name := loogle_term) "#loogle" str "go" : term
177
+ syntax (name := loogle_term) "#loogle" loogle_filters "go" : term
169
178
@[term_elab loogle_term] def loogleTermImpl : TermElab :=
170
179
fun stx expectedType? => do
171
180
match stx with
172
- | `(#loogle $s go) =>
173
- let s := s.getString
181
+ | `(#loogle $args go) =>
182
+ let s := (← PrettyPrinter.ppCategory ``loogle_filters args).pretty
174
183
let result ← getLoogleQueryJson s
175
184
match result with
176
185
| LoogleResult.success xs =>
@@ -196,7 +205,53 @@ syntax (name := loogle_term) "#loogle" str "go" : term
196
205
defaultTerm expectedType?
197
206
| _ => throwUnsupportedSyntax
198
207
208
+ syntax (name := loogle_tactic) "#loogle" loogle_filters "go" : tactic
209
+ @[tactic loogle_tactic] def loogleTacticImpl : Tactic :=
210
+ fun stx => do
211
+ match stx with
212
+ | `(tactic|#loogle $args go) =>
213
+ let s := (← PrettyPrinter.ppCategory ``loogle_filters args).pretty
214
+ let result ← getLoogleQueryJson s
215
+ match result with
216
+ | LoogleResult.success xs => do
217
+ let suggestionGroups := xs.map fun sr =>
218
+ (sr.name, sr.toTacticSuggestions)
219
+ for (name, sg) in suggestionGroups do
220
+ let sg ← sg.filterM fun s =>
221
+ let sugTxt := s.suggestion
222
+ match sugTxt with
223
+ | .string s => do
224
+ let stx? := runParserCategory (← getEnv) `tactic s
225
+ match stx? with
226
+ | Except.ok stx =>
227
+ let n? ← checkTactic (← getMainTarget) stx
228
+ return n?.isSome
229
+ | Except.error _ =>
230
+ pure false
231
+ | _ => pure false
232
+ unless sg.isEmpty do
233
+ TryThis.addSuggestions stx sg (header := s! "From: { name} " )
234
+
235
+ | LoogleResult.failure error suggestions? =>
236
+ logWarning s! "Loogle search failed with error: { error} "
237
+ logInfo loogleUsage
238
+ match suggestions? with
239
+ | some suggestions =>
240
+ let suggestions : List TryThis.Suggestion :=
241
+ suggestions.map fun s =>
242
+ {suggestion := .string s! "#loogle \" { s} \" go" }
243
+ unless suggestions.isEmpty do
244
+ TryThis.addSuggestions stx suggestions.toArray (header := s! "Did you maybe mean" )
245
+ | none => pure ()
246
+ | _ => throwUnsupportedSyntax
247
+
199
248
200
- -- example := #loogle "List ?a → ?b" go
249
+ example : 3 ≤ 5 := by
250
+ -- #loogle Nat.succ_le_succ go
251
+ decide
252
+
253
+ -- example := #loogle List ?a → ?b go
201
254
202
255
end LeanSearchClient
256
+
257
+ -- #loogle "sin", Real → Real, |- Real go
0 commit comments