| 1 |
%{ |
| 2 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 3 |
/*************************************************************************** |
| 4 |
* Copyright (c) 2010 Jürgen Riegel <[email protected]> * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
/* Lexer for the FreeCAD selection filter language */ |
| 24 |
|
| 25 |
/* flex -o SelectionFilter.lex.cpp SelectionFilter.l */ |
| 26 |
|
| 27 |
#include <string> |
| 28 |
|
| 29 |
#include "stdio.h" |
| 30 |
|
| 31 |
|
| 32 |
/* This disables inclusion of unistd.h, which is not available under Visual C++ |
| 33 |
* on Win32. The C++ scanner uses STL streams instead. */ |
| 34 |
#define YY_NO_UNISTD_H |
| 35 |
|
| 36 |
%} |
| 37 |
|
| 38 |
/*** Flex Declarations and Options ***/ |
| 39 |
|
| 40 |
/* change the name of the scanner class. results in "SelectionFilterFlexLexer" */ |
| 41 |
%option prefix="SelectionFilter" |
| 42 |
|
| 43 |
/* the manual says "somewhat more optimized" */ |
| 44 |
%option batch |
| 45 |
|
| 46 |
/* no support for include files is planned */ |
| 47 |
%option noyywrap nounput |
| 48 |
|
| 49 |
|
| 50 |
%% /*** Filter language Part ***/ |
| 51 |
|
| 52 |
|
| 53 |
[ \t] ; |
| 54 |
[\n]+ ; |
| 55 |
"SUBELEMENT" return TSUB; |
| 56 |
"SELECT" return TSELECT; |
| 57 |
"COUNT" return TCOUNT; |
| 58 |
".." return TSLICE; |
| 59 |
"::" return TNAMESPACE; |
| 60 |
|
| 61 |
[a-zA-Z_][a-zA-Z0-9_]* { |
| 62 |
yylval.string = StringFactory::New(yytext); |
| 63 |
return TIDENTIFIER; |
| 64 |
} |
| 65 |
[0-9]+ { |
| 66 |
long n = strtol (yytext, NULL, 10); |
| 67 |
yylval.number = n; |
| 68 |
return TNUMBER; |
| 69 |
} |