Example #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);
        }
Example #2
0
        public static bool TryCreateNewLineToken(string formatString, int offset, int length, out LispFormatTokenNewLine token, out string errorMessage)
        {
            token        = default;
            errorMessage = default;
            if (length != 2)
            {
                errorMessage = "Expected no format arguments";
                return(false);
            }

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