public void ValidateSingleCommand(List <string> warnings, string command, string pcommand, bool hasSubset, string scriptName, string owner)
        {
            List <string> cmddata = splitCommandArguments(command);
            string        cmd     = cmddata[0].ToLower();

            cmddata.RemoveAt(0);
            dCommand dcmd = getCmd(cmd);

            if (cmddata.Contains("{"))
            {
                Warn(warnings, WarnType.MINOR, "Braces as raw arguments to a command (old-style block command?) in '<<" + command + ">>' for " + scriptName);
            }
            if ((cmd == "case" || cmd == "default") && owner.ToLower().StartsWith("choose"))
            {
                if ((cmd == "case" && cmddata.Count != 1) || (cmd == "default" && cmddata.Count != 0))
                {
                    Warn(warnings, WarnType.WARNING, "Invalid case '<<" + command + ">>' for " + scriptName);
                }
            }
            else if (dcmd == null)
            {
                Warn(warnings, WarnType.ERROR, "Unknown command '" + cmd + "' for " + scriptName);
            }
            else
            {
                if (cmddata.Count < dcmd.Reqs)
                {
                    Warn(warnings, WarnType.ERROR, "Not enough arguments in '<<" + command + ">>' (expected at least " + dcmd.Reqs + ") for " + scriptName);
                }
                byte itype = 0;
                for (int i = 0; i < command.Length; i++)
                {
                    if (itype == 0 && command[i] == '\"')
                    {
                        itype = 1;
                    }
                    else if (itype == 0 && command[i] == '\'')
                    {
                        itype = 2;
                    }
                    else if (itype == 1 && command[i] == '\"')
                    {
                        itype = 0;
                    }
                    else if (itype == 2 && command[i] == '\'')
                    {
                        itype = 0;
                    }
                }
                if (itype != 0)
                {
                    Warn(warnings, WarnType.WARNING, "Uneven quotes in '<<" + command + ">>' for " + scriptName);
                }
            }
        }
