public override Yarn.Type VisitExpAddSub(YarnSpinnerV1Parser.ExpAddSubContext context)
            {
                var expressions = context.expression();

                switch (context.op.Text)
                {
                case "+":
                    // + supports strings and numbers
                    return(CheckOperation(context, expressions, context.op.Text, Yarn.Type.String, Yarn.Type.Number));

                case "-":
                    // - supports only numbers
                    return(CheckOperation(context, expressions, context.op.Text, Yarn.Type.Number));

                default:
                    throw new InvalidOperationException($"Internal error: {nameof(VisitExpAddSub)} got unexpected op {context.op.Text}");
                }
            }
Пример #2
0
 /// <summary>
 /// Exit a parse tree produced by the <c>expAddSub</c>
 /// labeled alternative in <see cref="YarnSpinnerV1Parser.expression"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitExpAddSub([NotNull] YarnSpinnerV1Parser.ExpAddSubContext context)
 {
 }
 /// <summary>
 /// Visit a parse tree produced by the <c>expAddSub</c>
 /// labeled alternative in <see cref="YarnSpinnerV1Parser.expression"/>.
 /// <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 VisitExpAddSub([NotNull] YarnSpinnerV1Parser.ExpAddSubContext context)
 {
     return(VisitChildren(context));
 }