|
|
Re: Reference output problem. [message #1768796 is a reply to message #1768794] |
Mon, 24 July 2017 04:17 |
Kaushal Patel Messages: 72 Registered: June 2017 |
Member |
|
|
Hi Christian,
I am writing a grammar for yang module.
//this is a small part of my dsl.
As you can see in the below code, I am trying to import 'typedef' of one module as a 'type' of other module.
typedef object-identifier {
type string {
pattern
'(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))(\.(0|([1-9]\d*)))*';
}
description
"The object-identifier type represents administratively
assigned names in a registration-hierarchical-name tree.
This type is a superset of the SMIv2 OBJECT IDENTIFIER type
since it is not restricted to 128 sub-identifiers. Hence,
this type SHOULD NOT be used to represent the SMIv2 OBJECT
IDENTIFIER type; the object-identifier-128 type SHOULD be
used instead.";
reference
"ISO9834-1: Information technology -- Open Systems
Interconnection -- Procedures for the operation of OSI
Registration Authorities: General procedures and top
arcs of the ASN.1 Object Identifier tree";
}
typedef object-identifier-128 {
type object-identifier {
pattern '\d*(\.\d*){1,127}';
}
description
"This type represents object-identifiers restricted to 128
sub-identifiers.
In the value set and its semantics, this type is equivalent
to the OBJECT IDENTIFIER type of the SMIv2.";
reference
"RFC 2578: Structure of Management Information Version 2
(SMIv2)";
}
Now I want the same output in two different files. I am importing different files for the 'type'.
module SNMPv2-MIB {
namespace "urn:ietf:params:xml:ns:yang:smiv2:SNMPv2-MIB";
prefix "snmpv2-mib";
import SNMPv2-TC {
prefix "snmpv2-tc";
}
// These are my import statements.
import ietf-yang-smiv2 {
prefix "smiv2";
}
import ietf-yang-types {
prefix "yang";
}
leaf sysDescr {
type yang:object-identifier; // < I want output like this in my other files
{
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.";
smiv2:max-access "read-only";
smiv2:oid "1.3.6.1.2.1.1.1";
}
leaf sysObjectID {
type yang:ietf-yang-types.object-identifier //< I got this output which is not correct.
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'.";
smiv2:max-access "read-only";
smiv2:oid "1.3.6.1.2.1.1.2";
}
I hope this will useful.
|
|
|
|
|
Re: Reference output problem. [message #1768799 is a reply to message #1768798] |
Mon, 24 July 2017 04:48 |
|
Sorry I don't understand
Can you please share a complete but minimal sample grammar
And sample model project
What is bad about
type yang:ietf-yang-types.object-identifier //< I got this
output which is not correct
What did you implement in scoping and iqualifiednameprovider
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Reference output problem. [message #1768800 is a reply to message #1768799] |
Mon, 24 July 2017 05:20 |
Kaushal Patel Messages: 72 Registered: June 2017 |
Member |
|
|
This is my grammar.
TypedefStatement:
'typedef' name=(STRINGARG|KEY_IDENTIFIER)
'{' (typedefsubstatemnet+=TypedefSubstatement)* '}';
TypedefSubstatement:
(TypeStatement
|DescriptionStatement
|ReferenceStatement
|DefaultStatement
|StatusStatement
)
;
//The crossreference must be done in different blocks
//identifier-ref-arg-str
//[TypedefStatement]
TypeStatement:
'type'
(type=BuiltInType | (pre=STRINGARG ':') ? imptype=[TypedefStatement])
(';'
|'{' (typesubstatements+=TypeSubStatement)* '}');
TypeSubStatement:
(
DefaultStatement
|EnumStatement
|LengthStatement
|PatternStatement
|RangeStatement
|TypeStatement
);
This is a yang dsl plugin which contains standard 'type' and 'typedef.
I am trying to reference from this file to another file. but I am not able to do it.
module ietf-yang-types {
namespace
"urn:ietf:params:xml:ns:yang:ietf-yang-types";
prefix "yang";
organization
"IETF NETMOD (NETCONF Data Modeling Language) Working Group";
description
"This module contains a collection of generally useful derived
YANG data types.
revision "2010-09-24" {
description "Initial revision.";
reference
"RFC 6021: Common YANG Data Types";
}
typedef counter32 {
type uint32;
description
"The counter32 type represents a non-negative integer
that monotonically increases until it reaches a
maximum value of 2^32-1 (4294967295 decimal), when it
wraps around and starts increasing again from zero.
In the value set and its semantics, this type is equivalent
to the Counter32 type of the SMIv2.";
reference
"RFC 2578: Structure of Management Information Version 2
(SMIv2)";
}
typedef zero-based-counter32 {
type counter32;
default "0";
description
"The zero-based-counter32 type represents a counter32
that has the defined 'initial' value zero.
In the value set and its semantics, this type is equivalent
to the ZeroBasedCounter32 textual convention of the SMIv2.";
reference
"RFC 4502: Remote Network Monitoring Management Information
Base Version 2";
}
typedef counter64 {
type uint64;
description
"The counter64 type represents a non-negative integer
that monotonically increases until it reaches a
maximum value of 2^64-1 (18446744073709551615 decimal),
when it wraps around and starts increasing again from zero.
In the value set and its semantics, this type is equivalent
to the Counter64 type of the SMIv2.";
reference
"RFC 2578: Structure of Management Information Version 2
(SMIv2)";
}
typedef zero-based-counter64 {
type counter64;
default "0";
description
"The zero-based-counter64 type represents a counter64 that
has the defined 'initial' value zero.
In the value set and its semantics, this type is equivalent
to the ZeroBasedCounter64 textual convention of the SMIv2.";
reference
"RFC 2856: Textual Conventions for Additional High Capacity
Data Types";
}
typedef gauge32 {
type uint32;
description
"The gauge32 type represents a non-negative integer, which
may increase or decrease, but shall never exceed a maximum
value, nor fall below a minimum value. The maximum value
cannot be greater than 2^32-1 (4294967295 decimal), and
the minimum value cannot be smaller than 0. The value of
a gauge32 has its maximum value whenever the information
being modeled is greater than or equal to its maximum
value, and has its minimum value whenever the information
being modeled is smaller than or equal to its minimum value.
If the information being modeled subsequently decreases
below (increases above) the maximum (minimum) value, the
gauge32 also decreases (increases).
In the value set and its semantics, this type is equivalent
to the Gauge32 type of the SMIv2.";
reference
"RFC 2578: Structure of Management Information Version 2
(SMIv2)";
}
typedef gauge64 {
type uint64;
description
"The gauge64 type represents a non-negative integer, which
may increase or decrease, but shall never exceed a maximum
value, nor fall below a minimum value. The maximum value
cannot be greater than 2^64-1 (18446744073709551615), and
the minimum value cannot be smaller than 0. The value of
a gauge64 has its maximum value whenever the information
being modeled is greater than or equal to its maximum
value, and has its minimum value whenever the information
being modeled is smaller than or equal to its minimum value.
If the information being modeled subsequently decreases
below (increases above) the maximum (minimum) value, the
gauge64 also decreases (increases).
In the value set and its semantics, this type is equivalent
to the CounterBasedGauge64 SMIv2 textual convention defined
in RFC 2856";
reference
"RFC 2856: Textual Conventions for Additional High Capacity
Data Types";
}
typedef object-identifier {
type string {
pattern
'(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))(\.(0|([1-9]\d*)))*';
}
description
"The object-identifier type represents administratively
assigned names in a registration-hierarchical-name tree.";
reference
"ISO9834-1: Information technology -- Open Systems
Interconnection -- Procedures for the operation of OSI
Registration Authorities: General procedures and top
arcs of the ASN.1 Object Identifier tree";
}
typedef object-identifier-128 {
type object-identifier {
pattern '\d*(\.\d*){1,127}';
}
description
"This type represents object-identifiers restricted to 128
sub-identifiers.
In the value set and its semantics, this type is equivalent
to the OBJECT IDENTIFIER type of the SMIv2.";
reference
"RFC 2578: Structure of Management Information Version 2
(SMIv2)";
}
typedef timeticks {
type uint32;
description
"The timeticks type represents a non-negative integer that
represents the time, modulo 2^32 (4294967296 decimal), in
hundredths of a second between two epochs. When a schema
node is defined that uses this type, the description of
the schema node identifies both of the reference epochs.
In the value set and its semantics, this type is equivalent
to the TimeTicks type of the SMIv2.";
reference
"RFC 2578: Structure of Management Information Version 2
(SMIv2)";
}
typedef timestamp {
type timeticks;
description
"The timestamp type represents the value of an associated
timeticks schema node at which a specific occurrence
happened. The specific occurrence must be defined in the
description of any schema node defined using this type. When
the specific occurrence occurred prior to the last time the
associated timeticks attribute was zero, then the timestamp
value is zero. Note that this requires all timestamp values
to be reset to zero when the value of the associated timeticks
attribute reaches 497+ days and wraps around to zero.
In the value set and its semantics, this type is equivalent
to the TimeStamp textual convention of the SMIv2.";
reference
"RFC 2579: Textual Conventions for SMIv2";
}
}
} // module ietf-yang-types
This is my another DSL plugin 'snmpv2-mib.yang'
I am trying to reference 'type' from ietf-yang-types.yang > snmpv2-mib.yang
module SNMPv2-MIB {
namespace "urn:ietf:params:xml:ns:yang:smiv2:SNMPv2-MIB";
prefix "snmpv2-mib";
import SNMPv2-TC {
prefix "snmpv2-tc";
}
import ietf-yang-smiv2 {
prefix "smiv2";
}
import ietf-yang-types {
prefix "yang";
}
organization
"IETF SNMPv3 Working Group";
revision 1993-04-01 {
description
"The initial revision of this MIB module was published
as RFC 1450.";
}
container SNMPv2-MIB {
config false;
container system {
smiv2:oid "1.3.6.1.2.1.1";
leaf sysDescr {
type yang:ietf-yang-types.object-identifier
{
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.";
smiv2:max-access "read-only";
smiv2:oid "1.3.6.1.2.1.1.1";
}
leaf sysObjectID {
type yang:object-identifier;
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'.";
smiv2:max-access "read-only";
smiv2:oid "1.3.6.1.2.1.1.2";
}
I hope now you can understand my problem.
Thanks.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Reference output problem. [message #1768955 is a reply to message #1768947] |
Tue, 25 July 2017 08:06 |
|
in eclipse you find a file menu
there you can select new JavaClass
Enter a package and a name
select DefaultDeclarativeQualifiedNameProvider as supertyper
implement a
QualifiedName qualifiedName(<TypeYouWantToName> xxxx) {
//TODO
return QualifiedName.create("part1", "part2");
}
method
add a binding to yourdslruntimemodule
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: Reference output problem. [message #1769037 is a reply to message #1769032] |
Wed, 26 July 2017 04:47 |
|
well its nice to have 1000 lines of young files but its not nice not to have a language spec
you did not share your nameprovider
thus it could be
public class MyDslQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
@Inject
private IQualifiedNameConverter qnc;
public QualifiedName qualifiedName(TypedefStatement s) {
return qnc.toQualifiedName(s.getName());
}
}
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
override bindIQualifiedNameProvider() {
MyDslQualifiedNameProvider
}
}
or it could be something different like ( i dont know how that stuff before the colon work?)
package org.xtext.example.mydsl3;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
import org.xtext.example.mydsl3.myDsl.Module;
import org.xtext.example.mydsl3.myDsl.PrefixStatement;
import org.xtext.example.mydsl3.myDsl.Statement;
import org.xtext.example.mydsl3.myDsl.TypedefStatement;
import com.google.inject.Inject;
public class MyDslQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
@Inject
private IQualifiedNameConverter qnc;
public QualifiedName qualifiedName(TypedefStatement s) {
// TODO handle submodule etc
//TODO are multiple prefixes possible then better adapt
// IDefaultResourceDescritionStrategy
// its your logic
Module m = EcoreUtil2.getContainerOfType(s, Module.class);
if (m != null) {
for (Statement sm : m.getStatements()) {
if (sm instanceof PrefixStatement) {
String name = ((PrefixStatement) sm).getName();
if (name != null) {
// dont know if you have a ivalueconverter service that strips the ""
name = name.substring(1, name.length()-1);
return qnc.toQualifiedName(name).append(qnc.toQualifiedName(s.getName()));
}
}
}
}
return qnc.toQualifiedName(s.getName());
}
}
package org.xtext.example.mydsl3.scoping;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.scoping.impl.ImportNormalizer;
import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider;
import org.xtext.example.mydsl3.myDsl.TypeStatement;
import com.google.inject.Inject;
public class MyDslImportedNamespaceAwareLocalScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {
@Inject
private IQualifiedNameConverter qnc;
@Override
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(EObject context, boolean ignoreCase) {
List<ImportNormalizer> result = super.internalGetImportedNamespaceResolvers(context, ignoreCase);
if (context instanceof TypeStatement) {
TypeStatement s = (TypeStatement)context;
if (s.getPre() != null)
result.add(doCreateImportNormalizer(qnc.toQualifiedName(((TypeStatement) context).getPre()) , true, ignoreCase));
}
return result;
}
}
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
override bindIQualifiedNameProvider() {
MyDslQualifiedNameProvider
}
override configureIScopeProviderDelegate(Binder binder) {
binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
.to(MyDslImportedNamespaceAwareLocalScopeProvider)
}
}
or you turn the prefix thingy to a reference as well and implement scoping based on the prefix thingy
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|