Exemplo n.º 1
0
        internal static string ResolveExceptionMessage(LexerExceptionCodes code, int length)
        {
            switch (code)
            {
            case LexerExceptionCodes.InvalidEscapeSequence:
                return("Invalid escape sequence '{0}'");

            case LexerExceptionCodes.Unknown:
                return("Unknown lexer error.");

            case LexerExceptionCodes.UnexpectedEndOfStream:
                return("Unexpected end of stream.");

            case LexerExceptionCodes.UnexpectedSymbol:
                return(length == 0 ? "Unexpected symbol." : "Unexpected symbol '{0}'.");

            case LexerExceptionCodes.UnterminatedBlockComment:
                return("Unterminated block comment.");

            case LexerExceptionCodes.UnterminatedStringLiteral:
                return("Unterminated string literal.");

            case LexerExceptionCodes.UnterminatedStringContainer:
                return("Unterminated string container.");

            default:
                throw new ArgumentOutOfRangeException(nameof(code), code, null);
            }
        }
Exemplo n.º 2
0
        private LexerException Exception(LexerExceptionCodes code, params object[] args)
        {
            var e = new LexerException(code, args);

            if (!_recordPosition)
            {
                return(e);
            }
            e.HasMoreInformation = true;
            e.ExceptionLine      = _currentLine;
            e.ExceptionColumn    = _currentColumn;
            e.ReferenceLine      = _tokenLine;
            e.ReferenceColumn    = _tokenColumn;
            return(e);
        }
Exemplo n.º 3
0
 public LexerException(LexerExceptionCodes code, params object[] args) : base(string.Format(ResolveExceptionMessage(code, args.Length), args))
 {
     Code = code;
 }
Exemplo n.º 4
0
 public LexerException(LexerExceptionCodes code) : this(code, new object[0])
 {
 }