Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
123 lines (107 sloc) 3.93 KB
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <token.h>
#include <Python-ast.h>
#include <pyarena.h>
typedef struct _memo {
int type;
void *node;
int mark;
struct _memo *next;
} Memo;
typedef struct {
int type;
PyObject *bytes;
int lineno, col_offset, end_lineno, end_col_offset;
Memo *memo;
} Token;
typedef struct {
struct tok_state *tok;
Token **tokens;
int mark;
int fill, size;
PyArena *arena;
} Parser;
typedef struct {
cmpop_ty cmpop;
expr_ty expr;
} CmpopExprPair;
typedef struct {
expr_ty key;
expr_ty value;
} KeyValuePair;
typedef struct {
arg_ty arg;
expr_ty value;
} NameDefaultPair;
typedef struct {
asdl_seq *plain_names;
asdl_seq *names_with_defaults; // asdl_seq* of NameDefaultsPair's
} SlashWithDefault;
typedef struct {
arg_ty vararg;
asdl_seq *kwonlyargs; // asdl_seq* of NameDefaultsPair's
arg_ty kwarg;
} StarEtc;
typedef struct {
operator_ty kind;
} AugOperator;
typedef struct {
void *element;
int is_keyword;
} KeywordOrStarred;
int insert_memo(Parser *p, int mark, int type, void *node);
int update_memo(Parser *p, int mark, int type, void *node);
int is_memoized(Parser *p, int type, void *pres);
int lookahead_with_string(int, void *(func)(Parser *, const char *), Parser *, const char *);
int lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int);
int lookahead(int, void *(func)(Parser *), Parser *);
Token *expect_token(Parser *p, int type);
Token *get_last_nonnwhitespace_token(Parser *);
int fill_token(Parser *p);
void *async_token(Parser *p);
void *await_token(Parser *p);
void *endmarker_token(Parser *p);
expr_ty name_token(Parser *p);
void *newline_token(Parser *p);
void *indent_token(Parser *p);
void *dedent_token(Parser *p);
expr_ty number_token(Parser *p);
expr_ty string_token(Parser *p);
void *keyword_token(Parser *p, const char *val);
int raise_syntax_error(Parser *p, const char *errmsg, ...);
void *CONSTRUCTOR(Parser *p, ...);
#define UNUSED(expr) do { (void)(expr); } while (0)
#define EXTRA_EXPR(head, tail) head->lineno, head->col_offset, tail->end_lineno, tail->end_col_offset, p->arena
#define EXTRA start_lineno, start_col_offset, end_lineno, end_col_offset, p->arena
PyObject *run_parser_from_file(const char *filename, void *(start_rule_func)(Parser *), int mode);
PyObject *run_parser_from_string(const char *str, void *(start_rule_func)(Parser *), int mode);
asdl_seq *singleton_seq(Parser *, void *);
asdl_seq *seq_insert_in_front(Parser *, void *, asdl_seq *);
asdl_seq *seq_flatten(Parser *, asdl_seq *);
expr_ty join_names_with_dot(Parser *, expr_ty, expr_ty);
int seq_count_dots(asdl_seq *);
alias_ty alias_for_star(Parser *);
void *seq_get_head(void *, asdl_seq *);
void *seq_get_tail(void *, asdl_seq *);
asdl_seq *map_names_to_ids(Parser *, asdl_seq *);
CmpopExprPair *cmpop_expr_pair(Parser *, cmpop_ty, expr_ty);
expr_ty Pegen_Compare(Parser *, expr_ty, asdl_seq *);
expr_ty set_expr_context(Parser *, expr_ty, expr_context_ty);
KeyValuePair *key_value_pair(Parser *, expr_ty, expr_ty);
asdl_seq *get_keys(Parser *, asdl_seq *);
asdl_seq *get_values(Parser *, asdl_seq *);
NameDefaultPair *name_default_pair(Parser *, arg_ty, expr_ty);
SlashWithDefault *slash_with_default(Parser *, asdl_seq *, asdl_seq *);
StarEtc *star_etc(Parser *, arg_ty, asdl_seq *, arg_ty);
arguments_ty make_arguments(Parser *, asdl_seq *, SlashWithDefault *,
asdl_seq *, asdl_seq *, StarEtc *);
arguments_ty empty_arguments(Parser *);
AugOperator *augoperator(Parser*, operator_ty type);
expr_ty construct_assign_target(Parser *p, expr_ty node);
stmt_ty function_def_decorators(Parser *, asdl_seq *, stmt_ty);
stmt_ty class_def_decorators(Parser *, asdl_seq *, stmt_ty);
KeywordOrStarred *keyword_or_starred(Parser *, void *, int);
asdl_seq *seq_extract_starred_exprs(Parser *, asdl_seq *);
asdl_seq *seq_delete_starred_exprs(Parser *, asdl_seq *);
expr_ty concatenate_strings(Parser *p, asdl_seq *);
You can’t perform that action at this time.