//default private static IIndentationGrammarAnalysis <SyntaxToken, SyntaxNode, GNode> match <GNode, TParent, T>( IIndentationGrammarAnalysis <SyntaxToken, SyntaxNode, GNode> self, Func <string, Scope, T> parser, Action <IIndentationGrammarAnalysis <SyntaxToken, SyntaxNode, GNode> > children, Action <TParent, T> then) where T : GNode, new() { return(self.match <TParent, T>((text, parent, scope) => { var result = parser(text, scope); if (result != null && then != null) { then(parent, result); } return result; }, children)); }
//roslyn public static IIndentationGrammarAnalysis <SyntaxToken, SyntaxNode, GNode> match <GNode, TParent, T>( this IIndentationGrammarAnalysis <SyntaxToken, SyntaxNode, GNode> self, Action <TParent, T> then, Action <IIndentationGrammarAnalysis <SyntaxToken, SyntaxNode, GNode> > children = null) where T : SyntaxNode where GNode : new() { return(self.match <TParent, GNode>((text, parent, scope) => { var expr = CSharp.ParseExpression(text) as T; var statement = expr == null ? CSharp.ParseStatement(text) as T : default(T); var result = statement ?? expr; if (result != null && !result.ContainsDiagnostics) { then(parent, result); return new GNode(); } return default(GNode); }, children)); }