Пример #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);
        }
Пример #2
0
        public static bool TryCreateTildeToken(string formatString, int offset, int length, out LispFormatTokenTilde token, out string errorMessage)
        {
            token        = default;
            errorMessage = default;
            var argumentString = formatString.Substring(offset + 1, length - 2);
            var count          = 1;

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

            token = new LispFormatTokenTilde(offset, length, count);
            return(true);
        }