Beispiel #1
0
        public string Parse(IParsedObject parent, ref System.IO.StreamReader file, params object[] parts)
        {
            if (!(parent is TaskContainer)) {
                throw new SyntaxErrorException ();
            }
            var name = (string)parts[0];
            var _do = (string)parts[1];

            var match = Regex.Match (name, ":(\\w+)");
            if (!match.Success)
                throw new SyntaxErrorException ();
            name = match.Groups[1].Value;

            string line = null;
            if (_do != "do") {
                while (!string.IsNullOrEmpty (line = file.ReadLine ())) {
                    match = Regex.Match (line, "^\\s*do\\b(.*)");
                    if (!match.Success) {
                        if (EmptyLine (line)) {
                            continue;
                        } else {
                            throw new SyntaxErrorException ();
                        }
                    } else {
                        _do = "do";
                        line = match.Groups[1].Value;
                        break;
                    }
                }
                if (_do != "do")
                    throw new SyntaxErrorException ();
            } else {
                line = (string)parts[2];
            }

            var _namespace = new PlainNamespace (name, parent);
            var end = false;
            do {
                if (string.IsNullOrEmpty(line)) continue;
                var child = CrakeFileParser.MatchKeyword (_namespace, ref file, line);
                match = Regex.Match (child, "^\\s*end\\b(.*)");
                if (match.Success) {
                    line = match.Groups[1].Value;
                    end = true;
                    break;
                }
            } while (!string.IsNullOrEmpty (line = file.ReadLine ()));

            if (!end)
                throw new SyntaxErrorException ();

            if (_namespace.LastDesc != null) throw new SyntaxErrorException("desc for no task");

            foreach (var task in _namespace.Tasks) {
                task.Name = string.Format ("{0}:{1}", _namespace.Name, task.Name);
                ((TaskContainer)parent).Tasks.Add (task);
            }

            return line;
        }
Beispiel #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 desc = string.Empty;
            var match = Regex.Match(line, "^(\"([^\\\\\"]*(:?\\\\.[^\\\\\"]*)*)\")(.*)");
            if (match.Success) {
                desc = Regex.Unescape(match.Groups[2].Value);
                line = match.Groups[4].Value;
            } else if ((match = Regex.Match(line, "^'([^']*)'(.*)")).Success) {
                desc = 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;
            }
            ((TaskContainer)parent).LastDesc = new PlainDesc(desc, parent);

            return line;
        }
Beispiel #3
0
 public string[] IsMatch(IParsedObject parent, ref System.IO.StreamReader file, string text)
 {
     var match = Regex.Match(text, "^\\s*$");
     if (match.Success) {
         return new string[] { string.Empty };
     }
     return null;
 }
Beispiel #4
0
 public string[] IsMatch(IParsedObject parent, ref System.IO.StreamReader file, string text)
 {
     var match = Regex.Match(text, "^\\s*(public|protected|private)\\s*(.*)");
     if (match.Success) {
         return new string[]{ match.Groups[2].Value };
     }
     return null;
 }
Beispiel #5
0
 public string[] IsMatch(IParsedObject parent, ref System.IO.StreamReader file, string text)
 {
     if (!string.IsNullOrEmpty (text)) {
         if (Regex.IsMatch(text, "^\\s*end\\b")){
             return new string[] { text };
         }
     }
     return null;
 }
Beispiel #6
0
 internal static string MatchKeyword(IParsedObject parent, ref StreamReader file, string line)
 {
     foreach (IKeyword keyword in Keywords) {
     var match = keyword.IsMatch(parent, ref file, line);
     if (match != null) {
       return keyword.Parse(parent, ref file, match);
     }
       }
       return null;
 }
Beispiel #7
0
 public string[] IsMatch(IParsedObject parent, ref System.IO.StreamReader file, string text)
 {
     if (!string.IsNullOrEmpty (text)) {
         var match = Regex.Match (text, "^\\s*task\\s+(.*)");
         if (match.Success) {
             return new string[] { match.Groups[1].Value };
         }
     }
     return null;
 }
Beispiel #8
0
 public string[] IsMatch(IParsedObject parent, ref System.IO.StreamReader file, string text)
 {
     if (!string.IsNullOrEmpty (text)) {
         var match = Regex.Match (text, "^\\s*namespace\\s+([^\\s]*)(\\s+(do)\\b)?(.*)");
         if (match.Success) {
             var name = match.Groups[1].Value == "do" ? string.Empty : match.Groups[1].Value;
             var _do = match.Groups[1].Value == "do" ? "do" : match.Groups[3].Value;
             return new string[] { name, _do, match.Groups[4].Value };
         }
     }
     return null;
 }
Beispiel #9
0
        public string Parse(IParsedObject parent, ref System.IO.StreamReader file, params object[] parts)
        {
            if (!(parent is CrakeFile)) throw new SyntaxErrorException();

            var method = new MethodHelper();
            var text = (string)parts[0];
            var step = Step.Return;
            do {
                foreach (var c in text.ToCharArray()) {
                    step = ParseChar(method, step, c);
                }
            } while (null != (text = file.ReadLine()));
            return null;
        }
Beispiel #10
0
        public string Parse(IParsedObject parent, ref System.IO.StreamReader file, params object[] parts)
        {
            if (!(parent is CrakeFile))
            {
                throw new SyntaxErrorException();
            }

            if (string.IsNullOrEmpty((string)parts[0]))
            {
                throw new SyntaxErrorException();
            }

            ((CrakeFile)parent).Imports.Add((string)parts[0]);
            return null;
        }
Beispiel #11
0
 public string[] IsMatch(IParsedObject parent, ref System.IO.StreamReader file, string text)
 {
     if (!string.IsNullOrEmpty(text)) {
         var match = Regex.Match(text, "^\\s*desc\\s+(.*)");
         if (match.Success) {
             return new string[] { match.Groups[1].Value };
         }
         /*
         var match = Regex.Match(text, "^\\s*desc\\s+(\"[^\\\\\"]*(:?\\\\.[^\\\\\"]*)*\")?;?$");
         if (match.Success) {
             return new string[] { match.Groups[1].Value };
         } else if ((match = Regex.Match(text, "^\\s*desc\\s+('[^']*')?;?$")).Success) {
             return new string[] { match.Groups[1].Value };
         }
         */
     }
     return null;
 }
Beispiel #12
0
        public string Parse(IParsedObject parent, ref System.IO.StreamReader file, params object[] parts)
        {
            if (!(parent is CrakeFile))
            {
                throw new SyntaxErrorException();
            }

            var dependency = (string)parts[0];
            var match = Regex.Match(dependency, "^\"(.+?)\";?$|^'(.+?)';?$");
            if (match.Success) {
                var name = string.IsNullOrEmpty(match.Groups[1].Value) ? match.Groups[2].Value : match.Groups[1].Value;
                ((CrakeFile)parent).Dependencies.Add(new CrakeFileDependency(name));
            } else if (Regex.IsMatch(dependency, "^[\\w\\.]+;?$")) {
                ((CrakeFile)parent).Dependencies.Add(new AssemblyDependency(dependency));
            } else {
                throw new SyntaxErrorException();
            }
            return null;
        }
Beispiel #13
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;
        }
Beispiel #14
0
 public PlainDesc(string text, IParsedObject parent)
 {
     Text = text;
     Parent = parent;
 }
Beispiel #15
0
 private int GetLineOfObject(IParsedObject obj)
 {
     return(marks[obj]);
 }
Beispiel #16
0
 public PlainTask(string name, IParsedObject parent)
 {
     this.parent = parent;
     Name = name;
     Prerequisites = new List<string>();
 }
Beispiel #17
0
 public string Parse(IParsedObject parent, ref System.IO.StreamReader file, params object[] parts)
 {
     return string.Empty;
 }
Beispiel #18
0
 public PlainNamespace(string name, IParsedObject parent)
 {
     this.Parent = parent;
     Name = name;
 }
Beispiel #19
0
 public string[] IsMatch(IParsedObject parent, ref System.IO.StreamReader file, string line)
 {
     throw new UnknownKeywordException(line);
 }
Beispiel #20
0
 public string Parse(IParsedObject parent, ref System.IO.StreamReader file, params object[] line)
 {
     throw new UnknownKeywordException((string)line[0]);
 }