Odeslat dotazOdeslat dotaz
 

OdpovědětMoving from Janurary CTP to May

  • 3. června 2009 22:33MyBrokenGnome Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    Sorry if this has already been covered over the past few days, but I didn't see it anywhere.  I'm using MGrammar in a project I'm working on to create a programming language.  I had taken some code from the MGBasic stuff as well as some other site I can't remember right now, both used the MGraphXamlReader and DynamicParserExtensions classes.  I had been loading my grammar via this code:

                var errorReporter = this.errorReporter;
                var compiler = new MGrammarCompiler
                {
                    SourceItems = new SourceItem[] {
                            new SourceItem {
                                Name = "EZLanguage",
                                ContentType = ContentType.Mg,
                                TextReader = new StringReader(grammarString)
                            },
                    },
                };
                if (compiler.Compile(errorReporter) != 0 || errorReporter.HasErrors)
                {
                    return null;
                }
                var dynamicParser = new DynamicParser();
                compiler.LoadDynamicParser(dynamicParser);

                return dynamicParser;

    And I've since switched it to (changed the names around but this code does work and parser isn't null after this runs

                        using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(language.mx"))
                        {
                            // Construct a DynamicParser based on the Simple.mx file
                            parser = DynamicParser.LoadFromStream(stream, "language");
                        }

    I've gone inside of the DynamicParserExtensions class, ParseToXaml method and changed this line which was giving an error
                var result = parser.Parse<object>(null, input, errorReporter);
    to
                var result = parser.Parse<object>(input, errorReporter, xamlMap);

    Which seems to me would still work as its still getting the same information.  However, when I run my app and try to map my code to xaml and then from xaml to c# objects (which used to work perfectly with this code) I'm now getting a

    An unhandled exception of type 'System.StackOverflowException'
    that just switches back and forth between the functions Parse, ParseToXaml, ParseToObject.  Has anyone experienced this and have any suggestions on how to get the MGraphXamlReader and DynamicParserExtensions classses to work with the new May CTP?  Thanks in advance!

Odpovědi

Všechny reakce

  • 4. června 2009 4:29Kraig BrockschmidtMSFT, ModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    There's actually a new object model with this CTP for dynamic parsing, and we're just about to post information on that in the next day or two. I just have to do a final review, so you can blame me for the delay :)

    I'll let you know as soon as it's live; it'll show up in our Featured Items as well on the home page so you can always just subscribe to that feed if you haven't already.

    .Kraig
  • 4. června 2009 8:59MyBrokenGnome Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    Kraig,

    Cool thanks, will be looking forward to that.
  • 4. června 2009 21:48Kraig BrockschmidtMSFT, ModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět

    The paper from Clemens Syzperski is now available at http://msdn.microsoft.com/en-us/library/dd878360.aspx. We're trying to improve the code formatting in the article, because the tool that we have to create an article like this has a whitespace phobia. But it should be plenty usable in the meantime. The URL will remain the same.

    .Kraig

  • 5. června 2009 6:09Shawn WildermuthMVPUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    The problem I think he's asking about (and that I need) is to know how to use a .mx image as a compiled grammar (as re-compiling the grammar is a time waster).  Is there a way to use a .mx file instead of the Compiler having to parse the .mg file?
    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.com
  • 5. června 2009 6:31Shawn WildermuthMVPUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Obsahuje kód
    I was suprised how simple it was to use a pre-complied image:

    This:

    Stream mgStream = File.OpenRead(mgPath);
    CompilationResults results = Compiler.Compile(
      new CompilerOptions
      {
        Sources = 
        {
          new TextItem 
          {
              Reader = new StreamReader(mgStream),
              ContentType = TextItemType.MGrammar 
          }
        }
      });
    theParser = results.ParserFactories[LanguageName].Create();
    theParser.GraphBuilder = new NodeGraphBuilder();
    
    


    Became this:

    var grammar = new MImage(mxPath);
    theParser = grammar.ParserFactories[LanguageName].Create();
    theParser.GraphBuilder = new NodeGraphBuilder();
    


    Nice!

    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.com
  • 5. června 2009 14:14MyBrokenGnome Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    I'm actually not sure either one of them is what I'm looking for.  When I was using the Janurary CTP I was using this code to load it

    var errorReporter = this.errorReporter;
                var compiler = new MGrammarCompiler
                {
                    SourceItems = new SourceItem[] {
                            new SourceItem {
                                Name = "EZLanguage",
                                ContentType = ContentType.Mg,
                                TextReader = new StringReader(grammarString)
                            },
                    },
                };
                if (compiler.Compile(errorReporter) != 0 || errorReporter.HasErrors)
                {
                    return null;
                }
                var dynamicParser = new DynamicParser();
                compiler.LoadDynamicParser(dynamicParser);

                return dynamicParser;


    You'll notice I'm using a string, grammarString.  This is not currently the issue as I've switched it over to use the compiled grammar file, so I don't think Shawn's example will help me.  When using the Janurary CTP I had been using the DynamicParsersExtensions and MGraphXamlReader classes to store the AST in XAML and then it was using LINQ to take the XAML and store them in classes.  Very much like these two guys did

    http://rogeralsing.com/2008/11/22/linqing-mgrammar-to-cil/
    http://www.nootaikok.com/2009/01/c-code-generation-using-mgrammar.html

    Now with the May CTP update the DynamicParsersExtensions and MGraphXamlReader classes no longer work.  I haven't read all of Kraig's post so it may or may not contain the answer I'm looking for, but basically I just need this functionality back (or something very close to it so I don't have to rewrite all my code :( )
  • 15. června 2009 18:58MyBrokenGnome Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    ::bump:: Anyone have any luck with this?  Looks like I'm going to have to revert back to the January ctp as the May version doesn't (apparently) do what we need it to.

    In case you're wondering why I need it to do this, using the techniques in the links from my last post I created a language in MGrammar that is very domain specific, but the code gets converted to C# and compiled on the fly.  With the May CTP I have yet to figure out how to get do the XAML mappings that I talked about in my previous post so that the MGraphXamlReader files will call the appropriate method depending on what type of node it reached in my MGrammar AST.
  • 18. června 2009 18:37Marcin Kruszynski Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    I have sucessfully converted Microsoft samples with MGraphXamlReader. May CTP still have old MGraph object model and I didn't change API to new model.
    My version of samples work for me.

    You can download them from: http://martinkruszynski.blogspot.com/2009/06/xaml-samples-ultra-flexible-event.html




    Martin Kruszyński

    BTW I have publicated my 2 Oslo samples recently: http://martinkruszynski.blogspot.com/2009/06/user-interface-modeling-with-oslo-my.html. In first my sample I tried to use new object model for MGraph and my parser works, but I'm waiting for more samples from Microsoft how to use new API.