Ejemplo n.º 1
0
        private static void ParseDirective(ParseState state, QuipCompiler Compiler)
        {
            state.Advance(1); //skip opening '#'.
            var Command = "";
            if (!IsWhitespace(state.Next()))
                ParseToken(out Command, state);

            if (String.IsNullOrEmpty(Command) || Command == "comment" || Command == "response" || Command == "nag")
            {
                var Text = "";
                ParseRestOfLine(out Text, state);
                if (Command == "comment") Compiler.CommentDirective(Text);
                else if (Command == "response") Compiler.ResponseDirective(Text);
                else if (Command == "nag") Compiler.NagDirective(Text);
                else Compiler.BlankDirective(Text);
            }
            else if (Command == "follows")
            {
                var TokenList = new List<String>();
                ParseList(TokenList, state);
                Compiler.FollowsDirective(TokenList);
            }
            else if (Command == "directly")
            {
                var TokenList = new List<String>();
                ParseList(TokenList, state);
                Compiler.DirectlyDirective(TokenList);
            }
            else if (Command == "supplies")
            {
                var TokenList = new List<String>();
                ParseList(TokenList, state);
                Compiler.SuppliesDirective(TokenList);
            }
            else if (Command == "unavailable")
            {
                var Text = "";
                ParseRestOfLine(out Text, state);
                Text = Text.Trim();
                if (!String.IsNullOrEmpty(Text))
                    Compiler.UnavailableDirective(Text);
            }
            else
            {
                throw new InvalidOperationException("Unknown directive: " + Command);
            }
        }