summaryrefslogtreecommitdiff
path: root/debian/patches/fix-bison-decls.patch
blob: c9cba056a8d601c9c6ab42db1545a446f0bae5ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
Cherry pick four upstream commits to fix bison declarations.

From 84df4540333450f9520c58b847bf5c5a54435321 Mon Sep 17 00:00:00 2001
From: Alex Merry <dev@randomguy3.me.uk>
Date: Mon, 29 Jul 2013 16:11:59 +0100
Subject: [PATCH 1/4] Allow empty square brackets for properties list

---
 tikzit/src/common/tikzparser.ym | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tikzit/src/common/tikzparser.ym b/tikzit/src/common/tikzparser.ym
index 794b06d..5c49ed9 100644
--- a/tikzit/src/common/tikzparser.ym
+++ b/tikzit/src/common/tikzparser.ym
@@ -123,7 +123,9 @@ tikzcmd: node | edge | boundingbox | ignore;
 ignore: "\\begin{pgfonlayer}" DELIMITEDSTRING | "\\end{pgfonlayer}";
 
 optproperties:
-	"[" properties "]"
+	"[" "]"
+	{ $$ = nil; }
+	| "[" properties "]"
 	{ $$ = $2; }
 	| { $$ = nil; };
 properties: property extraproperties
-- 
2.11.0


From 8de27c4c7c9a42a8224e3dfc865b25b184ce1399 Mon Sep 17 00:00:00 2001
From: Alex Merry <dev@randomguy3.me.uk>
Date: Mon, 29 Jul 2013 16:12:32 +0100
Subject: [PATCH 2/4] Do not reverse the order of the properties when parsing

---
 tikzit/src/common/tikzparser.ym | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tikzit/src/common/tikzparser.ym b/tikzit/src/common/tikzparser.ym
index 5c49ed9..98d25e4 100644
--- a/tikzit/src/common/tikzparser.ym
+++ b/tikzit/src/common/tikzparser.ym
@@ -128,16 +128,16 @@ optproperties:
 	| "[" properties "]"
 	{ $$ = $2; }
 	| { $$ = nil; };
-properties: property extraproperties
+properties: extraproperties property
 	{
-		[$2 addObject:$1];
-		$$ = $2;
+		[$1 addObject:$2];
+		$$ = $1;
 	};
 extraproperties:
-	"," property extraproperties
+	extraproperties property ","
 	{
-		[$3 addObject:$2];
-		$$ = $3;
+		[$1 addObject:$2];
+		$$ = $1;
 	}
 	| { $$ = [GraphElementData data]; };
 property:
-- 
2.11.0


From 456d1a0aa3699833d6db381d3ceec51e48451c17 Mon Sep 17 00:00:00 2001
From: Alex Merry <dev@randomguy3.me.uk>
Date: Fri, 2 Aug 2013 20:38:45 +0100
Subject: [PATCH 3/4] Use flex and bison options instead of #defines

Defining YY_EXTRA_TYPE is not the "proper" way to set that type (a
%option should be used instead), and defining YYLEX_PARAM will no longer
work with bison 3 (%lex-param is the correct thing to use).
---
 tikzit/src/common/TikzGraphAssembler+Parser.h |  3 ---
 tikzit/src/common/TikzGraphAssembler.m        |  3 +--
 tikzit/src/common/tikzlexer.lm                |  1 +
 tikzit/src/common/tikzparser.ym               | 10 +++++-----
 4 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/tikzit/src/common/TikzGraphAssembler+Parser.h b/tikzit/src/common/TikzGraphAssembler+Parser.h
index 55fa901..c9391a9 100644
--- a/tikzit/src/common/TikzGraphAssembler+Parser.h
+++ b/tikzit/src/common/TikzGraphAssembler+Parser.h
@@ -31,9 +31,6 @@
 /** Get a previously-stored node by name */
 - (Node*) nodeWithName:(NSString*)name;
 - (void) reportError:(const char *)message atLocation:(YYLTYPE*)yylloc;
-- (void*) scanner;
 @end
 
-#define YY_EXTRA_TYPE TikzGraphAssembler *
-
 // vi:ft=objc:noet:ts=4:sts=4:sw=4
diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m
index 2dd8d50..60b96ee 100644
--- a/tikzit/src/common/TikzGraphAssembler.m
+++ b/tikzit/src/common/TikzGraphAssembler.m
@@ -58,7 +58,7 @@
 
 	tikzStr = [t UTF8String];
 	yy_scan_string(tikzStr, scanner);
-	int result = yyparse(self);
+	int result = yyparse(scanner);
 	tikzStr = NULL;
 
 	[pool drain];
@@ -278,7 +278,6 @@
 		free (context);
 	}
 }
-- (void*) scanner { return scanner; }
 @end
 
 // vi:ft=objc:ts=4:noet:sts=4:sw=4
