.NET Framework Bookmark and Share   
 index > Microsoft Codename 'Oslo' > Getting rid of the extra { }
 

Getting rid of the extra { }

One of the most time-consuming aspects of creating a grammar appears to be figuring out how to get rid of extra stuff - like extra wrapper { } symbols that come from "nowhere".

I'm facing one of those now, and I just can't see where the extra brackets are coming from - but they cause invalid M as output, so they've gotta go.

Here are the relevant bits of grammar:

syntax AuthRule =
AuthAction autht:AuthType OpenParen role:C.List(RoleText, ",") CloseParen EndStatement
=> ClassAuthRule { AuthType = autht, Roles = role };

withC.List defined as:

syntax List(element, separator)
= n:element
=> { n }
| l:List(element, separator) separator n:element
=> { valuesof(l), n };

and RoleText defined as:

token Text = oq:'"' body:Language.Base.Letter+ cq:'"'
=> body;

syntax RoleText = body:Text
=> { Value = body };

The DSL input is

Allow Edit ("red", "blue");

What I get as output has too many brackets:

ClassAuthRule{
AuthType{
"Edit"
},
Roles{
{
{
Value{
"red"
}
},
{
Value{
"blue"
}
}
}
}
}

One pair of the outermost brackets for Roles shouldn't be there. What I should get (or at least want to get) is this:

Roles{
{
Value{
"red"
}
},
{
Value{
"blue"
}
}
}
}

Any ideas on how to remove the erroneous brackets are very welcome!!

Rockford Lhotka
Yes,

valuesof is sepecific to sequences and collections.

We are looking at operators on records now.
David Langworthy

Have you tried valuesof on your projector?

=> ClassAuthRule { AuthType = autht, Roles = valuesof(role) };

If that doesn't work, please post the full grammar.

David Langworthy

I have tried valuesof(role) - it results in this output in ipad:

Roles{
System.Dataflow.TermValuesWrapper
}

Here's the full grammar:

module CslaCommon
{
export Common;

language Common
{
// Parameterized List rule
syntax List(element, separator)
= n:element
=> { n }
| l:List(element, separator) separator n:element
=> { valuesof(l), n };

// Whitespace
token Tab = "\u0009";
token LF = "\u000A";
token CR = "\u000D";
token Space = "\u0020";
token Comma = ",";
token Whitespace = Tab | LF | CR | Space | Comma;
}
}

module Csla
{
import CslaCommon { Common as C };

language MCsla
{
final token True =
"true"
=> true;
final token False =
"false"
=> false;

//token Text = Language.Grammar.TextLiteral;
token Text = oq:'"' body:Language.Base.Letter+ cq:'"'
=> body;

syntax RoleText = body:Text
=> { Value = body };


token Param = p:(Language.Base.Digit+ | Text | True | False)
=> { Value = p };
token Token = Language.Base.Letter+ (Language.Base.Letter | Language.Base.Digit)*;

@{Classification["Keyword"]}
token Stereotype = "Object";

@{Classification["Keyword"]}
token In = "in";

@{Classification["Keyword"]}
token Scope = ("Public" | "Private");
@{Classification["Keyword"]}
token ReadOnly = "ReadOnly";
@{Classification["Keyword"]}
token Identity = "Identity";

@{Classification["Keyword"]}
token AuthAction = "Allow";
@{Classification["Keyword"]}
token AuthType = ("Create" | "Get" | "Edit" | "Delete");

@{Classification["Keyword"]}
token PropertyAuthAction = ("Allow" | "Deny");
@{Classification["Keyword"]}
token PropertyAuthType = ("Read" | "Write");

@{Classification["Keyword"]}
token Rule = "Rule";

final token EndStatement = ';';
final token BeginBlock = "{";
final token EndBlock = "}";
final token OpenParen = "(";
final token CloseParen = ")";

@{Classification["Comment"]}
token Comment = Language.Grammar.Comment;

syntax Boolean(e) =
e
=> true | empty => false;

syntax PropertyAuthRule =
ad:PropertyAuthAction autht:PropertyAuthType OpenParen role:C.List(RoleText, ",") CloseParen EndStatement
=> PropertyAuthRule { Action = ad, AuthType = autht, Roles = { valuesof(role) } };

syntax BusinessRuleNP =
Rule method:Token EndStatement
=> PropertyBizRule { Method = method, Blag = method };

syntax BusinessRuleWP =
Rule method:Token OpenParen params:C.List(Param, ",") CloseParen EndStatement
=> PropertyBizRule { Method = method, Params = { valuesof(params) } };

syntax BusinessRule =
np:BusinessRuleNP
=> np
| wp:BusinessRuleWP
=> wp;

syntax SimpleProperty =
scope:Scope ro:Boolean(ReadOnly) type:Token name:Token EndStatement
=> Property { Name = name, Scope =scope, ReadOnly = ro, Type = type };

syntax PropertyMembers =
p:PropertyAuthRule
=> p
| b:BusinessRule
=> b;

syntax ComplexProperty =
scope:Scope ro:Boolean(ReadOnly) type:Token name:Token BeginBlock items:PropertyMembers* EndBlock
=> Property { Name = name, Scope = scope, ReadOnly = ro, Type = type, PropertyMembers = { valuesof(items) } };

syntax Property =
s:SimpleProperty
=> s
| c:ComplexProperty
=> c;

syntax AuthRule =
AuthAction autht:AuthType OpenParen role:C.List(RoleText, ",") CloseParen EndStatement
=> ClassAuthRule { AuthType = autht, Roles = role };

syntax ClassMembers =
a:AuthRule
=> a
| p:Property
=> p;

syntax Object =
st:Stereotype class:Token In namespace:Token BeginBlock items:ClassMembers* EndBlock Identity ident:Token EndStatement
=> Class { Name = class, Namespace=namespace, Stereotype = st, Identity = ident, ClassMembers = { valuesof(items) } };

syntax Main = o:Object* => Classes { valuesof(o) };

interleave Ignore = C.Whitespace | Language.Grammar.Comment;
}
}

Rockford Lhotka

I'm comming back to life after the weekend . . .

Did you get this working?

David Langworthy
I have had the same issues in my grammars. The vauesof-Operator only seems to normalize values:
valuesof({ "x", { "x", "x", {"x"}}})
results in
{"x", "x", "x", "x"}

But it doesn't seem to normalize Entities (as defined in MGraph).
lcorneliussen
Yes,

valuesof is sepecific to sequences and collections.

We are looking at operators on records now.
David Langworthy
I just tried your grammar (with the following as input), and the extra layer of {} isn't there... I guess it was a bug that was fixed in the May 09 CTP?


Object foo in Blah {
Allow Edit ("red", "blue");
Allow Edit ("red", "blue");
} Identity Boo;
'blog: http://diakopter.blogspot.com/ JSMeta: http://jsmeta.org/
Matthew Wilson _diakopter_

You can use google to search for other answers

Custom Search

More Threads

• Oslo, ready for take off?
• Details on MGrammar Attributes ?
• IntelliPad or M are slow to start
• M0118: Cannot resolve the reference to 'Point'
• Welcome to the Microsoft Codename "Oslo" Forum
• Developing MSchema along with MGrammar to have the AST validated
• Removing a model from repository
• MGrammar interpreter generator (suggestion)
• Are Multi-User models possible?
• MGrammar for Behaviour-Driven Development