xref: /titanic_41/usr/src/cmd/fm/fminject/common/inj_lex.l (revision dd49f125507979bb2ab505a8daf2a46d1be27051)
1 %{
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License, Version 1.0 only
7  * (the "License").  You may not use this file except in compliance
8  * with the License.
9  *
10  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11  * or http://www.opensolaris.org/os/licensing.
12  * See the License for the specific language governing permissions
13  * and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  *
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <stdio.h>
30 #include <stdarg.h>
31 #include <string.h>
32 #include <errno.h>
33 
34 #include <inj.h>
35 #include <inj_lex.h>
36 #include <inj_string.h>
37 #include <inj_event.h>
38 #include <inj_grammar.h>
39 
40 int yynerrors;
41 const char *yyinname;
42 
43 %}
44 
45 /*
46  * S0 is for normal input processing.  SCOMMENT is used to process comments.
47  * We need a separate state for comments to prevent the lex regexp engine from
48  * overflowing its own buffers as it searches for the end of comments.
49  */
50 %s		S0 SCOMMENT
51 
52 RGX_IMM_SEQ	-?([0-9]+|0[xX][0-9A-Fa-f]+)
53 RGX_STR_SEQ	([^"\\\n]|\\[^"\n]|\\\")*
54 RGX_IDENT	[a-zA-Z][a-zA-Z0-9\-_]*
55 
56 %%
57 
58 <S0>"/*"		{ BEGIN(SCOMMENT); }
59 <SCOMMENT>.|\n		; /* discard */
60 <SCOMMENT>"*/"		{ BEGIN(S0); }
61 
62 <S0>evdef		{ return (INJ_TOK_EVDEF); }
63 <S0>fmridef		{ return (INJ_TOK_FMRIDEF); }
64 <S0>authdef		{ return (INJ_TOK_AUTHDEF); }
65 <S0>listdef		{ return (INJ_TOK_LISTDEF); }
66 
67 <S0>int8_t		{ return (INJ_TOK_INT8); }
68 <S0>int16_t		{ return (INJ_TOK_INT16); }
69 <S0>int32_t		{ return (INJ_TOK_INT32); }
70 <S0>int64_t		{ return (INJ_TOK_INT64); }
71 <S0>uint8_t		{ return (INJ_TOK_UINT8); }
72 <S0>uint16_t		{ return (INJ_TOK_UINT16); }
73 <S0>uint32_t		{ return (INJ_TOK_UINT32); }
74 <S0>uint64_t		{ return (INJ_TOK_UINT64); }
75 <S0>boolean		{ return (INJ_TOK_BOOLEAN); }
76 <S0>boolean_t		{ return (INJ_TOK_BOOLEAN); }
77 <S0>string		{ return (INJ_TOK_STRING); }
78 <S0>enum		{ return (INJ_TOK_ENUM); }
79 
80 <S0>event		{ return (INJ_TOK_EVENT); }
81 <S0>fmri		{ return (INJ_TOK_FMRI); }
82 <S0>auth		{ return (INJ_TOK_AUTH); }
83 <S0>list		{ return (INJ_TOK_LIST); }
84 
85 <S0>addhrtime		{ return (INJ_TOK_ADDHRT); }
86 <S0>endhrtime		{ return (INJ_TOK_ENDHRT); }
87 <S0>sleep		{ return (INJ_TOK_SLEEP); }
88 <S0>repeat		{ return (INJ_TOK_REPEAT); }
89 <S0>randomize		{ return (INJ_TOK_RANDOMIZE); }
90 
91 <S0>\"{RGX_STR_SEQ}$	{ yyerror("syntax error: \" unmatched"); }
92 
93 <S0>\"{RGX_STR_SEQ}\" {
94 		/* Quoted string */
95 		yylval.l_string = inj_strndup(yytext + 1, yyleng - 2);
96 		return (INJ_TOK_QSTRING);
97 	}
98 
99 <S0>{RGX_IDENT}("."{RGX_IDENT})+ {
100 		yylval.l_string = inj_strdup(yytext);
101 		return (INJ_TOK_FMACLASS);
102 	}
103 
104 <S0>{RGX_IDENT}	{
105 		yylval.l_string = inj_strdup(yytext);
106 		return (INJ_TOK_IDENT);
107 	}
108 
109 <S0>{RGX_IMM_SEQ} {
110 		yylval.l_string = inj_strdup(yytext);
111 		return (INJ_TOK_IMM);
112 	}
113 
114 <S0>[ \t\n]		;	/* Ignore whitespace */
115 
116 .			{ return (yytext[0]); }
117 
118 %%
119 
120 void
121 yyerror(const char *format, ...)
122 {
123 	int err = errno;
124 	va_list ap;
125 	char *s;
126 
127 	/* Don't print the line number if the message begins with a space */
128 	if (*format == ' ') {
129 		(void) fprintf(stderr, "%s: ", yyinname, yylineno);
130 		format++;
131 	} else
132 		(void) fprintf(stderr, "%s: %d: ", yyinname, yylineno);
133 
134 	va_start(ap, format);
135 	(void) vfprintf(stderr, format, ap);
136 	va_end(ap);
137 
138 	if (strchr(format, '\n') == NULL)
139 		(void) fprintf(stderr, " near \"%s\"\n", yytext);
140 
141 	yynerrors++;
142 	errno = err;
143 }
144 
145 int
146 yywrap(void)
147 {
148 	return (1);
149 }
150 
151 void
152 yyreset(void)
153 {
154 	BEGIN(S0);
155 }
156