Groonga 3.0.9 Source Code Document
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
groonga
vendor
mruby-eeac4be
include
mruby
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
{
20
mrb_sym
*
syms
;
21
int
slen
;
22
char
*
filename
;
23
short
lineno
;
24
int (*
partial_hook
)(
struct
mrb_parser_state
*);
25
void
*
partial_data
;
26
struct
RClass
*
target_class
;
27
mrb_bool
capture_errors
:1;
28
mrb_bool
dump_result
:1;
29
mrb_bool
no_exec
:1;
30
}
mrbc_context
;
31
32
mrbc_context
*
mrbc_context_new
(
mrb_state
*mrb);
33
void
mrbc_context_free
(
mrb_state
*mrb,
mrbc_context
*cxt);
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
;
40
uint16_t
lineno
,
filename_index
;
41
}
mrb_ast_node
;
42
43
/* lexer states */
44
enum
mrb_lex_state_enum
{
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. */
56
EXPR_MAX_STATE
57
};
58
59
/* saved error message */
60
struct
mrb_parser_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
75
enum
mrb_string_type
{
76
str_not_parsing
= (0),
77
str_squote
= (
STR_FUNC_PARSING
),
78
str_dquote
= (
STR_FUNC_PARSING
|
STR_FUNC_EXPAND
),
79
str_regexp
= (
STR_FUNC_PARSING
|
STR_FUNC_REGEXP
|
STR_FUNC_EXPAND
),
80
str_sword
= (
STR_FUNC_PARSING
|
STR_FUNC_WORD
|
STR_FUNC_ARRAY
),
81
str_dword
= (
STR_FUNC_PARSING
|
STR_FUNC_WORD
|
STR_FUNC_ARRAY
|
STR_FUNC_EXPAND
),
82
str_ssym
= (
STR_FUNC_PARSING
|
STR_FUNC_SYMBOL
),
83
str_ssymbols
= (
STR_FUNC_PARSING
|
STR_FUNC_SYMBOL
|
STR_FUNC_ARRAY
),
84
str_dsymbols
= (
STR_FUNC_PARSING
|
STR_FUNC_SYMBOL
|
STR_FUNC_ARRAY
|
STR_FUNC_EXPAND
),
85
str_heredoc
= (
STR_FUNC_PARSING
|
STR_FUNC_HEREDOC
),
86
str_xquote
= (
STR_FUNC_PARSING
|
STR_FUNC_XQUOTE
|
STR_FUNC_EXPAND
),
87
};
88
89
/* heredoc structure */
90
struct
mrb_parser_heredoc_info
{
91
mrb_bool
allow_indent
:1;
92
mrb_bool
line_head
:1;
93
enum
mrb_string_type
type
;
94
const
char
*
term
;
95
int
term_len
;
96
mrb_ast_node
*
doc
;
97
};
98
99
#ifndef MRB_PARSER_BUF_SIZE
100
# define MRB_PARSER_BUF_SIZE 1024
101
#endif
102
103
/* parser structure */
104
struct
mrb_parser_state
{
105
mrb_state
*
mrb
;
106
struct
mrb_pool
*
pool
;
107
mrb_ast_node
*
cells
;
108
const
char
*
s
, *
send
;
109
#ifdef ENABLE_STDIO
110
FILE *f;
111
#endif
112
mrbc_context
*
cxt
;
113
char
const
*
filename
;
114
int
lineno
;
115
int
column
;
116
117
enum
mrb_lex_state_enum
lstate
;
118
mrb_ast_node
*
lex_strterm
;
/* (type nest_level beg . end) */
119
120
unsigned
int
cond_stack
;
121
unsigned
int
cmdarg_stack
;
122
int
paren_nest
;
123
int
lpar_beg
;
124
int
in_def
,
in_single
,
cmd_start
;
125
mrb_ast_node
*
locals
;
126
127
mrb_ast_node
*
pb
;
128
char
buf
[
MRB_PARSER_BUF_SIZE
];
129
int
bidx
;
130
131
mrb_ast_node
*
heredocs
;
/* list of mrb_parser_heredoc_info* */
132
mrb_ast_node
*
parsing_heredoc
;
133
mrb_bool
heredoc_starts_nextline
:1;
134
mrb_bool
heredoc_end_now
:1;
/* for mirb */
135
136
void
*
ylval
;
137
138
size_t
nerr
;
139
size_t
nwarn
;
140
mrb_ast_node
*
tree
;
141
142
int
capture_errors
;
143
struct
mrb_parser_message
error_buffer
[10];
144
struct
mrb_parser_message
warn_buffer
[10];
145
146
mrb_sym
*
filename_table
;
147
size_t
filename_table_length
;
148
int
current_filename_index
;
149
150
jmp_buf
jmp
;
151
};
152
153
struct
mrb_parser_state
*
mrb_parser_new
(
mrb_state
*);
154
void
mrb_parser_free
(
struct
mrb_parser_state
*);
155
void
mrb_parser_parse
(
struct
mrb_parser_state
*,
mrbc_context
*);
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
164
struct
mrb_parser_state
*
mrb_parse_string
(
mrb_state
*,
const
char
*,
mrbc_context
*);
165
struct
mrb_parser_state
*
mrb_parse_nstring
(
mrb_state
*,
const
char
*,
int
,
mrbc_context
*);
166
int
mrb_generate_code
(
mrb_state
*,
struct
mrb_parser_state
*);
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
177
mrb_value
mrb_load_string_cxt
(
mrb_state
*mrb,
const
char
*
s
,
mrbc_context
*
cxt
);
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 */
Generated on Sun Nov 10 2013 09:49:05 for Groonga 3.0.9 Source Code Document by
1.8.1.2