Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » implement Xpath using Xtext
implement Xpath using Xtext [message #1769955] Mon, 07 August 2017 05:09 Go to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Everyone,

I am implementing Yang definition using Xtext.
Now my question is that how can I implement Xpath using Xtext?
I can simply write the path using STRINGARG but I want to implement content assist when someone write xpath.

Thanks.

Regards,
Kaushal Patel.
Re: implement Xpath using Xtext [message #1769964 is a reply to message #1769955] Mon, 07 August 2017 06:59 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

I'm not sure if Xtext is the right way to go here. At least it won't be trivial. You could of course customize the code completion for STRING attributes.
Re: implement Xpath using Xtext [message #1769965 is a reply to message #1769964] Mon, 07 August 2017 07:04 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Thanks Karsten,

At the moment, I am using STRING but I want to make it easy, using content assist. Is there any other way to implement Xpath using Xtext?
Re: implement Xpath using Xtext [message #1769970 is a reply to message #1769965] Mon, 07 August 2017 08:03 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

As said, you could customize the content assist within STRING by overriding the complete_STRING method of your proposal provider. I would not recommend implementing Xpath in Xtext. It is a bottomless hole if you are not very experienced with Xtext.
Re: implement Xpath using Xtext [message #1769973 is a reply to message #1769970] Mon, 07 August 2017 08:19 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

Hi Kaushal,

if for any reason you don't want to use the implementation here: https://github.com/yang-tools/yang-lsp
You could at least use it to see how YANG (incl Xpath) can be implemented in Xtext. It's all there.

Sven
Re: implement Xpath using Xtext [message #1770326 is a reply to message #1769970] Thu, 10 August 2017 03:12 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Karsten,

Sorry for late reply. Yes, I am new to Xtext but I want to learn how to implement Xpath in Xtext. If you can guide me then it would be helpful.

Thanks.

Kaushal.
Re: implement Xpath using Xtext [message #1770327 is a reply to message #1769973] Thu, 10 August 2017 03:16 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Sven,

I have already tried this YANG definition but I am getting many errors as my YANG definition is different from this. Have you used Xtend for mapping the path?

As I told earlier, I want to use content assist, but I am confused how can I map the directory?

Thanks

Kaushal.
Re: implement Xpath using Xtext [message #1770333 is a reply to message #1770327] Thu, 10 August 2017 06:53 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hello Everyone,

I am trying to implement XPath in my yang definition using Xtext.

I have tried below code to implement in the augmentstatement.
But i am getting error in my RuntimeModule.xtend and StandaloneSetup.xtend

I am trying to solve it but It doesn't work.

Is there any particular interface for it like (e.g. iqualifiednameprovider)?


SchemaNodeStatement:
	DatadefStatement |
	ExtensionStatement |
	GroupingStatement |
	IdentityStatement |
	NotificationStatement |
	TypedefStatement
;

AugmentStatement:
	'augment' path=SchemaNodeIdentifier (';' | '{' 
		(augmentsubstatements+= AugmentSubStatement)*
		'}'
	)
;

SchemaNodeIdentifier returns SchemaNodeIdentifier:
	RootSchemaNodeIdentifier ({SchemaNodeIdentifier.target=current} '/' schemaNode=[SchemaNodeStatement])
	
;

RootSchemaNodeIdentifier returns SchemaNodeIdentifier:
	isAbsolute?= '/' schemaNode = [SchemaNodeStatement]
;




Thank you.

Re: implement Xpath using Xtext [message #1770334 is a reply to message #1770333] Thu, 10 August 2017 06:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you be more specific about the error you get.
are you sure the workflow went trough without errors?
what do yopu actually try to "implement" ????


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770335 is a reply to message #1770334] Thu, 10 August 2017 07:11 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Christian,
I am trying to implement Xpath using xtext for yang definition.
I can easily implement using STRINGARG but I want to use it as content assist, when a user press control+space then it can show the suggestions of parent and children node.

class YangDefinitionRuntimeModule extends AbstractYangDefinitionRuntimeModule {
	
	override bindIQualifiedNameProvider() {
		YangDefinitionQualifiedNameProvider
	}
	
	


I am getting this error in my runtime module
AbstractYangDefinitionRuntimeModule cannot be resolved to a type.
and many more.

Re: implement Xpath using Xtext [message #1770336 is a reply to message #1770335] Thu, 10 August 2017 07:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
does running the workflow result in error?!?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770337 is a reply to message #1770336] Thu, 10 August 2017 07:13 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
yes.
Re: implement Xpath using Xtext [message #1770339 is a reply to message #1770337] Thu, 10 August 2017 07:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
well then you likely introduced ambiguities in your gramar that you should solve first

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770340 is a reply to message #1770339] Thu, 10 August 2017 07:29 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
But i am not getting any errors when I write my grammar.
But it shows the different errors in the generated Xtend and java files.


This is my project link.
https://drive.google.com/open?id=0B1qBozMfAwyAdjRTRWZ1a2xSSGc
Re: implement Xpath using Xtext [message #1770342 is a reply to message #1770340] Thu, 10 August 2017 07:36 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

> I have already tried this YANG definition but I am getting many errors as my YANG definition is different from this
Are you saying that our YANG implementation cannot handle your YANG files?
It is an implementation of the standard (https://tools.ietf.org/html/rfc7950), so those errors are either in your YANG files or bugs. But note, that we have tested the implementation with lots of publicly available yang files without issues.

If you want editor support for YANG, I suggest you get in touch and we see how we can collaborate.
If you want to learn Xtext, you should pick a simpler language to start with.

Cheers,
Sven

Re: implement Xpath using Xtext [message #1770409 is a reply to message #1770342] Fri, 11 August 2017 00:13 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Sven,

I am using version 1 YANG files (RFC6020). Does it make any problem?

Yes, your support would be helpful.
I attached my project in my last reply. You can see if it works with your YANG files or not.

Thanks,

Regards,
Kaushal.

[Updated on: Fri, 11 August 2017 00:20]

Report message to a moderator

Re: implement Xpath using Xtext [message #1770416 is a reply to message #1770409] Fri, 11 August 2017 05:14 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Everyone,

I am trying to solve my errors but when I generate my MWE2 Workflow it automatically deletes some java files like AbstractYangDefinitionRuntimeModeule and StandaloneSetupGenerated.

Buid automatically option is enable in my project. When I delete previous changes, it works perfectly without any error.
I am implementing SchemaNodeIdentifier.

Thanks.

Regards,
Kaushal Patel
Re: implement Xpath using Xtext [message #1770417 is a reply to message #1770416] Fri, 11 August 2017 05:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i assume your workflow log has errors if you regenerate after grammar changes. this is likely caused by ambiguities.
have a look at the log for details


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770525 is a reply to message #1770417] Mon, 14 August 2017 01:11 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Christian,

Yes, I am getting error like this:

Problems running workflow org.xtext.yang.yangdefinition.GenerateYangDefinition

I think there are some errors in my new rules which I am writing for SchemaNodeIdentifier, my old grammar is working perfectly. Can I map the directory with the SchemaNodeIdentifier or with the Xpath?

If yes, then how?

How can I map the parent nodes and the children nodes using Xpath?
Do I have to create XML file for it?

Looking for your response.

Thanks.

Regards,
Kaushal Patel
Re: implement Xpath using Xtext [message #1770526 is a reply to message #1770525] Mon, 14 August 2017 03:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You need to analyze the error message and fix the problem
I assume the path in the other grammar is quite similar to have a look at


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770533 is a reply to message #1770526] Mon, 14 August 2017 06:46 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Christian,

I have fixed my errors but now I am getting a new error.

I can import the schema node for my augment statement but I cannot get the perfect output.

I am getting this output with my current grammar.
  revision 2017-02-24 {
    description
     "Revision: v1.0";
  }

  container node {
	  container v1 {
		  uses nmos:version-1;
	  }
  }
  
  augment node /v1 /self                           //(Error)
  {
	  uses rc:restconf;
  }
  
  augment / node / v1 / self / mdp3020:restconf / data                   //(Error)
  {
	  uses mdp3020-from-snmp:MEDIALINKS-MDP3020;
  }  



This is what I want. Check the AugmentStatement. I need ( " " ) and i do not want any white space between two slashes(/). I also want few prefix statements wherever we need in nodes like (mdp3020:restconf).
  revision 2017-02-24 {
    description
     "Revision: v1.0";
  }

  container node {
	  container v1 {
		  uses nmos:version-1;
	  }
  }
  
  augment "/node/v1/self"                 //(correct output)
  {
	  uses rc:restconf;
  }
  
  augment "/node/v1/self/mdp3020:restconf/data"      //(correct output)
{
	  uses mdp3020-from-snmp:MEDIALINKS-MDP3020;
  }  



This is my current grammar.
ContainerStatement:
	'container' name=STRINGARG  (';' | '{'
		(containersubstatements+= ContainerSubStatement)*
	'}')
;

ContainerSubStatement:
	ConfigStatement | 
	ContainerStatement |
	LeafStatement |
	ListStatement |
	LeafListStatement |
	DescriptionStatement |
	UsesStatement |
	UnknownStatement

AugmentStatement:
	'augment' path= SchemaNodeIdentifier 
	(';' | '{' 
		(augmentsubstatements+= AugmentSubStatement)*
		'}'
	)
;

AugmentSubStatement:
	DescriptionStatement |
	LeafStatement |
	LeafListStatement |
	UsesStatement |
	StatusStatement |
	UnknownStatement
;


 SchemaNodeIdentifier returns SchemaNodeIdentifier:
	'"' RootSchemaNodeIdentifier ({SchemaNodeIdentifier.target=current}'/'schemaNode=[ContainerStatement|QName])* '"'
;

RootSchemaNodeIdentifier returns SchemaNodeIdentifier:
	isAbsolute?='/'? schemaNode=[ContainerStatement|QName]
;

Re: implement Xpath using Xtext [message #1770534 is a reply to message #1770533] Mon, 14 August 2017 06:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you nail that down to a complete but minimal grammar and a unit test

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770535 is a reply to message #1770534] Mon, 14 August 2017 07:04 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
I am not writing any unit test at the moment.



ContainerSubStatement:
	ConfigStatement | 
	ContainerStatement |
	LeafStatement |
	ListStatement |
	LeafListStatement |
	DescriptionStatement |
	UsesStatement |
	UnknownStatement
	
;

ConfigStatement:
	'config' boolarg=STRINGARG (';' | '{'
		(configunknownstatements+= UnknownStatement)*
		'}'
	)
;

UsesStatement:
	'uses' (pre=STRINGARG ':')? statement=[GroupingStatement] (';' | '{'
		(usessubstatements+= UsesSubStatement)*
		'}'
	);

UsesSubStatement:
	DescriptionStatement |
	ReferenceStatement |
	UnknownStatement
;

LeafStatement:
	'leaf' name=STRINGARG33 (';' | '{'
		(leafsubstatements+= LeafSubStatement)*
		'}'
	);
	
LeafSubStatement:
	TypeStatement |
	ConfigStatement | 
	DescriptionStatement |
	MandatoryStatement |
	StatusStatement |
	ReferenceStatement |
	UnknownStatement
;

TypeStatement:
	'type' (btype=BuiltInType | (prefix=STRINGARG ':') ? importtype=[TypedefStatement])
		(';' | '{'
		(typesubstatements+= TypeSubStatement)*
		'}'
	);
	
TypeSubStatement:
	LengthStatement |
	TypeStatement |
	PatternStatement |
	EnumStatement |
	RangeStatement|
	PathStatement |
	UnknownStatement
	;
	
PathStatement:
	'path' path=STRINGARG (';' | '{'
		(pathunknownstatements+= UnknownStatement)*
		'}'
	)
;

ListStatement:
	'list' name= (STRINGARG | KEY_IDENTIFIER) (';' | '{'
		(listsubstatements+= ListSubStatement)*
		'}'
	)
;

ListSubStatement:
	KeyStatement |
	DescriptionStatement |
	LeafStatement | 
	LeafListStatement |
	ConfigStatement |
	ContainerStatement |
	UsesStatement |
	ReferenceStatement |
	ChoiceStatement |
	UnknownStatement
;

LeafListStatement:
	'leaf-list' name=STRINGARG (';' | '{'
		(leafliststatements+= LeafListSubStatement)*
		'}'
	)
;

LeafListSubStatement:
	TypeStatement |
	ConfigStatement |
	DescriptionStatement |
	UnknownStatement
;

KeyStatement:
	'key' arg=(STRINGARG | STRINGARG2) (';' | '{' 
		(keyunknownstatements+= UnknownStatement)*
		'}'
	)
;

AugmentStatement:
	'augment' path= SchemaNodeIdentifier 
	(';' | '{' 
		(augmentsubstatements+= AugmentSubStatement)*
		'}'
	)
;

AugmentSubStatement:
	DescriptionStatement |
	LeafStatement |
	LeafListStatement |
	UsesStatement |
	StatusStatement |
	UnknownStatement
;


 SchemaNodeIdentifier returns SchemaNodeIdentifier:
	'"' RootSchemaNodeIdentifier ({SchemaNodeIdentifier.target=current}'/'schemaNode=[ContainerStatement|QName])* '"'
;

RootSchemaNodeIdentifier returns SchemaNodeIdentifier:
	isAbsolute?='/'? schemaNode=[ContainerStatement|QName]
;




I hope this works for you.
Re: implement Xpath using Xtext [message #1770540 is a reply to message #1770535] Mon, 14 August 2017 07:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no it does not, i want a MINIMAL but COMPLETE grammar that shows the problem
(in doubt create a new one)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770546 is a reply to message #1770540] Mon, 14 August 2017 09:13 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

To debug grammar ambiguities please study Holger's article: https://www.google.de/amp/s/blogs.itemis.com/en/debugging-xtext-grammars-what-to-do-when-your-language-is-ambiguous%3fhs_amp=true

We strongly recommend writing unit tests for the parser from the early beginning on and extend them ongoing.
Re: implement Xpath using Xtext [message #1770777 is a reply to message #1770546] Thu, 17 August 2017 04:20 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Christian,

I do not have any ambiguities in my grammar at the moment.

As i told you, the problem is whitespace between two nodes.

Here is the grammar for my problem:


AugmentStatement:
	'augment' path= SchemaNodeIdentifier 
	(';' | '{' 
		(augmentsubstatements+= AugmentSubStatement)*
		'}'
	)
;

AugmentSubStatement:
	DescriptionStatement |
	LeafStatement |
	LeafListStatement |
	UsesStatement |
	StatusStatement |
	UnknownStatement
;

SchemaNodeIdentifier returns SchemaNodeIdentifier:
	 RootSchemaNodeIdentifier ({SchemaNodeIdentifier.target=current}'/'(schemaNode=[ContainerStatement|QName]))*
;

RootSchemaNodeIdentifier returns SchemaNodeIdentifier:
	isAbsolute?='/'? schemaNode=[ContainerStatement|QName]
;


This is my errors:
index.php/fa/30400/0/

This is what i need in augment.
index.php/fa/30401/0/
Re: implement Xpath using Xtext [message #1770778 is a reply to message #1770777] Thu, 17 August 2017 04:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
sorry i need a COMPLETE BUT MINIMAL grammar i can copy & paste

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770780 is a reply to message #1770778] Thu, 17 August 2017 04:59 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Here is my full grammar just because all statements are interconnected with each other.

Some of the statements are also substatements.

you can download IF-MIB.yang and mdp-3020.yang files online to validate this grammar.


grammar org.xtext.yang.yangdefinition.YangDefinition with org.eclipse.xtext.common.Terminals

generate yangDefinition "http://www.xtext.org/yang/yangdefinition/YangDefinition"

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

YangFile:
	Module | SubModule
;

Module:
	'module' name=STRINGARG
	'{'
	(statements+=ModuleStatement)*
	'}'
;

ModuleStatement:
	YangVersionStatement |
	NamespaceStatement | 
	PrefixStatement |
	ImportStatement |
	OragnizationStatement|
	ContactStatement |
	DescriptionStatement |
	RevisionStatement |
	DatadefStatement|
	TypedefStatement |
	IdentityStatement|
	ExtensionStatement |
	GroupingStatement |
	NotificationStatement |
	AugmentStatement |
	IncludeStatement |
	UnknownStatement
	
;

SubModule:
	'submodule' name = STRINGARG
	'{'
		(statements+= SubModuleStatement)*
	'}'
;

SubModuleStatement:
	YangVersionStatement |
	ImportStatement |
	OragnizationStatement |
	ContactStatement |
	DescriptionStatement |
	RevisionStatement |
	DatadefStatement |
	TypedefStatement |
	IdentityStatement |
	ExtensionStatement |
	GroupingStatement |
	NotificationStatement |
	AugmentStatement |
	IncludeStatement|
	BelongsToStatement |
	UnknownStatement
;


DatadefStatement:
	ContainerStatement |
	LeafStatement |
	ListStatement |
	LeafListStatement
;

YangVersionStatement:
	'yang-version' version = STRINGARG
	(';' | '{'
		(yangversionunknownstatement+= UnknownStatement)*
		'}'
	)
;

NamespaceStatement:
	'namespace' uri= (STRINGARG4 | STRINGARG)
	(';' | '{'
		(namespaceunknownstatement+= UnknownStatement)*
		'}'
	);
	
PrefixStatement:
	'prefix' pre=STRINGARG 
	( ';' | '{'
		(prefixunknownstatement += UnknownStatement)*
		'}'	
	);
	
ImportStatement:
	'import' ImportURI=[YangFile | STRINGARG] 
	(';' | '{'
	(importsubstatements+= ImportSubStatement)*
	'}');
	
ImportSubStatement:
	PrefixStatement |
	RevisionStatement |
	TypeStatement|
	UnknownStatement
;

//identifier-arg-str	
IncludeStatement:
	'include' importURI=[YangFile | STRINGARG]
	(';' 
	|'{' (includesubstatements+=IncludeSubstatements)* '}');
IncludeSubstatements:
	(RevisionStatement |
	RevisionDateStatement |
	TypeStatement |
	UnknownStatement)
	;

	
RevisionDateStatement:
	'revision-date' date=(STRINGARG | DATE) (';' | '{'
		(revisiondateunknownstatements+= UnknownStatement)
		'}'
	)
;

OragnizationStatement:
	'organization' name=STRINGARG (';' | '{'
			(organizationunknownstatements+= UnknownStatement)*
		'}'
	);
	
ContactStatement:
	'contact' name=STRINGARG (';' | '{'
			(contactunknownstatements+= UnknownStatement)*
		'}'
	);
	
DescriptionStatement:
	'description' name=STRINGARG (';' | '{'
			(descriptionunknownstatements+= UnknownStatement)*
		'}'
	);

RevisionStatement:
	'revision' date=(STRINGARG | DATE) (';' | '{'
			(revisionsubstatements+= RevisionSubStatement)*
		'}'
	);

RevisionSubStatement:
	DescriptionStatement |
	ReferenceStatement|
	UnknownStatement
;

ReferenceStatement:
	'reference' (name=STRINGARG) (';' | '{'
		(referenceunknownstatements+=UnknownStatement)*
		'}'
	)
;

BelongsToStatement:
	'belongs-to' name=[ Module | STRINGARG] (';' | '{'
		(belongstosubstatements+= BelongsToSubStatement)*
		'}'
	)
;

BelongsToSubStatement:
	PrefixStatement |
	UnknownStatement
;

IdentityStatement:
	'identity' name=STRINGARG (';' | '{'
		(identitysubstatements+=IdentitySubstatement)*
		'}'
	);
	
IdentitySubstatement:
	DescriptionStatement |
	UnknownStatement
;

ExtensionStatement:
	'extension' name=(STRINGARG | KEY_IDENTIFIER) (';' | '{'
		(extensionsubstatements+=ExtensionSubStatement)*
		'}'
	)
;

ExtensionSubStatement:
ArgumentStatement |
DescriptionStatement|
ReferenceStatement |
StatusStatement |
UnknownStatement
;

ArgumentStatement:
	'argument' arg= STRINGARG33 
	(';' | '{'
		(argumentsubstatement += ArgumentSubStatement)*
		'}'
	)
;

ArgumentSubStatement:
	YinElement |
	UnknownStatement
;

YinElement:
	'yin-element' boolarg=STRINGARG (';' | '{'
		(yinunknownstatements+= UnknownStatement)*
		'}'
	)
	;

ContainerStatement:
	'container' name=STRINGARG33 (';' | '{'
		(containersubstatements+= ContainerSubStatement)*
	'}')
;

ContainerSubStatement:
	ConfigStatement | 
	ContainerStatement |
	LeafStatement |
	ListStatement |
	LeafListStatement |
	DescriptionStatement |
	UsesStatement |
	UnknownStatement
	
;

ConfigStatement:
	'config' boolarg=STRINGARG (';' | '{'
		(configunknownstatements+= UnknownStatement)*
		'}'
	)
;

UsesStatement:
	'uses' (pre=STRINGARG ':')? statement=[GroupingStatement] (';' | '{'
		(usessubstatements+= UsesSubStatement)*
		'}'
	);

UsesSubStatement:
	DescriptionStatement |
	ReferenceStatement |
	UnknownStatement
;

LeafStatement:
	'leaf' name=STRINGARG33 (';' | '{'
		(leafsubstatements+= LeafSubStatement)*
		'}'
	);
	
LeafSubStatement:
	TypeStatement |
	ConfigStatement | 
	DescriptionStatement |
	MandatoryStatement |
	StatusStatement |
	ReferenceStatement |
	UnknownStatement
;

TypeStatement:
	'type' (btype=BuiltInType | (prefix=STRINGARG ':') ? importtype=[TypedefStatement])
		(';' | '{'
		(typesubstatements+= TypeSubStatement)*
		'}'
	);
	
TypeSubStatement:
	LengthStatement |
	TypeStatement |
	PatternStatement |
	EnumStatement |
	RangeStatement|
	PathStatement |
	UnknownStatement
	;
	
PathStatement:
	'path' path=STRINGARG (';' | '{'
		(pathunknownstatements+= UnknownStatement)*
		'}'
	)
;
	
StatusStatement:
	'status' status=STRINGARG (';' | '{'
		(statusunknownstatements+= UnknownStatement)*
		'}'
	)
;

MandatoryStatement:
	'mandatory' boolarg = STRINGARG (';' | '{'
		(mandatoryunknownstatements+= UnknownStatement)*
		'}'
	)
;

LengthStatement:
	'length' length = STRINGARG (';' | '{'
		(lengthunknownstatements+= UnknownStatement)*
		'}'
	);
	
PatternStatement:
	'pattern' arg=STRINGARG (';' | '{'
		(patternunknownstatements+= UnknownStatement)*
		'}'
	);

EnumStatement:
	'enum' name=(STRINGARG | KEY_IDENTIFIER) (';' | '{' 
		(enumsubstatements+= EnumSubStatement)*
		'}'
	);

RangeStatement:
	'range' range=STRINGARG  (';' | '{'
		(rangeunknownstatements+=UnknownStatement)*
		'}'
	)
;	
	
EnumSubStatement:
	ValueStatement |
	DescriptionStatement |
	UnknownStatement
;

ValueStatement:
	'value' intarg= STRINGARG (';' | '{'
		(valueunknownstatements+= UnknownStatement)*
		'}'
	) 
;

TypedefStatement:
	'typedef' name=(STRINGARG | KEY_IDENTIFIER) (';' | '{'
		(typedefsubstatemenents+=TypedefSubStatement)*
		'}'
	);
	
TypedefSubStatement:
	TypeStatement |
	DescriptionStatement|
	ReferenceStatement |
	DefaultStatement |
	StatusStatement |
	UnknownStatement
;

DefaultStatement:
	'default' arg=STRINGARG (';' | '{'
		(defaultunknownstatements+=UnknownStatement)*
		'}'
	) 
;

ListStatement:
	'list' name= (STRINGARG | KEY_IDENTIFIER) (';' | '{'
		(listsubstatements+= ListSubStatement)*
		'}'
	)
;

ListSubStatement:
	KeyStatement |
	DescriptionStatement |
	LeafStatement | 
	LeafListStatement |
	ConfigStatement |
	ContainerStatement |
	UsesStatement |
	ReferenceStatement |
	ChoiceStatement |
	UnknownStatement
;

LeafListStatement:
	'leaf-list' name=STRINGARG (';' | '{'
		(leafliststatements+= LeafListSubStatement)*
		'}'
	)
;

LeafListSubStatement:
	TypeStatement |
	ConfigStatement |
	DescriptionStatement |
	UnknownStatement
;

KeyStatement:
	'key' arg=(STRINGARG | STRINGARG2) (';' | '{' 
		(keyunknownstatements+= UnknownStatement)*
		'}'
	)
;

ChoiceStatement:
	'choice' name=STRINGARG (';' | '{'
		(choicesubstatements+=ChoiceSubStatement)*
		'}'
	)
;

ChoiceSubStatement:
	DescriptionStatement |
	CaseStatement |
	UnknownStatement
;

CaseStatement:
	'case' name=STRINGARG33 (';' | '{'
		(casesubstatements+= CaseSubStatement)*
		'}'
	)
;

CaseSubStatement:
	LeafStatement |
	UnknownStatement
;

GroupingStatement:
	'grouping' name=STRINGARG33 (';' | '{'
		(groupingsubstatements+= GroupingSubStatement)*
		'}'
	)
;

GroupingSubStatement:
	LeafStatement |
	LeafListStatement |
	ListStatement |
	TypeStatement |
	UsesStatement |
	ContainerStatement |
	DescriptionStatement
;

NotificationStatement:
	'notification' name = STRINGARG (';' | '{'
		(notificationsubstatements+= NotificationSubStatement)*
		'}'
	);
	
NotificationSubStatement:
	DescriptionStatement |
	ContainerStatement |
	UnknownStatement
;

AugmentStatement:
	'augment' path= SchemaNodeIdentifier 
	(';' | '{' 
		(augmentsubstatements+= AugmentSubStatement)*
		'}'
	)
;

AugmentSubStatement:
	DescriptionStatement |
	LeafStatement |
	LeafListStatement |
	UsesStatement |
	StatusStatement |
	UnknownStatement
;


SchemaNodeIdentifier returns SchemaNodeIdentifier:
	 RootSchemaNodeIdentifier ({SchemaNodeIdentifier.target=current}'/'(schemaNode=[ContainerStatement|QName]))*
;

RootSchemaNodeIdentifier returns SchemaNodeIdentifier:
	isAbsolute?='/'? schemaNode=[ContainerStatement|QName]
;

UnknownStatement:
	((pre=STRINGARG ':')? (extension=[ExtensionStatement]) (arg=STRINGARG)?)
	(';'
		| '{'
			(unknownsubstatements+= UnknownSubStatement)*
		'}'
	);
	
	
UnknownSubStatement:
	DescriptionStatement |
	TypeStatement|
	StatusStatement |
	DefaultStatement |
	UnspecifiedStatement
;

UnspecifiedStatement:
	((pre=STRINGARG ':')? (statement=[ExtensionStatement]) (arg=STRINGARG)?)
	(';' | '{'
		(unknownsubstatements+= UnknownSubStatement)* '}'	
	);

BuiltInType:
	(btype = (
	  'binary'
	| 'bits'
	| 'boolean'
	| 'decimal64'
	| 'empty' 
    | 'enumeration'
    | 'identityref'
    | 'instance-identifier'
    | 'int8'
    | 'int16'
    | 'int32'
    | 'int64'
    | 'leafref'
    | 'string'
    | 'uint8'
    | 'uint16'
    | 'uint32'
    | 'uint64'
    | 'union'
    ))
    ;

KEY_IDENTIFIER:
	=>'value' | =>'status' | =>'namespace' | =>'notification' |=> 'path' |=> 'description' |
	=> 'string' | =>'error-message' |=>'config' |=>'range' | =>'revision' | =>'type' | 
	=>'boolean' | =>'prefix' | =>'range' | => 'key' | =>'fraction-digits';

//Lexer Rules

QName:
	(STRINGARG ':')? STRINGARG
;

STRINGARG:
	ID | 'default' | INT | CUSTOMSTRING ;
	
STRINGARG33:
	KEY_IDENTIFIER | STRINGARG;
	
STRINGARG2:
	ID ':' ID ;

STRINGARG4:
	((ID+':'+ID)+(':'+ID) * | (':'KEY_IDENTIFIER)*);
	
CUSTOMSTRING:
	(STRING ('+' STRING)*);

terminal ID: 
    ('^')?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'-'|'/'|'.'|'\"'|'0'..'9')*;
    
terminal DATE:
	INT'-'INT'-'INT;



Thanks.
Re: implement Xpath using Xtext [message #1770781 is a reply to message #1770780] Thu, 17 August 2017 05:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
that is not MINIMAL

and i need the model file
and the error message (screenshots are not helpful here)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 17 August 2017 05:41]

Report message to a moderator

Re: implement Xpath using Xtext [message #1770783 is a reply to message #1770781] Thu, 17 August 2017 06:11 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
I know this is not no minimal.

But all the statements are interconnected with each other.
if i will delete few statements then you are not able to implement my full module.
Just copy and paste this grammar so u can get idea.

And if you want to see the grammar which causes the problem then it is in AugmentStatement.

Please find the attached YANG files.

mdp-3020.yang is the main file and the others are submodules or yang modules.

you can find AugmentStatement in mdp-3020.yang file.

If you need anything just let me know.

Sorry for not writing minimal grammar. But if i will delete few rules then my dsl will not work properly.

Thanks.
Re: implement Xpath using Xtext [message #1770784 is a reply to message #1770783] Thu, 17 August 2017 06:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i dont get any parser errors. i get this stuff

Multiple markers at this line
- Couldn't resolve reference to ContainerStatement 'v1'.
- Couldn't resolve reference to ContainerStatement 'self'.
- Couldn't resolve reference to ContainerStatement 'mdp3020:restconf'.
- Couldn't resolve reference to ContainerStatement 'data'.

=> scoping


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770785 is a reply to message #1770784] Thu, 17 August 2017 06:25 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
This is my qualifiednameprovider.java



package org.xtext.yang.yangdefinition;

import javax.inject.Inject;

import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
import org.xtext.yang.yangdefinition.yangDefinition.ContainerStatement;
import org.xtext.yang.yangdefinition.yangDefinition.ExtensionStatement;
import org.xtext.yang.yangdefinition.yangDefinition.GroupingStatement;
import org.xtext.yang.yangdefinition.yangDefinition.TypedefStatement;

public class YangDefinitionQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {

	@Inject
	private IQualifiedNameConverter qnc;
	
	public QualifiedName qualifiedName(TypedefStatement s) {
		return qnc.toQualifiedName(s.getName());
	}
	
	public QualifiedName qualifiedName(GroupingStatement g) {
		return qnc.toQualifiedName(g.getName());
	}
	
	public QualifiedName qualifiedName(ExtensionStatement e) {
		return qnc.toQualifiedName(e.getName());
	}
	
	public QualifiedName qualifiedName(ContainerStatement c) {
		return qnc.toQualifiedName(c.getName());
	}
	

}





I am getting these errors:

>Couldn't resolve reference to ContainerStatement '"/node/v1/self"'.
>Couldn't resolve reference to ContainerStatement '"/node/v1/self/mdp3020:restconf/data"'.


I need this output with my current grammar.

  augment "/node/v1/self"
  {
	  uses rc:restconf;
  }
  
  augment "/node/v1/self/mdp3020:restconf/data"
  {
	  uses mdp3020-from-snmp:MEDIALINKS-MDP3020;
  }  


Re: implement Xpath using Xtext [message #1770788 is a reply to message #1770785] Thu, 17 August 2017 06:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes but where is mdp3020:restconf defined?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770789 is a reply to message #1770788] Thu, 17 August 2017 07:04 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
it's in ietf-restcong.yang file.

mdp3020 is a prefix of the current file and the restconf is in different file.

grouping restconf{

container restconf{
                          ...
container data {
                           ...
    }
  }
}


when you click on restconf with control/command key it will take you to the grouping statement.
Re: implement Xpath using Xtext [message #1770791 is a reply to message #1770789] Thu, 17 August 2017 07:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
but where in your nameprovider or IDefaultResourceDescriptionStrategy or ScopeProvider do you reflect that?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770793 is a reply to message #1770791] Thu, 17 August 2017 07:28 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
I am using nameprovider for augment statement to get the node from all the files. u can see in my nameprovide as defined in above post.
Re: implement Xpath using Xtext [message #1770794 is a reply to message #1770793] Thu, 17 August 2017 07:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes but there is not thing with name "mdp3020:restconf" ?!?!??!?!?!!??!!?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770854 is a reply to message #1770794] Fri, 18 August 2017 00:38 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
mdp3020 is a prefix of the same file(mdp3020.yang) which is used to navigate the restconf which is in ietf-restconf.yang file.

> copy all the yang files in your dsl (when you run the project(xtext) as eclipse application) then just click on the restconf with command key, it will navigate you to the below code in ietf-restconf.yang file


grouping restconf {
        
description "Added to pass pyang --ietf validation";    	
      
container restconf {
       
 description
          "Conceptual container representing the
         application/yang.api resource type.";
        
container data {
          
description
            "Container representing the application/yang.datastore
           resource type. Represents the conceptual root of all
           operational data and configuration data supported by
           the server.  The child nodes of this container can be
           any data resource (application/yang.data), which are
           defined as top-level data nodes from the YANG modules
           advertised by the server in the ietf-restconf-monitoring
           module.";
        }  // container data



Re: implement Xpath using Xtext [message #1770861 is a reply to message #1770854] Fri, 18 August 2017 04:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Yes but where in the nameprovider idefaultresourcedescriptionstrstegy or scopeprovider do you implement that logic ?????????????

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770862 is a reply to message #1770861] Fri, 18 August 2017 04:45 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
In nameprovider, and i am only binding qualifiednameprovider in the runtime module
container statement in qualifiednameprovider. You can see last code segment of my qualifiednameprovider.
Re: implement Xpath using Xtext [message #1770863 is a reply to message #1770862] Fri, 18 August 2017 05:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i nowhere see

firstpart + ":" + secondPart

i feel not to answer anymore if you totally ignore my hints


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770864 is a reply to message #1770863] Fri, 18 August 2017 05:35 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi Christian,
Sorry about the confusion.
I get it what you are trying to say,

This is my xtext grammar for the firstpart+ ":"+ secondpart.


SchemaNodeIdentifier returns SchemaNodeIdentifier:
	 RootSchemaNodeIdentifier ({SchemaNodeIdentifier.target=current}'/'((prefix=STRINGARG':')? schemaNode=[ContainerStatement]))*
;

RootSchemaNodeIdentifier returns SchemaNodeIdentifier:
	isAbsolute?='/'? ((prefix=STRINGARG':')?schemaNode=[ContainerStatement])
;



The first part is a prefix which i am writing as a string but for the second part, I am using cross-reference as you can see in the above grammar.
I made some changes to fix the problem. But still could not able implement the valid output.

This is my qualifiednameprovider, you can see the last code for container statement.

package org.xtext.yang.yangdefinition;

import javax.inject.Inject;

import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
import org.xtext.yang.yangdefinition.yangDefinition.ContainerStatement;
import org.xtext.yang.yangdefinition.yangDefinition.ExtensionStatement;
import org.xtext.yang.yangdefinition.yangDefinition.GroupingStatement;
import org.xtext.yang.yangdefinition.yangDefinition.TypedefStatement;

public class YangDefinitionQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {

	@Inject
	private IQualifiedNameConverter qnc;
	
	public QualifiedName qualifiedName(TypedefStatement s) {
		return qnc.toQualifiedName(s.getName());
	}
	
	public QualifiedName qualifiedName(GroupingStatement g) {
		return qnc.toQualifiedName(g.getName());
	}
	
	public QualifiedName qualifiedName(ExtensionStatement e) {
		return qnc.toQualifiedName(e.getName());
	}
	
	public QualifiedName qualifiedName(ContainerStatement c) {
		return qnc.toQualifiedName(c.getName());
	}
	

}



I am binding my qualifiednameprovider in runtimemodule,


/*
 * generated by Xtext 2.10.0
 */
package org.xtext.yang.yangdefinition



/**
 * Use this class to register components to be used at runtime / without the Equinox extension registry.
 */
class YangDefinitionRuntimeModule extends AbstractYangDefinitionRuntimeModule {
	
	override bindIQualifiedNameProvider() {
		YangDefinitionQualifiedNameProvider
	}
	
	
}


Re: implement Xpath using Xtext [message #1770865 is a reply to message #1770864] Fri, 18 August 2017 05:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
schemaNode=[ContainerStatement|QName]

QName:
(STRINGARG ':')? STRINGARG
;

????????
!!!!!!!!!!!!!
??????????
!!!!!!!!!!!!!!
?????????


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: implement Xpath using Xtext [message #1770866 is a reply to message #1770865] Fri, 18 August 2017 05:57 Go to previous messageGo to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
I deleted it.

Re: implement Xpath using Xtext [message #1770868 is a reply to message #1770866] Fri, 18 August 2017 06:02 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
?

sorry you shoudl get sme basic understanding how scoping works


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Infer local variable inside a method
Next Topic:Ambiguity detected but why?
Goto Forum:
  


Current Time: Fri Apr 19 20:34:05 GMT 2024

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

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

Back to the top