public override object VisitLiteralExpression([NotNull] DoshikParser.LiteralExpressionContext context)
        {
            SetWholeExpression(context);
            VisitChildren(context);
            _compilationContext.SetParsingAntlrContext(context);

            var node = new LiteralExpressionNode(context);

            Sequence.Sequence.Add(node);

            var literalCtx        = context.literal();
            var integerLiteralCtx = literalCtx.integerLiteral();

            if (integerLiteralCtx != null && integerLiteralCtx.INT_LITERAL() != null)
            {
                node.LiteralValue = integerLiteralCtx.INT_LITERAL().GetText();
                node.LiteralType  = LiteralExpressionNode.LiteralTypeOption.Int;
            }
            else if (integerLiteralCtx != null && integerLiteralCtx.INT_HEX_LITERAL() != null)
            {
                node.LiteralValue = integerLiteralCtx.INT_HEX_LITERAL().GetText();
                node.LiteralType  = LiteralExpressionNode.LiteralTypeOption.IntHex;
            }
            else if (literalCtx.FLOAT_LITERAL() != null)
            {
                node.LiteralValue = literalCtx.FLOAT_LITERAL().GetText();
                node.LiteralType  = LiteralExpressionNode.LiteralTypeOption.Float;
            }
            else if (literalCtx.STRING_LITERAL() != null)
            {
                node.LiteralValue = literalCtx.STRING_LITERAL().GetText();
                node.LiteralType  = LiteralExpressionNode.LiteralTypeOption.String;
            }
            else if (literalCtx.BOOL_LITERAL() != null)
            {
                node.LiteralValue = literalCtx.BOOL_LITERAL().GetText();
                node.LiteralType  = LiteralExpressionNode.LiteralTypeOption.Bool;
            }
            else if (literalCtx.NULL_LITERAL() != null)
            {
                node.LiteralValue = literalCtx.NULL_LITERAL().GetText();
                node.LiteralType  = LiteralExpressionNode.LiteralTypeOption.Null;
            }
            else
            {
                throw new System.NotImplementedException();
            }

            return(null);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Visit a parse tree produced by the <c>literalExpression</c>
 /// labeled alternative in <see cref="DoshikParser.primary"/>.
 /// <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 VisitLiteralExpression([NotNull] DoshikParser.LiteralExpressionContext context)
 {
     return(VisitChildren(context));
 }
 /// <summary>
 /// Exit a parse tree produced by the <c>literalExpression</c>
 /// labeled alternative in <see cref="DoshikParser.primary"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitLiteralExpression([NotNull] DoshikParser.LiteralExpressionContext context)
 {
 }