Esempio n. 1
0
        public IXenonASTElement Compile(Lexer Lexer, XenonErrorLogger Logger)
        {
            XenonASTHymnVerse verse = new XenonASTHymnVerse();

            Lexer.GobbleWhitespace();

            // optionally allow params for verse title. used for e.g. 'chorus'/'refrain'/'verse 1' etc.
            if (Lexer.Inspect("("))
            {
                Lexer.Consume();
                verse.SubName = Lexer.ConsumeUntil(")").Trim();
                Lexer.Consume();
                Lexer.GobbleWhitespace();
            }

            Lexer.GobbleandLog("{", "Expect opening brace at start of verse.");

            while (!Lexer.Inspect("}"))
            {
                XenonASTContent content = new XenonASTContent()
                {
                    TextContent = Lexer.Consume()
                };
                verse.Content.Add(content);
            }

            Lexer.GobbleandLog("}", "Missing closing brace for verse.");

            return(verse);
        }
        public IXenonASTElement Compile(Lexer Lexer, XenonErrorLogger Logger)
        {
            XenonASTElementCollection liturgys = new XenonASTElementCollection();

            // assume all tokens inside braces are litrugy commands
            // only excpetions are we will gobble all leading whitespace in braces, and will remove the last
            // character of whitespace before last brace


            Lexer.GobbleWhitespace();

            // optional params
            if (Lexer.Inspect("("))
            {
                var args = Lexer.ConsumeArgList(false, "startnewline");
                if (args["startnewline"] == "true")
                {
                    ForceSpeakerStartOnNewline = true;
                }
                Lexer.GobbleWhitespace();
            }

            Lexer.GobbleandLog("{", "Expected opening brace at start of liturgy.");
            Lexer.GobbleWhitespace();
            XenonASTLiturgy liturgy = CompileSubContent(Lexer, Logger);

            liturgys.Elements.Add(liturgy);
            while (!Lexer.Inspect("}"))
            {
                Lexer.GobbleandLog("#", "Only '#break' command recognized in '#liturgy' block");
                if (Lexer.Inspect("break"))
                {
                    Lexer.GobbleandLog("break");
                    Lexer.GobbleWhitespace();
                }
                else
                {
                    Logger.Log(new XenonCompilerMessage()
                    {
                        ErrorMessage = "Expected Command 'break'", ErrorName = "Unrecognized Command", Generator = "Compiler - XenonASTLiturgy", Inner = "", Level = XenonCompilerMessageType.Error, Token = Lexer.CurrentToken
                    });
                }
                liturgy = CompileSubContent(Lexer, Logger);
                liturgys.Elements.Add(liturgy);
            }
            Lexer.GobbleandLog("}", "Missing closing brace for liturgy.");
            return(liturgys);
        }
        public IXenonASTElement Compile(Lexer Lexer, XenonErrorLogger Logger)
        {
            XenonASTTextHymn textHymn = new XenonASTTextHymn();

            Lexer.GobbleWhitespace();

            var args = Lexer.ConsumeArgList(true, "title", "name", "tune", "number", "copyright");

            textHymn.HymnTitle     = args["title"];
            textHymn.HymnName      = args["name"];
            textHymn.Tune          = args["tune"];
            textHymn.Number        = args["number"];
            textHymn.CopyrightInfo = args["copyright"];

            if (Lexer.Inspect("("))
            {
                Lexer.Consume();
                string sisoverlay = Lexer.ConsumeUntil(")");
                bool   isoverlay;
                bool.TryParse(sisoverlay, out isoverlay);
                textHymn.IsOverlay = isoverlay;
                Lexer.Consume();
            }

            Lexer.GobbleWhitespace();
            Lexer.GobbleandLog("{", "Expect opening brace for body of hymn. Verses go here");
            Lexer.GobbleWhitespace();

            while (Lexer.Inspect("#"))
            {
                Lexer.GobbleandLog("#", "Expecting '#verse' command");
                // only valid command at this point (so far) is a verse
                if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Verse]))
                {
                    Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Verse], "Only verse command is valid here");
                    XenonASTHymnVerse verse = new XenonASTHymnVerse();
                    textHymn.Verses.Add((XenonASTHymnVerse)verse.Compile(Lexer, Logger));
                }
                Lexer.GobbleWhitespace();
            }

            Lexer.GobbleWhitespace();
            Lexer.GobbleandLog("}", "Missing closing brace on hymn command.");


            return(textHymn);
        }
