コード例 #1
0
        private TeasePage CreatePage(string line)
        {
            var result = new TeasePage {
                Comments = line
            };

            var stream = new ANTLRStringStream(line);
            var lexer  = new FlashTeaseScriptLexer(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new FlashTeaseScriptParser(tokens);

            try
            {
                IAstRuleReturnScope <CommonTree> teaseReturn = parser.tease();
                if (teaseReturn.Tree != null)
                {
                    var pageNode = teaseReturn.Tree;
                    if (pageNode.Type != FlashTeaseScriptLexer.PAGE)
                    {
                        pageNode = pageNode.GetFirstChildWithType(FlashTeaseScriptLexer.PAGE) as CommonTree;
                    }

                    if (pageNode != null && pageNode.Type == FlashTeaseScriptLexer.PAGE)
                    {
                        var idNode = pageNode.GetFirstChildWithType(FlashTeaseScriptLexer.ID) as CommonTree;
                        if (idNode != null)
                        {
                            result.Id = GetPageId(idNode);
                        }

                        var propertiesNode = pageNode.GetFirstChildWithType(FlashTeaseScriptLexer.PROPERTIES) as CommonTree;
                        if (propertiesNode != null)
                        {
                            result.Text = GetText(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.TEXT) as CommonTree);

                            var image = GetImage(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.PIC) as CommonTree);
                            if (image != null)
                            {
                                result.ImageList.Add(image);
                            }
                            var audio = GetAudio(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.SOUND) as CommonTree);
                            if (audio != null)
                            {
                                result.AudioList.Add(audio);
                            }
                            var delay = GetDelay(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.DELAY) as CommonTree);
                            if (delay != null)
                            {
                                result.DelayList.Add(delay);
                            }

                            result.ButtonList.AddRange(GetButtons(propertiesNode));

                            result.SetFlags   = GetFlags(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.SET) as CommonTree);
                            result.UnsetFlags = GetFlags(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.UNSET) as CommonTree);
                        }
                    }
                }

                if (parser.HasError)
                {
                    result.Errors = String.Format("ParserError ({0}): {1}. Please correct by hand.", parser.ErrorPosition, parser.ErrorMessage);
                }
            }
            catch (Exception)
            {
                result.Errors = String.Format("ParserError ({0}): {1}. Please correct by hand.", parser.ErrorPosition, parser.ErrorMessage);
            }

            if (String.IsNullOrEmpty(result.Id))
            {
                result.Id     = Guid.NewGuid().ToString();
                result.Errors = String.Format("This page had no id, so one is generated. {0}", result.Errors);
            }

            return(result);
        }
コード例 #2
0
        private TeasePage CreatePage(string line)
        {
            var result = new TeasePage { Comments = line };

            var stream = new ANTLRStringStream(line);
            var lexer = new FlashTeaseScriptLexer(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new FlashTeaseScriptParser(tokens);

            try
            {
                IAstRuleReturnScope<CommonTree> teaseReturn = parser.tease();
                if (teaseReturn.Tree != null)
                {
                    var pageNode = teaseReturn.Tree;
                    if (pageNode.Type != FlashTeaseScriptLexer.PAGE)
                    {
                        pageNode = pageNode.GetFirstChildWithType(FlashTeaseScriptLexer.PAGE) as CommonTree;
                    }

                    if (pageNode != null && pageNode.Type == FlashTeaseScriptLexer.PAGE)
                    {
                        var idNode = pageNode.GetFirstChildWithType(FlashTeaseScriptLexer.ID) as CommonTree;
                        if (idNode != null)
                        {
                            result.Id = GetPageId(idNode);
                        }

                        var propertiesNode = pageNode.GetFirstChildWithType(FlashTeaseScriptLexer.PROPERTIES) as CommonTree;
                        if (propertiesNode != null)
                        {
                            result.Text = GetText(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.TEXT) as CommonTree);

                            var image = GetImage(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.PIC) as CommonTree);
                            if (image != null)
                            {
                                result.ImageList.Add(image);
                            }
                            var audio = GetAudio(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.SOUND) as CommonTree);
                            if (audio != null)
                            {
                                result.AudioList.Add(audio);
                            }
                            var delay =  GetDelay(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.DELAY) as CommonTree);
                            if (delay != null)
                            {
                                result.DelayList.Add(delay);
                            }

                            result.ButtonList.AddRange(GetButtons(propertiesNode));

                            result.SetFlags = GetFlags(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.SET) as CommonTree);
                            result.UnsetFlags = GetFlags(propertiesNode.GetFirstChildWithType(FlashTeaseScriptLexer.UNSET) as CommonTree);
                        }
                    }
                }

                if (parser.HasError)
                {
                    result.Errors = String.Format("ParserError ({0}): {1}. Please correct by hand.", parser.ErrorPosition, parser.ErrorMessage);
                }
            }
            catch (Exception)
            {
                result.Errors = String.Format("ParserError ({0}): {1}. Please correct by hand.", parser.ErrorPosition, parser.ErrorMessage);
            }

            if (String.IsNullOrEmpty(result.Id))
            {
                result.Id = Guid.NewGuid().ToString();
                result.Errors = String.Format("This page had no id, so one is generated. {0}", result.Errors);
            }

            return result;
        }