예제 #1
0
        private void MarkRule_GenerateAllMarksHandler(object sender, MarkRuleEventArgs e)
        {
            var path = e.GetRulesPath();

            if (_marks.ContainsKey(path) == false)
            {
                _marks.Add(path, ActionsDescription.TryParse("", ""));
            }
        }
예제 #2
0
        private void AddMark(Dictionary <string, ActionsDescription> marks, string mark)
        {
            string markpath, description;
            int    x = mark.IndexOf("->");

            if (x < 0)
            {
                markpath    = mark;
                description = "";
            }
            else
            {
                markpath    = mark.Substring(0, x).Trim();
                description = mark.Substring(x + 2).Trim();
            }

            ActionsDescription.Action[] extraActions = null;
            if (marks.ContainsKey(markpath))
            {
                Console.WriteLine("Warning: Duplicated mark {0}", markpath);
                extraActions = marks[markpath].Actions;
                marks.Remove(markpath);
            }

            var xmark = ActionsDescription.TryParse(description, markpath, extraActions);

            if (xmark == null)
            {
                throw new Exception(string.Format("Error: Failed to parse mark {0}", markpath));
            }
            else
            {
                if (xmark.Actions == null || xmark.Actions[0].Mark != Marks.Group)
                {
                    marks.Add(markpath, xmark);
                }
                else
                {
                    try
                    {
                        var group = _groups[xmark.Actions[0].Args[1]];

                        foreach (var item in group)
                        {
                            marks.Add(markpath + item.Key, item.Value.Clone("?", xmark.Actions[0].Args[0]));
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                        Console.WriteLine("Group not defined {0}", xmark.Actions[0].Args[0]);
                        throw new Exception();
                    }
                }
            }
        }
예제 #3
0
        public ActionsDescription Clone(string oldValue, string newValue)
        {
            var actionDescription = new ActionsDescription()
            {
                Actions     = new Action[Actions.Length],
                Description = "// GENERATED",
            };

            for (int i = 0; i < Actions.Length; i++)
            {
                actionDescription.Actions[i] = Actions[i].Clone(oldValue, newValue);
            }

            return(actionDescription);
        }
예제 #4
0
		public ActionsDescription Clone(string oldValue, string newValue)
		{
			var actionDescription = new ActionsDescription()
			{
				Actions = new Action[Actions.Length],
				Description = "// GENERATED",
			};

			for (int i = 0; i < Actions.Length; i++)
				actionDescription.Actions[i] = Actions[i].Clone(oldValue, newValue);

			return actionDescription;
		}
예제 #5
0
		public static ActionsDescription TryParse(string description, string path, Action[] extraActions)
		{
			if (description != "" && description.TrimEnd().EndsWith(";") == false)
				description += ";";

			var reservArgs = path.Split('.');
			var actions = new List<Action>(extraActions ?? new Action[0]);

			var match = _regex.Match(description);
			while (match.Success)
			{
				Action action = null;
				try
				{
					switch (match.Groups["func"].Value)
					{
						case "Custom":
							action = new Action(Marks.Custom, 4);
							SetArg(action, 0, match, reservArgs, 1);
							TestArg(1, match, "Begin", "End", "Each", "AfterBegin");
							action.Args[1] = match.Groups["arg2"].Value;
							action.Args[2] = match.Groups["arg3"].Value.Trim('"');
							action.Args[3] = match.Groups["arg4"].Value;
							break;
						case "Const":
							action = new Action(Marks.Const, 3);
							SetArg(action, 0, match, reservArgs, 2);
							SetArg(action, 1, match, reservArgs, 2);
							SetArg(action, 2, match, 10);
							break;
						case "Range":
							action = new Action(Marks.Range, 3);
							SetArg(action, 0, match, reservArgs, 1);
							SetArg(action, 1, match, 0);
							SetArg(action, 2, match, 0);
							break;
						case "LookupRange":
							action = new Action(Marks.Range, 3);
							SetArg(action, 0, match, reservArgs, 1);
							SetArg(action, 1, match, 1);
							SetArg(action, 2, match, -1);
							break;
						case "BeginRange":
							action = new Action(Marks.BeginRange, 3);
							SetArg(action, 0, match, reservArgs, 1);
							TestArg(1, match, "", "AtBegin", "AtEnd");
							SetArg(action, 1, match, "AtBegin");
							SetArg(action, 2, match, 0);
							break;
						case "EndRange":
							action = new Action(Marks.EndRange, 3);
							SetArg(action, 0, match, reservArgs, 1);
							TestArg(1, match, "", "AtBegin", "AtEnd");
							SetArg(action, 1, match, "AtEnd");
							SetArg(action, 2, match, 0);
							break;
						case "EndRangeIfInvalid":
							action = new Action(Marks.EndRangeIfInvalid, 3);
							SetArg(action, 0, match, reservArgs, 1);
							TestArg(1, match, "", "AtBegin", "AtEnd");
							SetArg(action, 1, match, "AtEnd");
							SetArg(action, 2, match, 0);
							break;
						case "ContinueRange":
							action = new Action(Marks.ContinueRange, 1);
							SetArg(action, 0, match, reservArgs, 1);
							break;
						case "Reset":
							action = new Action(Marks.ResetRange, 1);
							SetArg(action, 0, match, reservArgs, 1);
							break;
						case "ResetIfInvalid":
							action = new Action(Marks.ResetRangeIfInvalid, 1);
							SetArg(action, 0, match, reservArgs, 1);
							break;
						case "Count":
							action = new Action(Marks.Count, 3);
							SetArg(action, 0, match, reservArgs, 1);
							SetArg(action, 1, match, 10);
							SetArg(action, 2, match, 0);
							break;
						case "Decimal":
							action = new Action(Marks.Decimal, 3);
							SetArg(action, 0, match, reservArgs, 1);
							SetArg(action, 1, match, "int");
							SetArg(action, 2, match, action.Args[1] + ".MinValue");
							break;
						case "Hex":
							action = new Action(Marks.Hex, 3);
							SetArg(action, 0, match, reservArgs, 1);
							SetArg(action, 1, match, "int");
							SetArg(action, 2, match, action.Args[1] + ".MinValue");
							break;
						case "Bool":
							action = new Action(Marks.Bool, 1);
							SetArg(action, 0, match, reservArgs, 1);
							break;
						case "BoolEx":
							action = new Action(Marks.BoolEx, 1);
							SetArg(action, 0, match, reservArgs, 1);
							break;
						case "BoolExNot":
							action = new Action(Marks.BoolExNot, 1);
							SetArg(action, 0, match, reservArgs, 1);
							break;
						case "Group":
							action = new Action(Marks.Group, 2);
							SetArg(action, 0, match, "");
							SetArg(action, 1, match, "NoneStruct");
							break;
						//case "AlternativeIsError":
						//    action = new Action(Marks.Error, 0);
						//    break;
						default:
							throw new Exception();
					}
				}
				catch
				{
					return null;
				}

				actions.Add(action);

				match = match.NextMatch();
			}

			var result = new ActionsDescription() { Description = description, };

			if (actions != null && actions.Count > 0)
				result.Actions = actions.ToArray();

			if (result.IsEmpty == false && result.Actions == null)
				return null;

			return result;
		}
예제 #6
0
        public static ActionsDescription TryParse(string description, string path, Action[] extraActions)
        {
            if (description != "" && description.TrimEnd().EndsWith(";") == false)
            {
                description += ";";
            }

            var reservArgs = path.Split('.');
            var actions    = new List <Action>(extraActions ?? new Action[0]);

            var match = _regex.Match(description);

            while (match.Success)
            {
                Action action = null;
                try
                {
                    switch (match.Groups["func"].Value)
                    {
                    case "Custom":
                        action = new Action(Marks.Custom, 4);
                        SetArg(action, 0, match, reservArgs, 1);
                        TestArg(1, match, "Begin", "End", "Each", "AfterBegin");
                        action.Args[1] = match.Groups["arg2"].Value;
                        action.Args[2] = match.Groups["arg3"].Value.Trim('"');
                        action.Args[3] = match.Groups["arg4"].Value;
                        break;

                    case "Const":
                        action = new Action(Marks.Const, 3);
                        SetArg(action, 0, match, reservArgs, 2);
                        SetArg(action, 1, match, reservArgs, 2);
                        SetArg(action, 2, match, 10);
                        break;

                    case "Range":
                        action = new Action(Marks.Range, 3);
                        SetArg(action, 0, match, reservArgs, 1);
                        SetArg(action, 1, match, 0);
                        SetArg(action, 2, match, 0);
                        break;

                    case "LookupRange":
                        action = new Action(Marks.Range, 3);
                        SetArg(action, 0, match, reservArgs, 1);
                        SetArg(action, 1, match, 1);
                        SetArg(action, 2, match, -1);
                        break;

                    case "BeginRange":
                        action = new Action(Marks.BeginRange, 3);
                        SetArg(action, 0, match, reservArgs, 1);
                        TestArg(1, match, "", "AtBegin", "AtEnd");
                        SetArg(action, 1, match, "AtBegin");
                        SetArg(action, 2, match, 0);
                        break;

                    case "EndRange":
                        action = new Action(Marks.EndRange, 3);
                        SetArg(action, 0, match, reservArgs, 1);
                        TestArg(1, match, "", "AtBegin", "AtEnd");
                        SetArg(action, 1, match, "AtEnd");
                        SetArg(action, 2, match, 0);
                        break;

                    case "EndRangeIfInvalid":
                        action = new Action(Marks.EndRangeIfInvalid, 3);
                        SetArg(action, 0, match, reservArgs, 1);
                        TestArg(1, match, "", "AtBegin", "AtEnd");
                        SetArg(action, 1, match, "AtEnd");
                        SetArg(action, 2, match, 0);
                        break;

                    case "ContinueRange":
                        action = new Action(Marks.ContinueRange, 1);
                        SetArg(action, 0, match, reservArgs, 1);
                        break;

                    case "Reset":
                        action = new Action(Marks.ResetRange, 1);
                        SetArg(action, 0, match, reservArgs, 1);
                        break;

                    case "ResetIfInvalid":
                        action = new Action(Marks.ResetRangeIfInvalid, 1);
                        SetArg(action, 0, match, reservArgs, 1);
                        break;

                    case "Count":
                        action = new Action(Marks.Count, 3);
                        SetArg(action, 0, match, reservArgs, 1);
                        SetArg(action, 1, match, 10);
                        SetArg(action, 2, match, 0);
                        break;

                    case "Decimal":
                        action = new Action(Marks.Decimal, 3);
                        SetArg(action, 0, match, reservArgs, 1);
                        SetArg(action, 1, match, "int");
                        SetArg(action, 2, match, action.Args[1] + ".MinValue");
                        break;

                    case "Hex":
                        action = new Action(Marks.Hex, 3);
                        SetArg(action, 0, match, reservArgs, 1);
                        SetArg(action, 1, match, "int");
                        SetArg(action, 2, match, action.Args[1] + ".MinValue");
                        break;

                    case "Bool":
                        action = new Action(Marks.Bool, 1);
                        SetArg(action, 0, match, reservArgs, 1);
                        break;

                    case "BoolEx":
                        action = new Action(Marks.BoolEx, 1);
                        SetArg(action, 0, match, reservArgs, 1);
                        break;

                    case "BoolExNot":
                        action = new Action(Marks.BoolExNot, 1);
                        SetArg(action, 0, match, reservArgs, 1);
                        break;

                    case "Group":
                        action = new Action(Marks.Group, 2);
                        SetArg(action, 0, match, "");
                        SetArg(action, 1, match, "NoneStruct");
                        break;

                    //case "AlternativeIsError":
                    //    action = new Action(Marks.Error, 0);
                    //    break;
                    default:
                        throw new Exception();
                    }
                }
                catch
                {
                    return(null);
                }

                actions.Add(action);

                match = match.NextMatch();
            }

            var result = new ActionsDescription()
            {
                Description = description,
            };

            if (actions != null && actions.Count > 0)
            {
                result.Actions = actions.ToArray();
            }

            if (result.IsEmpty == false && result.Actions == null)
            {
                return(null);
            }

            return(result);
        }