Esempio n. 4
0
        public IXenonASTElement Compile(Lexer Lexer, XenonErrorLogger Logger)
        {
            if (Lexer.GobbleandLog("#"))
            {
                return(CompileCommand(Lexer, Logger));
            }

            throw new XenonCompilerException();
        }
        public IXenonASTElement Compile(Lexer Lexer, XenonErrorLogger Logger)
        {
            XenonASTElementCollection litverses = new XenonASTElementCollection();

            // assume all tokens inside braces are litrugy commands
            // only excpetions are we will gobble all leading whitespace in braces, and will remove the last
            // character of whitespace before last brace


            Lexer.GobbleWhitespace();
            var args = Lexer.ConsumeArgList(true, "title", "reference");

            Title     = args["title"];
            Reference = args["reference"];
            Lexer.GobbleWhitespace();
            Lexer.GobbleandLog("{", "Expected opening brace at start of litverse.");
            Lexer.GobbleWhitespace();
            XenonASTLiturgyVerse litverse = CompileSubContent(Lexer, Logger);

            litverses.Elements.Add(litverse);
            while (!Lexer.Inspect("}"))
            {
                Lexer.GobbleandLog("#", "Only '#break' command recognized in '#litverse' block");
                if (Lexer.Inspect("break"))
                {
                    Lexer.GobbleandLog("break");
                    Lexer.GobbleWhitespace();
                }
                else
                {
                    Logger.Log(new XenonCompilerMessage()
                    {
                        ErrorMessage = "Expected Command 'break'", ErrorName = "Unrecognized Command", Generator = "Compiler - XenonASTLitVerse", Inner = "", Level = XenonCompilerMessageType.Error, Token = Lexer.CurrentToken
                    });
                }
                litverse = CompileSubContent(Lexer, Logger);
                litverses.Elements.Add(litverse);
            }
            Lexer.GobbleandLog("}", "Missing closing brace for litverse.");
            return(litverses);
        }
        public IXenonASTElement Compile(Lexer Lexer, XenonErrorLogger Logger)
        {
            XenonASTScript script = new XenonASTScript();

            Lexer.GobbleWhitespace();
            StringBuilder sb = new StringBuilder();

            Lexer.GobbleandLog("{");
            Lexer.GobbleWhitespace();
            while (!Lexer.InspectEOF())
            {
                sb.Append(Lexer.Consume());
                if (Lexer.Inspect("}"))
                {
                    script.Source = sb.ToString();
                    Lexer.Consume();
                    break;
                }
            }
            return(script);
        }
