JetBrains / Nitra

Public Nitra repository
Other
554 stars 43 forks source link

Designing a parameter list #12

Closed asillye closed 9 years ago

asillye commented 9 years ago

This is a little bit howto question - was unsure where to post..

When designing a parameter list, is it possible to force the different types of list elements to appear only once? I mean:

syntax NamePar = "name" ":" Identifier;
syntax AuthorPar = "author" ":" UserIdentifier;
sytnax DescriptionPar = "description" ":" StringLiteral;
syntax MainDefVersion1 = Identifier "{" NamePar? AuthorPar? DescriptionPar "}";
syntax DefParts
{
  | Name  = NamePar 
  | Author = AuthorPar
  | Description = DescriptionPar
}
syntax MainDefVersion2 = Identifier "{" (DefParts; "," )* "}";

So under MainDef I would like to accept the NamePar, AuthorPar, DescriptionPar in any order but max only once. MainDef1 is almost ok, but enforces order, MainDefVersion2 works without order but accepts any number of parts, and also accepts the same one multiple times. (Currently we use the 2nd with postprocessing..)

Was thinking to just enter all permutations, but I have 15+ different of these params, so that's a no go..

The problem is somewhat similar to C# constructor initialization where you can give each property only once. e.g.

var exampleInstance = new MainDef { 
  Name = "Friends", 
  Author ="Chandler M.", 
  Description = "Bing!" ,
// can't write here Name again
}

Thank you Adam

someone-with-default-username commented 9 years ago

This is question of typing (code validation and name binding), not syntax. Ver.2 in your example is correct one syntax declaration, it needs only validation procedure (can be implemented with rule methods).

Design of typing process for languages is our next milestone.

attilah commented 9 years ago

I think a good example for this would be the PerMember part of the rule method for MapDeclarationBody syntax declaration in NitraSyntax.nitra.

From: someone-with-default-username [mailto:notifications@github.com] Sent: Thursday, November 13, 2014 2:39 PM To: JetBrains/Nitra Subject: Re: [Nitra] Designing a parameter list (#12)

This is question of typing (code validation and name binding), not syntax. Ver.2 in your example is correct one syntax declaration, it needs only validation procedure (can be implemented with rule methods).

Design of typing process for languages is our next milestone.

— Reply to this email directly or view it on GitHubhttps://github.com/JetBrains/Nitra/issues/12#issuecomment-62891003.

asillye commented 9 years ago

Thanks Guys. We worked around currently - let's see V2 with the typing.