Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-mcp

Model Context Protocol server for Pudu language documentation and compiler tools

0.1.2Apache-2.01

InstallClose

Derives.pudu

Pudu42 lines1.4 KB

GitHub ↗
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 Entry89/// What starts a published derive strategy.10const EXPORTED_DERIVE: Str = "export derive "1112/// What opens a doc comment line.13const DOC_LINE: Str = "///"1415/// What opens a strategy's body.16const BODY_OPEN: Str = "\{"1718/// The kind a strategy is listed under.19const KIND: Str = "derive"2021/// Every derive strategy the module publishes, as `derive Trait for T: Shape`, each with the doc22/// comment written directly above it.23export 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