Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 191819 - [parser] Predefined functions like 'oclAsType' are incorrectly defined in OCL grammer
Summary: [parser] Predefined functions like 'oclAsType' are incorrectly defined in OCL...
Status: CLOSED FIXED
Alias: None
Product: OCL
Classification: Modeling
Component: Core (show other bugs)
Version: 1.1.0   Edit
Hardware: PC All
: P2 normal (vote)
Target Milestone: 2.0.0   Edit
Assignee: Ed Willink CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 184048 259031
Blocks:
  Show dependency tree
 
Reported: 2007-06-09 11:08 EDT by Sergey Boyko CLA
Modified: 2011-05-27 02:47 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Boyko CLA 2007-06-09 11:08:38 EDT
Consider for example the following expression:
  Set{1}.oclAsType(Sequence(Real))
It can't be parsed, error "illegal operation signature: (Sequence(OclType))".
Of course expression like
  1.oclAsType(Real)
is parsed ok (well, it's can't be evaluated but this is another issue).

The reason is that grammer (OCLLPGParser.g) defines such operation calls as follow:
  operationCallExpCS ::= oclAsType isMarkedPreCS '(' argumentsCSopt ')'
  operationCallExpCS ::= oclIsKindOf isMarkedPreCS '(' argumentsCSopt ')'
  operationCallExpCS ::= oclIsTypeOf isMarkedPreCS '(' argumentsCSopt ')'
While 'argumentsCSopt' is actually reduced to 'oclExpressionCS' which can't be reduced to 'typeCS'.

Rules above should be replaced with:
  operationCallExpCS ::= oclAsType isMarkedPreCS '(' typeCS ')'
  operationCallExpCS ::= oclIsKindOf isMarkedPreCS '(' typeCS ')'
  operationCallExpCS ::= oclIsTypeOf isMarkedPreCS '(' typeCS ')'
Comment 1 Christian Damus CLA 2007-06-11 08:53:15 EDT
The OclAny operations oclIsKindOf etc. aren't applicable to CollectionTypes and TupleTypes, which the OCL specification indicates do not conform to OclAny.  Note that

  Set{1}.oclAsType(Sequence(Real))

would expand as an implicit collect iterator to

  Set{1}->collect(oclAsType(Sequence(Real)))

which doesn't make sense, as Integer cannot be cast to Sequence(Real).  What one would want is to be able to write

  Set{1}->oclAsType(Sequence(Real))

but as I mentioned before, this operation does not apply to collections.

So, the problem that I see is that the parser is providing the wrong error message; it should be "cannot find operation 'oclAsType'".  This would be fixed by updating the rules for oclAsType/oclIsKindOf/oclIsTypeOf as you suggest.  They happen to work for non-collection types only because oclExpressionCS reduces to enumLiteralExpCS and variableExpCS, which are both able to yield references to types.  The typeCS is more appropriate.  Good catch!
Comment 2 Christian Damus CLA 2007-06-15 13:54:20 EDT
Should fix this in the first Europa maintenance release.
Comment 3 Sergey Boyko CLA 2007-06-18 04:56:24 EDT
One more note on 'typeCS':
There is the same problem with additionally defined operations that requires TypeExp as the parameter(s).

I mean that for example 'myFunc(ecore::EPackage)' is parsed ok, but 'myFunc(Sequence(ecore::EPackage))' fails.

The reason is the same as for 'oclAsType()'-like operations.
Comment 4 Artem Tikhomirov CLA 2008-10-21 14:20:28 EDT
Christian, do you consider this one for 1.3? Not that it hurts too much, but seems to be a right move, and cleans QVT stuff a bit ;)
Comment 5 Ed Willink CLA 2009-06-24 12:37:40 EDT
It's not always a good idea to be too precise in the grammar, since syntax errors are a bit obtuse. This looks like a strong case for a superset grammar that accepts typical user errors so that a more intelligible semantic error can be produced instead.
Comment 6 Ed Willink CLA 2009-09-13 02:58:08 EDT
Attachment #146988 [details] to Bug 184048 eliminates all predefined functions (other than iterators) from the grammar, so they can no longer be parsed wrongly.

Attachment #147054 [details] to Bug 259031 fixes a matching problem for Type arguments. This may fix the problem. Revision of OclAny inheritance behaviour almost certainly will.
Comment 7 Ed Willink CLA 2009-12-06 13:51:37 EST
The parser problems were fixed in 292112
Comment 8 Ed Willink CLA 2011-05-27 02:47:27 EDT
Closing after over 18 months in resolved state.