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