Codebase list libcypher-parser / 1868f77
Merge tag 'dist/0.3.1' into debian Upstream version 0.3.1 Chris Leishman 7 years ago
11 changed file(s) with 175 addition(s) and 79 deletion(s). Raw diff Collapse all Expand all
241241 am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/aminclude.am \
242242 $(srcdir)/config.h.in $(srcdir)/cypher-lint.1.in \
243243 $(srcdir)/cypher-parser.pc.in compile config.guess config.sub \
244 depcomp install-sh ltmain.sh missing
244 install-sh ltmain.sh missing
245245 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
246246 distdir = $(PACKAGE)-$(VERSION)
247247 top_distdir = $(distdir)
00 #! /bin/sh
11 # Guess values for system-dependent variables and create Makefiles.
2 # Generated by GNU Autoconf 2.69 for libcypher-parser 0.3.0.
2 # Generated by GNU Autoconf 2.69 for libcypher-parser 0.3.1.
33 #
44 #
55 # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
586586 # Identity of this package.
587587 PACKAGE_NAME='libcypher-parser'
588588 PACKAGE_TARNAME='libcypher-parser'
589 PACKAGE_VERSION='0.3.0'
590 PACKAGE_STRING='libcypher-parser 0.3.0'
589 PACKAGE_VERSION='0.3.1'
590 PACKAGE_STRING='libcypher-parser 0.3.1'
591591 PACKAGE_BUGREPORT=''
592592 PACKAGE_URL=''
593593
13981398 # Omit some internal or obsolete options to make the list less imposing.
13991399 # This message is too long to be a string in the A/UX 3.1 sh.
14001400 cat <<_ACEOF
1401 \`configure' configures libcypher-parser 0.3.0 to adapt to many kinds of systems.
1401 \`configure' configures libcypher-parser 0.3.1 to adapt to many kinds of systems.
14021402
14031403 Usage: $0 [OPTION]... [VAR=VALUE]...
14041404
14691469
14701470 if test -n "$ac_init_help"; then
14711471 case $ac_init_help in
1472 short | recursive ) echo "Configuration of libcypher-parser 0.3.0:";;
1472 short | recursive ) echo "Configuration of libcypher-parser 0.3.1:";;
14731473 esac
14741474 cat <<\_ACEOF
14751475
16091609 test -n "$ac_init_help" && exit $ac_status
16101610 if $ac_init_version; then
16111611 cat <<\_ACEOF
1612 libcypher-parser configure 0.3.0
1612 libcypher-parser configure 0.3.1
16131613 generated by GNU Autoconf 2.69
16141614
16151615 Copyright (C) 2012 Free Software Foundation, Inc.
20742074 This file contains any messages produced by compilers while
20752075 running configure, to aid debugging if configure makes a mistake.
20762076
2077 It was created by libcypher-parser $as_me 0.3.0, which was
2077 It was created by libcypher-parser $as_me 0.3.1, which was
20782078 generated by GNU Autoconf 2.69. Invocation command line was
20792079
20802080 $ $0 $@
29392939
29402940 # Define the identity of the package.
29412941 PACKAGE='libcypher-parser'
2942 VERSION='0.3.0'
2942 VERSION='0.3.1'
29432943
29442944
29452945 cat >>confdefs.h <<_ACEOF
1707817078 # report actual input values of CONFIG_FILES etc. instead of their
1707917079 # values after options handling.
1708017080 ac_log="
17081 This file was extended by libcypher-parser $as_me 0.3.0, which was
17081 This file was extended by libcypher-parser $as_me 0.3.1, which was
1708217082 generated by GNU Autoconf 2.69. Invocation command line was
1708317083
1708417084 CONFIG_FILES = $CONFIG_FILES
1714417144 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
1714517145 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
1714617146 ac_cs_version="\\
17147 libcypher-parser config.status 0.3.0
17147 libcypher-parser config.status 0.3.1
1714817148 configured by $0, generated by GNU Autoconf 2.69,
1714917149 with options \\"\$ac_cs_config\\"
1715017150
1313 #
1414 dnl Process this file with autoconf to produce a configure script
1515 AC_PREREQ([2.69])
16 AC_INIT([libcypher-parser],[0.3.0])
16 AC_INIT([libcypher-parser],[0.3.1])
1717 AC_CONFIG_SRCDIR([src/lib/cypher-parser.h])
1818 AC_CONFIG_MACRO_DIR([m4])
1919 AM_INIT_AUTOMAKE([foreign])
4242 Attempt to limit output to the specified width, and render using wrapped
4343 columns.
4444 .TP
45 .I \-\-stream
46 Output each statement as it is read, rather than parsing the entire input
47 first (note: will result in inconsistent formatting of AST dumps).
48 .TP
4549 .I \-\-version
4650 Print the cypher\-lint version and exit.
4751 .SH USAGE
0 libcypher-parser (0.3.0-1) unstable; urgency=low
0 libcypher-parser (0.3.1-1) unstable; urgency=low
11
22 * Initial packaging. Closes: #825072
33
4 -- Chris Leishman <chris@leishman.org> Tue, 07 Jun 2016 01:40:50 +0000
4 -- Chris Leishman <chris@leishman.org> Tue, 07 Jun 2016 04:06:17 +0000
467467 cypher_parse_result_nerrors@Base 0.3.0
468468 cypher_parse_result_nnodes@Base 0.3.0
469469 cypher_parse_result_nroots@Base 0.3.0
470 cypher_parse_segment_eof@Base 0.3.1
470471 cypher_parse_segment_fprint_ast@Base 0.3.0
471472 cypher_parse_segment_get_directive@Base 0.3.0
472473 cypher_parse_segment_get_error@Base 0.3.0
1515 */
1616 #include "../../config.h"
1717 #include "cypher-parser.h"
18 #include <assert.h>
1819 #include <errno.h>
1920 #include <getopt.h>
2021 #include <libgen.h>
2930 #define COLORIZE_OPT 1004
3031 #define ONLY_STATEMENTS_OPT 1005
3132 #define OUTPUT_WIDTH_OPT 1006
32 #define VERSION_OPT 1007
33 #define STREAM_OPT 1007
34 #define VERSION_OPT 1008
3335
3436 static struct option longopts[] =
3537 { { "ast", no_argument, NULL, 'a' },
3739 { "help", no_argument, NULL, 'h' },
3840 { "only-statements", no_argument, NULL, ONLY_STATEMENTS_OPT },
3941 { "output-width", required_argument, NULL, OUTPUT_WIDTH_OPT },
42 { "stream", no_argument, NULL, STREAM_OPT },
4043 { "version", no_argument, NULL, VERSION_OPT },
4144 { NULL, 0, NULL, 0 } };
4245
5154 " --help, -h Output this usage information.\n"
5255 " --only-statements Only parse statements (and not client commands).\n"
5356 " --output-width <n> Attempt to limit output to the specified width.\n"
57 " --stream Output each statement as it is read, rather than parsing\n"
58 " the entire input first (note: will result in inconsistent\n"
59 " formatting of AST dumps).\n"
5460 " --version Output the version of cypher-lint and libcypher-parser\n"
5561 "\n",
5662 prog_name);
6470 bool dump_ast;
6571 bool colorize_output;
6672 bool colorize_errors;
73 bool stream;
6774 };
6875
6976
7077 static int process(FILE *stream, struct lint_config *config);
78 static int process_streamed(FILE *stream, struct lint_config *config,
79 cypher_parser_config_t *cp_config,
80 const struct cypher_parser_colorization *error_colorization,
81 const struct cypher_parser_colorization *output_colorization);
82 static int process_all(FILE *stream, struct lint_config *config,
83 cypher_parser_config_t *cp_config,
84 const struct cypher_parser_colorization *error_colorization,
85 const struct cypher_parser_colorization *output_colorization);
7186 static int parse_callback(void *data, cypher_parse_segment_t *segment);
87 static void print_error(const cypher_parse_error_t *error,
88 const struct cypher_parser_colorization *colorization);
7289
7390
7491 int main(int argc, char *argv[])
118135 break;
119136 case OUTPUT_WIDTH_OPT:
120137 config.width = atoi(optarg);
138 break;
139 case STREAM_OPT:
140 config.stream = true;
121141 break;
122142 case VERSION_OPT:
123143 fprintf(stdout, "neo4j-lint: %s\n", PACKAGE_VERSION);
145165 }
146166
147167
168 int process(FILE *stream, struct lint_config *config)
169 {
170 cypher_parser_config_t *cp_config = cypher_parser_new_config();
171 if (cp_config == NULL)
172 {
173 return -1;
174 }
175
176 const struct cypher_parser_colorization *error_colorization =
177 cypher_parser_no_colorization;
178 if (config->colorize_errors)
179 {
180 error_colorization = cypher_parser_ansi_colorization;
181 cypher_parser_config_set_error_colorization(cp_config,
182 error_colorization);
183 }
184
185 const struct cypher_parser_colorization *output_colorization =
186 config->colorize_output? cypher_parser_ansi_colorization : NULL;
187
188 int err = (config->stream)?
189 process_streamed(stream, config, cp_config,
190 error_colorization, output_colorization) :
191 process_all(stream, config, cp_config,
192 error_colorization, output_colorization);
193
194 int errsv = errno;
195 cypher_parser_config_free(cp_config);
196 errno = errsv;
197 return err;
198 }
199
200
148201 struct parse_callback_data
149202 {
150203 struct lint_config *config;
154207 };
155208
156209
157 int process(FILE *stream, struct lint_config *config)
158 {
159 cypher_parser_config_t *cp_config = cypher_parser_new_config();
160 if (cp_config == NULL)
161 {
162 return -1;
163 }
164
165 const struct cypher_parser_colorization *error_colorization =
166 cypher_parser_no_colorization;
167 if (config->colorize_errors)
168 {
169 error_colorization = cypher_parser_ansi_colorization;
170 cypher_parser_config_set_error_colorization(cp_config,
171 error_colorization);
172 }
173
174 const struct cypher_parser_colorization *output_colorization =
175 config->colorize_output? cypher_parser_ansi_colorization : NULL;
176
177
210 int process_streamed(FILE *stream, struct lint_config *config,
211 cypher_parser_config_t *cp_config,
212 const struct cypher_parser_colorization *error_colorization,
213 const struct cypher_parser_colorization *output_colorization)
214 {
178215 struct parse_callback_data callback_data =
179216 { .config = config,
180217 .error_colorization = error_colorization,
182219 .nerrors = 0
183220 };
184221
185 int result = -1;
186222 if (cypher_fparse_each(stream, parse_callback, &callback_data, NULL,
187223 cp_config, config->flags))
188224 {
189225 perror("cypher_fparse_each");
226 return -1;
227 }
228
229 return (callback_data.nerrors == 0)? 0 : 1;
230 }
231
232
233 int parse_callback(void *data, cypher_parse_segment_t *segment)
234 {
235 struct parse_callback_data *cbdata =
236 (struct parse_callback_data *)data;
237 struct lint_config *config = cbdata->config;
238
239 unsigned int i = 0;
240 const cypher_parse_error_t *error;
241 for (; (error = cypher_parse_segment_get_error(segment, i)) != NULL; ++i)
242 {
243 print_error(error, cbdata->error_colorization);
244 }
245
246 cbdata->nerrors += i;
247
248 if (config->dump_ast && cypher_parse_segment_fprint_ast(segment, stdout,
249 config->width, cbdata->output_colorization, 0) < 0)
250 {
251 perror("cypher_parse_segment_fprint_ast");
252 return -1;
253 }
254
255 return 0;
256 }
257
258
259 int process_all(FILE *stream, struct lint_config *config,
260 cypher_parser_config_t *cp_config,
261 const struct cypher_parser_colorization *error_colorization,
262 const struct cypher_parser_colorization *output_colorization)
263 {
264 cypher_parse_result_t *result =
265 cypher_fparse(stream, NULL, cp_config, config->flags);
266 if (result == NULL)
267 {
268 perror("cypher_fparse");
269 return -1;
270 }
271
272 int err = -1;
273
274 unsigned int i = 0;
275 const cypher_parse_error_t *error;
276 for (; (error = cypher_parse_result_get_error(result, i)) != NULL; ++i)
277 {
278 print_error(error, error_colorization);
279 }
280
281 if (config->dump_ast && cypher_parse_result_fprint_ast(result, stdout,
282 config->width, output_colorization, 0) < 0)
283 {
284 perror("cypher_parse_result_fprint_ast");
190285 goto cleanup;
191286 }
192287
193 result = (callback_data.nerrors > 0)? 0 : 1;
288 err = (cypher_parse_result_nerrors(result) == 0)? 0 : 1;
194289
195290 int errsv;
196291 cleanup:
197292 errsv = errno;
198 cypher_parser_config_free(cp_config);
293 cypher_parse_result_free(result);
199294 errno = errsv;
200 return result;
201 }
202
203
204 int parse_callback(void *data, cypher_parse_segment_t *segment)
205 {
206 struct parse_callback_data *callback_data =
207 (struct parse_callback_data *)data;
208 struct lint_config *config = callback_data->config;
209
210 unsigned int i = 0;
211 const cypher_parse_error_t *error;
212 for (; (error = cypher_parse_segment_get_error(segment, i)) != NULL; ++i)
213 {
214 struct cypher_input_position pos =
215 cypher_parse_error_position(error);
216 const char *msg = cypher_parse_error_message(error);
217 const char *context = cypher_parse_error_context(error);
218 unsigned int offset = cypher_parse_error_context_offset(error);
219 fprintf(stderr, "%s %s(line %u, column %u, offset %zu)%s%s\n", msg,
220 callback_data->error_colorization->error_message[0],
221 pos.line, pos.column, pos.offset,
222 callback_data->error_colorization->error_message[1],
223 (context == NULL)? "" : ":");
224 fprintf(stderr, "%s\n%*.*s^\n", context, offset, offset, " ");
225 }
226
227 callback_data->nerrors += i;
228
229 if (config->dump_ast && cypher_parse_segment_fprint_ast(segment, stdout,
230 config->width, callback_data->output_colorization, 0) < 0)
231 {
232 perror("cypher_parse_result_fprint");
233 return -1;
234 }
235
236 return 0;
237 }
295 return err;
296 }
297
298
299 void print_error(const cypher_parse_error_t *error,
300 const struct cypher_parser_colorization *colorization)
301 {
302 struct cypher_input_position pos = cypher_parse_error_position(error);
303 const char *msg = cypher_parse_error_message(error);
304 const char *context = cypher_parse_error_context(error);
305 unsigned int offset = cypher_parse_error_context_offset(error);
306 fprintf(stderr, "%s %s(line %u, column %u, offset %zu)%s%s\n", msg,
307 colorization->error_message[0], pos.line, pos.column, pos.offset,
308 colorization->error_message[1], (context == NULL)? "" : ":");
309 fprintf(stderr, "%s\n%*.*s^\n", context, offset, offset, " ");
310 }
130130 vector.h
131131
132132 libcypher_parser_la_CFLAGS = $(PTHREAD_CFLAGS) $(OPENSSL_CFLAGS) -Wpedantic -Wvla
133 libcypher_parser_la_LDFLAGS = -version-info 3:0:0
133 libcypher_parser_la_LDFLAGS = -version-info 4:0:1
134134 libcypher_parser_la_LIBADD = $(PTHREAD_LIBS) $(OPENSSL_LIBS) $(LIBM)
135135
136136 parser.c: parser_leg.c
607607 vector.h
608608
609609 libcypher_parser_la_CFLAGS = $(PTHREAD_CFLAGS) $(OPENSSL_CFLAGS) -Wpedantic -Wvla
610 libcypher_parser_la_LDFLAGS = -version-info 3:0:0
610 libcypher_parser_la_LDFLAGS = -version-info 4:0:1
611611 libcypher_parser_la_LIBADD = $(PTHREAD_LIBS) $(OPENSSL_LIBS) $(LIBM)
612612 EXTRA_DIST = parser_leg.c
613613 MAINTAINERCLEANFILES = parser_leg.c
53835383 const cypher_parse_segment_t *segment);
53845384
53855385 /**
5386 * Check if the parse encountered the end of the input.
5387 *
5388 * Indicates if the segment was terminated by to the end of the input.
5389 *
5390 * @param [segment] The parse segment.
5391 * @return `true` if the end of input was encountered, `false` if the
5392 * segment was terminated with an expected character.
5393 */
5394 __cypherlang_pure
5395 bool cypher_parse_segment_eof(const cypher_parse_segment_t *segment);
5396
5397 /**
53865398 * Print a represetation of the AST from a parse segment to a stream.
53875399 *
53885400 * Useful for debugging purposes. This is equivalent to calling
162162 }
163163
164164
165 bool cypher_parse_segment_eof(const cypher_parse_segment_t *segment)
166 {
167 return segment->eof;
168 }
169
170
165171 int cypher_parse_segment_fprint_ast(const cypher_parse_segment_t *segment,
166172 FILE *stream, unsigned int width,
167173 const struct cypher_parser_colorization *colorization,