mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
add context to parser, that would hold local variable info, filename, and line number. mrbc_context argument has been added to mrb_parse_xxx() functions. Normally, you just to need to add NULL (or 0) to the last argument of the above functions.
This commit is contained in:
+26
-11
@@ -14,13 +14,26 @@ extern "C" {
|
||||
#include "mruby.h"
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* load context */
|
||||
typedef struct mrbc_context {
|
||||
mrb_sym *syms;
|
||||
int slen;
|
||||
char *filename;
|
||||
int lineno;
|
||||
} mrbc_context;
|
||||
|
||||
mrbc_context* mrbc_context_new(mrb_state *mrb);
|
||||
void mrbc_context_free(mrb_state *mrb, mrbc_context *cxt);
|
||||
const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s);
|
||||
|
||||
/* AST node structure */
|
||||
typedef struct mrb_ast_node {
|
||||
struct mrb_ast_node *car, *cdr;
|
||||
} mrb_ast_node;
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* lexer states */
|
||||
enum mrb_lex_state_enum {
|
||||
EXPR_BEG, /* ignore newline, +/- is a sign. */
|
||||
EXPR_END, /* newline significant, +/- is an operator. */
|
||||
@@ -36,21 +49,23 @@ enum mrb_lex_state_enum {
|
||||
EXPR_MAX_STATE
|
||||
};
|
||||
|
||||
/* saved error message */
|
||||
struct mrb_parser_message {
|
||||
int lineno;
|
||||
int column;
|
||||
char* message;
|
||||
};
|
||||
|
||||
/* parser structure */
|
||||
struct mrb_parser_state {
|
||||
mrb_state *mrb;
|
||||
struct mrb_pool *pool;
|
||||
mrb_ast_node *cells;
|
||||
const char *s, *send;
|
||||
FILE *f;
|
||||
char *filename;
|
||||
int lineno;
|
||||
int column;
|
||||
const char *filename;
|
||||
|
||||
enum mrb_lex_state_enum lstate;
|
||||
int sterm;
|
||||
@@ -59,6 +74,8 @@ struct mrb_parser_state {
|
||||
unsigned int cmdarg_stack;
|
||||
int paren_nest;
|
||||
int lpar_beg;
|
||||
int in_def, in_single, cmd_start;
|
||||
mrb_ast_node *locals;
|
||||
|
||||
mrb_ast_node *pb;
|
||||
char buf[1024];
|
||||
@@ -66,9 +83,6 @@ struct mrb_parser_state {
|
||||
|
||||
mrb_ast_node *heredoc;
|
||||
|
||||
int in_def, in_single, cmd_start;
|
||||
mrb_ast_node *locals;
|
||||
|
||||
void *ylval;
|
||||
|
||||
int nerr;
|
||||
@@ -82,22 +96,23 @@ struct mrb_parser_state {
|
||||
jmp_buf jmp;
|
||||
};
|
||||
|
||||
/* parser structure */
|
||||
struct mrb_parser_state* mrb_parser_new(mrb_state*);
|
||||
const char *mrb_parser_filename(struct mrb_parser_state*, const char*);
|
||||
int mrb_parser_lineno(struct mrb_parser_state*, int);
|
||||
void mrb_parser_parse(struct mrb_parser_state*);
|
||||
|
||||
/* utility functions */
|
||||
struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*);
|
||||
struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*);
|
||||
struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int);
|
||||
struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*);
|
||||
struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*);
|
||||
struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int,mrbc_context*);
|
||||
int mrb_generate_code(mrb_state*, mrb_ast_node*);
|
||||
|
||||
/* program load functions */
|
||||
mrb_value mrb_load_file(mrb_state*,FILE*);
|
||||
mrb_value mrb_load_string(mrb_state *mrb, const char *path);
|
||||
mrb_value mrb_load_nstring(mrb_state *mrb, const char *path, int len);
|
||||
mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
|
||||
mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *path, mrbc_context *cxt);
|
||||
mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *path, int len, mrbc_context *cxt);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" { */
|
||||
|
||||
Reference in New Issue
Block a user