Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Combining two grammars problem(Combine yang and xpath grammar)
Combining two grammars problem [message #1706031] Fri, 21 August 2015 08:43 Go to next message
Mario Toffia is currently offline Mario ToffiaFriend
Messages: 5
Registered: August 2015
Junior Member
Hi,

We're in progress of finalizing a grammar for the YANG model language. It has a expressions that are xpath expressions. I've prototyped (against better knowledge) a xpath grammar (using a ANTLR grammar as source). However the team tells me that it is not possible to combine the two grammars and get completeion/highlightning etc).

One of the problems is that it is possible in YANG to split strings as:
" /a"
' /b/c'
"/d/"+"e"
"/f"+' /g/h'

and thus the concatenated is what we need to feed to the xpath grammar part.

The other problem that they say it's impossible to have separate grammar file for xpath and use that in the yang.xtext and have all the ide goodies.

Is this solveable?

Cheers,
Mario
Re: Combining two grammars problem [message #1706080 is a reply to message #1706031] Fri, 21 August 2015 22:05 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hey Mario,

it's really hard to help you without some examples and more details on your YANG language and how it should use xPath. Where and how should xPath be embedded and what will it query?

In general it is possible to combine languages. The effort it will take depends on what your language should look like. That's why we need more information first.

Cheers,
Stefan
Re: Combining two grammars problem [message #1706138 is a reply to message #1706080] Mon, 24 August 2015 07:08 Go to previous messageGo to next message
Mario Toffia is currently offline Mario ToffiaFriend
Messages: 5
Registered: August 2015
Junior Member
Hi,

Sorry for being vauge. I'll try to explain a bit better.

In yang it is possible to place a must expression that is really constraints on managed elements that you model. It could look like this (simple one):
container interface {
         leaf ifType {
             type enumeration {
                 enum ethernet;
                 enum atm;
             }
         }
         leaf ifMTU {
             type uint32;
         }
         must "ifType != 'ethernet' or " +
              "(ifType = 'ethernet' and ifMTU = 1500)" {
             error-message "An ethernet MTU must be 1500";
         }
         must "ifType != 'atm' or " +
              "(ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)" {
             error-message "An atm MTU must be  64 .. 17966";
         }
     }


The must expression is really a XPath expression.
What I really wanted is that this xpath is not a QUOTED_STRING instead it is "my" xpath grammar so we can have completion/highlightning etc. but it must work in with string concatenation since you can break up a string in several parts (resulting in a complete xpath).

In our DSL the must expression is the following:
Must:
  'must' xpath=QUOTED_STRING (';'|'{'
    (description += Description |
     errorMessage += ErrorMessage |
     errorAppTag += ErrorAppTag | 
     reference += Reference |
     subelements +=FromExtension)* 
                
  '}')
;


/**
 * see RFC 6.1.3  (rfc6020#section-6.1.3)
 * 
 * A String can be surrounded with single or double quotes and broken over lines using a +
 */
terminal QUOTED_STRING  : 
      (('"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"') |
      ("'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"))
      (' '|'\t'|'\n'|'\r')*
      
      ('+'(' '|'\t'|'\n'|'\r')*
        (('"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"') |
        ("'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"))
        (' '|'\t'|'\n'|'\r')*
        )*
    ;


I hope this shares some more lights on my problem.

Cheers,
Mario
Re: Combining two grammars problem [message #1706156 is a reply to message #1706138] Mon, 24 August 2015 09:13 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hey Mario,

I must be missing something: Why would I want to split the XPath? At least in the examples above it doesn't make sense.

If you drop the splitting idea, then your proposal of replacing Quoted_String with the XPath parser rule would just work.

Cheers,
Stefan
Re: Combining two grammars problem [message #1706161 is a reply to message #1706156] Mon, 24 August 2015 09:50 Go to previous messageGo to next message
Mario Toffia is currently offline Mario ToffiaFriend
Messages: 5
Registered: August 2015
Junior Member
Hi,

Sorry but that how these guys do (I'd guess some people want to see everything in their 80 characters terminal windows) so it is out of my control.

I totally agree that would have been the natural thing to do if I where in control of the RFC - It's a IETF RFC (rfc6020 Smile)

Is it possible to handle this case using some form of a callback that can concatenate everything and pass it to the xpath root rule and thus get all support from xtext?

Cheers,
Mario Smile

[Updated on: Mon, 24 August 2015 09:51]

Report message to a moderator

Re: Combining two grammars problem [message #1706192 is a reply to message #1706161] Mon, 24 August 2015 15:28 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Oh I didn't know that your team does not control the langauge =)

In that case you'll have to parse the xPath as Strings in your grammar and then evaluate them in the different Xtext services (Validator, HighlightingCalculator, ProposalProvider etc.).

You can use the IDerivedStateComputer/DerivedStateAwareResource to hook into Xtext's lifecycle before all the services are run. There you parse all the xPath expressions and add them as secondary contents to your resource. You will want to keep track of where each parsed expression came from in the original yang source tree. Then you can use these parsed models to do validation, highlighting etc.

Cheers,
Stefan
Re: Combining two grammars problem [message #1706201 is a reply to message #1706192] Mon, 24 August 2015 18:13 Go to previous messageGo to next message
Mario Toffia is currently offline Mario ToffiaFriend
Messages: 5
Registered: August 2015
Junior Member
Thanks for the reply! Smile

We will do an test shot for this and hopefully we will get this right!

Cheers,
Mario
Re: Combining two grammars problem [message #1706636 is a reply to message #1706201] Fri, 28 August 2015 10:22 Go to previous messageGo to next message
Richard Senington is currently offline Richard SeningtonFriend
Messages: 1
Registered: August 2015
Junior Member
Hello all,

I work with Mario and I have been working on most of the implementation of the Yang language in XText. Mario has asked to to try to explain in a little more detail what I have done and where my issue is.

I reached the same conclusion that you have posted, that the XPath must be stored as a string.

This is in keeping with Yang itself, which defines most things as Strings internally.

I provide a new value converter to parse the string structure and convert it into a simple string without speech marks or concatenation.

I already make use of the Validator and can make use of the Highlighting and code completion hooks.
In the Validator I already look at the XPath so that is ok.

There are two directions to my questions.
1) doing it cleanly. Ideally I would embed one grammar inside the other, and gain all the above (highlighting completion etc). I could create a new language for XText, parse and highlight the string internally and translate the highlighting back (at least I think I can, there are problems with the broken strings). Is this the proposal for how to implement that part of this?

2) providing code following. This is rather like scoping. Currently the scoping system ignores xpath, but for many other elements it takes a name and finds the element it refers to. This is all fine. XPath can refer to many things. Is there a way to intercept the code following (f3) so that it gives a drop down box? Or for that matter allows you to follow parts of the XPath.

I hope that this is clear enough and that you can help me.

Richard
Re: Combining two grammars problem [message #1706704 is a reply to message #1706636] Fri, 28 August 2015 20:37 Go to previous message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hi Richard,

1) Yes, I would also create an xpath-language and use that to parse the converted string. Note that you will need to keep an offset mapping to translate all the highlighting and validation markers back to the original locations (which might be different due to concatenation)

2) Navigation can be customized through the IHyperLinkHelper interface. Have a look at the default implementations and the domain model example language. If you return several hyperlinks at one position, the user will get a dropdown.

Cheers,
Stefan
Previous Topic:Linux kernel (ARM) dts parser.
Next Topic:Accessing text file resource using Xtend
Goto Forum:
  


Current Time: Thu Apr 25 14:08:15 GMT 2024

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

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

Back to the top