Skip to content

Commit

Permalink
some work on BooColorizerParser generator to make it more reusable.. …
Browse files Browse the repository at this point in the history
…created a general pattern for a reusable code generator from ometa
  • Loading branch information
olsonjeffery committed Oct 19, 2008
1 parent 480e328 commit 0aab593
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
Expand Up @@ -20,6 +20,23 @@
</SccAuxPath>
<SccProvider>
</SccProvider>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>BooLangStudio.snk</AssemblyOriginatorKeyFile>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -71,9 +88,44 @@
<Name>BooColorizerParser</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="BooLangStudio.snk" />
</ItemGroup>
<ItemGroup>
<Folder Include="GeneratedCode\" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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.
Expand Down
Binary file added Source/BooColorizerParserGenerator/BooLangStudio.snk
Binary file not shown.
Expand Up @@ -6,22 +6,20 @@

namespace BooColorizerParserGenerator
{
public class OMetaGrammarCodeGenerator : OMetaCSConsoleProgram<BooColorizerParserGenerated>
public class OMetaGrammarCodeGenerator<TGrammar> : OMetaCSConsoleProgram<TGrammar> where TGrammar : OMeta<char>, new()
{
public void CompileGrammarFromSourceAndOutputToFile()
public void CompileGrammarFromSourceAndOutputToFile(string ometacsPath, string generatedClassPath)
{
// We want to make the default case simple and have it
// "magically" just work.
var ometacsPath = Environment.CurrentDirectory + @"\..\..\..\BooColorizerParser\BooColorizerParser.ometacs";
var generatedParserPath = Environment.CurrentDirectory + @"\..\..\..\BooColorizerParser\BooColorizerParserGenerated.cs";
var generatedCode =
Grammars.ParseGrammarThenOptimizeThenTranslate<OMetaParser, OMetaOptimizer, OMetaTranslator>
(File.ReadAllText(ometacsPath),
parser => parser.Grammar,
translator => translator.OptimizeGrammar,
optimizer => optimizer.Trans
);
Grammars.WriteGeneratedCode(generatedCode, generatedParserPath);
Grammars.WriteGeneratedCode(generatedCode, generatedClassPath);
}
}
}
8 changes: 6 additions & 2 deletions Source/BooColorizerParserGenerator/Program.cs
@@ -1,11 +1,15 @@
using System;

namespace BooColorizerParserGenerator
{
public class Program
{
public static void Main()
{
var grammarCodeGenerator = new OMetaGrammarCodeGenerator();
grammarCodeGenerator.CompileGrammarFromSourceAndOutputToFile();
var grammarCodeGenerator = new OMetaGrammarCodeGenerator<BooColorizerParser.ColorizerParser>();
var ometacsPath = Environment.CurrentDirectory + @"\..\..\..\BooColorizerParser\ColorizerParser.ometacs";
var generatedParserPath = Environment.CurrentDirectory + @"\..\..\..\BooColorizerParser\ColorizerParser.cs";
grammarCodeGenerator.CompileGrammarFromSourceAndOutputToFile(ometacsPath, generatedParserPath);
}
}
}

0 comments on commit 0aab593

Please sign in to comment.