Beispiel #2
0
        public void LoadFrom(string[] lines)
        {
            string fname = "UNKNOWN";

            for (int i = 0; i < lines.Length; i++)
            {
                string cline = lines[i].Trim();
                if (cline.StartsWith("/<FILE:"))
                {
                    fname = cline.Substring("/<FILE:".Length);
                }
                if (!cline.StartsWith("//"))
                {
                    continue;
                }
                if (cline.Length < 4)
                {
                    cline = "//  ";
                }
                cline = cline.Substring(3).Trim();
                if (cline.StartsWith("<--["))
                {
                    string  objtype = cline.Substring(4, cline.Length - 5).ToLower();
                    dObject nobj    = null;
                    switch (objtype)
                    {
                    case "action":
                        nobj = new dAction();
                        Actions.Add((dAction)nobj);
                        break;

                    case "example":
                    case "tutorial":
                        nobj = new dTutorial();
                        Tutorials.Add((dTutorial)nobj);
                        break;

                    case "mechanism":
                        nobj = new dMechanism();
                        Mechanisms.Add((dMechanism)nobj);
                        break;

                    case "tag":
                        nobj = new dTag();
                        Tags.Add((dTag)nobj);
                        break;

                    case "command":
                        nobj = new dCommand();
                        Commands.Add((dCommand)nobj);
                        break;

                    case "language":
                        nobj = new dLanguage();
                        Languages.Add((dLanguage)nobj);
                        break;

                    case "event":
                        nobj = new dEvent();
                        Events.Add((dEvent)nobj);
                        break;

                    case "requirement":
                        break;

                    default:
                        Logger.Output(LogType.ERROR, "Unknown object type " + objtype + " in " + fname);
                        break;
                    }
                    if (nobj == null)
                    {
                        continue;
                    }
                    nobj.FileName = fname;
                    Objects.Add(nobj);
                    i++;
                    while (i < lines.Length)
                    {
                        cline = lines[i].Trim();
                        if (!cline.StartsWith("//"))
                        {
                            Logger.Output(LogType.ERROR, "Found line <<" + cline + ">> in the middle of an object declaration in " + fname);
                            i++;
                            continue;
                        }
                        if (cline.Length < 4)
                        {
                            cline = "//  ";
                        }
                        cline = cline.Substring(3);
                        if (cline == "-->")
                        {
                            break;
                        }
                        if (!cline.StartsWith("@"))
                        {
                            Logger.Output(LogType.ERROR, "Found line '// " + cline + "' in the middle of an object declaration in " + fname);
                            i++;
                            continue;
                        }
                        string typer = cline.Substring(1);
                        string value = "";
                        if (typer.Contains(' '))
                        {
                            value += typer.Substring(typer.IndexOf(' ') + 1);
                            typer  = typer.Substring(0, typer.IndexOf(' '));
                        }
                        while (i + 1 < lines.Length)
                        {
                            cline = lines[i + 1].Trim();
                            if (cline.Length < 4)
                            {
                                cline = "//  ";
                            }
                            cline = cline.Substring(3);
                            if ((cline.StartsWith("@") && !cline.StartsWith("@ ")) || cline == "-->")
                            {
                                break;
                            }
                            value += "\n" + cline;
                            i++;
                        }
                        nobj.ApplyVar(typer.ToLower(), value);
                        i++;
                    }
                }
            }
        }
 public void LoadFrom(string[] lines)
 {
     string fname = "UNKNOWN";
     for (int i = 0; i < lines.Length; i++)
     {
         string cline = lines[i].Trim();
         if (cline.StartsWith("/<FILE:"))
         {
             fname = cline.Substring("/<FILE:".Length);
         }
         if (!cline.StartsWith("//"))
         {
             continue;
         }
         if (cline.Length < 4)
         {
             cline = "//  ";
         }
         cline = cline.Substring(3).Trim();
         if (cline.StartsWith("<--["))
         {
             string objtype = cline.Substring(4, cline.Length - 5).ToLower();
             dObject nobj = null;
             switch (objtype)
             {
                 case "action":
                     nobj = new dAction();
                     Actions.Add((dAction)nobj);
                     break;
                 case "example":
                 case "tutorial":
                     nobj = new dTutorial();
                     Tutorials.Add((dTutorial)nobj);
                     break;
                 case "mechanism":
                     nobj = new dMechanism();
                     Mechanisms.Add((dMechanism)nobj);
                     break;
                 case "tag":
                     nobj = new dTag();
                     Tags.Add((dTag)nobj);
                     break;
                 case "command":
                     nobj = new dCommand();
                     Commands.Add((dCommand)nobj);
                     break;
                 case "language":
                     nobj = new dLanguage();
                     Languages.Add((dLanguage)nobj);
                     break;
                 case "event":
                     nobj = new dEvent();
                     Events.Add((dEvent)nobj);
                     break;
                 case "requirement":
                     break;
                 default:
                     Logger.Output(LogType.ERROR, "Unknown object type " + objtype + " in " + fname);
                     break;
             }
             if (nobj == null)
             {
                 continue;
             }
             nobj.FileName = fname;
             Objects.Add(nobj);
             i++;
             while (i < lines.Length)
             {
                 cline = lines[i].Trim();
                 if (!cline.StartsWith("//"))
                 {
                     Logger.Output(LogType.ERROR, "Found line <<" + cline + ">> in the middle of an object declaration in " + fname);
                     i++;
                     continue;
                 }
                 if (cline.Length < 4)
                 {
                     cline = "//  ";
                 }
                 cline = cline.Substring(3);
                 if (cline == "-->")
                 {
                     break;
                 }
                 if (!cline.StartsWith("@"))
                 {
                     Logger.Output(LogType.ERROR, "Found line '// " + cline + "' in the middle of an object declaration in " + fname);
                     i++;
                     continue;
                 }
                 string typer = cline.Substring(1);
                 string value = "";
                 if (typer.Contains(' '))
                 {
                     value += typer.Substring(typer.IndexOf(' ') + 1);
                     typer = typer.Substring(0, typer.IndexOf(' '));
                 }
                 while (i + 1 < lines.Length)
                 {
                     cline = lines[i + 1].Trim();
                     if (cline.Length < 4)
                     {
                         cline = "//  ";
                     }
                     cline = cline.Substring(3);
                     if ((cline.StartsWith("@") && !cline.StartsWith("@ ")) || cline == "-->")
                     {
                         break;
                     }
                     value += "\n" + cline;
                     i++;
                 }
                 nobj.ApplyVar(typer.ToLower(), value);
                 i++;
             }
         }
     }
 }