xref: /freebsd/usr.sbin/bluetooth/bthidd/lexer.l (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1 %{
2 /*
3  * lexer.l
4  */
5 
6 /*-
7  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
8  *
9  * Copyright (c) 2006 Maksim Yevmenkin <m_evmenkin@yahoo.com>
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $Id: lexer.l,v 1.3 2006/09/07 21:06:53 max Exp $
34  * $FreeBSD$
35  */
36 #define L2CAP_SOCKET_CHECKED
37 #include <bluetooth.h>
38 #include <stdlib.h>
39 #include "parser.h"
40 
41 	int	yylex	(void);
42 
43 #define	YY_DECL	int yylex(void)
44 %}
45 
46 %option yylineno noyywrap nounput noinput
47 
48 delim				[ \t\n]
49 ws				{delim}+
50 empty				{delim}*
51 comment				\#.*
52 
53 hexdigit			[0-9a-fA-F]
54 hexbyte				{hexdigit}{hexdigit}?
55 hexword				{hexdigit}{hexdigit}?{hexdigit}?{hexdigit}?
56 
57 device_word			device
58 bdaddr_word			bdaddr
59 name_word			name
60 vendor_id_word			vendor_id
61 product_id_word			product_id
62 version_word			version
63 control_psm_word		control_psm
64 interrupt_psm_word		interrupt_psm
65 reconnect_initiate_word		reconnect_initiate
66 battery_power_word		battery_power
67 normally_connectable_word	normally_connectable
68 hid_descriptor_word		hid_descriptor
69 true_word			true
70 false_word			false
71 
72 bdaddrstring			{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}
73 hexbytestring			0x{hexbyte}
74 hexwordstring			0x{hexword}
75 string				\".+\"
76 
77 %%
78 
79 \;				return (';');
80 \:				return (':');
81 \{				return ('{');
82 \}				return ('}');
83 
84 {ws}				;
85 {empty}				;
86 {comment}			;
87 
88 {device_word}			return (T_DEVICE);
89 {bdaddr_word}			return (T_BDADDR);
90 {name_word}			return (T_NAME);
91 {vendor_id_word}		return (T_VENDOR_ID);
92 {product_id_word}		return (T_PRODUCT_ID);
93 {version_word}			return (T_VERSION);
94 {control_psm_word}		return (T_CONTROL_PSM);
95 {interrupt_psm_word}		return (T_INTERRUPT_PSM);
96 {reconnect_initiate_word}	return (T_RECONNECT_INITIATE);
97 {battery_power_word}		return (T_BATTERY_POWER);
98 {normally_connectable_word}	return (T_NORMALLY_CONNECTABLE);
99 {hid_descriptor_word}		return (T_HID_DESCRIPTOR);
100 {true_word}			return (T_TRUE);
101 {false_word}			return (T_FALSE);
102 
103 {bdaddrstring}			{
104 				return (bt_aton(yytext, &yylval.bdaddr)?
105 						T_BDADDRSTRING : T_ERROR);
106 				}
107 
108 {hexbytestring}			{
109 				char	*ep;
110 
111 				yylval.num = strtoul(yytext, &ep, 16);
112 
113 				return (*ep == '\0'? T_HEXBYTE : T_ERROR);
114 				}
115 
116 {hexwordstring}			{
117 				char	*ep;
118 
119 				yylval.num = strtoul(yytext, &ep, 16);
120 
121 				return (*ep == '\0'? T_HEXWORD : T_ERROR);
122 				}
123 
124 {string}			{
125 				yytext[strlen(yytext) - 1] = 0;
126 				yylval.string = &yytext[1];
127 				return (T_STRING);
128 				}
129 
130 .				return (T_ERROR);
131 
132 %%
133 
134