Groonga 3.0.9 Source Code Document
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
compile.h
Go to the documentation of this file.
1 /*
2 ** mruby/compile.h - mruby parser
3 **
4 ** See Copyright Notice in mruby.h
5 */
6 
7 #ifndef MRUBY_COMPILE_H
8 #define MRUBY_COMPILE_H 1
9 
10 #if defined(__cplusplus)
11 extern "C" {
12 #endif
13 
14 #include "mruby.h"
15 #include <setjmp.h>
16 
17 struct mrb_parser_state;
18 /* load context */
19 typedef struct mrbc_context {
21  int slen;
22  char *filename;
23  short lineno;
24  int (*partial_hook)(struct mrb_parser_state*);
25  void *partial_data;
30 } mrbc_context;
31 
34 const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s);
35 void mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*partial_hook)(struct mrb_parser_state*), void*data);
36 
37 /* AST node structure */
38 typedef struct mrb_ast_node {
39  struct mrb_ast_node *car, *cdr;
41 } mrb_ast_node;
42 
43 /* lexer states */
45  EXPR_BEG, /* ignore newline, +/- is a sign. */
46  EXPR_END, /* newline significant, +/- is an operator. */
47  EXPR_ENDARG, /* ditto, and unbound braces. */
48  EXPR_ENDFN, /* ditto, and unbound braces. */
49  EXPR_ARG, /* newline significant, +/- is an operator. */
50  EXPR_CMDARG, /* newline significant, +/- is an operator. */
51  EXPR_MID, /* newline significant, +/- is an operator. */
52  EXPR_FNAME, /* ignore newline, no reserved words. */
53  EXPR_DOT, /* right after `.' or `::', no reserved words. */
54  EXPR_CLASS, /* immediate after `class', no here document. */
55  EXPR_VALUE, /* alike EXPR_BEG but label is disallowed. */
57 };
58 
59 /* saved error message */
61  int lineno;
62  int column;
63  char* message;
64 };
65 
66 #define STR_FUNC_PARSING 0x01
67 #define STR_FUNC_EXPAND 0x02
68 #define STR_FUNC_REGEXP 0x04
69 #define STR_FUNC_WORD 0x08
70 #define STR_FUNC_SYMBOL 0x10
71 #define STR_FUNC_ARRAY 0x20
72 #define STR_FUNC_HEREDOC 0x40
73 #define STR_FUNC_XQUOTE 0x80
74 
87 };
88 
89 /* heredoc structure */
94  const char *term;
95  int term_len;
97 };
98 
99 #ifndef MRB_PARSER_BUF_SIZE
100 # define MRB_PARSER_BUF_SIZE 1024
101 #endif
102 
103 /* parser structure */
106  struct mrb_pool *pool;
108  const char *s, *send;
109 #ifdef ENABLE_STDIO
110  FILE *f;
111 #endif
113  char const *filename;
114  int lineno;
115  int column;
116 
118  mrb_ast_node *lex_strterm; /* (type nest_level beg . end) */
119 
120  unsigned int cond_stack;
121  unsigned int cmdarg_stack;
123  int lpar_beg;
126 
129  int bidx;
130 
131  mrb_ast_node *heredocs; /* list of mrb_parser_heredoc_info* */
134  mrb_bool heredoc_end_now:1; /* for mirb */
135 
136  void *ylval;
137 
138  size_t nerr;
139  size_t nwarn;
141 
145 
149 
150  jmp_buf jmp;
151 };
152 
154 void mrb_parser_free(struct mrb_parser_state*);
156 
157 void mrb_parser_set_filename(struct mrb_parser_state*, char const*);
158 char const* mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);
159 
160 /* utility functions */
161 #ifdef ENABLE_STDIO
162 struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*);
163 #endif
165 struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int,mrbc_context*);
167 
168 /* program load functions */
169 #ifdef ENABLE_STDIO
170 mrb_value mrb_load_file(mrb_state*,FILE*);
171 #endif
172 mrb_value mrb_load_string(mrb_state *mrb, const char *s);
173 mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, int len);
174 #ifdef ENABLE_STDIO
175 mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
176 #endif
178 mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *cxt);
179 
180 #if defined(__cplusplus)
181 } /* extern "C" { */
182 #endif
183 
184 #endif /* MRUBY_COMPILE_H */