Visual Studio Developer Center > Visual Studio Forums > Visual Studio Extensibility > Help Creating Default Managed Babel Project

Unanswered Help Creating Default Managed Babel Project

  • Saturday, February 16, 2008 6:18 AM
     
     
    I'm trying to create a new language service for a small language I've written, and I can't seem to figure out how to create the new managed babel language project.  I've followed the step in the SDK and in the Managed Babel Overview( I have the 2007.02 SDK but the Overview PDF is from 7/21/06), but neither of them actually setup the Babel files.  In both cases, the step are to create a new "Visual Studio Integration Package".  After going through the wizard, I have a shell project with a Guid.cs and VsPkg.cs file, just as the docs say.  However, the next step is to add the "invariant" (e.g. AuthoringScope.cs) and "user supplied" (e.g. Resolver.cs) files, but I can't find where to add them from.  The docs don't explain this.  I can't tell if the wizard was supposed to create them, or if I have to hunt them down and copy them manually.  It's been very very frustrating trying to understand what to do.

    It looks now like I'll have to copy the ManagedMyC project, delete all of the specific stuff, and try to start over.  Is this what others have done?  Have I missed some important step regarding the "invariant" files like AuthoringScope.cs?

    Thanks,
    Jeff

All Replies

  • Saturday, February 16, 2008 12:17 PM
    Moderator
     
     
    Hi Jeff,

    Have a look at my blog post: Simple Managed Language Service Sample - MyLanguageService

    Hope that helps,
  • Sunday, February 17, 2008 4:59 AM
     
     

    Thank you for the sample project, Dmitry.  I was able to get my language service working last night after copying MyManagedC and replacing some of its files.

     

    For others with the same question, I copied MyManagedC from the SDK samples folder.  It has a ManagedBabel folder that contains links (inside the VS proj, not on disk) to the Managed Babel source files.  These files are also located in the SDK, under VisualStudioIntegration\Common\Source\CSharp\Babel\.  Copy all of these files, except the ManagedBabel.files file, into the ManagedBabel folder in your language service project.  I did this so I could make edits to Managed Babel as needed, because it does not seem to have been finished (you can see lots of commented out code in it).

    Next, I replaced the yacc and lexer file with one for my language.  In MyManagedC, building your project sends these files through mppg and mplex and produces csharp files for the lexer and parser.  I found when I started to add actions to my parser rules that I could not debug into the parser source because VS thought the breakpoints and errors were relativ to lines in the parer.y file.  To work around this, I modified the project xml to create msbuild targets that manually run mppg and mplex before building.  I often have to manually clean the project before I can get VS to rerun mppg, but it still beats not having any source to debug.  Now, I can set breakpoints in the mppg output parser csharp file.  For others, here's how I did it.  These changes should be made to your csproj that contains the lexer and parser files.

     

    First, tell VS to compile your generated csharp files instead of your .y and .lex files:

    Code Snippet

     

      <ItemGroup>
        <Compile Include="Gen\lexer.mplex.cs" />
        <Compile Include="Gen\parser.mppg.cs" />
      </ItemGroup>
      <ItemGroup>
        <None Include="Generated\lexer.lex" />
        <None Include="Generated\parser.y" />
      </ItemGroup>

     

     

    Next, setup build targets for msbuild.

     

    Code Snippet
    <Import Project="C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Tools\Build\Microsoft.VsSDK.targets" />
      <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
           Other similar extension points exist, see Microsoft.Common.targets.
      -->
      <Target Name="BeforeBuild">
      </Target>
      <Target Name="AfterBuild">
      </Target>
      <PropertyGroup>
        <GenDir>$(ProjectDir)gen</GenDir>
        <BinderDir>$(ProjectDir)binder</BinderDir>
        <ParserDir>$(ProjectDir)Generated</ParserDir>
        <ColorizationDir>$(ParserDir)\Colorization</ColorizationDir>
        <KeywordDir>$(ParserDir)\Keywords</KeywordDir>
        <BuiltInDir>$(BinderDir)\builtins</BuiltInDir>
        <ToolsDir>$(ProjectDir)..\Tools</ToolsDir>
        <LocalBinDir>$(ToolsDir)\Bin</LocalBinDir>
        <MppgExe>"C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Tools\bin\mppg.exe"</MppgExe>
        <MplexExe>"C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Tools\bin\MPLex.exe"</MplexExe>
      </PropertyGroup>
      <Target Name="BeforeBuild" Outputs="$(GenDir)\Parser.mppg.cs;$(GenDir)\lexer.mplex.cs" DependsOnTargets="BuildGen">
      </Target>
      <Target Name="AfterClean" DependsOnTargets="CleanGen">
      </Target>
      <!-- Clean generated file target -->
      <Target Name="CleanGen">
        <Delete Condition="Exists('$(GenDir)')" Files="&#xD;&#xA;            $(GenDir)\parser.mppg.cs;&#xD;&#xA;            " TreatErrorsAsWarnings="true">
        </Delete>
      </Target>
      <!-- Build generated file target -->
      <Target Name="BuildGen" Outputs="$(GenDir)\Parser.mppg.cs;" DependsOnTargets="Generate_ParserMppgCs">
      </Target>
      <!-- Create gen directory -->
      <Target Name="CreateGenDir">
        <MakeDir Directories="$(GenDir)" Condition="!Exists('$(GenDir)')" />
      </Target>
      <!-- Generate parser.mppg.cs -->
      <Target Name="Generate_ParserMppgCs" DependsOnTargets="CreateGenDir" Inputs="$(ParserDir)\parser.y" Outputs="$(GenDir)\parser.mppg.cs">
        <!-- C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Tools\bin\MPLex.exe "/out:obj\Debug\lexer.cs" "/frame:Generated\mplex.frame" "Generated\lexer.lex"  -->
        <Exec Command="$(MplexExe) &quot;/out:$(GenDir)\lexer.mplex.cs&quot; &quot;/frame:Generated\mplex.frame&quot; &quot;Generated\lexer.lex&quot;" WorkingDirectory="$(ProjectDir)" Outputs="$(GenDir)\lexer.mplex.cs" />
        <Message Text="Generating $(GenDir)\parser.mppg.cs..." />
        <!-- (2) generate contents of mppg file and write it to parser.mppg.cs.no_pragmas -->
        <Exec Command="$(MppgExe) /no-lines &quot;Generated\parser.y&quot; &gt; &quot;$(GenDir)\parser.mppg.cs&quot; 2&gt;&quot;$(GenDir)\errors.txt&quot;" WorkingDirectory="$(ProjectDir)" Outputs="$(GenDir)\parser.mppg.cs">
          <Output TaskParameter="Outputs" ItemName="ParserMppg" />
        </Exec>
      </Target>
      <PropertyGroup>
        <PreBuildEvent>
        </PreBuildEvent>
      </PropertyGroup>

     

    Hopefully this helps anyone else with my same questions.  I asked my colleague at work and he also started from the MyManagedC sample when he wrote his language service, so it seems that's the easiest option.

     

    -Jeff

     

    (P.S., sorry about the colors.  the message editor went crazy on me)