private static ILSLListExpr BasicAtomToExpr(LSLParser.Expr_AtomContext c, string numericPrefix = null) { if (c.string_literal != null) { if (numericPrefix != null) { throw new InvalidOperationException( "LSLListParser.BasicAtomToExpr: Numeric prefix cannot be added to a string literal node."); } return(new LSLListStringExpr(c.GetText())); } if (c.float_literal != null) { numericPrefix = numericPrefix ?? ""; return(new LSLListFloatExpr(numericPrefix + c.GetText())); } if (c.hex_literal != null) { if (numericPrefix != null) { throw new InvalidOperationException( "LSLListParser.BasicAtomToExpr: Numeric prefix cannot be added to a hex literal node."); } return(new LSLListFloatExpr(c.GetText(), true)); } if (c.integer_literal != null) { numericPrefix = numericPrefix ?? ""; return(new LSLListIntegerExpr(numericPrefix + c.GetText())); } return(null); }
internal LSLIntegerLiteralNode(LSLParser.Expr_AtomContext context) : base(context.GetText(), LSLType.Integer, new LSLSourceCodeRange(context)) { }
private static ILSLListExpr ListExpressionFromRotation(LSLListParsingFlags parsingFlags, LSLParser.Expr_AtomContext atomToken) { object[] rotComponents = { atomToken.rotation_literal.rotation_x, atomToken.rotation_literal.rotation_y, atomToken.rotation_literal.rotation_z, atomToken.rotation_literal.rotation_s }; for (int i = 0; i < rotComponents.Length; i++) { var atom = rotComponents[i] as LSLParser.Expr_AtomContext; var prefix = rotComponents[i] as LSLParser.Expr_PrefixOperationContext; if (atom != null) { if (atom.float_literal != null || atom.integer_literal != null || atom.hex_literal != null) { rotComponents[i] = BasicAtomToExpr(atom); } else if (atom.variable != null) { if ((parsingFlags & LSLListParsingFlags.AllowVariableReferencesInRotations) == LSLListParsingFlags.AllowVariableReferencesInRotations) { rotComponents[i] = new LSLListVariableExpr(atomToken.GetText()); } throw new LSLListParserOptionsConstraintException( "Variable references are not allowed in Rotation literals."); } else { goto throw_type_error; } } else if (prefix != null) { var floatOrInt = prefix.expr_rvalue as LSLParser.Expr_AtomContext; var operation = prefix.operation.Text; var validType = floatOrInt != null && (floatOrInt.float_literal != null || floatOrInt.integer_literal != null); if (validType && (operation == "-" || operation == "+")) { rotComponents[i] = BasicAtomToExpr(floatOrInt, operation); } else { throw new LSLListParserSyntaxException( string.Format( "The Negative and Positive prefix operator can only be used on Floats and Integers inside of a Rotation, operator '{0}' is not valid.", operation)); } } else { goto throw_type_error; } continue; throw_type_error: throw new LSLListParserSyntaxException( "Rotations must contain only Float and Integer literal values."); } return(new LSLListRotationExpr((ILSLListExpr)rotComponents[0], (ILSLListExpr)rotComponents[1], (ILSLListExpr)rotComponents[2], (ILSLListExpr)rotComponents[3])); }
/// <summary> /// Exit a parse tree produced by the <c>Expr_Atom</c> /// labeled alternative in <see cref="LSLParser.expression"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitExpr_Atom([NotNull] LSLParser.Expr_AtomContext context) { }
internal LSLStringLiteralNode(LSLParser.Expr_AtomContext context, string preProcessedText) : base(context.GetText(), LSLType.String, new LSLSourceCodeRange(context)) { PreProcessedText = preProcessedText; }
/// <summary> /// Visit a parse tree produced by the <c>Expr_Atom</c> /// labeled alternative in <see cref="LSLParser.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 VisitExpr_Atom([NotNull] LSLParser.Expr_AtomContext context) { return(VisitChildren(context)); }