stash 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,333 @@
1
+ #ifndef yyHEADER_H
2
+ #define yyHEADER_H 1
3
+ #define yyIN_HEADER 1
4
+
5
+ #line 6 "../lib/lex.yy.h"
6
+
7
+ #line 8 "../lib/lex.yy.h"
8
+
9
+ #define YY_INT_ALIGNED short int
10
+
11
+ /* A lexical scanner generated by flex */
12
+
13
+ #define FLEX_SCANNER
14
+ #define YY_FLEX_MAJOR_VERSION 2
15
+ #define YY_FLEX_MINOR_VERSION 5
16
+ #define YY_FLEX_SUBMINOR_VERSION 35
17
+ #if YY_FLEX_SUBMINOR_VERSION > 0
18
+ #define FLEX_BETA
19
+ #endif
20
+
21
+ /* First, we deal with platform-specific or compiler-specific issues. */
22
+
23
+ /* begin standard C headers. */
24
+ #include <stdio.h>
25
+ #include <string.h>
26
+ #include <errno.h>
27
+ #include <stdlib.h>
28
+
29
+ /* end standard C headers. */
30
+
31
+ /* flex integer type definitions */
32
+
33
+ #ifndef FLEXINT_H
34
+ #define FLEXINT_H
35
+
36
+ /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
37
+
38
+ #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
39
+
40
+ /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
41
+ * if you want the limit (max/min) macros for int types.
42
+ */
43
+ #ifndef __STDC_LIMIT_MACROS
44
+ #define __STDC_LIMIT_MACROS 1
45
+ #endif
46
+
47
+ #include <inttypes.h>
48
+ typedef int8_t flex_int8_t;
49
+ typedef uint8_t flex_uint8_t;
50
+ typedef int16_t flex_int16_t;
51
+ typedef uint16_t flex_uint16_t;
52
+ typedef int32_t flex_int32_t;
53
+ typedef uint32_t flex_uint32_t;
54
+ #else
55
+ typedef signed char flex_int8_t;
56
+ typedef short int flex_int16_t;
57
+ typedef int flex_int32_t;
58
+ typedef unsigned char flex_uint8_t;
59
+ typedef unsigned short int flex_uint16_t;
60
+ typedef unsigned int flex_uint32_t;
61
+ #endif /* ! C99 */
62
+
63
+ /* Limits of integral types. */
64
+ #ifndef INT8_MIN
65
+ #define INT8_MIN (-128)
66
+ #endif
67
+ #ifndef INT16_MIN
68
+ #define INT16_MIN (-32767-1)
69
+ #endif
70
+ #ifndef INT32_MIN
71
+ #define INT32_MIN (-2147483647-1)
72
+ #endif
73
+ #ifndef INT8_MAX
74
+ #define INT8_MAX (127)
75
+ #endif
76
+ #ifndef INT16_MAX
77
+ #define INT16_MAX (32767)
78
+ #endif
79
+ #ifndef INT32_MAX
80
+ #define INT32_MAX (2147483647)
81
+ #endif
82
+ #ifndef UINT8_MAX
83
+ #define UINT8_MAX (255U)
84
+ #endif
85
+ #ifndef UINT16_MAX
86
+ #define UINT16_MAX (65535U)
87
+ #endif
88
+ #ifndef UINT32_MAX
89
+ #define UINT32_MAX (4294967295U)
90
+ #endif
91
+
92
+ #endif /* ! FLEXINT_H */
93
+
94
+ #ifdef __cplusplus
95
+
96
+ /* The "const" storage-class-modifier is valid. */
97
+ #define YY_USE_CONST
98
+
99
+ #else /* ! __cplusplus */
100
+
101
+ /* C99 requires __STDC__ to be defined as 1. */
102
+ #if defined (__STDC__)
103
+
104
+ #define YY_USE_CONST
105
+
106
+ #endif /* defined (__STDC__) */
107
+ #endif /* ! __cplusplus */
108
+
109
+ #ifdef YY_USE_CONST
110
+ #define yyconst const
111
+ #else
112
+ #define yyconst
113
+ #endif
114
+
115
+ /* An opaque pointer. */
116
+ #ifndef YY_TYPEDEF_YY_SCANNER_T
117
+ #define YY_TYPEDEF_YY_SCANNER_T
118
+ typedef void* yyscan_t;
119
+ #endif
120
+
121
+ /* For convenience, these vars (plus the bison vars far below)
122
+ are macros in the reentrant scanner. */
123
+ #define yyin yyg->yyin_r
124
+ #define yyout yyg->yyout_r
125
+ #define yyextra yyg->yyextra_r
126
+ #define yyleng yyg->yyleng_r
127
+ #define yytext yyg->yytext_r
128
+ #define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
129
+ #define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
130
+ #define yy_flex_debug yyg->yy_flex_debug_r
131
+
132
+ /* Size of default input buffer. */
133
+ #ifndef YY_BUF_SIZE
134
+ #define YY_BUF_SIZE 16384
135
+ #endif
136
+
137
+ #ifndef YY_TYPEDEF_YY_BUFFER_STATE
138
+ #define YY_TYPEDEF_YY_BUFFER_STATE
139
+ typedef struct yy_buffer_state *YY_BUFFER_STATE;
140
+ #endif
141
+
142
+ #ifndef YY_TYPEDEF_YY_SIZE_T
143
+ #define YY_TYPEDEF_YY_SIZE_T
144
+ typedef size_t yy_size_t;
145
+ #endif
146
+
147
+ #ifndef YY_STRUCT_YY_BUFFER_STATE
148
+ #define YY_STRUCT_YY_BUFFER_STATE
149
+ struct yy_buffer_state
150
+ {
151
+ FILE *yy_input_file;
152
+
153
+ char *yy_ch_buf; /* input buffer */
154
+ char *yy_buf_pos; /* current position in input buffer */
155
+
156
+ /* Size of input buffer in bytes, not including room for EOB
157
+ * characters.
158
+ */
159
+ yy_size_t yy_buf_size;
160
+
161
+ /* Number of characters read into yy_ch_buf, not including EOB
162
+ * characters.
163
+ */
164
+ yy_size_t yy_n_chars;
165
+
166
+ /* Whether we "own" the buffer - i.e., we know we created it,
167
+ * and can realloc() it to grow it, and should free() it to
168
+ * delete it.
169
+ */
170
+ int yy_is_our_buffer;
171
+
172
+ /* Whether this is an "interactive" input source; if so, and
173
+ * if we're using stdio for input, then we want to use getc()
174
+ * instead of fread(), to make sure we stop fetching input after
175
+ * each newline.
176
+ */
177
+ int yy_is_interactive;
178
+
179
+ /* Whether we're considered to be at the beginning of a line.
180
+ * If so, '^' rules will be active on the next match, otherwise
181
+ * not.
182
+ */
183
+ int yy_at_bol;
184
+
185
+ int yy_bs_lineno; /**< The line count. */
186
+ int yy_bs_column; /**< The column count. */
187
+
188
+ /* Whether to try to fill the input buffer when we reach the
189
+ * end of it.
190
+ */
191
+ int yy_fill_buffer;
192
+
193
+ int yy_buffer_status;
194
+
195
+ };
196
+ #endif /* !YY_STRUCT_YY_BUFFER_STATE */
197
+
198
+ void yyrestart (FILE *input_file ,yyscan_t yyscanner );
199
+ void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
200
+ YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
201
+ void yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
202
+ void yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
203
+ void yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
204
+ void yypop_buffer_state (yyscan_t yyscanner );
205
+
206
+ YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
207
+ YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
208
+ YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
209
+
210
+ void *yyalloc (yy_size_t ,yyscan_t yyscanner );
211
+ void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
212
+ void yyfree (void * ,yyscan_t yyscanner );
213
+
214
+ /* Begin user sect3 */
215
+
216
+ #define yywrap(n) 1
217
+ #define YY_SKIP_YYWRAP
218
+
219
+ #define yytext_ptr yytext_r
220
+
221
+ #ifdef YY_HEADER_EXPORT_START_CONDITIONS
222
+ #define INITIAL 0
223
+ #define statement 1
224
+ #define raw 2
225
+ #define comment 3
226
+ #define delimiter_start 4
227
+ #define delimiter_end 5
228
+
229
+ #endif
230
+
231
+ #ifndef YY_NO_UNISTD_H
232
+ /* Special case for "unistd.h", since it is non-ANSI. We include it way
233
+ * down here because we want the user's section 1 to have been scanned first.
234
+ * The user has a chance to override it with an option.
235
+ */
236
+ #include <unistd.h>
237
+ #endif
238
+
239
+ #ifndef YY_EXTRA_TYPE
240
+ #define YY_EXTRA_TYPE void *
241
+ #endif
242
+
243
+ int yylex_init (yyscan_t* scanner);
244
+
245
+ int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
246
+
247
+ /* Accessor methods to globals.
248
+ These are made visible to non-reentrant scanners for convenience. */
249
+
250
+ int yylex_destroy (yyscan_t yyscanner );
251
+
252
+ int yyget_debug (yyscan_t yyscanner );
253
+
254
+ void yyset_debug (int debug_flag ,yyscan_t yyscanner );
255
+
256
+ YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner );
257
+
258
+ void yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
259
+
260
+ FILE *yyget_in (yyscan_t yyscanner );
261
+
262
+ void yyset_in (FILE * in_str ,yyscan_t yyscanner );
263
+
264
+ FILE *yyget_out (yyscan_t yyscanner );
265
+
266
+ void yyset_out (FILE * out_str ,yyscan_t yyscanner );
267
+
268
+ yy_size_t yyget_leng (yyscan_t yyscanner );
269
+
270
+ char *yyget_text (yyscan_t yyscanner );
271
+
272
+ int yyget_lineno (yyscan_t yyscanner );
273
+
274
+ void yyset_lineno (int line_number ,yyscan_t yyscanner );
275
+
276
+ /* Macros after this point can all be overridden by user definitions in
277
+ * section 1.
278
+ */
279
+
280
+ #ifndef YY_SKIP_YYWRAP
281
+ #ifdef __cplusplus
282
+ extern "C" int yywrap (yyscan_t yyscanner );
283
+ #else
284
+ extern int yywrap (yyscan_t yyscanner );
285
+ #endif
286
+ #endif
287
+
288
+ #ifndef yytext_ptr
289
+ static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
290
+ #endif
291
+
292
+ #ifdef YY_NEED_STRLEN
293
+ static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
294
+ #endif
295
+
296
+ #ifndef YY_NO_INPUT
297
+
298
+ #endif
299
+
300
+ /* Amount of stuff to slurp up with each read. */
301
+ #ifndef YY_READ_BUF_SIZE
302
+ #define YY_READ_BUF_SIZE 8192
303
+ #endif
304
+
305
+ /* Number of entries by which start-condition stack grows. */
306
+ #ifndef YY_START_STACK_INCR
307
+ #define YY_START_STACK_INCR 25
308
+ #endif
309
+
310
+ /* Default declaration of generated scanner - a define so the user can
311
+ * easily add parameters.
312
+ */
313
+ #ifndef YY_DECL
314
+ #define YY_DECL_IS_OURS 1
315
+
316
+ extern int yylex (yyscan_t yyscanner);
317
+
318
+ #define YY_DECL int yylex (yyscan_t yyscanner)
319
+ #endif /* !YY_DECL */
320
+
321
+ /* yy_get_previous_state - get the state just before the EOB char was reached */
322
+
323
+ #ifdef YY_DECL_IS_OURS
324
+ #undef YY_DECL_IS_OURS
325
+ #undef YY_DECL
326
+ #endif
327
+
328
+ #line 65 "../lib/lexer.l"
329
+
330
+
331
+ #line 339 "../lib/lex.yy.h"
332
+ #undef yyIN_HEADER
333
+ #endif /* yyHEADER_H */
@@ -0,0 +1,50 @@
1
+ #include "intern.h"
2
+
3
+ mustache_node_t* mustache_create_node()
4
+ {
5
+ mustache_node_t* node = mustache_malloc(sizeof(mustache_node_t));
6
+ node->type = NODE_UNKNOWN;
7
+ node->parent = NULL;
8
+ node->first_child = NULL;
9
+ node->prv_sibling = NULL;
10
+ node->next_sibling = NULL;
11
+ node->token = NULL;
12
+ node->execute = NULL;
13
+ node->optimize = NULL;
14
+ return node;
15
+ }
16
+
17
+ void mustache_destroy_node(mustache_node_t* node)
18
+ {
19
+ if (node->first_child) {
20
+ mustache_destroy_node(node->first_child);
21
+ }
22
+
23
+ if (node->next_sibling) {
24
+ mustache_destroy_node(node->next_sibling);
25
+ }
26
+
27
+ free_token(node->token);
28
+ mustache_free(node);
29
+ }
30
+
31
+ bool mustache_build_template(
32
+ char* template,
33
+ mustache_node_t* root,
34
+ mustache_error_t** error)
35
+ {
36
+ mustache_token_t* tokens = NULL;
37
+ get_tokens(template, &tokens);
38
+ build_template(tokens, root, error);
39
+ root->optimize(root);
40
+ return true;
41
+ }
42
+
43
+ bool mustache_execute_template(mustache_node_t* node, mustache_context_t* ctx)
44
+ {
45
+ ctx->prefix = "";
46
+ rb_gc_disable();
47
+ bool result = node->execute(node, ctx);
48
+ rb_gc_enable();
49
+ return result;
50
+ }
@@ -0,0 +1,124 @@
1
+ #include <stddef.h>
2
+ #include <stdbool.h>
3
+
4
+ typedef struct mustache_context mustache_context_t;
5
+ typedef struct mustache_value mustache_value_t;
6
+ typedef struct mustache_node mustache_node_t;
7
+ typedef struct mustache_token mustache_token_t;
8
+ typedef struct mustache_error mustache_error_t;
9
+
10
+ enum mustache_token_type {
11
+ TOKEN_RAW,
12
+ TOKEN_SECTION_START,
13
+ TOKEN_ISECTION_START,
14
+ TOKEN_SECTION_END,
15
+ TOKEN_COMMENT,
16
+ TOKEN_TEXT,
17
+ TOKEN_NEWLINE,
18
+ TOKEN_PARTIAL,
19
+ TOKEN_IDENTIFIER,
20
+ TOKEN_ERROR
21
+ };
22
+
23
+ enum mustache_node_type {
24
+ NODE_UNKNOWN,
25
+ NODE_BLOCK,
26
+ NODE_COMMENT,
27
+ NODE_TEXT,
28
+ NODE_NEWLINE,
29
+ NODE_RAW_VARIABLE,
30
+ NODE_VARIABLE,
31
+ NODE_SECTION,
32
+ NODE_INVERTED_SECTION,
33
+ NODE_PARTIAL
34
+ };
35
+
36
+ enum mustache_value_type {
37
+ VALUE_LIST,
38
+ VALUE_OBJECT,
39
+ VALUE_VALUE
40
+ };
41
+
42
+ union mustache_value_data {
43
+ mustache_context_t** list;
44
+ mustache_context_t* object;
45
+ char* value;
46
+ };
47
+
48
+ struct mustache_token {
49
+ mustache_token_t* next;
50
+ mustache_token_t* prv;
51
+ enum mustache_token_type type;
52
+ char* text;
53
+ };
54
+
55
+ struct mustache_value {
56
+ enum mustache_value_type type;
57
+ union mustache_value_data data;
58
+ size_t length;
59
+ void (*destroy) (mustache_value_t* value);
60
+ };
61
+
62
+ struct mustache_error {
63
+ mustache_token_t* last_token;
64
+ enum mustache_token_type expected_token;
65
+ char* error_text;
66
+ };
67
+
68
+ struct mustache_context {
69
+
70
+ mustache_value_t* (*get_data) (
71
+ char* key,
72
+ void* data,
73
+ mustache_context_t* lookup_context,
74
+ mustache_context_t* execution_context);
75
+
76
+ mustache_node_t* (*get_partial) (
77
+ char* key,
78
+ void* data);
79
+
80
+ void (*destroy) (
81
+ mustache_context_t* ctx);
82
+
83
+ mustache_context_t* parent;
84
+ void* data;
85
+ void* partials;
86
+ char* prefix;
87
+ void* custom;
88
+ bool debug_mode;
89
+ };
90
+
91
+ struct mustache_node {
92
+ enum mustache_node_type type;
93
+ mustache_node_t* parent;
94
+ mustache_node_t* first_child;
95
+ mustache_node_t* prv_sibling;
96
+ mustache_node_t* next_sibling;
97
+ mustache_token_t* token;
98
+
99
+ bool (*execute)(
100
+ mustache_node_t* node,
101
+ mustache_context_t* ctx);
102
+
103
+ bool (*optimize)(
104
+ mustache_node_t* node);
105
+ };
106
+
107
+ mustache_node_t* mustache_create_node();
108
+
109
+ void mustache_destroy_node(mustache_node_t* node);
110
+
111
+ bool mustache_build_template(
112
+ char* template,
113
+ mustache_node_t* root,
114
+ mustache_error_t** error);
115
+
116
+ bool mustache_execute_template(
117
+ mustache_node_t* node,
118
+ mustache_context_t* ctx);
119
+
120
+ /* Functions to be defined by each implementation */
121
+
122
+ void* mustache_malloc(long size);
123
+ void mustache_free(void* ptr);
124
+ bool mustache_write_to_buffer(mustache_context_t* m_ctx, char* data, size_t data_length);