Skip to content

Instantly share code, notes, and snippets.

@jagregory
jagregory / gist:17751
Created October 19, 2008 00:14
SmartIndentationBlog.ViewFilterSimple
View gist:17751
public class BooViewFilter : ViewFilter
{
public BooViewFilter(CodeWindowManager mgr, IVsTextView view) : base(mgr, view)
{}
}
View gist:17754
public bool Execute()
{
int line, col;
view.GetCaretPos(out line, out col);
indenter.SetIndentationForNextLine(line);
return false;
}
View gist:17761
string diffContent = File.ReadAllText("MyDiffFile.diff");
Diff diff = Diff.CreateFrom(diffContent);
View gist:17762
@@ -1,3 +1,6 @@
This is a small text file
+that I quite like,
with a few lines of text
-inside, nothing much.
View RebuildParser.cs
public void RebuildGitNumstatParser()
{
var contents = File.ReadAllText(@"..\..\..\SharpDiff\Parsers\GitNumstatParser.ometacs");
var result = Grammars.ParseGrammarThenOptimizeThenTranslate
<OMetaParser, OMetaOptimizer, OMetaTranslator>
(contents,
p => p.Grammar,
o => o.OptimizeGrammar,
t => t.Trans);
View GitNumstatParser.cs
public class GitNumstatParser : Parser
{
}
View NumstatTests.cs
[Test]
public void ParsesNumber()
{
var result = Parse<int>("1", x => x.Number);
Assert.That(result, Is.EqualTo(1));
}
View NumstatTests.cs
protected T Parse<T>(string text, Func<GitNumstatParser, Rule<char>> ruleFetcher)
{
return Grammars.ParseWith(text, ruleFetcher).As<T>();
}
View NumstatTests.cs
[Test]
public void ParsesAdditionsAndSubtractionValues()
{
var result = Parse<FileStats>("3\t8\tmyFile.txt\r\n", x => x.Number);
Assert.That(result.Additions, Is.EqualTo(3));
Assert.That(result.Subtractions, Is.EqualTo(8));
}
View FileStats.cs
public class FileStats
{
public FileStats(int additions, int subtractions)
{
Additions = additions;
Subtractions = subtractions;
}
public int Additions { get; private set; }
public int Subtractions { get; private set; }