Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » [Parsing Pivot] No viable alternative at input
[Parsing Pivot] No viable alternative at input [message #1392764] Wed, 02 July 2014 20:30 Go to next message
Laura M is currently offline Laura MFriend
Messages: 3
Registered: July 2014
Junior Member
Hi,

I am trying to parse an external OCL file with the Pivot and the new Eclipse Luna, by a standalone way. So I initialize my pivot OCL object as below :

EPackage.Registry registry = new EPackageRegistryImpl();
registry.put(RamPackage.eNS_URI, RamPackage.eINSTANCE);

ResourceSet resource = RamPackage.eINSTANCE.eResource().getResourceSet();
org.eclipse.ocl.examples.pivot.OCL.initialize(resource);

String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT;
EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
        new OCLInvocationDelegateFactory.Global());
EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
        new OCLSettingDelegateFactory.Global());
EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI,
        new OCLValidationDelegateFactory.Global());

OCLinEcoreStandaloneSetup.doSetup();

org.eclipse.ocl.examples.pivot.model.OCLstdlib.install();
org.eclipse.ocl.examples.xtext.oclstdlib.OCLstdlibStandaloneSetup.doSetup();
org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup.doSetup();
org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup.doSetup();

return OCL.newInstance(new PivotEnvironmentFactory(registry, null));


I use the tuple syntax of the OCL file (in order to add additional information for each constraint) and the OCLHelper object to create an invariant :

Resource asResource = ocl.parse(uri);

for (TreeIterator<EObject> tit = asResource.getAllContents(); tit.hasNext();) {
    EObject nextObject = tit.next();
    
    if (nextObject instanceof Constraint) {
        Constraint next = (Constraint) nextObject;

        EClassifier context = (EClassifier) ocl.getMetaModelManager().getEcoreOfPivot(EClassifier.class, next.getContext());

        ExpressionInOCL expressionInOCL = ocl.getSpecification(next);
        TupleLiteralExpImpl tuple = (TupleLiteralExpImpl) expressionInOCL.getBodyExpression();
        ExpressionInOCL query;

        // Gets all the elements from the tuple
        for (TupleLiteralPart tp : tuple.getPart()) {
            String name = tp.getName();
            if (name.equalsIgnoreCase("query_string")) {
                OCLHelper helper = ocl.createOCLHelper(context);
                query = helper.createInvariant(tp.getInitExpression().toString());
            }
            //...
        }

        //...
    }
}


And the parsing fails when I use OCL operators like = or <> :

context Aspect
inv validName : Tuple {
    query_string : String =  name <> 'Test'
}


The corresponding exception is :

org.eclipse.ocl.examples.pivot.SemanticException: The 'ram::Aspect' constraint is invalid: 'self.name.<>('Test')'
1: no viable alternative at input '<>'
        at org.eclipse.ocl.examples.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:185)
        at org.eclipse.ocl.examples.pivot.context.AbstractParserContext.parse(AbstractParserContext.java:125)
        at org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createInvariant(OCLHelperImpl.java:88)
        ...


I certainly forgot something, can you help me please?

