Merge lp:~nbrinza/zorba/error-messages into lp:zorba

Proposed by Nicolae Brinza
Status: Merged
Approved by: Chris Hillery
Approved revision: 10847
Merged at revision: 11174
Proposed branch: lp:~nbrinza/zorba/error-messages
Merge into: lp:zorba
Diff against target: 274 lines (+87/-41)
8 files modified
ChangeLog (+1/-0)
src/compiler/parser/symbol_table.cpp (+22/-12)
src/compiler/parser/symbol_table.h (+26/-22)
src/compiler/parser/xquery_parser.cpp (+8/-3)
src/compiler/parser/xquery_parser.y (+8/-3)
test/rbkt/ExpQueryResults/zorba/parser/syntax-errors/unexpected-qname-03.xml.res (+1/-0)
test/rbkt/Queries/zorba/parser/syntax-errors/missing-comma-02.xq (+1/-1)
test/rbkt/Queries/zorba/parser/syntax-errors/unexpected-qname-03.xq (+20/-0)
To merge this branch: bzr merge lp:~nbrinza/zorba/error-messages
Reviewer Review Type Date Requested Status
Chris Hillery Approve
Nicolae Brinza Approve
Review via email: mp+142697@code.launchpad.net

Commit message

Parser error messages contain the actual offending QName.

Description of the change

Parser error messages contain the actual offending QName.

To post a comment you must log in.
Revision history for this message
Nicolae Brinza (nbrinza) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~nbrinza/zorba/error-messages into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job error-messages-2013-01-10T14-11-42.339Z is finished.
  The final status was:

  1 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job error-messages-2013-01-10T15-29-49.206Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job error-messages-2013-01-10T21-28-43.79Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-01-10 10:44:36 +0000
