A component based functional template language

add externals #3

Open t.ewert.foo
Open opened by t.ewert.foo

In pinc files the user should be able to define new external tags through the external keyword. For example:

external PdfSearch = (search: string, limit: int, offset: int) -> array({
  filename: string,
  p: int,
  highlightText: string,
  url: string,
})

... 

let response = #PdfSearch(search: "foo", limit: 20, offset: 0);

A tool (pigen) should then be able to generate external code in a language of your choice. For the example above, it could look like this (in php):

<?php 

class PdfSearchResponse {
  public string $filename;
  public int $p;
  public string $highlightText;
  public string $url;
}

class PdfSearchExternal extends PincExternal {
  /**
   * @return array<PdfSearchResponse>
   */
  abstract protected function run(string $search, int $limit, int $offset): array

  private function decode(string $request): mixed
  {
    // Generated by Pigen. Do not modify!
  }

  private function encode(array $response): string
  {
    // Generated by Pigen. Do not modify!
  }

  private function execute(string $request): void
  {
    // Generated by Pigen. Do not modify!
    $decoded = $this->decode($request);
    $result = $this->run(
      $decoded->search,
      $decoded->limit,
      $decoded->offset
    );

    $encoded = $this->encode($result);

    $this->respond($encoded);
  }
}

Sign up or Sign in to add to the discussion.