ST.Parser.Core (st_parser v0.2.0)
View SourceLow-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 basic type.
Parses a branch in a session type.
Parses an end session type.
Parses an identifier.
Parses an input session type.
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 output structures.
Helper function for parser post-processing to wrap tuple types.
Functions
@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
@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
@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
@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
@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
@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
@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
@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
@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
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.
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.
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]}
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.
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.