Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #12: add MsBuild task for running IronMeta
- Loading branch information
1 parent
e124390
commit 056bd8b
Showing
5 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Why not use
Path.GetExtension()
?