Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "externals" #19

Open
eWert-Online opened this issue Dec 31, 2023 · 0 comments
Open

Implement "externals" #19

eWert-Online opened this issue Dec 31, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@eWert-Online
Copy link
Member

eWert-Online commented Dec 31, 2023

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);
  }
}
@eWert-Online eWert-Online added the enhancement New feature or request label Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant