#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; public class Util { // simplistic regex for formal parameters, any string of non-whitespace and not comma characters is allowed as a type name // this has to be changed to allow for e.g., generic types (S) and for expressions in actual parameters (max(x, 0) + 1)) private static string refOrOutGroup = @"(?:(?(out|ref))\s+)"; // "ref " | "out " private static string typeGroup = @"(?:(?[^,]+)\s+)"; private static string identGroup = @"(?:(?[^,]+)\s*)"; private static Regex formalParameterExpr = new Regex(@"\s*,?\s*" + refOrOutGroup + "?" + typeGroup + "?" + identGroup, RegexOptions.ECMAScript); public static IEnumerable ExtractParameters(string formalParameterSrc) { var matches = formalParameterExpr.Matches(formalParameterSrc); foreach (var m in matches.OfType()) { yield return new TerminalNode.FieldDefinition(m.Groups["refOrOut"].Value, m.Groups["type"].Value, m.Groups["id"].Value); } } }