1 /*
2 * SysDB - src/frontend/scanner.l
3 * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
28 %{
30 #include "frontend/parser.h"
31 #include "frontend/grammar.h"
32 #include "utils/error.h"
34 #include <errno.h>
36 #include <string.h>
38 void
39 sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
41 %}
43 %option never-interactive
44 %option reentrant
45 %option bison-bridge
46 %option bison-locations
47 %option 8bit
48 %option yylineno
49 %option nodefault
50 %option noinput
51 %option nounput
52 %option noyywrap
53 %option verbose
54 %option warn
55 %option prefix="sdb_fe_yy" outfile="lex.yy.c"
57 %x CSC
59 whitespace ([ \t\n\r\f]+)
60 simple_comment ("--"[^\n\r]*)
62 /*
63 * C style comments
64 */
65 csc_start \/\*
66 csc_inside ([^*/]+|[^*]\/|\*[^/])
67 csc_end \*\/
69 identifier ([A-Za-z_][A-Za-z_0-9$]*)
71 %%
73 {whitespace} |
74 {simple_comment} { /* ignore */ }
76 {csc_start} { BEGIN(CSC); }
77 <CSC>{csc_inside} { /* ignore */ }
78 <CSC>{csc_end} { BEGIN(INITIAL); }
79 <CSC><<EOF>> {
80 sdb_fe_yyerror(yylval, yyscanner, "unterminated C-style comment");
81 return SCANNER_ERROR;
82 }
84 {identifier} {
85 /* XXX */
86 if (! strcasecmp(yytext, "LIST"))
87 return LIST;
89 return IDENTIFIER;
90 }
92 . { /* do nothing for now */ }
94 %%
96 sdb_fe_yyscan_t
97 sdb_fe_scanner_init(const char *str)
98 {
99 yyscan_t scanner;
101 if (sdb_fe_yylex_init(&scanner)) {
102 char errbuf[1024];
103 sdb_log(SDB_LOG_ERR, "frontend: yylex_init failed: %s",
104 sdb_strerror(errno, errbuf, sizeof(errbuf)));
105 return NULL;
106 }
108 /* the newly allocated buffer state (YY_BUFFER_STATE) is stored inside the
109 * scanner and, thus, will be freed by yylex_destroy */
110 yy_scan_string(str, scanner);
111 return scanner;
112 } /* sdb_fe_scanner_init */
114 void
115 sdb_fe_scanner_destroy(sdb_fe_yyscan_t scanner)
116 {
117 sdb_fe_yylex_destroy(scanner);
118 } /* sdb_fe_scanner_destroy */
120 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */