ST.Parser.Core (st_parser v0.4.1)

View Source

Low-level implementation of the Session Type Parser.

This module contains the NimbleParsec-based parser definitions for session types. Most users should use the higher-level API in the ST.Parser module rather than directly using the functions in this module.

The parser handles:

  • Basic payload types (string, number, boolean, unit)
  • Complex payload types (lists, tuples)
  • Session type constructs (input, output, end)
  • Branch definitions with continuations

Summary

Functions

Parses a branch in a session type.

Parses an end session type.

Parses an identifier.

Parses an input session type.

Parses a named handler reference.

Parses an output session type.

Parses a complete session type expression.

Parses a tuple type.

Parses a payload type.

Helper function for parser post-processing to wrap branch structures.

Helper function for parser post-processing to wrap input structures.

Helper function to wrap a type as a list type.

Helper function for parser post-processing to wrap name structures.

Helper function for parser post-processing to wrap output structures.

Helper function for parser post-processing to wrap tuple types.

Functions

parse_basic_type(binary, opts \\ [])

@spec parse_basic_type(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses a basic type.

Parameters

  • input: String containing the basic type expression

Returns

  • A NimbleParsec result tuple

parse_branch(binary, opts \\ [])

@spec parse_branch(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses a branch in a session type.

Parameters

  • input: String containing the branch expression

Returns

  • A NimbleParsec result tuple

parse_end(binary, opts \\ [])

@spec parse_end(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses an end session type.

Parameters

  • input: String containing the end expression

Returns

  • A NimbleParsec result tuple

parse_identifier(binary, opts \\ [])

@spec parse_identifier(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses an identifier.

Parameters

  • input: String containing the identifier

Returns

  • A NimbleParsec result tuple

parse_input(binary, opts \\ [])

@spec parse_input(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses an input session type.

Parameters

  • input: String containing the input expression

Returns

  • A NimbleParsec result tuple

parse_name(binary, opts \\ [])

@spec parse_name(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses a named handler reference.

Parameters

  • input: String containing the handler name

Returns

  • A NimbleParsec result tuple

parse_output(binary, opts \\ [])

@spec parse_output(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses an output session type.

Parameters

  • input: String containing the output expression

Returns

  • A NimbleParsec result tuple

parse_session_type(binary, opts \\ [])

@spec parse_session_type(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses a complete session type expression.

Parameters

  • input: String containing the session type expression

Returns

  • A NimbleParsec result tuple

parse_tuple(binary, opts \\ [])

@spec parse_tuple(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses a tuple type.

Parameters

  • input: String containing the tuple expression

Returns

  • A NimbleParsec result tuple

payload_type(binary, opts \\ [])

@spec payload_type(binary(), keyword()) ::
  {:ok, [term()], rest, context, line, byte_offset}
  | {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
     byte_offset: non_neg_integer(),
     rest: binary(),
     reason: String.t(),
     context: map()

Parses a payload type.

Parameters

  • input: String containing the payload type expression

Returns

  • A NimbleParsec result tuple

wrap_branch(rest, list, context, line, offset)

Helper function for parser post-processing to wrap branch structures.

Parameters

Standard NimbleParsec post-traverse callback parameters.

Returns

A tuple containing the rest of the input, a list with the branch structure, and the context.

wrap_input(rest, branches_and_role, context, line, offset)

Helper function for parser post-processing to wrap input structures.

Parameters

Standard NimbleParsec post-traverse callback parameters.

Returns

A tuple containing the rest of the input, a list with the input structure, and the context.

wrap_list_type(type)

@spec wrap_list_type(atom()) :: {:list, [atom()]}

Helper function to wrap a type as a list type.

Parameters

  • type: The element type of the list

Returns

  • A tuple of the form {:list, [type]}

wrap_name(rest, list, context, line, offset)

Helper function for parser post-processing to wrap name structures.

Parameters

Standard NimbleParsec post-traverse callback parameters.

Returns

A tuple containing the rest of the input, a list with the name structure, and the context.

wrap_output(rest, branches_and_role, context, line, offset)

Helper function for parser post-processing to wrap output structures.

Parameters

Standard NimbleParsec post-traverse callback parameters.

Returns

A tuple containing the rest of the input, a list with the output structure, and the context.

wrap_tuple_type(rest, args, context, line, offset)

Helper function for parser post-processing to wrap tuple types.

Parameters

Standard NimbleParsec post-traverse callback parameters.

Returns

A tuple containing the rest of the input, a list with the tuple type, and the context.