Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » yang definition using xtext
yang definition using xtext [message #1768284] Mon, 17 July 2017 00:07 Go to next message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Hi

I am confused in import and extension rule in xtext.
How can I import one xtext editor in the second xtext editor?
Can I import values as well?

I have created one xtext grammar rule for both.

// This is snmp.yang

namespace "urn:ietf:params:xml:ns:yang:smiv2:SNMPv2:MIB";
	prefix "snmpv2-mib";

	import SNMP-TC {
		prefix "snmp-tc";
	}
	
	import ietf-yang-smiv2 {
		prefix "smiv2";
	}
	
	import ietf-yang-types{
		prefix "yang";
	}

container SNMPv2-MIB {
		config false;
		
		container system {
			smiv2:oid "1.3.6.1.2.1.1";
			
			leaf sysDesc {
				type snmpv2-tc:DisplayString {
					length "0..255";
				}
				description 
				"A textual description of the entity.  This value should
          		include the full name and version identification of
          		the system's hardware type, software operating-system,
          		and networking software.";
			}
			
			leaf sysObjectID {
        			type yang:object-identifier-128;
        			description
         		"The vendor's authoritative identification of the
          		network management subsystem contained in the entity.
          		This value is allocated within the SMI enterprises
          		subtree (1.3.6.1.4.1) and provides an easy and
          		unambiguous means for determining `what kind of box' is
          		being managed.  For example, if vendor `Flintstones,
          		Inc.' was assigned the subtree 1.3.6.1.4.1.424242,
          		it could assign the identifier 1.3.6.1.4.1.424242.1.1
          		to its `Fred Router'.";
          	}
         
          leaf sysUpTime {
        			type yang:timeticks;
        			description
         		"The time (in hundredths of a second) since the
          		network management portion of the system was last
          		re-initialized.";
          	}


above is my one xtext editor.

//this is smi.yang

module yang-smi {
	
	yang-version 1;
	
	namespace "urn:ietf:params:xml:nsLyang:yang-smi";
	
	prefix smi;
	
	organization "YANG Language Design Team";

    contact
      "Martin Bjorklund (Editor) <mbj@tail-f.com>";

    description
      "This module contains extensions for dealing with 
         SMIv2 modules.";

    revision 2008-03-20 {
      description "Initial revision.";
    }
    
    extension oid {
    	argument "oid" {
    		yin-element  false;
    	}
    	
    	description 
    	"OBJECT-IDENTIFIER value assigned to a particular node.";
    }
    
    extension display-hint {
      argument "hint" {
        yin-element false;
      }
      description
        "DISPLAY-HINT value provided in a TEXTUAL-CONVENTION macro.";
    }

    extension default {
      argument "default" {
        yin-element false;
      }
      description
        "DEFVAL value provided in an OBJECT-TYPE macro.";
    }
  }
	




This is my second xtext editor.



//My xtext file.

grammar org.xtext.yang.snmpv2.SnmpV2 with org.eclipse.xtext.common.Terminals

generate snmpV2 "http://www.xtext.org/yang/snmpv2/SnmpV2"

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

YangFile: 
	Module | SubModule ;
	
Module:
	'module' name=STRINGARG
	'{'
		(statements += Statement)*
	'}'
;

Statement:
	NamespaceStatement | PrefixStatement |ImportStatement |
	OrganizationStatement | ContactStatement | DescriptionStatement |
	RevisionStatement | DatadefStatement | YangVersionStatement |
	ExtensionStatement ;
	

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

SubModuleStatement:
	DatadefStatement | ImportStatement
;

YangVersionStatement:
	'yang-version' version=STRINGARG  ';'
;	
	
NamespaceStatement:
	'namespace' uri= (STRINGARG4 | STRINGARG) ';'
;

PrefixStatement:
	'prefix' name=STRINGARG ';'
;

ImportStatement:
	'import' importURI=STRINGARG '{'
	(prefix+=PrefixStatement)
	'}'
;

OrganizationStatement:
	'organization' name=STRINGARG ';'
;

ContactStatement:
	'contact' name=STRINGARG ';'
;

DescriptionStatement:
	'description' name=STRINGARG ';'
;

RevisionStatement:
	'revision' date = DATE '{'
	(description+= DescriptionStatement) 
	'}'
;

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

ExtensionSubStatement:
	ArgumentStatement | 
	StatusStatement |
	DescriptionStatement | 
	ReferenceStatement
;

ArgumentStatement:
	'argument' arg=(STRINGARG | KEY_IDENTIFIER) '{'
	(arguments+=ArgumentSubStatement)*
	'}'
;

ArgumentSubStatement:
	YinElementStatement
;

YinElementStatement:
	'yin-element' boolarg=STRINGARG ';'
;

ReferenceStatement:
	'reference' reference=STRINGARG ';'
;

DatadefStatement:
	ContainerStatement | LeafStatement 
;

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

ContainerSubStatement:
	(ConfigStatement | DescriptionStatement | TypeStatement |
		DatadefStatement | OIDStatement )
	
;

ConfigStatement:
	'config' boolarg=STRINGARG ';'
;

OIDStatement:
	"smiv2:oid" name = STRINGARG ';'
;


LeafStatement:
	'leaf' name=STRINGARG '{'
	(leafsubstatements += LeafSubStatement)*
	'}'
;

LeafSubStatement:
	TypeStatement | StatusStatement | DescriptionStatement | OIDStatement | AccessStatement
;

AccessStatement:
	'smiv2:max-access' name=STRINGARG ';'
;

TypeStatement:
	'type' name=STRINGARG4
	(';' | '{'
	(typesubstatements+=TypeSubStatement)*
	'}')
;

StatusStatement:
	'status' name = STRINGARG ';'
;

TypeSubStatement:
	LengthStatement| RangeStatement | EnumStatement 
;

LengthStatement:
	'length' name=STRINGARG ';'
;

RangeStatement:
	'range' name=STRINGARG ';'
;

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

EnumSubStatement:
	'value' name=STRINGARG ';'
;

STRINGARG:
	ID | 'default' | CUSTOMSTRING | INT  ;
	
STRINGARG4:
	((ID+':'+ID)+(':'+ID) * | (':'KEY_IDENTIFIER)*);
	
CUSTOMSTRING:
	(STRING ('+' STRING)*);
	
KEY_IDENTIFIER:
	=>'value' | =>'status' | =>'namespace' | =>'notification' |=> 'path' |=> 'description' |
	=> 'string' | =>'error-message' |=>'config' |=>'range' | =>'revision' | =>'type' | 
	=>'boolean' | =>'prefix' | =>'range' | => 'key' | =>'fraction-digits';
	

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




This is my xtext grammar.

Now my question is,

Can I import objects from smi.yang to snmp.yang file?
If I can then How?

I know Xtext is a framework for development of programming languages and domain-specific languages and to define programming language using a powerful grammar language.

Re: yang definition using xtext [message #1768294 is a reply to message #1768284] Mon, 17 July 2017 07:41 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

Hi Kaushal,

you can, of course, import and reference objects from other files.
You would export the module names through the ResourceDescriptionManager, which will add them to the global index.
Then you can find them during scoping using the GlobalScopeProvider.

But before you go there and implement YANG yourself, you might want to check out
https://github.com/yang-tools/yang-lsp

It is an open-source implementation of YANG in Xtext, which we (TypeFox.io) are working on.
If you have any questions regarding that implementation, simply open an issue on the github repo.

Regards,
Sven
Re: yang definition using xtext [message #1768362 is a reply to message #1768294] Tue, 18 July 2017 00:47 Go to previous message
Kaushal Patel is currently offline Kaushal PatelFriend
Messages: 72
Registered: June 2017
Member
Couldn't resolve reference to TypedefStatement 'counter32'.
Couldn't resolve reference to TypedefStatement 'timestamp'
Couldn't resolve reference to TypedefStatement 'DisplayString'.

I got these errors in my xtext editor.
I am trying to import object type from another xtext editor.
I dont get any errors in default type.

This is my grammar.


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


TypeStatement:
	'type' (type=BuiltInType | (pre=STRINGARG':') ? importtype=[TypedefStatement])
	(';' 
	|'{' (typesubstatements+=TypeSubStatement)* '}'); 


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

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


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


Previous Topic:Are grammar mixins transitive?
Next Topic:reference errors
Goto Forum:
  


Current Time: Tue Mar 19 05:11:55 GMT 2024

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

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

Back to the top