Beispiel #1
0
        private void AddNode(TreeIter parent, OptionsNode optionsNode)
        {
            parent = store.AppendValues(parent, "options", optionsNode);

            Dictionary <string, object> options = new Dictionary <string, object>();

            if (optionsNode.BuildTextNodes.HasValue)
            {
                options["buildTextNodes"] = optionsNode.BuildTextNodes.Value;
            }

            if (optionsNode.RecursionBehaviour.HasValue)
            {
                options["recursionBehaviour"] = optionsNode.RecursionBehaviour.Value;
            }

            if (optionsNode.DropPrecedence.HasValue)
            {
                options["dropPrecedence"] = optionsNode.DropPrecedence.Value;
            }

            if (optionsNode.Whitespace.HasValue)
            {
                options["whitespace"] = optionsNode.Whitespace.Value;
            }

            if (optionsNode.Exclude.HasValue)
            {
                options["exclude"] = optionsNode.Exclude.Value;
            }

            foreach (KeyValuePair <string, object> option in options)
            {
                store.AppendValues(parent, option.Key + " = "
                                   + ObjectViewerDirectory.GetDescription(option.Value), optionsNode);
            }

            AddNode(parent, optionsNode.Body);
        }
        public override ParseGraphNode BuildParseGraph(RuntimeState state)
        {
            ParseGraphNode parseGraph = body.BuildParseGraph(state);

            if (options.Count == 0)
            {
                return(parseGraph);
            }

            OptionsNode optionsNode = new OptionsNode(Source, parseGraph);

            foreach (Option option in options)
            {
                string optionKey = option.optionKey.name;
                object optionValue;

                if (option.optionValue == null)
                {
                    optionValue = true;
                }
                else
                {
                    optionValue = option.optionValue.Get(state);
                }

                switch (optionKey)
                {
                case "buildTextNodes":
                    optionsNode.BuildTextNodes.Value = ConvertNode.ToBool(optionValue);
                    break;

                case "dropPrecedence":
                    optionsNode.DropPrecedence.Value = ConvertNode.ToBool(optionValue);
                    break;

                case "recursive":
                {
                    if (ConvertNode.ToBool(optionValue))
                    {
                        optionsNode.RecursionBehaviour.Value = RecursionBehaviour.Recursive;
                    }
                    else
                    {
                        optionsNode.RecursionBehaviour.Value = RecursionBehaviour.None;
                    }
                } break;

                case "leftRecursive":
                    optionsNode.RecursionBehaviour.Value = RecursionBehaviour.LeftRecursive;
                    break;

                case "rightRecursive":
                    optionsNode.RecursionBehaviour.Value = RecursionBehaviour.RightRecursive;
                    break;

                case "whitespace":
                    optionsNode.Whitespace.Value = Pattern.PatternForType((Type)optionValue);
                    break;

                case "exclude":
                    optionsNode.Exclude.Value = Pattern.PatternForType((Type)optionValue);
                    break;
                }
            }

            return(optionsNode);
        }