3+++ ChangeLog 2013-01-10 15:28:28 +0000
4@@ -31,6 +31,7 @@
5 * Convert LET vars whose domain sequence has exactly one item to FOR vars.
6
7 Bug Fixes/Other Changes:
8+ * Fixed bug #949064 (faulty QName should be printed in the error message)
9 * Fixed bug #1072644 (broken parser error location)
10 * Change XQXQ (XQuery-for-XQuery) module now part of Zorba core
11 * Fixed mustCopyInputNodes() method of no-copy, and jsoniq functions.
12
13=== modified file 'src/compiler/parser/symbol_table.cpp'
14--- src/compiler/parser/symbol_table.cpp 2012-09-19 21:16:15 +0000
15+++ src/compiler/parser/symbol_table.cpp 2013-01-10 15:28:28 +0000
16@@ -56,8 +56,9 @@
17 }
18
19 symbol_table::symbol_table(uint32_t initial_heapsize)
20-:
21- heap(initial_heapsize)
22+ :
23+ heap(initial_heapsize),
24+ last_qname(-1)
25 {
26 }
27
28@@ -107,7 +108,8 @@
29
30 off_t symbol_table::put_ncname(char const* text, uint32_t length)
31 {
32- return heap.put(text, 0, length);
33+ last_qname = heap.put(text, 0, length);
34+ return last_qname;
35 }
36
37 off_t symbol_table::put_qname(char const* text, uint32_t length, bool do_trim_start, bool do_trim_end, bool is_eqname)
38@@ -125,7 +127,9 @@
39 }
40
41 if (!is_eqname)
42- return heap.put(text, 0, length);
43+ {
44+ last_qname = heap.put(text, 0, length);
45+ }
46 else
47 {
48 // EQName: Q{prefix}name
49@@ -138,8 +142,10 @@
50 off_t uri = put_uri(prefix.c_str(), prefix.size());
51 name = get(uri) + ":" + name;
52
53- return heap.put(name.c_str(), 0, name.size());
54+ last_qname = heap.put(name.c_str(), 0, name.size());
55 }
56+
57+ return last_qname;
58 }
59
60 off_t symbol_table::put_uri(char const* text, uint32_t length)
61@@ -226,15 +232,19 @@
62
63 std::string symbol_table::get(off_t id)
64 {
65- uint32_t n = heap.get_length0(id);
66- char *buf;
67- buf = (char*)malloc(n+1);
68- heap.get0(id, buf, 0, n+1);
69- std::string retstr = string(buf, 0, n);
70- free(buf);
71- return retstr;
72+ uint32_t n = heap.get_length0(id);
73+ char *buf;
74+ buf = (char*)malloc(n+1);
75+ heap.get0(id, buf, 0, n+1);
76+ std::string retstr = string(buf, 0, n);
77+ free(buf);
78+ return retstr;
79 }
80
81+std::string symbol_table::get_last_qname()
82+{
83+ return get(last_qname);
84+}
85
86 } /* namespace zorba */
87 /* vim:set et sw=2 ts=2: */
88
89=== modified file 'src/compiler/parser/symbol_table.h'
90--- src/compiler/parser/symbol_table.h 2012-09-19 21:16:15 +0000
91+++ src/compiler/parser/symbol_table.h 2013-01-10 15:28:28 +0000
92@@ -28,14 +28,15 @@
93
94 class ZORBA_DLL_PUBLIC symbol_table
95 {
96-protected: // state
97- fxcharheap heap;
98-
99-public: // ctor,dtor
100- symbol_table(uint32_t initial_heapsize=1024);
101- ~symbol_table();
102-
103-public: // table interface
104+protected: // state
105+ fxcharheap heap;
106+ off_t last_qname; // will store the offset of the last added qname or ncname
107+
108+public: // ctor,dtor
109+ symbol_table(uint32_t initial_heapsize=1024);
110+ ~symbol_table();
111+
112+public: // table interface
113 off_t put(char const* text);
114
115 /* Accepted values for normalizationType:
116@@ -43,22 +44,25 @@
117 * normalizationType = 1 -- EOL normalization
118 * normalizationType = 2 -- Attribute value normalization
119 */
120- off_t put(char const* text, uint32_t length, int normalizationType = 0);
121+ off_t put(char const* text, uint32_t length, int normalizationType = 0);
122
123- off_t put_ncname(char const* text, uint32_t length);
124- off_t put_qname(char const* text, uint32_t length,
125+ off_t put_ncname(char const* text, uint32_t length);
126+ off_t put_qname(char const* text, uint32_t length,
127 bool do_trim_start = false, bool do_trim_end = false, bool is_eqname = false);
128- off_t put_uri(char const* text, uint32_t length);
129- off_t put_varname(char const* text, uint32_t length);
130- off_t put_entityref(char const* text, uint32_t length);
131- off_t put_charref(char const* text, uint32_t length);
132- off_t put_stringlit(char const* text, uint32_t length);
133- off_t put_commentcontent(char const* text, uint32_t length);
134-
135- std::string get(off_t id);
136- uint32_t size() const;
137-
138- xs_decimal* decimalval(char const* text, uint32_t length);
139+ off_t put_uri(char const* text, uint32_t length);
140+ off_t put_varname(char const* text, uint32_t length);
141+ off_t put_entityref(char const* text, uint32_t length);
142+ off_t put_charref(char const* text, uint32_t length);
143+ off_t put_stringlit(char const* text, uint32_t length);
144+ off_t put_commentcontent(char const* text, uint32_t length);
145+
146+ uint32_t size() const;
147+
148+ std::string get(off_t id);
149+
150+ std::string get_last_qname(); // It will return the last added qname or ncname
151+
152+ xs_decimal* decimalval(char const* text, uint32_t length);
153 xs_double* doubleval(char const* text, uint32_t length); // Will return NULL if std::range_error is raised
154 xs_integer* integerval(char const* text, uint32_t length); // Will return NULL if std::range_error is raised
155
156
157=== modified file 'src/compiler/parser/xquery_parser.cpp'
158--- src/compiler/parser/xquery_parser.cpp 2013-01-08 16:08:11 +0000
159+++ src/compiler/parser/xquery_parser.cpp 2013-01-10 15:28:28 +0000
160@@ -5134,7 +5134,7 @@
161 #line 2711 "/home/colea/xquery_bzr/error-messages/src/compiler/parser/xquery_parser.y"
162 {
163 (yyval.node) = (yysemantic_stack_[(3) - (3)].node); // to prevent the Bison warning
164- error((yylocation_stack_[(3) - (2)]), "syntax error, unexpected QName \""
165+ error((yylocation_stack_[(3) - (2)]), "syntax error, unexpected qualified name \""
166 + static_cast<VarInDeclList*>((yysemantic_stack_[(3) - (3)].node))->operator[](0)->get_var_name()->get_qname().str() + "\" (missing \"$\" sign?)");
167 delete (yysemantic_stack_[(3) - (3)].node);
168 YYERROR;
169@@ -17802,7 +17802,7 @@
170 if (prevErr != NULL)
171 {
172 // Error message heuristics: if the current error message has the "(missing comma "," between expressions?)" text,
173- // and the old message has a "','" text, the replace the old message with the new one. Unfortunately this
174+ // and the old message has a "','" text, then replace the old message with the new one. Unfortunately this
175 // makes the parser error messages harder to internationalize.
176 if (msg.find("(missing comma \",\" between expressions?)") != string::npos
177 &&
178@@ -17810,9 +17810,14 @@
179 return;
180 }
181
182- // remove the double quoting "''" from every token description
183+ // Replace the first occurrence of "unexpected "'QName'"" with "unexpected qualified name %actual_qname%"
184 string message = msg;
185 int pos;
186+ std::string unexpected_qname = "unexpected \"'QName'\"";
187+ if ((pos = message.find(unexpected_qname)) != -1)
188+ message = message.substr(0, pos) + "unexpected qualified name \"" + driver.symtab.get_last_qname() + "\"" + message.substr(pos+unexpected_qname.length());
189+
190+ // remove the double quoting "''" from every token description
191 while ((pos = message.find("\"'")) != -1 || (pos = message.find("'\"")) != -1)
192 message.replace(pos, 2, "\"");
193 driver.set_expr(new ParseErrorNode(driver.createQueryLoc(loc), err::XPST0003, message));
194
195=== modified file 'src/compiler/parser/xquery_parser.y'
196--- src/compiler/parser/xquery_parser.y 2013-01-08 16:08:11 +0000
197+++ src/compiler/parser/xquery_parser.y 2013-01-10 15:28:28 +0000
198@@ -2710,7 +2710,7 @@
199 FOR error VarInDeclList
200 {
201 $$ = $3; // to prevent the Bison warning
202- error(@2, "syntax error, unexpected QName \""
203+ error(@2, "syntax error, unexpected qualified name \""
204 + static_cast<VarInDeclList*>($3)->operator[](0)->get_var_name()->get_qname().str() + "\" (missing \"$\" sign?)");
205 delete $3;
206 YYERROR;
207@@ -6987,7 +6987,7 @@
208 if (prevErr != NULL)
209 {
210 // Error message heuristics: if the current error message has the "(missing comma "," between expressions?)" text,
211- // and the old message has a "','" text, the replace the old message with the new one. Unfortunately this
212+ // and the old message has a "','" text, then replace the old message with the new one. Unfortunately this
213 // makes the parser error messages harder to internationalize.
214 if (msg.find("(missing comma \",\" between expressions?)") != string::npos
215 &&
216@@ -6995,9 +6995,14 @@
217 return;
218 }
219
220- // remove the double quoting "''" from every token description
221+ // Replace the first occurrence of "unexpected "'QName'"" with "unexpected qualified name %actual_qname%"
222 string message = msg;
223 int pos;
224+ std::string unexpected_qname = "unexpected \"'QName'\"";
225+ if ((pos = message.find(unexpected_qname)) != -1)
226+ message = message.substr(0, pos) + "unexpected qualified name \"" + driver.symtab.get_last_qname() + "\"" + message.substr(pos+unexpected_qname.length());
227+
228+ // remove the double quoting "''" from every token description
229 while ((pos = message.find("\"'")) != -1 || (pos = message.find("'\"")) != -1)
230 message.replace(pos, 2, "\"");
231 driver.set_expr(new ParseErrorNode(driver.createQueryLoc(loc), err::XPST0003, message));
232
233=== added file 'test/rbkt/ExpQueryResults/zorba/parser/syntax-errors/unexpected-qname-03.xml.res'
234--- test/rbkt/ExpQueryResults/zorba/parser/syntax-errors/unexpected-qname-03.xml.res 1970-01-01 00:00:00 +0000
235+++ test/rbkt/ExpQueryResults/zorba/parser/syntax-errors/unexpected-qname-03.xml.res 2013-01-10 15:28:28 +0000
236@@ -0,0 +1,1 @@
237+true
238\ No newline at end of file
239
240=== modified file 'test/rbkt/Queries/zorba/parser/syntax-errors/missing-comma-02.xq'
241--- test/rbkt/Queries/zorba/parser/syntax-errors/missing-comma-02.xq 2013-01-08 16:08:11 +0000
242+++ test/rbkt/Queries/zorba/parser/syntax-errors/missing-comma-02.xq 2013-01-10 15:28:28 +0000
243@@ -63,5 +63,5 @@
244 }
245 catch err:XPST0003
246 {
247- $err:description eq 'invalid expression: syntax error, unexpected "QName", expecting "with"'
248+ $err:description eq 'invalid expression: syntax error, unexpected qualified name "width", expecting "with"'
249 }
250
251=== added file 'test/rbkt/Queries/zorba/parser/syntax-errors/unexpected-qname-03.xq'
252--- test/rbkt/Queries/zorba/parser/syntax-errors/unexpected-qname-03.xq 1970-01-01 00:00:00 +0000
253+++ test/rbkt/Queries/zorba/parser/syntax-errors/unexpected-qname-03.xq 2013-01-10 15:28:28 +0000
254@@ -0,0 +1,20 @@
255+(:
256+ Syntax error with an improved error message:
257+ unexpected qualified name %actual_qname%
258+:)
259+
260+import module namespace refl = "http://www.zorba-xquery.com/modules/reflection";
261+declare namespace err="http://www.w3.org/2005/xqt-errors";
262+
263+let $query :=
264+'local:f bad()'
265+
266+return
267+try
268+{
269+ refl:eval($query)
270+}
271+catch err:XPST0003
272+{
273+ $err:description eq 'invalid expression: syntax error, unexpected qualified name "bad", expecting "end of file" or "," or "}"'
274+}

Subscribers

People subscribed via source and target branches