
Derives.pudu
Pudu42 lines1.4 KB
1/** @Domain.Reference.Derives.Scanner — derive strategies read from source text */2module PuduLangMcp.Domain.Reference.Derives34import Std.List as List5import Std.Option as Option6import Std.Text as Text7import PuduLangMcp.Domain.Reference.Entry as Entry8910const EXPORTED_DERIVE: Str = "export derive "111213const DOC_LINE: Str = "///"141516const BODY_OPEN: Str = "\{"171819const KIND: Str = "derive"20212223export fn strategiesOf(moduleName: Str, text: Str) -> Array[Entry.Entry] {24 var found: Array[Entry.Entry] = []25 var doc: Array[Str] = []26 for line in text.split("\n") {27 let trimmed = line.trim()28 if trimmed.startsWith(DOC_LINE) {29 doc = doc.push(Text.stripPrefix(Text.stripPrefix(trimmed, DOC_LINE), " "))30 } else {31 if line.startsWith(EXPORTED_DERIVE) {32 let head = Text.stripPrefix(line, "export ")33 let header = Text.breakOn(head, BODY_OPEN)[0].trim()34 let name = Option.unwrapOr(List.first(&Text.stripPrefix(header, KIND + " ").split(" ")), "")35 found = found.push(Entry.Entry{moduleName: moduleName, kind: KIND, name: name, signature: header, doc: doc.join("\n")})36 }37 doc = []38 }39 }40 found41}42