source: branches/HeuristicLab.Problems.GPDL/HeuristicLab.Problems.GPDL/3.4/SourceReader.cs @ 9430

Last change on this file since 9430 was 9430, checked in by gkronber, 7 years ago

initial import of GPDL parser plugin

File size: 1.3 KB
Line 
1using System.Collections.Generic;
2using System;
3using System.Linq;
4using System.Text;
5using System.Text.RegularExpressions;
6
7public class SourceReader {
8  private static Action<string> nextAction;
9  public static void WithNext(Action<string> action) {
10    if (nextAction != null) throw new ArgumentException();
11    nextAction = action;
12  }
13  public static void Handle(string src) {
14    if (nextAction != null)
15      nextAction(src);
16    nextAction = null;
17  }
18
19  private static Regex formalParameterExpr = new Regex(@"\s*,?\s*((?<refOrOut>(out|ref))\s+)?(?<type>[_\w]*)\s+(?<id>[_\w]*)\s*");
20  public static IEnumerable<TerminalNode.FieldDefinition> ExtractFormalParameters(string formalParameterSrc) {
21    var match = formalParameterExpr.Match(formalParameterSrc);
22    var matches = formalParameterExpr.Matches(formalParameterSrc);
23
24    foreach (var m in matches.OfType<Match>()) {
25      yield return new TerminalNode.FieldDefinition(m.Groups["refOrOut"].Value, m.Groups["type"].Value, m.Groups["id"].Value);
26    }
27    //var nParameters = match.Groups["id"].Captures.Count;
28    //for (int i = 0; i < nParameters; i++) {
29    //  yield return new TerminalNode.FieldDefinition(match.Groups["refOrOut"].Captures[i].Value, match.Groups["type"].Captures[i].Value, match.Groups["id"].Captures[i].Value);
30    //}
31  }
32}
Note: See TracBrowser for help on using the repository browser.