public int CountAltsForRule( CommonTree t )
        {
            CommonTree block = (CommonTree)t.GetFirstChildWithType(BLOCK);
            if (block == null || block.ChildCount == 0)
                return 0;

            return block.Children.Count(i => i.Type == ALT);
        }
        private string GetPageId(CommonTree node)
        {
            if (node.Type == FlashTeaseScriptLexer.RANGE)
            {
                var fromNode = node.GetChild(0) as CommonTree;
                var toNode = node.GetChild(1) as CommonTree;
                if (fromNode != null && toNode != null)
                {
                    var fromText = String.Concat(fromNode.Children.Select(child => child.Text).ToArray());
                    var toText = String.Concat(toNode.Children.Select(child => child.Text).ToArray());

                    var prefix = node.GetFirstChildWithType(FlashTeaseScriptLexer.PREFIX) as CommonTree;

                    string prefixText = (prefix != null) ? prefix.GetChild(0).Text.Trim('\'', '"') : null;

                    return String.Format("{0}({1}..{2})", prefixText, fromText, toText);
                }
            }
            return String.Concat(node.Children.Select(child => child.Text).ToArray());
        }
        private IEnumerable<string> ProcessFunctionParameters(CommonTree child)
        {
            CommonTree parameterTree = child.GetFirstChildWithType(GoLexer.LPAREN) as CommonTree;
            if (parameterTree == null)
                yield break;

            foreach (CommonTree parameter in parameterTree.Children)
            {
                if (parameter.Type == GoLexer.RPAREN)
                    continue;

                if (parameter.ChildCount == 0)
                {
                    yield return parameter.Text;
                }
                else if (parameter.ChildCount == 1)
                {
                    yield return string.Format("{0} {1}", parameter.Text, GetTypeString((CommonTree)parameter.GetChild(0)));
                }
                else
                {
                    yield return "<unknown parameter>";
                }
            }
        }
        private TeaseDelay GetDelay(CommonTree delayNode)
        {
            if (delayNode == null)
            {
                return null;
            }

            var result = new TeaseDelay();

            var timeNode = delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.TIME) as CommonTree;
            if (timeNode != null)
            {
                var minNode = (CommonTree)timeNode.GetFirstChildWithType(FlashTeaseScriptLexer.MIN);
                int minSecs = Convert.ToInt32(minNode.GetChild(0).Text);
                if (minNode.ChildCount > 1)
                {
                    var minUnit = minNode.GetChild(1).Text;
                    switch (minUnit)
                    {
                        case "hrs": { minSecs = minSecs * 60 * 60; break; }
                        case "min": { minSecs = minSecs * 60; break; }
                        default: break;
                    }
                }

                var maxNode = timeNode.GetFirstChildWithType(FlashTeaseScriptLexer.MAX) as CommonTree;
                int maxSecs = -1;
                if (maxNode != null)
                {
                    maxSecs = Convert.ToInt32(maxNode.GetChild(0).Text);
                    if (maxNode.ChildCount > 1)
                    {
                        var maxUnit = maxNode.GetChild(1).Text;
                        switch (maxUnit)
                        {
                            case "hrs": { maxSecs = maxSecs * 60 * 60; break; }
                            case "min": { maxSecs = maxSecs * 60; break; }
                            default: break;
                        }
                    }
                }

                result.Seconds = (maxSecs > minSecs) ? String.Format("({0}..{1})", minSecs, maxSecs) : String.Format("{0}", minSecs);
            }

            result.Target = GetPageId(delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.TARGET).GetChild(0) as CommonTree);

            var styleNode = delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.STYLE) as CommonTree;
            if (styleNode != null && styleNode.ChildCount > 0)
            {
                switch (styleNode.GetChild(0).Text.ToLowerInvariant())
                {
                    case "hidden": result.Style = DelayStyle.Hidden; break;
                    case "secret": result.Style = DelayStyle.Secret; break;
                    default: result.Style = DelayStyle.Normal; break;
                }
            }

            return result;
        }
        private IEnumerable<TeaseButton> GetButtons(CommonTree propertiesNode)
        {
            var result = new List<TeaseButton>();

            var goNode = propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.GO) as CommonTree;
            if (goNode != null)
            {
                result.Add(new TeaseButton { Text = "Continue", Target = GetPageId(goNode.GetChild(0) as CommonTree) });
            }
            var ynNode = propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.YN) as CommonTree;
            if (ynNode != null)
            {
                result.Add(new TeaseButton { Text = "Yes", Target = GetPageId(ynNode.GetFirstChildWithType(FlashTeaseScriptLexer.YES).GetChild(0) as CommonTree) });
                result.Add(new TeaseButton { Text = "No", Target = GetPageId(ynNode.GetFirstChildWithType(FlashTeaseScriptLexer.NO).GetChild(0) as CommonTree) });
            }
            var buttonsNode = propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.BUTTONS) as CommonTree;
            if (buttonsNode != null)
            {
                foreach (CommonTree buttonNode in buttonsNode.Children.Where(x => x.Type == FlashTeaseScriptLexer.BUTTON))
                {
                    result.Add(new TeaseButton
                    {
                        Text = buttonNode.GetFirstChildWithType(FlashTeaseScriptLexer.CAP).GetChild(0).Text.Trim('\'', '"'),
                        Target = GetPageId(buttonNode.GetFirstChildWithType(FlashTeaseScriptLexer.TARGET).GetChild(0) as CommonTree)
                    });
                }
            }

            result.Reverse();
            return result;
        }
        private TeaseMedia GetAudio(CommonTree soundNode)
        {
            if (soundNode == null)
            {
                return null;
            }

            var result = new  TeaseMedia();

            var idNode = soundNode.GetFirstChildWithType(FlashTeaseScriptLexer.ID) as CommonTree;
            if (idNode != null)
            {
                result.Id = idNode.GetChild(0).Text.Trim('\'', '"');
            }

            var loopsNode = soundNode.GetFirstChildWithType(FlashTeaseScriptLexer.LOOPS) as CommonTree;
            if (loopsNode != null && loopsNode.ChildCount > 0)
            {
                result.Repeat = loopsNode.GetChild(0).Text;
            }
            return result;
        }
        private static string GetParameterType(CommonTree tree)
        {
            int index = 0;

            while (index < tree.ChildCount)
            {
                switch (tree.GetChild(index).Type)
                {
                case Java2Lexer.MONKEYS_AT:
                case Java2Lexer.FINAL:
                    index++;
                    continue;

                default:
                    break;
                }

                break;
            }

            string typeText = GetTypeText((CommonTree)tree.GetChild(index));

            if (tree.GetFirstChildWithType(Java2Lexer.ELLIPSIS) != null)
                typeText = typeText + "...";

            return typeText;
        }
Beispiel #8
0
        private TeaseDelay GetDelay(CommonTree delayNode)
        {
            if (delayNode == null)
            {
                return null;
            }

            var result = new TeaseDelay();

            var timeNode = delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.TIME) as CommonTree;
            if (timeNode != null)
            {
                int secs = System.Convert.ToInt32(timeNode.GetChild(0).Text);
                if (timeNode.GetChild(1).Text == "min")
                {
                    secs = secs * 60;
                }
                result.Seconds = secs.ToString();
            }

            result.Target = GetPageId(delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.TARGET).GetChild(0) as CommonTree);

            var styleNode = delayNode.GetFirstChildWithType(FlashTeaseScriptLexer.STYLE) as CommonTree;
            if (styleNode != null && styleNode.ChildCount > 0)
            {
                switch (styleNode.GetChild(0).Text)
                {
                    case "hidden": result.Style = DelayStyle.Hidden; break;
                    case "secret": result.Style = DelayStyle.Secret; break;
                    default: result.Style = DelayStyle.Normal; break;
                }
            }

            return result;
        }