|
Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
|
A simple sexp reader to be used with textual IR. More...
#include <stdint.h>#include "serene/rt/impl/array_list.h"#include "serene/rt/source_manager.h"#include "serene/rt/errors.h"Go to the source code of this file.
Data Structures | |
| struct | srn_sexp_atom_t |
| struct | srn_sexp_str_t |
| struct | srn_sexp_num_t |
| A number literal, kept as the raw text it was written with (e.g. More... | |
| struct | srn_sexp_cons_t |
| struct | srn_sexp_list_t |
| struct | srn_sexp_node_t |
| struct | srn_sexp_parser_t |
| struct | srn_sexp_tree_t |
| struct | reader_fiber_arg_t |
Typedefs | |
| typedef struct srn_sexp_node_t | srn_sexp_node_t |
| typedef struct srn_src_location_t | srn_src_location_t |
| typedef struct srn_sexp_parser_t | srn_sexp_parser_t |
| typedef struct array_list_t | array_list_t |
| typedef enum srn_sexp_node_type_e | srn_sexp_node_type_e |
| typedef struct srn_sexp_atom_t | srn_sexp_atom_t |
| typedef struct srn_sexp_str_t | srn_sexp_str_t |
| typedef struct srn_sexp_num_t | srn_sexp_num_t |
| A number literal, kept as the raw text it was written with (e.g. | |
| typedef struct srn_sexp_cons_t | srn_sexp_cons_t |
| typedef struct srn_sexp_list_t | srn_sexp_list_t |
| typedef struct srn_sexp_tree_t | srn_sexp_tree_t |
| typedef struct reader_fiber_arg_t | reader_fiber_arg_t |
Enumerations | |
| enum | srn_sexp_node_type_e : uint8_t { SRN_SEXP_ATOM , SRN_SEXP_CONS , SRN_SEXP_LIST , SRN_SEXP_NUM , SRN_SEXP_SEQ , SRN_SEXP_STR } |
A simple sexp reader to be used with textual IR.
The IR types we use for the runtime have a lispy representation, and this reader will parse symbolic expressions in a basic form and different layers of IR can use this reader and transform the symbolic expressions to a format that they like.
I wrote this parser mostly to act as an inefficient way to parse different layers of IR without needing to have multiple parsers. Long in the future when we have everything in place, I should write efficient parsers for only the crucial layers of IR and avoid this generic one.
Definition in file reader.h.
| typedef struct reader_fiber_arg_t reader_fiber_arg_t |
| typedef struct srn_sexp_atom_t srn_sexp_atom_t |
| typedef struct srn_sexp_cons_t srn_sexp_cons_t |
| typedef struct srn_sexp_list_t srn_sexp_list_t |
| typedef enum srn_sexp_node_type_e srn_sexp_node_type_e |
| typedef struct srn_sexp_num_t srn_sexp_num_t |
A number literal, kept as the raw text it was written with (e.g.
"42", "-3.14", "+1e10"). The reader only recognises the shape of a number, it does not parse it into an int/float value or fix its precision, that is a later phase's job.
| typedef struct srn_sexp_str_t srn_sexp_str_t |
| typedef struct srn_sexp_tree_t srn_sexp_tree_t |
| enum srn_sexp_node_type_e : uint8_t |
| Enumerator | |
|---|---|
| SRN_SEXP_ATOM | |
| SRN_SEXP_CONS | |
| SRN_SEXP_LIST | |
| SRN_SEXP_NUM | |
| SRN_SEXP_SEQ | |
| SRN_SEXP_STR | |
Definition at line 51 of file reader.h.
| srn_sexp_node_t * read_expr | ( | srn_sexp_parser_t * | parser, |
| srn_error_t ** | err ) |
Definition at line 552 of file reader.c.
| srn_fiber_result_t read_from_buffer | ( | srn_context_t * | ctx, |
| void * | arg ) |
Definition at line 584 of file reader.c.
| srn_sexp_node_t * srn_sexp_make_atom | ( | srn_context_t * | ctx, |
| const char * | name ) |
Definition at line 176 of file reader.c.
| srn_sexp_node_t * srn_sexp_make_cons | ( | srn_context_t * | ctx, |
| srn_sexp_node_t * | head, | ||
| srn_sexp_node_t * | tail ) |
Definition at line 211 of file reader.c.
| srn_sexp_node_t * srn_sexp_make_list | ( | srn_context_t * | ctx | ) |
Definition at line 224 of file reader.c.
| srn_sexp_node_t * srn_sexp_make_node | ( | srn_context_t * | ctx, |
| srn_sexp_node_type_e | type ) |
| srn_sexp_node_t * srn_sexp_make_num | ( | srn_context_t * | ctx, |
| const char * | text ) |
Definition at line 198 of file reader.c.
| srn_sexp_node_t * srn_sexp_make_str | ( | srn_context_t * | ctx, |
| const char * | data ) |
Definition at line 187 of file reader.c.
| srn_sexp_tree_t * srn_sexp_read_from_file | ( | srn_context_t * | ctx, |
| void * | reading_context, | ||
| const char * | path ) |
Read the symbolic expressions from a file.
reading_context is a piece of data that the reader might provide as an identity or a piece of data that gives meaning to the result. For example a namespace key.
Definition at line 643 of file reader.c.
| srn_sexp_tree_t * srn_sexp_read_from_string | ( | srn_context_t * | ctx, |
| void * | reading_context, | ||
| const char * | buf ) |
Read the symbolic expressions from a buffer.
reading_context is a piece of data that the reader might provide as an identity or a piece of data that gives meaning to the result. For example a namespace key.
Definition at line 636 of file reader.c.
| const char * srn_sexp_to_debug_string | ( | srn_context_t * | ctx, |
| srn_sexp_tree_t * | tree ) |
Convert the given sexp to a string for debugging purposes.
The string will contain metadata info as well.
Definition at line 860 of file reader.c.