public override int VisitExpTypeConversion(YarnSpinnerParser.ExpTypeConversionContext context) { // Evaluate the single expression, and then call the type-conversion function Visit(context.expression()); // Push the number of parameters onto the stack compiler.Emit(OpCode.PushFloat, new Operand(1)); string functionName; switch (context.type().typename.Type) { case YarnSpinnerLexer.TYPE_STRING: functionName = "string"; break; case YarnSpinnerLexer.TYPE_BOOL: functionName = "bool"; break; case YarnSpinnerLexer.TYPE_NUMBER: functionName = "number"; break; default: throw new ParseException($"Cannot convert {context.expression().GetText()} to {context.type().GetText()}: unknown type"); } // Call the function compiler.Emit(OpCode.CallFunc, new Operand(functionName)); return(0); }
public override Yarn.Type VisitExpTypeConversion(YarnSpinnerParser.ExpTypeConversionContext context) { // Validate the type of the expression; the actual conversion // will be done at runtime, and may fail depending on the // actual value Visit(context.expression()); // Return a value whose type depends on which type we're using switch (context.type().typename.Type) { case YarnSpinnerLexer.TYPE_NUMBER: return(Yarn.Type.Number); case YarnSpinnerLexer.TYPE_STRING: return(Yarn.Type.String); case YarnSpinnerLexer.TYPE_BOOL: return(Yarn.Type.Bool); default: throw new ArgumentOutOfRangeException($"Unsupported type {context.type().GetText()}"); } }
/// <summary> /// Exit a parse tree produced by the <c>expTypeConversion</c> /// labeled alternative in <see cref="YarnSpinnerParser.expression"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitExpTypeConversion([NotNull] YarnSpinnerParser.ExpTypeConversionContext context) { }
/// <summary> /// Visit a parse tree produced by the <c>expTypeConversion</c> /// labeled alternative in <see cref="YarnSpinnerParser.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 VisitExpTypeConversion([NotNull] YarnSpinnerParser.ExpTypeConversionContext context) { return(VisitChildren(context)); }