Ejemplo n.º 1
0
        public static bool TryBuildEscapeSequenceFormatToken(char escapeCode, string formatString, int offset, int length, out ILispFormatToken token, out string errorMessage)
        {
            token = default;
            switch (char.ToLowerInvariant(escapeCode))
            {
            case LispFormatTokenTilde.EscapeCode:
                if (LispFormatTokenTilde.TryCreateTildeToken(formatString, offset, length, out var tildeToken, out errorMessage))
                {
                    token = tildeToken;
                    return(true);
                }
                break;

            case LispFormatTokenNewLine.EscapeCode:
                if (LispFormatTokenNewLine.TryCreateNewLineToken(formatString, offset, length, out var newlineToken, out errorMessage))
                {
                    token = newlineToken;
                    return(true);
                }
                break;

            case LispFormatTokenLineStart.EscapeCode:
                if (LispFormatTokenLineStart.TryCreateLineStartToken(formatString, offset, length, out var lineStartToken, out errorMessage))
                {
                    token = lineStartToken;
                    return(true);
                }
                break;

            case LispFormatTokenAExpression.EscapeCode:
                if (LispFormatTokenAExpression.TryCreateAExpressionToken(formatString, offset, length, out var aToken, out errorMessage))
                {
                    token = aToken;
                    return(true);
                }
                break;

            case LispFormatTokenSExpression.EscapeCode:
                if (LispFormatTokenSExpression.TryCreateSExpressionToken(formatString, offset, length, out var sToken, out errorMessage))
                {
                    token = sToken;
                    return(true);
                }
                break;

            default:
                errorMessage = $"Unsuppored escape code '{escapeCode}'";
                break;
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static bool TryCreateAExpressionToken(string formatString, int offset, int length, out LispFormatTokenAExpression token, out string errorMessage)
        {
            token        = default;
            errorMessage = default;
            var argumentString = formatString.Substring(offset + 1, length - 2);
            var width          = 0;

            if (argumentString.Length > 0)
            {
                if (!int.TryParse(argumentString, out width))
                {
                    errorMessage = $"Unable to parse argument string '{argumentString}'";
                    return(false);
                }
            }

            token = new LispFormatTokenAExpression(offset, length, width);
            return(true);
        }