diff --git a/tikzit/src/common/tikzlexer.lm b/tikzit/src/common/tikzlexer.lm
index a0e5968..fe7ab0d 100644
--- a/tikzit/src/common/tikzlexer.lm
+++ b/tikzit/src/common/tikzlexer.lm
@@ -34,6 +34,7 @@
 %option yylineno
 %option noyywrap
 %option header-file="common/tikzlexer.h"
+%option extra-type="TikzGraphAssembler *"
 
 %s props
 %s xcoord
diff --git a/tikzit/src/common/tikzparser.ym b/tikzit/src/common/tikzparser.ym
index 98d25e4..6eea833 100644
--- a/tikzit/src/common/tikzparser.ym
+++ b/tikzit/src/common/tikzparser.ym
@@ -38,7 +38,8 @@ struct noderef {
 %defines "common/tikzparser.h"
 %pure-parser
 %locations
-%parse-param {TikzGraphAssembler *assembler}
+%lex-param {void *scanner}
+%parse-param {void *scanner}
 %error-verbose
 
 %union {
@@ -47,8 +48,7 @@ struct noderef {
 	GraphElementProperty *prop;
 	GraphElementData *data;
 	Node *node;
-	struct noderef noderef;
-};
+	struct noderef noderef; };
 
 %{
 #import "TikzGraphAssembler+Parser.h"
@@ -56,8 +56,8 @@ struct noderef {
 #import "GraphElementProperty.h"
 #import "Node.h"
 #import "tikzlexer.h"
-#define YYLEX_PARAM [assembler scanner]
-void yyerror(YYLTYPE *yylloc, TikzGraphAssembler *assembler, const char *str) {
+#define assembler yyget_extra(scanner)
+void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) {
 	[assembler reportError:str atLocation:yylloc];
 }
 %}
-- 
2.11.0


From 279644fb0b99dfb07ceaf713ca610e043131c6f4 Mon Sep 17 00:00:00 2001
From: Alex Merry <dev@randomguy3.me.uk>
Date: Fri, 2 Aug 2013 21:24:08 +0100
Subject: [PATCH 4/4] Tidy up and document bison decls in tikzparser.ym

---
 tikzit/src/common/tikzparser.ym | 48 ++++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/tikzit/src/common/tikzparser.ym b/tikzit/src/common/tikzparser.ym
index 6eea833..9901f79 100644
--- a/tikzit/src/common/tikzparser.ym
+++ b/tikzit/src/common/tikzparser.ym
@@ -18,11 +18,25 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-
-#import "Edge.h"
-
 %}
 
+%error-verbose
+/* enable maintaining locations for better error messages */
+%locations
+/* the name of the header file */
+%defines "common/tikzparser.h"
+/* make it re-entrant (no global variables) */
+%pure-parser
+/* We use a pure (re-entrant) lexer.  This means yylex
+   will take a void* (opaque) type to maintain its state */
+%lex-param {void *scanner}
+/* Since this parser is also pure, yyparse needs to take
+   that lexer state as an argument */
+%parse-param {void *scanner}
+
+/* things required to use the parser (will go in the header);
+   in particular, declarations/imports for types in the %union
+   must go here */
 %code requires {
 #import <Foundation/Foundation.h>
 @class TikzGraphAssembler;
@@ -35,36 +49,40 @@ struct noderef {
 };
 }
 
-%defines "common/tikzparser.h"
-%pure-parser
-%locations
-%lex-param {void *scanner}
-%parse-param {void *scanner}
-%error-verbose
-
+/* possible data types for semantic values */
 %union {
 	NSPoint pt;
 	NSString *nsstr;
 	GraphElementProperty *prop;
 	GraphElementData *data;
 	Node *node;
-	struct noderef noderef; };
+	struct noderef noderef;
+}
 
-%{
-#import "TikzGraphAssembler+Parser.h"
+%code {
 #import "GraphElementData.h"
 #import "GraphElementProperty.h"
 #import "Node.h"
+#import "Edge.h"
+
 #import "tikzlexer.h"
+#import "TikzGraphAssembler+Parser.h"
+/* the assembler (used by this parser) is stored in the lexer
+   state as "extra" data */
 #define assembler yyget_extra(scanner)
+
+/* pass errors off to the assembler */
 void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) {
 	[assembler reportError:str atLocation:yylloc];
 }
-%}
+}
 
+/* yyloc is set up with first_column = last_column = 1 by default;
+   however, it makes more sense to think of us being "before the
+   start of the line" before we parse anything */
 %initial-action {
 	yylloc.first_column = yylloc.last_column = 0;
-};
+}
 
 
 %token BEGIN_TIKZPICTURE_CMD "\\begin{tikzpicture}"
-- 
2.11.0