Beispiel #1
0
        public UstNode VisitLiteral(JavaParser.LiteralContext context)
        {
            var textSpan = context.GetTextSpan();

            ITerminalNode stringLiteral = context.STRING_LITERAL();

            if (stringLiteral != null)
            {
                string text = stringLiteral.GetText();
                return(new StringLiteral(text.Substring(1, text.Length - 2), textSpan, FileNode));
            }

            if (context.integerLiteral() != null)
            {
                return(Visit(context.integerLiteral()));
            }

            ITerminalNode boolLiteral = context.BOOL_LITERAL();

            if (boolLiteral != null)
            {
                return(new BooleanLiteral(bool.Parse(boolLiteral.GetText()), textSpan, FileNode));
            }

            ITerminalNode charLiteral = context.CHAR_LITERAL();

            if (charLiteral != null)
            {
                return(new StringLiteral(charLiteral.GetText(), textSpan, FileNode));
            }

            ITerminalNode floatLiteral = context.FLOAT_LITERAL();

            if (floatLiteral != null)
            {
                var text = floatLiteral.GetText().ToLowerInvariant().Replace("d", "").Replace("f", "").Replace("_", "");
                return(new FloatLiteral(double.Parse(text), textSpan, FileNode));
            }

            if (context.Start.Type == JavaParser.NULL_LITERAL)
            {
                return(new NullLiteral(textSpan, FileNode));
            }

            return(VisitChildren(context));
        }
Beispiel #2
0
        public Ust VisitLiteral(JavaParser.LiteralContext context)
        {
            var textSpan = context.GetTextSpan();

            ITerminalNode stringLiteral = context.STRING_LITERAL();

            if (stringLiteral != null)
            {
                string text = stringLiteral.GetText();
                return(new StringLiteral(text.Substring(1, text.Length - 2), textSpan));
            }

            if (context.integerLiteral() != null)
            {
                return(Visit(context.integerLiteral()));
            }

            if (context.floatLiteral() != null)
            {
                return(Visit(context.floatLiteral()));
            }

            ITerminalNode boolLiteral = context.BOOL_LITERAL();

            if (boolLiteral != null)
            {
                return(new BooleanLiteral(bool.Parse(boolLiteral.GetText()), textSpan));
            }

            ITerminalNode charLiteral = context.CHAR_LITERAL();

            if (charLiteral != null)
            {
                string text = charLiteral.GetText();
                return(new StringLiteral(text.Substring(1, text.Length - 2), textSpan));
            }

            if (context.Start.Type == JavaParser.NULL_LITERAL)
            {
                return(new NullLiteral(textSpan));
            }

            return(VisitChildren(context));
        }