log-e-sappho/src/msph/msph_token.h

179 lines
2.7 KiB
C

#ifndef _MSPH_EXPR_H
#define _MSPH_EXPR_H
/*
* TYPES:
* Conj
* Disj
* Impl
* Arrow
* Box
* (Sub)
* Forall
*
* True
* False
* Var
* Nominal
*
* Record
*
* DEFINITIONS/DIRECTIVES:
* Type definition (type A[X..] = T)
* Nominal definition (nominal N)
* Member definition (member mname : T)
*
* {
* member a: A
* member b: B
* }
*
* Subtyping check (check A <: B, checks if A <: B)
*
* EXTRA DEFINITIONS
* Class definition (class C[...] { ... }, shorthand)
*
* EXPRESSIONS
* Conj
* Disj
* Impl
* Arrow
* Box
* (Sub)
* Forall
*
* True
* False
* Var
* Nominal
*
* Trait ({ ... }, creates scoping)
*
*
* TOKENS
* lbrace {
* rbrace }
* lbrak [
* rbrak ]
* lparen (
* rparen )
* colon :
* equals =
*
* op_and &
* op_or |
* op_impl =>
* op_sub <:
*
* kw_type type
* kw_nominal nominal
* kw_member member
* kw_check check
* kw_box box
* kw_forall forall
*
* k_true True
* k_false False
*
* ident C, anid, ...
*
*/
struct msph_ctx {
int err;
int err_info;
};
enum msph_tok_type {
TOK_START,
TOK_LBRACE, // {
TOK_RBRACE, // }
TOK_LBRAK, // [
TOK_RBRAK, // ]
TOK_LPAREN, // (
TOK_RPAREN, // )
TOK_OP_COLON, // :
TOK_OP_EQUALS, // =
TOK_OP_AMP, // &
TOK_OP_PIPE, // |
TOK_OP_RARROW, // =>
TOK_OP_SUB, // <:
TOK_KW_TYPE, // type
TOK_KW_NOMINAL, // nominal
TOK_KW_MEMBER, // member
TOK_KW_CHECK, // check
TOK_KW_BOX, // box
TOK_KW_FORALL, // forall
TOK_CONST_TRUE, // True
TOK_CONST_FALSE, // False
TOK_IDENT, // identifiers
TOK_END
};
#define MSPH_TOKEN_BUF_SZ 128
struct token_s {
char buf[MSPH_TOKEN_BUF_SZ];
};
union token_data {
struct token_s s;
};
struct msph_token {
int type;
union token_data d;
};
#define MSPH_PATH_LEN 1024
#define MSPH_FILE_BUF_LEN 4096
#define MSPH_TOKEN_SRC_FILE 1
struct msph_token_src_file {
FILE *f;
int eof;
size_t pos; // TODO rename bufpos
size_t end; // TODO rename bufend
size_t read_pos;
char buf[MSPH_FILE_BUF_LEN];
char name[MSPH_PATH_LEN];
};
#define MSPH_TOKEN_SRC_STR 2
struct msph_token_src_str {
const char *s;
size_t len;
size_t pos;
};
union msph_token_src_data {
struct msph_token_src_file file;
struct msph_token_src_str str;
};
struct msph_token_src {
int type
union msph_token_src_data inner;
};
struct msph_token_stream {
struct msph_ctx *ctx;
struct msph_token_src src;
};
struct msph_token_stream *msph_token_stream_fopen(struct msph_ctx *,
const char *);
struct msph_token_stream *msph_token_stream_frombuf(struct msph_ctx *,
const char *, size_t);
int msph_token_stream_close(struct msph_token_stream*);
struct msph_token *msph_token_source_pop(struct msph_token_stream *);
#endif /* _MSPH_EXPR_H */