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)
        {
            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);
        }