Permalink
Browse files

close #12: add MsBuild task for running IronMeta

  • Loading branch information...
kulibali committed Jan 8, 2016
1 parent e124390 commit 056bd8bad7f7619e1a0aa0c81545062330bd741e
Showing with 64 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +7 −0 README.md
  3. +1 −1 Source/CommonAssemblyInfo.cs
  4. +50 −0 Source/Library/IronMetaGenerate.cs
  5. +5 −0 Source/Library/Library.csproj
View
@@ -1,5 +1,6 @@
.vs
Source/IronMeta.snk
*.nupkg
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
View
@@ -11,6 +11,13 @@ IronMeta is available on [NuGet](https://www.nuget.org/packages/IronMeta/). To
Once you have installed the NuGet package, add a grammar file with the extension .ironmeta to your project. Then generate a C# class from it. You can do this in two ways:
- You can install a [Visual Studio extension](https://visualstudiogallery.msdn.microsoft.com/73263c7c-319f-4f9e-a05a-b493094a4eb0) that provides a custom tool for generating C# code from IronMeta files. You must set the "Custom Tool" property of your IronMeta file to be `IronMetaGenerator`. Then the C# code will be generated whenever your grammer file changes. Syntax errors will appear in your Error List.
- `IronMeta.Library.dll` contains an MsBuild task called "IronMetaGenerate". A simple example of how to use this:
<UsingTask TaskName="IronMetaGenerate" AssemblyFile="path_to\IronMeta.Library.dll" />
<Target Name="BeforeBuild">
<IronMetaGenerate Input="MyParser.ironmeta" Output="MyParser.g.cs" Namespace="MyNamespace" Force="true" />
</Target>
- A command-line program `IronMeta.exe` is included in the NuGet package, in the `tools` directory. The program takes the following arguments:
- `-o {output}` (optional): Specify the output file name (defaults to `{input}_.g.cs`).
- `-n {namespace}` (optional): Specify the namespace to use for the generated parser (defaults to the name of the directory the input file is in).
@@ -8,4 +8,4 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("4.2.*")]
[assembly: AssemblyInformationalVersionAttribute("4.2.3")]
[assembly: AssemblyInformationalVersionAttribute("4.2.4")]
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using IronMeta.Generator;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace IronMeta
{
/// <summary>
/// An MsBuild task for generating parsers.
/// </summary>
public class IronMetaGenerate : Task
{
[Required]
public string Input { get; set; }
public string Namespace { get; set; }
public string Output { get; set; }
public bool Force { get; set; }
static readonly Regex IronMetaFileName = new Regex(@"^(.*).ironmeta\s*$", RegexOptions.Compiled);

This comment has been minimized.

Show comment
Hide comment
@JayBazuzi

JayBazuzi Jan 11, 2016

Why not use Path.GetExtension()?

@JayBazuzi

JayBazuzi Jan 11, 2016

Why not use Path.GetExtension()?

This comment has been minimized.

Show comment
Hide comment
@kulibali

kulibali Jan 11, 2016

Owner

Because I tend to overgeneralize by default, I guess.

@kulibali

kulibali Jan 11, 2016

Owner

Because I tend to overgeneralize by default, I guess.

public override bool Execute()
{
if (string.IsNullOrWhiteSpace(Output))
{
var match = IronMetaFileName.Match(Input);
if (match.Success)
Output = match.Groups[1].Value + ".g.cs";
else
Output = Input + ".g.cs";
}
var result = CSharpShell.Process(Input, Output, Namespace, Force);
if (result.Success)
return true;
int num, offset;
result.MatchState.GetLine(result.ErrorIndex, out num, out offset);
Log.LogError("", "", "", Input, num, offset, num, offset, result.Error);
return false;
}
}
}
@@ -42,6 +42,10 @@
<AssemblyOriginatorKeyFile>..\IronMeta.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Tasks.v4.0" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Verophyle.Regexp, Version=1.1.5684.13780, Culture=neutral, PublicKeyToken=74cddc3ca888ce35, processorArchitecture=MSIL">
@@ -59,6 +63,7 @@
<Compile Include="Generator\IGenerator.cs" />
<Compile Include="Generator\AstNode.cs" />
<Compile Include="Generator\Parser.g.cs" />
<Compile Include="IronMetaGenerate.cs" />
<Compile Include="Matcher\Matcher.cs" />
<Compile Include="Matcher\MatchItem.cs" />
<Compile Include="Matcher\MatchResult.cs" />

0 comments on commit 056bd8b

Please sign in to comment.