Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 283214

Summary: [xpath2] Conditional Expressions cause XpathParserException
Product: [WebTools] WTP Source Editing Reporter: David Carver <d_a_carver>
Component: wst.xpathAssignee: David Carver <d_a_carver>
Status: RESOLVED FIXED QA Contact: David Carver <d_a_carver>
Severity: normal    
Priority: P3 CC: jesper
Version: unspecifiedKeywords: helpwanted
Target Milestone: 3.2 M1   
Hardware: PC   
OS: Linux   
Whiteboard:
Bug Depends on:    
Bug Blocks: 262765    
Attachments:
Description Flags
Code changes in grammar file for this change
d_a_carver: iplog+
Updated test cases with more success than failure
d_a_carver: iplog+
Generated lexer and grammar
d_a_carver: iplog-
Fix the remaining three tests none

Description David Carver CLA 2009-07-10 20:11:12 EDT
The CUP based parser has problems with parsing XPath if then else statements.    In particular the parser throws an error when it reaches the "then" statement.

http://www.w3.org/TR/xpath20/

XPath             ::= Expr:exps {: RESULT = new XPath(exps); :} ;

Expr              ::= ExprSingle:ex 
			{: 
				Collection exps = new ArrayList();
				exps.add(ex);
				RESULT = exps;
			:}
                    | Expr:exprs COMMA ExprSingle:ex 
		    	{: 
				exprs.add(ex);
				RESULT = exprs;
			:} 
		    ;

ExprSingle        ::= ForExpr:n {: RESULT = n; :}
                    | QuantifiedExpr:n {: RESULT = n; :}
                    | IfExpr:n {: RESULT = n; :}
                    | OrExpr:n {: RESULT = n; :}
		    ;

IfExpr            ::= IF LPAR Expr:exps RPAR THEN ExprSingle:t ELSE ExprSingle:e
			{: RESULT = new IfExpr(exps, t, e); :}
		    ;
		    
Are the current definitions.
Comment 1 David Carver CLA 2009-07-10 20:13:21 EDT
The simple xpath expression throws a parsing exception at the "then" statement:

if (1 != 0) then 2 else 3
Comment 2 Jesper Moller CLA 2009-07-13 19:00:23 EDT
This is fixed by differentiating reserved and non-reserved words in the QName production, so that if ( ex ) doesn't look like a function call of an unqualified function. Patch underway.
Comment 3 Jesper Moller CLA 2009-07-13 19:12:01 EDT
Created attachment 141460 [details]
Code changes in grammar file for this change
Comment 4 Jesper Moller CLA 2009-07-13 19:13:02 EDT
Created attachment 141461 [details]
Updated test cases with more success than failure

I still get three failures in this test.
Comment 5 Jesper Moller CLA 2009-07-13 19:14:51 EDT
Created attachment 141462 [details]
Generated lexer and grammar

If you don't have CUP and JFlex set up in your lib folder yet. (big patch, breaks 250 code line, but it's all just generated code.
Comment 6 David Carver CLA 2009-07-13 19:20:29 EDT
Okay, I'll take a look at these, and will just regenerate based on the grammar changes and the updated test cases.   I'll see about getting this in later tonight.   Thanks for the patches Jesper.
Comment 7 David Carver CLA 2009-07-13 21:46:52 EDT
I've applied the Grammar patches and unit test patches.   The last three conditional tests will need to be tweaked so that we can compare the correct results as they are XQuery tests and not strictly XPath 2.0 tests (i.e. the results file is XQuery).  We need to compare the two attributes values and not the entire XML String for Test 12.


Comment 8 David Carver CLA 2009-07-13 22:42:28 EDT
Code checked into HEAD, build started.  Thanks for the patch.  I'll keep this bug opened until we resolve the last three remaining unit tests.
Comment 9 Jesper Moller CLA 2009-07-14 19:13:42 EDT
Created attachment 141583 [details]
Fix the remaining three tests

One was just about expecting XML nodes instead of text (using buildXMLResultString)

The next required extending the buildXMLResultString to also be able to format atomic results (in effect making buildResultString obsolete)

The last one was tricky, since there was a real bug in comparing result sequences containing untyped atomic values (copy-and-paste error). Also, the extected result had to be massaged.

So now it's all green!
Comment 10 Jesper Moller CLA 2009-07-14 19:15:53 EDT
I mean, the if-then-else tests are all green now, not the entire suite...

The comparison bugfix actually fixes some 11 other test failures :-)
Comment 11 David Carver CLA 2009-07-15 00:01:07 EDT
latest patch applied to head, and build passes. Thans for the patches Jesper.