| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
/*************************************************************************** |
| 3 |
* Copyright (c) 2010 Jürgen Riegel <[email protected]> * |
| 4 |
* * |
| 5 |
* This library is free software; you can redistribute it and/or * |
| 6 |
* modify it under the terms of the GNU Library General Public * |
| 7 |
* License as published by the Free Software Foundation; either * |
| 8 |
* version 2 of the License, or (at your option) any later version. * |
| 9 |
* * |
| 10 |
* This library is distributed in the hope that it will be useful, * |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 |
* GNU Library General Public License for more details. * |
| 14 |
* * |
| 15 |
* You should have received a copy of the GNU Library General Public * |
| 16 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 17 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 18 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 19 |
* * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
/* Parser for the FreeCAD selection filter language */ |
| 23 |
|
| 24 |
/* bison -o SelectionFilter.tab.c SelectionFilter.y */ |
| 25 |
|
| 26 |
|
| 27 |
/* Represents the many different ways we can access our data */ |
| 28 |
%union { |
| 29 |
std::string *string; |
| 30 |
Node_Object *object; |
| 31 |
Node_Slice *slice; |
| 32 |
Node_Block *block; |
| 33 |
int token; |
| 34 |
int number; |
| 35 |
} |
| 36 |
|
| 37 |
/* Define our terminal symbols (tokens). This should |
| 38 |
match our tokens.l lex file. We also define the node type |
| 39 |
they represent. |
| 40 |
*/ |
| 41 |
%token <string> TIDENTIFIER |
| 42 |
%token <token> TSUB TSELECT TCOUNT TSLICE TNAMESPACE |
| 43 |
%token <number> TNUMBER |
| 44 |
|
| 45 |
/* Define the type of node our nonterminal symbols represent. |
| 46 |
The types refer to the %union declaration above. |
| 47 |
*/ |
| 48 |
%type <slice> count |
| 49 |
%type <object> matchline |
| 50 |
%type <string> type subname |
| 51 |
%type <block> matchlines block |
| 52 |
|
| 53 |
%start filter |
| 54 |
|
| 55 |
%% |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
type : TSELECT TIDENTIFIER { $$ = $2; } |
| 60 |
| TSELECT TIDENTIFIER TNAMESPACE TIDENTIFIER { $$ = StringFactory::New(*$2 + "::" + *$4); } |
| 61 |
|
| 62 |
subname : { $$ = 0; } |
| 63 |
| TSUB TIDENTIFIER { $$ = $2; } |
| 64 |
|
| 65 |
count : { $$ = 0; } |
| 66 |
| TCOUNT TNUMBER TSLICE TNUMBER { $$ = new Node_Slice($2,$4); } |
| 67 |
| TCOUNT TNUMBER TSLICE { $$ = new Node_Slice($2); } |
| 68 |
| TCOUNT TNUMBER { $$ = new Node_Slice($2,$2); } |
| 69 |
|
| 70 |
matchline : type subname count { $$ = new Node_Object($1,$2,$3); } |
| 71 |
|
| 72 |
matchlines : matchline { $$ = new Node_Block($1); } |
| 73 |
| matchlines matchline { $$ = $1 ; $$->Objects.emplace_back($2); } |
| 74 |
|
| 75 |
block : matchlines { $$ = $1; } |
| 76 |
|
| 77 |
filter: block { TopBlock = $1; } |
| 78 |
; |
| 79 |
|
| 80 |
|
| 81 |
%% |