Exemplo n.º 1
0
        public Token next(Mode mode)
        {
            Char ch = nextChar();
            switch (mode)
            {
                case Mode.DTEXT:
                    if (isDText(ch))
                        curToken = lexDText();
                    else if (isFWS(ch))
                        curToken = lexFWS();
                    else if (ch == ']')
                        curToken = new Token(Token.Type.RBRACKET, "]");
                    else
                        throw new LexerException("Unexpected character in " + mode + " mode: " + ch);
                    break;
                case Mode.DEFAULT:
                    switch (ch)
                    {
                        case Char.MinValue: curToken = new Token(Token.Type.EOS, ""); break;
                        case '(': curToken = lexComment(); break;
                        case '\r': curToken = lexCRLForFWS(); break;
                        case ' ': case '\t': curToken = lexFWS(); break;
                        //case '\\': return lexQuotedChar();
                        case '"': curToken = lexQuotedString(); break;
                        case '<': curToken = new Token(Token.Type.LESS, "<"); break;
                        case '>': curToken = new Token(Token.Type.GREAT, ">"); break;
                        case '@': curToken = new Token(Token.Type.AT, "@"); break;
                        case ',': curToken = new Token(Token.Type.COMMA, ","); break;
                        case ';': curToken = new Token(Token.Type.SEMICOLON, ";"); break;
                        case ':': curToken = new Token(Token.Type.COLON, ":"); break;
                        case '[': curToken = new Token(Token.Type.LBRACKET, "["); break;
                        case ']': curToken = new Token(Token.Type.RBRACKET, "]"); break;
                        default:
                            if (isAtomChar(ch))
                            {
                                curToken = lexDotAtom();  // dot-atom allowed?
                                break;
                            }
                            else
                                throw new LexerException("Unrecognized token at '" + curChar() + "'");
                    }
                    break;
                //if (0x21 < curChar && curChar < 0x7e) return new Token(Token.Type.VChar);
            }

            return curToken;
        }
Exemplo n.º 2
0
 internal void expectCurrent(Token.Type type)
 {
     if (curToken.type != type)
         throw new LexerException("Unexpected token " + curToken.type + " while expected " + type);
 }