示例#1
0
 public void ShouldAllowRequireOnlyInRootDeclaration()
 {
     var file = new StreamReader(new MemoryStream());
     var parent = new PlainTask(null, null);
     var actual = imports.IsMatch(parent, ref file, "imports System;");
     Assert.IsNotNull(actual);
     imports.Parse(parent, ref file, actual);
 }
示例#2
0
        public string Parse(IParsedObject parent, ref System.IO.StreamReader file, params object[] parts)
        {
            if (!(parent is TaskContainer))
                throw new SyntaxErrorException ();

            var line = (string)parts[0];
            var task = new PlainTask (null, parent);
            var match = Regex.Match (line, "^\\s*:(\\w+)\\s+(.*)");
            if (match.Success) {
                task.Name = match.Groups[1].Value;
                line = match.Groups[2].Value;
            } else {
                throw new SyntaxErrorException ();
            }

              if ((match = Regex.Match (line, "^=>\\s+(.*)")).Success) {
            line = match.Groups[1].Value;
                if ((match = Regex.Match (line, "^\\[([^\\[]+)\\]\\s+(.*)")).Success) {
              line = match.Groups[2].Value;
                    var items = match.Groups[1].Value.Split(',');
                    foreach (var item in items) {
                        if ((match = Regex.Match(item, "^\\s*:(\\w+)\\b")).Success) {
                            task.Prerequisites.Add(match.Groups[1].Value);
                        } else if ((match = Regex.Match(item, "^\\s*\"([\\w:]+)\"\\s*$")).Success) {
                            task.Prerequisites.Add(match.Groups[1].Value);
                        } else {
                            throw new SyntaxErrorException("prerequisite syntax error");
                        }
                    }
                } else {
                    if ((match = Regex.Match(line, "^\\s*:(\\w+)\\s+(.*)")).Success) {
            task.Prerequisites.Add(match.Groups[1].Value);
                        line = match.Groups[2].Value;
                    } else if ((match = Regex.Match(line, "^\\s*\"([\\w:]+)\"\\s+(.*)")).Success) {
            task.Prerequisites.Add(match.Groups[1].Value);
            line = match.Groups[2].Value;
                    } else {
                        throw new SyntaxErrorException("prerequisite syntax error");
                    }
                }
            }

            var _do = false;
            do {
                if (!(match = Regex.Match (line, "^\\s*do\\s*(.*)")).Success) {
                    if (Regex.IsMatch (line, "^\\s*//|^\\s*$")) {
                        continue;
                    } else {
                        throw new SyntaxErrorException ("command not expected. expected do\n" + line);
                    }
                } else {
                    _do = true;
                    line = match.Groups[1].Value;
                    break;
                }
            } while (!string.IsNullOrEmpty (line = file.ReadLine ()));
            if (!_do) throw new SyntaxErrorException ("do not found");

            var end = false;
            var body = new StringBuilder();
            do {
                if (string.IsNullOrEmpty(line)) continue;
                if ((match = Regex.Match (line, "^\\s*end\\b(.*)")).Success) {
                    line = match.Groups[1].Value;
                    end = true;
                    break;
                } else {
                    body.AppendLine(line);
                }
            } while (null != (line = file.ReadLine ()));
            if (!end) throw new SyntaxErrorException("end not found");

            task.Body = body.ToString();

            if (((TaskContainer)parent).LastDesc != null) {
                task.Description = ((TaskContainer)parent).LastDesc.Text;
                ((TaskContainer)parent).LastDesc = null;
            }

              ResolveCalls(task);

            ((TaskContainer)parent).Tasks.Add (task);

            return line;
        }
示例#3
0
 private void ResolveCalls(PlainTask task)
 {
     task.Body = Regex.Replace(task.Body, "\\bPARAMS\\s*\\[[^\\]]+\\]", "Crake.CrakeParameters.$0", RegexOptions.Multiline);
 }
示例#4
0
 public void ShouldValidateParent()
 {
     var file = new StreamReader (new MemoryStream ());
     var parent = new PlainTask (null, null);
     keyword.Parse (parent, ref file, ":name1", "do");
 }
示例#5
0
 public void AddTask(PlainTask task)
 {
     throw new System.NotImplementedException();
 }