Regards.
Laura
Re: [Parsing Pivot] No viable alternative at input [message #1392792 is a reply to message #1392764] Wed, 02 July 2014 21:24 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Try your OCL in an interactive editor first. Fix the bugs before you try
to run standalone.

Regards

Ed Willink

On 02/07/2014 21:47, Laura M wrote:
> Hi,
>
> I am trying to parse an external OCL file with the Pivot and the new
> Eclipse Luna, by a standalone way. So I initialize my pivot OCL object
> as below :
>
> EPackage.Registry registry = new EPackageRegistryImpl();
> registry.put(RamPackage.eNS_URI, RamPackage.eINSTANCE);
>
> ResourceSet resource = RamPackage.eINSTANCE.eResource().getResourceSet();
> org.eclipse.ocl.examples.pivot.OCL.initialize(resource);
>
> String oclDelegateURI = OCLDelegateDomain.OCL_DELEGATE_URI_PIVOT;
> EOperation.Internal.InvocationDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
>
> new OCLInvocationDelegateFactory.Global());
> EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(oclDelegateURI,
>
> new OCLSettingDelegateFactory.Global());
> EValidator.ValidationDelegate.Registry.INSTANCE.put(oclDelegateURI,
> new OCLValidationDelegateFactory.Global());
>
> OCLinEcoreStandaloneSetup.doSetup();
>
> org.eclipse.ocl.examples.pivot.model.OCLstdlib.install();
> org.eclipse.ocl.examples.xtext.oclstdlib.OCLstdlibStandaloneSetup.doSetup();
>
> org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup.doSetup();
>
> org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup.doSetup();
>
>
> return OCL.newInstance(new PivotEnvironmentFactory(registry, null));
>
> I use the tuple syntax of the OCL file (in order to add additional
> information for each constraint) and the OCLHelper object to create an
> invariant :
>
> Resource asResource = ocl.parse(uri);
>
> for (TreeIterator<EObject> tit = asResource.getAllContents();
> tit.hasNext();) {
> EObject nextObject = tit.next();
> if (nextObject instanceof Constraint) {
> Constraint next = (Constraint) nextObject;
>
> EClassifier context = (EClassifier)
> ocl.getMetaModelManager().getEcoreOfPivot(EClassifier.class,
> next.getContext());
>
> ExpressionInOCL expressionInOCL = ocl.getSpecification(next);
> TupleLiteralExpImpl tuple = (TupleLiteralExpImpl)
> expressionInOCL.getBodyExpression();
> ExpressionInOCL query;
>
> // Gets all the elements from the tuple
> for (TupleLiteralPart tp : tuple.getPart()) {
> String name = tp.getName();
> if (name.equalsIgnoreCase("query_string")) {
> OCLHelper helper = ocl.createOCLHelper(context);
> query =
> helper.createInvariant(tp.getInitExpression().toString());
> }
> //...
> }
>
> //...
> }
> }
>
> And the parsing fails when I use OCL operators like = or <> :
>
> context Aspect
> inv validName : Tuple {
> query_string : String = name <> 'Test'
> }
>
> The corresponding exception is :
>
> org.eclipse.ocl.examples.pivot.SemanticException: The 'ram::Aspect'
> constraint is invalid: 'self.name.<>('Test')'
> 1: no viable alternative at input '<>'
> at
> org.eclipse.ocl.examples.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:185)
> at
> org.eclipse.ocl.examples.pivot.context.AbstractParserContext.parse(AbstractParserContext.java:125)
> at
> org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createInvariant(OCLHelperImpl.java:88)
> ...
>
> I certainly forgot something, can you help me please?
>
> Regards.
> Laura
Re: [Parsing Pivot] No viable alternative at input [message #1393278 is a reply to message #1392792] Thu, 03 July 2014 14:38 Go to previous messageGo to next message
Laura M is currently offline Laura MFriend
Messages: 3
Registered: July 2014
Junior Member
Hi,

Thanks for your advice!
Indeed, I tried it in the interactive editor and:
- the request that I wrote in my OCL file (name <> 'test') works;
- the returned request after OCL parsing (self.name.<>('test')) does not work.

The OCL document is parsed a first time by:
Resource asResource = ocl.parse(uri);


If I display the content of the asResource object, my constraint is translated to "self.name.<>('test')" so I guess that when I create the invariant the second time with the OCLHelper from the already parsed expression, OCL fails.

Is it true?
So, I found a way to retrieve the original string with a PrettyPrinter ...
OCLHelper helper = ocl.createOCLHelper(context);
String originalOCLExpression = PrettyPrinter.print(tp.getInitExpression());
query = helper.createQuery(originalOCLExpression);


In this case, it works. It's not very beautiful, but it's the solution that I found for the moment. Because I have to parse the document to retrieve Tuple objects, but I don't succeed to create correct ExpressionInOCL from already parsed expressions.

Regards,
Laura

[Updated on: Thu, 03 July 2014 14:39]

Report message to a moderator

Re: [Parsing Pivot] No viable alternative at input [message #1393348 is a reply to message #1393278] Thu, 03 July 2014 16:59 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I cannot follow your discussion. I can investigate reproducible bugs. I
cannot investigate fluff.

Your original example had obvious errors which was why I referred you to
an editor.

"- the returned request after OCL parsing ("self.name.<>('test')") does
not work. "

I have no idea why you think this should work.

In OCL 2.0 there was an ill-defined concept of conceptual operations
such as .<>(). 'conceptual' is usually a sign of a bad bit of
specification writing. In OCL 2.3 this was changed to an option for
deprecated support. The Pivot OCL has no support for conceptual operations.

Regards

Ed Willink


On 03/07/2014 15:38, Laura M wrote:
> Hi,
>
> Thanks for your advice!
> Indeed, I tried it in the interactive editor and:
> - the request that I wrote in my OCL file (name <> 'test') works;
> - the returned request after OCL parsing ("self.name.<>('test')") does
> not work.
>
> The OCL document is parsed a first time by:
> Resource asResource = ocl.parse(uri);
>
> If I display the content of the asResource object, my constraint is
> translated to "self.name.<>('test')" so I guess that when I create the
> invariant the second time with the OCLHelper from the already parsed
> expression, OCL fails.
>
> Is it true?
> So, I found a way to retrieve the original string with a PrettyPrinter
> ...
> OCLHelper helper = ocl.createOCLHelper(context);
> String originalOCLExpression =
> PrettyPrinter.print(tp.getInitExpression());
> query = helper.createQuery(originalOCLExpression);
>
> In this case, it works. It's not very beautiful, but it's the solution
> that I found for the moment. Because I have to parse the document to
> retrieve Tuple objects, but I don't succeed to create correct
> ExpressionInOCL from already parsed expressions.
>
> Regards,
> Laura
Re: [Parsing Pivot] No viable alternative at input [message #1393388 is a reply to message #1393348] Thu, 03 July 2014 18:22 Go to previous messageGo to next message
Laura M is currently offline Laura MFriend
Messages: 3
Registered: July 2014
Junior Member
Hi,

Well, I will try to be more understandable. Confused

I wrote "name <> 'test'" in my OCL file, and not "self.name.<>('test')".
But this constraint is encapsulated in a tuple object in my OCL file, like the sample below:
context Aspect
inv validName : Tuple {
    query_string : String =  name <> 'Test'
}


So, when I parse this file thanks to the OCL object, I obtain a list of constraints (I followed the tutorial in the Eclipse Luna Documentation).
Resource asResource = ocl.parse(uri);

for (TreeIterator<EObject> tit = asResource.getAllContents(); tit.hasNext();) {
    EObject nextObject = tit.next();
    
    if (nextObject instanceof Constraint) {
        Constraint next = (Constraint) nextObject;



Unfortunately, these constraints in my OCL file are tuples, like the sample I wrote above. They need to be treated: I have to retrieve parts of each tuple and build a constraint from the string into the "query_string" tuple part.
        EClassifier context = (EClassifier) ocl.getMetaModelManager().getEcoreOfPivot(EClassifier.class, next.getContext());

        ExpressionInOCL expressionInOCL = ocl.getSpecification(next);
        TupleLiteralExp tuple = (TupleLiteralExp) expressionInOCL.getBodyExpression();
        ExpressionInOCL query;

        // Gets all the elements from the tuple
        for (TupleLiteralPart tp : tuple.getPart()) {
            String name = tp.getName();
            if (name.equalsIgnoreCase("query_string")) {
                OCLHelper helper = ocl.createOCLHelper(context);
                query = helper.createInvariant(tp.getInitExpression().toString());
            }
            //...
        }

        //...
    }
}


That is what I want (tuple parsing to build constraint).

So, my problem is: the method ocl.parse(uri) transforms all parts of tuples, and if I display the parsed constraint object, I obtain something like:
context Aspect
inv validName : Tuple {
    query_string : String =  self.name.<>('Test')
}


After, when I try to build an invariant from this transformed query string, it does not work. That's why I use a PrettyPrinter as a temporary solution to revert the query back to its initial syntax.

Regards,
Laura
Re: [Parsing Pivot] No viable alternative at input [message #1393436 is a reply to message #1393388] Thu, 03 July 2014 20:04 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
http://wiki.eclipse.org/OCL/ForumNetiquette


On 03/07/2014 19:22, Laura M wrote:
> Hi,
>
> Well, I will try to be more understandable. :?
> I wrote "name <> 'test'" in my OCL file, and not "self.name.<>('test')".
> But this constraint is encapsulated in a tuple object in my OCL file,
> like the sample below:
> context Aspect
> inv validName : Tuple {
> query_string : String = name <> 'Test'
> }
>
> So, when I parse this file thanks to the OCL object, I obtain a list
> of constraints (I followed the tutorial in the Eclipse Luna
> Documentation).
> Resource asResource = ocl.parse(uri);
>
> for (TreeIterator<EObject> tit = asResource.getAllContents();
> tit.hasNext();) {
> EObject nextObject = tit.next();
> if (nextObject instanceof Constraint) {
> Constraint next = (Constraint) nextObject;
>
>
>
> Unfortunately, these constraints in my OCL file are tuples, like the
> sample I wrote above. They need to be treated: I have to retrieve
> parts of each tuple and build a constraint from the string into the
> "query_string" tuple part.
>
> EClassifier context = (EClassifier)
> ocl.getMetaModelManager().getEcoreOfPivot(EClassifier.class,
> next.getContext());
>
> ExpressionInOCL expressionInOCL = ocl.getSpecification(next);
> TupleLiteralExp tuple = (TupleLiteralExp)
> expressionInOCL.getBodyExpression();
> ExpressionInOCL query;
>
> // Gets all the elements from the tuple
> for (TupleLiteralPart tp : tuple.getPart()) {
> String name = tp.getName();
> if (name.equalsIgnoreCase("query_string")) {
> OCLHelper helper = ocl.createOCLHelper(context);
> query =
> helper.createInvariant(tp.getInitExpression().toString());
> }
> //...
> }
>
> //...
> }
> }
>
> That is what I want (tuple parsing to build constraint).
>
> So, my problem is: the method ocl.parse(uri) transforms all parts of
> tuples, and if I display the parsed constraint object, I obtain
> something like:
> context Aspect
> inv validName : Tuple {
> query_string : String = self.name.<>('Test')
> }
>
> After, when I try to build an invariant from this transformed query
> string, it does not work. That's why I use a PrettyPrinter as a
> temporary solution to revert the query back to its initial syntax.
>
> Regards,
> Laura
Previous Topic:OCL for defining attribute facet
Next Topic:Default Value of an Unsettable Enum Attribute
Goto Forum:
  


Current Time: Thu Apr 25 18:56:16 GMT 2024

Powered by FUDForum. Page generated in 0.03150 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top