Пример #1
0
        public void ValidateEvent(List <string> warnings, string eventname, string scriptName)
        {
            if (!eventname.StartsWith("on"))
            {
                Warn(warnings, WarnType.ERROR, "Fully invalid event '" + eventname + "', has no 'ON' in it, for " + scriptName);
                return;
            }
            if (eventname.Contains("@"))
            {
                Warn(warnings, WarnType.ERROR, "Fully invalid event '" + eventname + "', has 'x@' object notation, for " + scriptName);
                return;
            }
            if (eventname.Contains("<"))
            {
                Warn(warnings, WarnType.ERROR, "Fully invalid event '" + eventname + "', has '<...>' tags, for " + scriptName);
                return;
            }
            dEvent          matched = null;
            List <string[]> switches;
            string          evtname = StripSwitches(warnings, eventname, scriptName, out switches);

            foreach (dEvent evt in AllMeta.Events)
            {
                if (evt.Regex != null)
                {
                    if (evt.Regex.IsMatch(evtname))
                    {
                        matched = evt;
                        break;
                    }
                    else
                    {
                        Logger.Output(LogType.DEBUG, "Can't match '" + evtname + "' to " + evt.Regex.ToString() + "!"); // TODO: Remove me
                    }
                }
                else
                {
                    // TODO: match somehow?
                    Logger.Output(LogType.DEBUG, "Event " + evt.Names[0] + " does not have a matcher regex!");
                }
            }
            if (matched == null)
            {
                Warn(warnings, WarnType.MINOR, "Unable to recognize event '<<" + eventname
                     + ">>' (Our system can currently only recognize a small fraction of events, so this does not yet mean much), for " + scriptName);
            }
            else
            {
                // TODO: Validate switches
            }
        }
Пример #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++;
             }
         }
     }
 }