2023-04-05

(sph lang parser type-signature)

a parser and writer for a type signature notation.

part of sph-lib

library description

input/output

  expressions separated by: "->"

  example: input -> output

  example: input ->

  output arguments are optional. if left-out the output is unspecified

multiple arguments

  expressions separated by a space character: " "

  example: a b c -> d

alternative data-types

  expressions separated by a slash: "/"

  example: a b/c/d -> e

  example: a port/string/integer -> e

alternative names

  expressions separated by a colon: ":"

  example: a b:c:d -> e

  data-types always come first

  data-type:helpful-alternative-name:another-alternative-name

  example: a port:input-port:source -> e

optional arguments

  enclosed with square brackets: []

  example: a [b c] -> d

repetition

  none or many consecutive occurences of an expression

  expression followed by a space character and three dots: " ..."

  example: a b ... c ... -> d

function-name specification

  identifier followed by a space character and two colons: " ::"

  example: name :: a b -> c

procedures, dictionaries

  a function signature enclosed with curly brackets: "{" "}"

  unlimited nesting

  example: {a ->}

  example with data-type: procedure:{a ... -> list:b}

  example: hashtable:{key -> value}

lists, vectors, pairs, and more

  using scheme read syntax

  example list: (a (b c))

  example vector: #(a #(b c))

  example using both: (integer #(char ...))

multiline signatures

  two colons followed by a newline, optionally followed by one or multiple

  input expressions per line separated by newlines, a line with only a "->",

  optionally followed by output expression separated by newlines,

  ending with end-of-string or two successive newline characters

  example

    ::

    a

    b

    ->

    c

    line outside of signature

examples

  list any [symbol:exclusive/inclusive] -> (list:left list:right)

  procedure:{any -> boolean} procedure:{list:matched-elements -> list:replacements} list:source -> list

multiline example

  ::

  procedure:{alist:header procedure:fold-lines:{string:line any:result procedure:next:{any:result -> any} -> any} result -> any}

  procedure:{header port result ->} any port [string]

  ->

  any

module name

(sph lang parser type-signature)

exported bindings

procedure: parsed-type-signature->string a [line-prefix] ->
list [string] -> string
\"line-prefix\" could be indent space
procedure: peg-type-signature str strlen at ->
procedure: string->parsed-type-signature a ->
string -> list/boolean
procedure: type-signature-simplify-tree a ->
this simplify a few cases like over-nested elements and no-arguments