MGrammar projections: numbers without inverted commas Hi,<br><br>I've a problem. I have &quot;M&quot; model with Integer field. <br>I've written DSL for this model and I want parse DSL input to &quot;M&quot; language for compilation and deploying to repository. <br>Because MGrammar output contains numbers with inverted commas, I can't compile it. <br><br>Look at simple examples:<br><br>When I write fixed number in projection, I get number without inverted commas in output:<br><br> Input: 1+2<br><br> DSL:  module Expression {<br>    language Expression {      <br>        token Digits = (&quot;0&quot;..&quot;9&quot;)+;<br>        syntax Main<br>          = e:E =&gt; e;<br>        syntax E<br>          = d:Digits =&gt; d<br>          | l:E &quot;+&quot; r:E =&gt; Add[1,2] ;<br>    }<br>}<br><br>Output: Add[ 1, 2]<br><br><br>But when I use projection with number parameters:<br><br>Input: 1+2<br><br> DSL:  module Expression {<br>    language Expression {      <br>        token Digits = (&quot;0&quot;..&quot;9&quot;)+;<br>        syntax Main<br>          = e:E =&gt; e;<br>        syntax E<br>          = d:Digits =&gt; d<br>          | l:E &quot;+&quot; r:E =&gt; Add[l,r] ;<br>    }<br>}<br><br>Output: Add[ &quot;1&quot;, &quot;2&quot;]<br><br>I get output with inverted commas :(<br><br><br>Do you know how can I make projections with numbers without inverted commas?<br>© 2009 Microsoft Corporation. All rights reserved.Tue, 14 Jul 2009 16:40:52 Za7125010-ddf1-417e-afaf-9b55bbcacb26http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#a7125010-ddf1-417e-afaf-9b55bbcacb26http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#a7125010-ddf1-417e-afaf-9b55bbcacb26Marcin Kruszynskihttp://social.msdn.microsoft.com/Profile/en-US/?user=Marcin%20KruszynskiMGrammar projections: numbers without inverted commas Hi,<br><br>I've a problem. I have &quot;M&quot; model with Integer field. <br>I've written DSL for this model and I want parse DSL input to &quot;M&quot; language for compilation and deploying to repository. <br>Because MGrammar output contains numbers with inverted commas, I can't compile it. <br><br>Look at simple examples:<br><br>When I write fixed number in projection, I get number without inverted commas in output:<br><br> Input: 1+2<br><br> DSL:  module Expression {<br>    language Expression {      <br>        token Digits = (&quot;0&quot;..&quot;9&quot;)+;<br>        syntax Main<br>          = e:E =&gt; e;<br>        syntax E<br>          = d:Digits =&gt; d<br>          | l:E &quot;+&quot; r:E =&gt; Add[1,2] ;<br>    }<br>}<br><br>Output: Add[ 1, 2]<br><br><br>But when I use projection with number parameters:<br><br>Input: 1+2<br><br> DSL:  module Expression {<br>    language Expression {      <br>        token Digits = (&quot;0&quot;..&quot;9&quot;)+;<br>        syntax Main<br>          = e:E =&gt; e;<br>        syntax E<br>          = d:Digits =&gt; d<br>          | l:E &quot;+&quot; r:E =&gt; Add[l,r] ;<br>    }<br>}<br><br>Output: Add[ &quot;1&quot;, &quot;2&quot;]<br><br>I get output with inverted commas :(<br><br><br>Do you know how can I make projections with numbers without inverted commas?<br>Mon, 23 Feb 2009 06:52:12 Z2009-02-23T06:52:12Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#cd138344-cf5e-4f3a-8f9e-281a04435a5bhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#cd138344-cf5e-4f3a-8f9e-281a04435a5bKraig Brockschmidthttp://social.msdn.microsoft.com/Profile/en-US/?user=Kraig%20BrockschmidtMGrammar projections: numbers without inverted commas Marcin--just wanted to let you know that I'm working on getting an answer for you from the development team. Hopefully I'll have something for you soon.<br><br>.KraigTue, 24 Feb 2009 16:58:04 Z2009-02-24T16:58:04Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#b76d9ee8-7ca0-49cb-b497-20a2be9a742chttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#b76d9ee8-7ca0-49cb-b497-20a2be9a742cPaul Vickhttp://social.msdn.microsoft.com/Profile/en-US/?user=Paul%20VickMGrammar projections: numbers without inverted commas Marcin,<br><br>Unfortunately, we don't yet have the capability to translate text on the right hand side of a production. So given a string &quot;1&quot;, there isn't any way directly in the language to translate it to the number 1. This is something we're working on for a future CTP, but it just isn't available yet. As a workaround, you'd have to create your own graph builder and supply that to the parser and do the translation in the graph builder.<br><br>Paul<hr class="sig">Paul Vick MSFTThu, 26 Feb 2009 00:42:12 Z2009-02-26T00:42:12Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#1fc7316e-f661-43bb-98de-c2cc6203d091http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#1fc7316e-f661-43bb-98de-c2cc6203d091Miguel Llopishttp://social.msdn.microsoft.com/Profile/en-US/?user=Miguel%20LlopisMGrammar projections: numbers without inverted commas<p>+1 for Paul´s comment.</p> <p>What your grammar is producing as &quot;number&quot; is the &quot;token Digit&quot; production.</p> <p>This is a documented issue. If you take a look into &quot;MGrammar Language Specification&quot; document, that comes with our CTP (under /Documents/), you will find at section 4.3.2. the following:</p> <p>        <em> (5)    Token rules do not permit a constructor to be specified and output text values.</em></p> <p>Converting this token value to an integer is a step that you'd need to do when you consume your graph output, as Paul mentioned.</p> <p>Happy coding,<br>M.<br></p>Thu, 26 Feb 2009 07:16:58 Z2009-02-26T07:16:58Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#34d55298-3cd1-4866-8a0c-d43e1dee893bhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#34d55298-3cd1-4866-8a0c-d43e1dee893bShawn Wildermuthhttp://social.msdn.microsoft.com/Profile/en-US/?user=Shawn%20WildermuthMGrammar projections: numbers without inverted commasAny word on a good solution to this?<hr class="sig">The Silverlight Tour is Coming to: Boston, MA - April 29-May 1, 2009 Washington, DC - June 16-18, 2009 http://silverlight-tour.com http://wildermuth.com http://agilitrain.comMon, 29 Jun 2009 20:26:56 Z2009-06-29T20:26:56Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#41548957-a49f-48cd-b091-5a078b9f161chttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#41548957-a49f-48cd-b091-5a078b9f161cdmatsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=dmatsonMGrammar projections: numbers without inverted commasI believe the following post should have a solution for you:<br/><a href="http://blogs.msdn.com/modelcitizen/archive/2009/06/17/top-six-common-mgrammar-integration-errors.aspx">Top Six Common MGrammar Integration Errors</a><br/>Specifically, Common Error #1: Getting Non-Text Output from MGrammar. Note that there's also a code download at the very bottom of the post with a sample C# project.<br/><br/>Let me know if this helps.<br/><br/>DavidMon, 13 Jul 2009 19:10:50 Z2009-07-13T19:10:50Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#e5b191d8-cca8-4ad1-94e0-6b09fc349f9ahttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#e5b191d8-cca8-4ad1-94e0-6b09fc349f9aShawn Wildermuthhttp://social.msdn.microsoft.com/Profile/en-US/?user=Shawn%20WildermuthMGrammar projections: numbers without inverted commasI appreciate the advice, but I'd love to know the future on this. It seems as though the idea of the output of a DSL needing to be text only is a severe limitation. I am of the opinion if most use of MGrammar is going to involve writing a parser, then the use of DSLs is going to be pretty limited. I'd like to see one of two solutions: <div><br/></div> <div>- Projection from MGrammar be closer to MGraph (this is my mantra for a few months now).</div> <div><br/></div> <div>or</div> <div><br/></div> <div>- Type inference in m.exe so that if I project with the MSchema as a reference, that simple type conversions should be supported (let us figure out how to make sure that the string will coalese into a MSchema type).</div> <div><br/></div> <div>Other ideas?</div><hr class="sig">The Silverlight Tour is Coming to: Boston, MA - April 29-May 1, 2009 Washington, DC - June 16-18, 2009 http://silverlight-tour.com http://wildermuth.com http://agilitrain.comMon, 13 Jul 2009 19:38:10 Z2009-07-13T19:38:10Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#8bc60f4d-a62d-4f73-95af-e5ed5174e4e6http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#8bc60f4d-a62d-4f73-95af-e5ed5174e4e6Matthew Wilson _diakopter_http://social.msdn.microsoft.com/Profile/en-US/?user=Matthew%20Wilson%20_diakopter_MGrammar projections: numbers without inverted commasHere's a tongue-in-cheek answer... (kindof).  I figure if the Original Poster is already going to be walking the syntax tree as the output of this parse of an expression language, he's going to have to do some arithmetic at some point anyway... ;)<br/> <br/> module Expression {<br/>     language Expression {<br/>         syntax WholeNum<br/>             = DigitNum<br/>             | tens:WholeNum<br/>               ones:DigitNum<br/>                 =&gt; Add[ Mult[10, tens], ones]<br/>             ;<br/>         token DigitNum<br/>             = &quot;0&quot; =&gt; 0<br/>             | &quot;1&quot; =&gt; 1<br/>             | &quot;2&quot; =&gt; 2<br/>             | &quot;3&quot; =&gt; 3<br/>             | &quot;4&quot; =&gt; 4<br/>             | &quot;5&quot; =&gt; 5<br/>             | &quot;6&quot; =&gt; 6<br/>             | &quot;7&quot; =&gt; 7<br/>             | &quot;8&quot; =&gt; 8<br/>             | &quot;9&quot; =&gt; 9<br/>             ;<br/>         syntax Main<br/>           = e:E =&gt; e;<br/>         syntax E<br/>           = d:WholeNum =&gt; d<br/>           | l:E &quot;+&quot; r:E =&gt; Add[l,r] ;<br/>     }<br/> }<br/> <br/> input: 12+345<br/> <br/> output: Add[<br/>   Add[<br/>     Mult[<br/>       10,<br/>       WholeNum[<br/>         1<br/>       ]<br/>     ],<br/>     2<br/>   ],<br/>   Add[<br/>     Mult[<br/>       10,<br/>       Add[<br/>         Mult[<br/>           10,<br/>           WholeNum[<br/>             3<br/>           ]<br/>         ],<br/>         4<br/>       ]<br/>     ],<br/>     5<br/>   ]<br/> ] <hr class=sig> 'blog: http://diakopter.blogspot.com/ JSMeta: http://jsmeta.org/Mon, 13 Jul 2009 22:51:05 Z2009-07-13T22:52:25Zhttp://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#18cd3332-be83-4813-a7bd-18e5070e7fe7http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/a7125010-ddf1-417e-afaf-9b55bbcacb26#18cd3332-be83-4813-a7bd-18e5070e7fe7dmatsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=dmatsonMGrammar projections: numbers without inverted commasThe project I posted is definitely a work-around. We definitely want this scenario to be much easier.<br/><br/>From <a href="http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/45cef89b-2bc5-4889-901d-f161a93257b0">http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/45cef89b-2bc5-4889-901d-f161a93257b0</a>:<br/><span style="font-family:'Calibri', 'sans-serif';color:#1f497d;font-size:11pt">“Our goal is to remove the distinctions between the function bodies in today’s MSchema and the right-hand-sides of grammar rules in today’s MGrammar. This includes a consistent set of operators and functions for use in both contexts as well as the ability to type-ascribe (a la today’s MSchema) the results. The corresponding design and implementation work is ongoing.”<br/></span><br/>I believe that's close to (or the same as) your first solution, if I'm understanding you correctly.<br/><br/>DavidTue, 14 Jul 2009 16:40:52 Z2009-07-14T16:40:52Z