melbourne 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +3 -0
- data/LICENSE +27 -0
- data/README.rdoc +38 -0
- data/Rakefile +38 -0
- data/VERSION.yml +4 -0
- data/ext/melbourne/bstring-license.txt +29 -0
- data/ext/melbourne/bstrlib.c +2918 -0
- data/ext/melbourne/bstrlib.h +302 -0
- data/ext/melbourne/extconf.rb +76 -0
- data/ext/melbourne/grammar.cpp +11885 -0
- data/ext/melbourne/grammar.hpp +14 -0
- data/ext/melbourne/grammar.y +6013 -0
- data/ext/melbourne/internal.hpp +137 -0
- data/ext/melbourne/lex.c.tab +136 -0
- data/ext/melbourne/local_state.hpp +41 -0
- data/ext/melbourne/melbourne.cpp +37 -0
- data/ext/melbourne/node.hpp +262 -0
- data/ext/melbourne/node_types.cpp +245 -0
- data/ext/melbourne/node_types.hpp +135 -0
- data/ext/melbourne/node_types.rb +190 -0
- data/ext/melbourne/quark.cpp +52 -0
- data/ext/melbourne/quark.hpp +14 -0
- data/ext/melbourne/symbols.cpp +219 -0
- data/ext/melbourne/symbols.hpp +116 -0
- data/ext/melbourne/var_table.cpp +113 -0
- data/ext/melbourne/var_table.hpp +33 -0
- data/ext/melbourne/visitor.cpp +1052 -0
- data/ext/melbourne/visitor.hpp +20 -0
- data/lib/melbourne/ast/constants.rb +128 -0
- data/lib/melbourne/ast/control_flow.rb +382 -0
- data/lib/melbourne/ast/data.rb +19 -0
- data/lib/melbourne/ast/definitions.rb +561 -0
- data/lib/melbourne/ast/exceptions.rb +182 -0
- data/lib/melbourne/ast/file.rb +15 -0
- data/lib/melbourne/ast/grapher.rb +75 -0
- data/lib/melbourne/ast/literals.rb +268 -0
- data/lib/melbourne/ast/node.rb +21 -0
- data/lib/melbourne/ast/operators.rb +117 -0
- data/lib/melbourne/ast/self.rb +17 -0
- data/lib/melbourne/ast/sends.rb +451 -0
- data/lib/melbourne/ast/values.rb +74 -0
- data/lib/melbourne/ast/variables.rb +251 -0
- data/lib/melbourne/ast.rb +22 -0
- data/lib/melbourne/parser.rb +38 -0
- data/lib/melbourne/processor.rb +460 -0
- data/lib/melbourne.rb +46 -0
- data/spec/helpers/ast/node.rb +15 -0
- data/spec/helpers/ast/reduced_graph.rb +64 -0
- data/spec/lib/parser/alias_spec.rb +97 -0
- data/spec/lib/parser/and_spec.rb +63 -0
- data/spec/lib/parser/array_spec.rb +157 -0
- data/spec/lib/parser/attrasgn_spec.rb +401 -0
- data/spec/lib/parser/back_ref_spec.rb +20 -0
- data/spec/lib/parser/call_spec.rb +958 -0
- data/spec/lib/parser/case_spec.rb +577 -0
- data/spec/lib/parser/cdecl_spec.rb +108 -0
- data/spec/lib/parser/class_spec.rb +221 -0
- data/spec/lib/parser/colon2_spec.rb +13 -0
- data/spec/lib/parser/colon3_spec.rb +12 -0
- data/spec/lib/parser/const_spec.rb +12 -0
- data/spec/lib/parser/cvar_spec.rb +55 -0
- data/spec/lib/parser/cvasgn_spec.rb +71 -0
- data/spec/lib/parser/cvdecl_spec.rb +31 -0
- data/spec/lib/parser/defined_spec.rb +353 -0
- data/spec/lib/parser/defn_spec.rb +1409 -0
- data/spec/lib/parser/defs_spec.rb +247 -0
- data/spec/lib/parser/dot2_spec.rb +29 -0
- data/spec/lib/parser/dot3_spec.rb +29 -0
- data/spec/lib/parser/dregx_spec.rb +127 -0
- data/spec/lib/parser/dstr_spec.rb +453 -0
- data/spec/lib/parser/dsym_spec.rb +31 -0
- data/spec/lib/parser/dxstr_spec.rb +31 -0
- data/spec/lib/parser/ensure_spec.rb +279 -0
- data/spec/lib/parser/false_spec.rb +12 -0
- data/spec/lib/parser/flip2_spec.rb +138 -0
- data/spec/lib/parser/flip3_spec.rb +100 -0
- data/spec/lib/parser/for_spec.rb +279 -0
- data/spec/lib/parser/gasgn_spec.rb +34 -0
- data/spec/lib/parser/gvar_spec.rb +33 -0
- data/spec/lib/parser/hash_spec.rb +77 -0
- data/spec/lib/parser/iasgn_spec.rb +54 -0
- data/spec/lib/parser/if_spec.rb +439 -0
- data/spec/lib/parser/iter_spec.rb +2582 -0
- data/spec/lib/parser/lasgn_spec.rb +1066 -0
- data/spec/lib/parser/lit_spec.rb +75 -0
- data/spec/lib/parser/masgn_spec.rb +1970 -0
- data/spec/lib/parser/match2_spec.rb +47 -0
- data/spec/lib/parser/match3_spec.rb +54 -0
- data/spec/lib/parser/match_spec.rb +19 -0
- data/spec/lib/parser/module_spec.rb +102 -0
- data/spec/lib/parser/nil_spec.rb +13 -0
- data/spec/lib/parser/not_spec.rb +39 -0
- data/spec/lib/parser/nth_ref_spec.rb +12 -0
- data/spec/lib/parser/op_asgn_spec.rb +619 -0
- data/spec/lib/parser/or_spec.rb +155 -0
- data/spec/lib/parser/postexe_spec.rb +31 -0
- data/spec/lib/parser/regex_spec.rb +52 -0
- data/spec/lib/parser/rescue_spec.rb +1028 -0
- data/spec/lib/parser/return_spec.rb +151 -0
- data/spec/lib/parser/sclass_spec.rb +172 -0
- data/spec/lib/parser/str_spec.rb +162 -0
- data/spec/lib/parser/super_spec.rb +276 -0
- data/spec/lib/parser/true_spec.rb +12 -0
- data/spec/lib/parser/undef_spec.rb +222 -0
- data/spec/lib/parser/until_spec.rb +286 -0
- data/spec/lib/parser/valias_spec.rb +12 -0
- data/spec/lib/parser/while_spec.rb +458 -0
- data/spec/lib/parser/xstr_spec.rb +12 -0
- data/spec/lib/parser/yield_spec.rb +202 -0
- data/spec/lib/parser/zsuper_spec.rb +101 -0
- data/spec/matchers/parse_as.rb +27 -0
- data/spec/spec_helper.rb +10 -0
- metadata +168 -0
@@ -0,0 +1,302 @@
|
|
1
|
+
/*
|
2
|
+
* This source file is part of the bstring string library. This code was
|
3
|
+
* written by Paul Hsieh in 2002-2007, and is covered by the BSD open source
|
4
|
+
* license. Refer to the accompanying documentation for details on usage and
|
5
|
+
* license.
|
6
|
+
*/
|
7
|
+
|
8
|
+
/*
|
9
|
+
* bstrlib.c
|
10
|
+
*
|
11
|
+
* This file is the core module for implementing the bstring functions.
|
12
|
+
*/
|
13
|
+
|
14
|
+
#ifndef BSTRLIB_INCLUDE
|
15
|
+
#define BSTRLIB_INCLUDE
|
16
|
+
|
17
|
+
#ifdef __cplusplus
|
18
|
+
extern "C" {
|
19
|
+
#endif
|
20
|
+
|
21
|
+
#include <stdarg.h>
|
22
|
+
#include <string.h>
|
23
|
+
#include <limits.h>
|
24
|
+
#include <ctype.h>
|
25
|
+
|
26
|
+
#if !defined (BSTRLIB_VSNP_OK) && !defined (BSTRLIB_NOVSNP)
|
27
|
+
# if defined (__TURBOC__) && !defined (__BORLANDC__)
|
28
|
+
# define BSTRLIB_NOVSNP
|
29
|
+
# endif
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#define BSTR_ERR (-1)
|
33
|
+
#define BSTR_OK (0)
|
34
|
+
#define BSTR_BS_BUFF_LENGTH_GET (0)
|
35
|
+
|
36
|
+
typedef struct tagbstring * bstring;
|
37
|
+
typedef const struct tagbstring * const_bstring;
|
38
|
+
|
39
|
+
/* Copy functions */
|
40
|
+
#define cstr2bstr bfromcstr
|
41
|
+
extern bstring bfromcstr (const char * str);
|
42
|
+
extern bstring bfromcstralloc (int mlen, const char * str);
|
43
|
+
extern bstring blk2bstr (const void * blk, int len);
|
44
|
+
extern char * bstr2cstr (const_bstring s, char z);
|
45
|
+
extern int bcstrfree (char * s);
|
46
|
+
extern bstring bstrcpy (const_bstring b1);
|
47
|
+
extern int bassign (bstring a, const_bstring b);
|
48
|
+
extern int bassignmidstr (bstring a, const_bstring b, int left, int len);
|
49
|
+
extern int bassigncstr (bstring a, const char * str);
|
50
|
+
extern int bassignblk (bstring a, const void * s, int len);
|
51
|
+
|
52
|
+
/* Destroy function */
|
53
|
+
extern int bdestroy (bstring b);
|
54
|
+
|
55
|
+
/* Space allocation hinting functions */
|
56
|
+
extern int balloc (bstring s, int len);
|
57
|
+
extern int ballocmin (bstring b, int len);
|
58
|
+
|
59
|
+
/* Substring extraction */
|
60
|
+
extern bstring bmidstr (const_bstring b, int left, int len);
|
61
|
+
|
62
|
+
/* Various standard manipulations */
|
63
|
+
extern int bconcat (bstring b0, const_bstring b1);
|
64
|
+
extern int bconchar (bstring b0, char c);
|
65
|
+
extern int bcatcstr (bstring b, const char * s);
|
66
|
+
extern int bcatblk (bstring b, const void * s, int len);
|
67
|
+
extern int binsert (bstring s1, int pos, const_bstring s2, unsigned char fill);
|
68
|
+
extern int binsertch (bstring s1, int pos, int len, unsigned char fill);
|
69
|
+
extern int breplace (bstring b1, int pos, int len, const_bstring b2, unsigned char fill);
|
70
|
+
extern int bdelete (bstring s1, int pos, int len);
|
71
|
+
extern int bsetstr (bstring b0, int pos, const_bstring b1, unsigned char fill);
|
72
|
+
extern int btrunc (bstring b, int n);
|
73
|
+
|
74
|
+
/* Scan/search functions */
|
75
|
+
extern int bstricmp (const_bstring b0, const_bstring b1);
|
76
|
+
extern int bstrnicmp (const_bstring b0, const_bstring b1, int n);
|
77
|
+
extern int biseqcaseless (const_bstring b0, const_bstring b1);
|
78
|
+
extern int bisstemeqcaselessblk (const_bstring b0, const void * blk, int len);
|
79
|
+
extern int biseq (const_bstring b0, const_bstring b1);
|
80
|
+
extern int bisstemeqblk (const_bstring b0, const void * blk, int len);
|
81
|
+
extern int biseqcstr (const_bstring b, const char * s);
|
82
|
+
extern int biseqcstrcaseless (const_bstring b, const char * s);
|
83
|
+
extern int bstrcmp (const_bstring b0, const_bstring b1);
|
84
|
+
extern int bstrncmp (const_bstring b0, const_bstring b1, int n);
|
85
|
+
extern int binstr (const_bstring s1, int pos, const_bstring s2);
|
86
|
+
extern int binstrr (const_bstring s1, int pos, const_bstring s2);
|
87
|
+
extern int binstrcaseless (const_bstring s1, int pos, const_bstring s2);
|
88
|
+
extern int binstrrcaseless (const_bstring s1, int pos, const_bstring s2);
|
89
|
+
extern int bstrchrp (const_bstring b, int c, int pos);
|
90
|
+
extern int bstrrchrp (const_bstring b, int c, int pos);
|
91
|
+
#define bstrchr(b,c) bstrchrp ((b), (c), 0)
|
92
|
+
#define bstrrchr(b,c) bstrrchrp ((b), (c), blength(b)-1)
|
93
|
+
extern int binchr (const_bstring b0, int pos, const_bstring b1);
|
94
|
+
extern int binchrr (const_bstring b0, int pos, const_bstring b1);
|
95
|
+
extern int bninchr (const_bstring b0, int pos, const_bstring b1);
|
96
|
+
extern int bninchrr (const_bstring b0, int pos, const_bstring b1);
|
97
|
+
extern int bfindreplace (bstring b, const_bstring find, const_bstring repl, int pos);
|
98
|
+
extern int bfindreplacecaseless (bstring b, const_bstring find, const_bstring repl, int pos);
|
99
|
+
|
100
|
+
/* List of string container functions */
|
101
|
+
struct bstrList {
|
102
|
+
int qty, mlen;
|
103
|
+
bstring * entry;
|
104
|
+
};
|
105
|
+
extern struct bstrList * bstrListCreate (void);
|
106
|
+
extern int bstrListDestroy (struct bstrList * sl);
|
107
|
+
extern int bstrListAlloc (struct bstrList * sl, int msz);
|
108
|
+
extern int bstrListAllocMin (struct bstrList * sl, int msz);
|
109
|
+
|
110
|
+
/* String split and join functions */
|
111
|
+
extern struct bstrList * bsplit (const_bstring str, unsigned char splitChar);
|
112
|
+
extern struct bstrList * bsplits (const_bstring str, const_bstring splitStr);
|
113
|
+
extern struct bstrList * bsplitstr (const_bstring str, const_bstring splitStr);
|
114
|
+
extern bstring bjoin (const struct bstrList * bl, const_bstring sep);
|
115
|
+
extern int bsplitcb (const_bstring str, unsigned char splitChar, int pos,
|
116
|
+
int (* cb) (void * parm, int ofs, int len), void * parm);
|
117
|
+
extern int bsplitscb (const_bstring str, const_bstring splitStr, int pos,
|
118
|
+
int (* cb) (void * parm, int ofs, int len), void * parm);
|
119
|
+
extern int bsplitstrcb (const_bstring str, const_bstring splitStr, int pos,
|
120
|
+
int (* cb) (void * parm, int ofs, int len), void * parm);
|
121
|
+
|
122
|
+
/* Miscellaneous functions */
|
123
|
+
extern int bpattern (bstring b, int len);
|
124
|
+
extern int btoupper (bstring b);
|
125
|
+
extern int btolower (bstring b);
|
126
|
+
extern int bltrimws (bstring b);
|
127
|
+
extern int brtrimws (bstring b);
|
128
|
+
extern int btrimws (bstring b);
|
129
|
+
|
130
|
+
#if !defined (BSTRLIB_NOVSNP)
|
131
|
+
extern bstring bformat (const char * fmt, ...);
|
132
|
+
extern int bformata (bstring b, const char * fmt, ...);
|
133
|
+
extern int bassignformat (bstring b, const char * fmt, ...);
|
134
|
+
extern int bvcformata (bstring b, int count, const char * fmt, va_list arglist);
|
135
|
+
|
136
|
+
#define bvformata(ret, b, fmt, lastarg) { \
|
137
|
+
bstring bstrtmp_b = (b); \
|
138
|
+
const char * bstrtmp_fmt = (fmt); \
|
139
|
+
int bstrtmp_r = BSTR_ERR, bstrtmp_sz = 16; \
|
140
|
+
for (;;) { \
|
141
|
+
va_list bstrtmp_arglist; \
|
142
|
+
va_start (bstrtmp_arglist, lastarg); \
|
143
|
+
bstrtmp_r = bvcformata (bstrtmp_b, bstrtmp_sz, bstrtmp_fmt, bstrtmp_arglist); \
|
144
|
+
va_end (bstrtmp_arglist); \
|
145
|
+
if (bstrtmp_r >= 0) { /* Everything went ok */ \
|
146
|
+
bstrtmp_r = BSTR_OK; \
|
147
|
+
break; \
|
148
|
+
} else if (-bstrtmp_r <= bstrtmp_sz) { /* A real error? */ \
|
149
|
+
bstrtmp_r = BSTR_ERR; \
|
150
|
+
break; \
|
151
|
+
} \
|
152
|
+
bstrtmp_sz = -bstrtmp_r; /* Doubled or target size */ \
|
153
|
+
} \
|
154
|
+
ret = bstrtmp_r; \
|
155
|
+
}
|
156
|
+
|
157
|
+
#endif
|
158
|
+
|
159
|
+
typedef int (*bNgetc) (void *parm);
|
160
|
+
typedef size_t (* bNread) (void *buff, size_t elsize, size_t nelem, void *parm);
|
161
|
+
|
162
|
+
/* Input functions */
|
163
|
+
extern bstring bgets (bNgetc getcPtr, void * parm, char terminator);
|
164
|
+
extern bstring bread (bNread readPtr, void * parm);
|
165
|
+
extern int bgetsa (bstring b, bNgetc getcPtr, void * parm, char terminator);
|
166
|
+
extern int bassigngets (bstring b, bNgetc getcPtr, void * parm, char terminator);
|
167
|
+
extern int breada (bstring b, bNread readPtr, void * parm);
|
168
|
+
|
169
|
+
/* Stream functions */
|
170
|
+
extern struct bStream * bsopen (bNread readPtr, void * parm);
|
171
|
+
extern void * bsclose (struct bStream * s);
|
172
|
+
extern int bsbufflength (struct bStream * s, int sz);
|
173
|
+
extern int bsreadln (bstring b, struct bStream * s, char terminator);
|
174
|
+
extern int bsreadlns (bstring r, struct bStream * s, const_bstring term);
|
175
|
+
extern int bsread (bstring b, struct bStream * s, int n);
|
176
|
+
extern int bsreadlna (bstring b, struct bStream * s, char terminator);
|
177
|
+
extern int bsreadlnsa (bstring r, struct bStream * s, const_bstring term);
|
178
|
+
extern int bsreada (bstring b, struct bStream * s, int n);
|
179
|
+
extern int bsunread (struct bStream * s, const_bstring b);
|
180
|
+
extern int bspeek (bstring r, const struct bStream * s);
|
181
|
+
extern int bssplitscb (struct bStream * s, const_bstring splitStr,
|
182
|
+
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm);
|
183
|
+
extern int bssplitstrcb (struct bStream * s, const_bstring splitStr,
|
184
|
+
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm);
|
185
|
+
extern int bseof (const struct bStream * s);
|
186
|
+
|
187
|
+
struct tagbstring {
|
188
|
+
int mlen;
|
189
|
+
int slen;
|
190
|
+
unsigned char * data;
|
191
|
+
};
|
192
|
+
|
193
|
+
/* Accessor macros */
|
194
|
+
#define blengthe(b, e) (((b) == (void *)0 || (b)->slen < 0) ? (int)(e) : ((b)->slen))
|
195
|
+
#define blength(b) (blengthe ((b), 0))
|
196
|
+
#define bdataofse(b, o, e) (((b) == (void *)0 || (b)->data == (void*)0) ? (char *)(e) : ((char *)(b)->data) + (o))
|
197
|
+
#define bdataofs(b, o) (bdataofse ((b), (o), (void *)0))
|
198
|
+
#define bdatae(b, e) (bdataofse (b, 0, e))
|
199
|
+
#define bdata(b) (bdataofs (b, 0))
|
200
|
+
#define bchare(b, p, e) ((((unsigned)(p)) < (unsigned)blength(b)) ? ((b)->data[(p)]) : (e))
|
201
|
+
#define bchar(b, p) bchare ((b), (p), '\0')
|
202
|
+
|
203
|
+
/* Static constant string initialization macro */
|
204
|
+
#if defined(_MSC_VER) && defined(_DEBUG)
|
205
|
+
# if _MSC_VER <= 1310
|
206
|
+
# define bsStatic(q) {-32, (int) sizeof(q)-1, (unsigned char *) ("" q "")}
|
207
|
+
# endif
|
208
|
+
#endif
|
209
|
+
#ifndef bsStatic
|
210
|
+
# define bsStatic(q) {-__LINE__, (int) sizeof(q)-1, (unsigned char *) ("" q "")}
|
211
|
+
#endif
|
212
|
+
|
213
|
+
/* Static constant block parameter pair */
|
214
|
+
#define bsStaticBlkParms(q) ((void *)("" q "")), ((int) sizeof(q)-1)
|
215
|
+
|
216
|
+
/* Reference building macros */
|
217
|
+
#define cstr2tbstr btfromcstr
|
218
|
+
#define btfromcstr(t,s) { \
|
219
|
+
(t).data = (unsigned char *) (s); \
|
220
|
+
(t).slen = ((t).data) ? ((int) (strlen) ((char *)(t).data)) : 0; \
|
221
|
+
(t).mlen = -1; \
|
222
|
+
}
|
223
|
+
#define blk2tbstr(t,s,l) { \
|
224
|
+
(t).data = (unsigned char *) (s); \
|
225
|
+
(t).slen = l; \
|
226
|
+
(t).mlen = -1; \
|
227
|
+
}
|
228
|
+
#define btfromblk(t,s,l) blk2tbstr(t,s,l)
|
229
|
+
#define bmid2tbstr(t,b,p,l) { \
|
230
|
+
bstring bstrtmp_s = (b); \
|
231
|
+
if (bstrtmp_s && bstrtmp_s->data && bstrtmp_s->slen >= 0) { \
|
232
|
+
int bstrtmp_left = (p); \
|
233
|
+
int bstrtmp_len = (l); \
|
234
|
+
if (bstrtmp_left < 0) { \
|
235
|
+
bstrtmp_len += bstrtmp_left; \
|
236
|
+
bstrtmp_left = 0; \
|
237
|
+
} \
|
238
|
+
if (bstrtmp_len > bstrtmp_s->slen - bstrtmp_left) \
|
239
|
+
bstrtmp_len = bstrtmp_s->slen - bstrtmp_left; \
|
240
|
+
if (bstrtmp_len <= 0) { \
|
241
|
+
(t).data = (unsigned char *)""; \
|
242
|
+
(t).slen = 0; \
|
243
|
+
} else { \
|
244
|
+
(t).data = bstrtmp_s->data + bstrtmp_left; \
|
245
|
+
(t).slen = bstrtmp_len; \
|
246
|
+
} \
|
247
|
+
} else { \
|
248
|
+
(t).data = (unsigned char *)""; \
|
249
|
+
(t).slen = 0; \
|
250
|
+
} \
|
251
|
+
(t).mlen = -__LINE__; \
|
252
|
+
}
|
253
|
+
#define btfromblkltrimws(t,s,l) { \
|
254
|
+
int bstrtmp_idx = 0, bstrtmp_len = (l); \
|
255
|
+
unsigned char * bstrtmp_s = (s); \
|
256
|
+
if (bstrtmp_s && bstrtmp_len >= 0) { \
|
257
|
+
for (; bstrtmp_idx < bstrtmp_len; bstrtmp_idx++) { \
|
258
|
+
if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
|
259
|
+
} \
|
260
|
+
} \
|
261
|
+
(t).data = bstrtmp_s + bstrtmp_idx; \
|
262
|
+
(t).slen = bstrtmp_len - bstrtmp_idx; \
|
263
|
+
(t).mlen = -__LINE__; \
|
264
|
+
}
|
265
|
+
#define btfromblkrtrimws(t,s,l) { \
|
266
|
+
int bstrtmp_len = (l) - 1; \
|
267
|
+
unsigned char * bstrtmp_s = (s); \
|
268
|
+
if (bstrtmp_s && bstrtmp_len >= 0) { \
|
269
|
+
for (; bstrtmp_len >= 0; bstrtmp_len--) { \
|
270
|
+
if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
|
271
|
+
} \
|
272
|
+
} \
|
273
|
+
(t).data = bstrtmp_s; \
|
274
|
+
(t).slen = bstrtmp_len + 1; \
|
275
|
+
(t).mlen = -__LINE__; \
|
276
|
+
}
|
277
|
+
#define btfromblktrimws(t,s,l) { \
|
278
|
+
int bstrtmp_idx = 0, bstrtmp_len = (l) - 1; \
|
279
|
+
unsigned char * bstrtmp_s = (s); \
|
280
|
+
if (bstrtmp_s && bstrtmp_len >= 0) { \
|
281
|
+
for (; bstrtmp_idx <= bstrtmp_len; bstrtmp_idx++) { \
|
282
|
+
if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
|
283
|
+
} \
|
284
|
+
for (; bstrtmp_len >= bstrtmp_idx; bstrtmp_len--) { \
|
285
|
+
if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
|
286
|
+
} \
|
287
|
+
} \
|
288
|
+
(t).data = bstrtmp_s + bstrtmp_idx; \
|
289
|
+
(t).slen = bstrtmp_len + 1 - bstrtmp_idx; \
|
290
|
+
(t).mlen = -__LINE__; \
|
291
|
+
}
|
292
|
+
|
293
|
+
/* Write protection macros */
|
294
|
+
#define bwriteprotect(t) { if ((t).mlen >= 0) (t).mlen = -1; }
|
295
|
+
#define bwriteallow(t) { if ((t).mlen == -1) (t).mlen = (t).slen + ((t).slen == 0); }
|
296
|
+
#define biswriteprotected(t) ((t).mlen <= 0)
|
297
|
+
|
298
|
+
#ifdef __cplusplus
|
299
|
+
}
|
300
|
+
#endif
|
301
|
+
|
302
|
+
#endif
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
$CFLAGS += " -ggdb3"
|
4
|
+
|
5
|
+
# Courtesy of EventMachine. Thank you EventMachine and tmm1 !
|
6
|
+
|
7
|
+
def check_libs(libs = [], fatal = false)
|
8
|
+
libs.all? { |lib| have_library(lib) || (abort("could not find library: #{lib}") if fatal) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_heads(heads = [], fatal = false)
|
12
|
+
heads.all? { |head| have_header(head) || (abort("could not find header: #{head}") if fatal)}
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_define(name)
|
16
|
+
$defs.push("-D#{name}")
|
17
|
+
end
|
18
|
+
|
19
|
+
case RUBY_PLATFORM
|
20
|
+
when /mswin32/, /mingw32/, /bccwin32/
|
21
|
+
check_heads(%w[windows.h winsock.h], true)
|
22
|
+
check_libs(%w[kernel32 rpcrt4 gdi32], true)
|
23
|
+
|
24
|
+
if GNU_CHAIN
|
25
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
|
26
|
+
else
|
27
|
+
$defs.push "-EHs"
|
28
|
+
$defs.push "-GR"
|
29
|
+
end
|
30
|
+
|
31
|
+
when /solaris/
|
32
|
+
add_define 'OS_SOLARIS8'
|
33
|
+
|
34
|
+
if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
|
35
|
+
# SUN CHAIN
|
36
|
+
add_define 'CC_SUNWspro'
|
37
|
+
$preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
|
38
|
+
$CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
|
39
|
+
CONFIG['CCDLFLAGS'] = "-KPIC"
|
40
|
+
CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
|
41
|
+
else
|
42
|
+
# GNU CHAIN
|
43
|
+
# on Unix we need a g++ link, not gcc.
|
44
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared"
|
45
|
+
end
|
46
|
+
|
47
|
+
when /openbsd/
|
48
|
+
# OpenBSD branch contributed by Guillaume Sellier.
|
49
|
+
|
50
|
+
# on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
|
51
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
|
52
|
+
CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
|
53
|
+
|
54
|
+
when /darwin/
|
55
|
+
# on Unix we need a g++ link, not gcc.
|
56
|
+
# Ff line contributed by Daniel Harple.
|
57
|
+
CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
|
58
|
+
|
59
|
+
when /aix/
|
60
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
|
61
|
+
|
62
|
+
else
|
63
|
+
# on Unix we need a g++ link, not gcc.
|
64
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared"
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
create_makefile('ext/melbourne')
|
69
|
+
|
70
|
+
File.open("Makefile","a+") do |f|
|
71
|
+
f.puts <<END
|
72
|
+
|
73
|
+
grammar.cpp: grammar.y
|
74
|
+
bison -o grammar.cpp grammar.y
|
75
|
+
END
|
76
|
+
end
|