Esempio n. 7
0
        private XenonASTExpression CompileCommand(Lexer Lexer, XenonErrorLogger Logger)
        {
            XenonASTExpression expr = new XenonASTExpression();

            if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Resource]))
            {
                XenonASTResource resource = new XenonASTResource();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Resource]);
                expr.Command = (IXenonASTCommand)resource.Compile(Lexer, Logger);
                return(expr);
            }
            if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Script]))
            {
                XenonASTScript script = new XenonASTScript();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Script]);
                expr.Command = (IXenonASTCommand)script.Compile(Lexer, Logger);
                return(expr);
            }


            if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.SetVar]))
            {
                XenonASTSetVariable xenonASTSetVariable = new XenonASTSetVariable();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.SetVar]);
                expr.Command = (IXenonASTCommand)xenonASTSetVariable.Compile(Lexer, Logger);
                return(expr);
            }
            if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Video]))
            {
                XenonASTVideo video = new XenonASTVideo();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Video]);
                expr.Command = (IXenonASTCommand)video.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.FilterImage]))
            {
                XenonASTFilterImage fimage = new XenonASTFilterImage();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.FilterImage]);
                expr.Command = (IXenonASTCommand)fimage.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.FullImage]))
            {
                XenonASTFullImage fullimage = new XenonASTFullImage();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.FullImage]);
                expr.Command = (IXenonASTCommand)fullimage.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.FitImage]))
            {
                XenonASTFitImage fitimage = new XenonASTFitImage();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.FitImage]);
                expr.Command = (IXenonASTCommand)fitimage.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.AutoFitImage]))
            {
                XenonASTAutoFitImage autofit = new XenonASTAutoFitImage();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.AutoFitImage]);
                expr.Command = (IXenonASTCommand)autofit.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.LiturgyImage]))
            {
                XenonASTLiturgyImage liturgyimage = new XenonASTLiturgyImage();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.LiturgyImage]);
                expr.Command = (IXenonASTCommand)liturgyimage.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Break]))
            {
                XenonASTSlideBreak slidebreak = new XenonASTSlideBreak();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Break]);
                expr.Command = (IXenonASTCommand)slidebreak.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Liturgy]))
            {
                XenonASTLiturgy liturgy = new XenonASTLiturgy();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Liturgy]);
                expr.Command = (IXenonASTCommand)liturgy.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.LiturgyVerse]))
            {
                XenonASTLiturgyVerse litverse = new XenonASTLiturgyVerse();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.LiturgyVerse]);
                expr.Command = (IXenonASTCommand)litverse.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.TitledLiturgyVerse]))
            {
                XenonASTTitledLiturgyVerse tlverse = new XenonASTTitledLiturgyVerse();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.TitledLiturgyVerse]);
                expr.Command = (IXenonASTCommand)tlverse.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Reading]))
            {
                XenonASTReading reading = new XenonASTReading();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Reading]);
                expr.Command = (IXenonASTCommand)reading.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Sermon]))
            {
                XenonASTSermon sermon = new XenonASTSermon();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Sermon]);
                expr.Command = (IXenonASTCommand)sermon.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.AnthemTitle]))
            {
                XenonASTAnthemTitle anthem = new XenonASTAnthemTitle();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.AnthemTitle]);
                expr.Command = (IXenonASTCommand)anthem.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.TwoPartTitle]))
            {
                XenonAST2PartTitle title = new XenonAST2PartTitle();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.TwoPartTitle]);
                expr.Command = (IXenonASTCommand)title.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.TextHymn]))
            {
                XenonASTTextHymn texthymn = new XenonASTTextHymn();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.TextHymn]);
                expr.Command = (IXenonASTCommand)texthymn.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Copyright]))
            {
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Copyright]);
                expr.Command = new XenonASTPrefabCopyright();
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.ViewServices]))
            {
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.ViewServices]);
                expr.Command = new XenonASTPrefabViewServices();
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.ViewSeries]))
            {
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.ViewSeries]);
                expr.Command = new XenonASTPrefabViewSeries();
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.ApostlesCreed]))
            {
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.ApostlesCreed]);
                expr.Command = new XenonASTPrefabApostlesCreed();
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.LordsPrayer]))
            {
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.LordsPrayer]);
                expr.Command = new XenonASTPrefabLordsPrayer();
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.NiceneCreed]))
            {
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.NiceneCreed]);
                expr.Command = new XenonASTPrefabNiceneCreed();
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Script_LiturgyOff]))
            {
                var command = new XenonASTPrefabScriptLiturgyOff();
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Script_LiturgyOff]);
                expr.Command = (IXenonASTCommand)command.Compile(Lexer, Logger);
                return(expr);
            }
            else if (Lexer.Inspect(LanguageKeywords.Commands[LanguageKeywordCommand.Script_OrganIntro]))
            {
                Lexer.GobbleandLog(LanguageKeywords.Commands[LanguageKeywordCommand.Script_OrganIntro]);
                expr.Command = new XenonASTPrefabScriptOrganIntro();
                return(expr);
            }
            else
            {
                Logger.Log(new XenonCompilerMessage()
                {
                    Level = XenonCompilerMessageType.Error, ErrorName = "Unknown Command", ErrorMessage = $"{Lexer.Peek()} is not a recognized command", Token = Lexer.Peek(), Generator = "Compiler"
                });
                throw new XenonCompilerException();
            }
        }