Browse Source

Enable using patterns in place of catch clauses.

pull/100/head
Daniel Grunwald 15 years ago
parent
commit
a642c61a4e
  1. 2
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Match.cs
  2. 5
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs
  3. 29
      NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs

2
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Match.cs

@ -12,6 +12,8 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching @@ -12,6 +12,8 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
/// </summary>
public sealed class Match
{
// TODO: maybe we should add an implicit Match->bool conversion? (operator implicit bool(Match m) { return m != null; })
List<KeyValuePair<string, AstNode>> results = new List<KeyValuePair<string, AstNode>>();
internal int CheckPoint()

5
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Pattern.cs

@ -79,6 +79,11 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching @@ -79,6 +79,11 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
return p != null ? new SwitchSectionPlaceholder(p) : null;
}
public static implicit operator CatchClause(Pattern p)
{
return p != null ? new CatchClausePlaceholder(p) : null;
}
// Make debugging easier by giving Patterns a ToString() implementation
public override string ToString()
{

29
NRefactory/ICSharpCode.NRefactory/CSharp/Ast/PatternMatching/Placeholder.cs

@ -210,4 +210,33 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching @@ -210,4 +210,33 @@ namespace ICSharpCode.NRefactory.CSharp.PatternMatching
return child.DoMatchCollection(role, pos, match, backtrackingStack);
}
}
sealed class CatchClausePlaceholder : CatchClause
{
readonly AstNode child;
public CatchClausePlaceholder(AstNode child)
{
this.child = child;
}
public override NodeType NodeType {
get { return NodeType.Placeholder; }
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return ((IPatternAstVisitor<T, S>)visitor).VisitPlaceholder(this, child, data);
}
protected internal override bool DoMatch(AstNode other, Match match)
{
return child.DoMatch(other, match);
}
internal override bool DoMatchCollection(Role role, AstNode pos, Match match, Stack<Pattern.PossibleMatch> backtrackingStack)
{
return child.DoMatchCollection(role, pos, match, backtrackingStack);
}
}
}

Loading…
Cancel
Save