示例#1
0
        public override Chat VisitLine([NotNull] DialogicParser.LineContext context)
        {
            var cmd   = context.GetChild <DialogicParser.CommandContext>(0).GetText();
            var actx  = context.GetChild <DialogicParser.ArgsContext>(0);
            var xargs = actx.children.Where(arg => arg is DialogicParser.ArgContext).ToArray();
            var args  = Array.ConvertAll(xargs, arg => arg.GetText().Trim());

            //Console.WriteLine("cmd: " + cmd + " args: '" + String.Join(",",args)    + "'");

            Command c = Command.Create(cmd, args);

            if (c is Chat)
            {
                chats.Add((Chat)c);
            }
            else if (c is Opt)
            {
                Opt     o    = (Opt)c;
                Command last = LastOfType(parsed, typeof(Ask));
                if (!(last is Ask))
                {
                    throw new Exception("Opt must follow Ask");
                }
                ((Ask)last).AddOption(o);
            }
            else
            {
                if (chats.Count == 0)
                {
                    chats.Add(new Chat());
                }
                chats.Last().AddCommand(c);
            }

            parsed.Push(c);

            return(VisitChildren(context));
        }
示例#2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DialogicParser.line"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitLine([NotNull] DialogicParser.LineContext context)
 {
     return(VisitChildren(context));
 }