public Type scanIdentifier()

in src/com/amazon/ion/impl/IonTokenReader.java [578:664]


    public Type scanIdentifier(int c) throws IOException
    {
        // reset our local value buffer
        resetValue();

        // we don't have an identifier type any longer, just string
        this.t = Type.constSymbol;

        // some strings are keywords, most are not
        // mostly we'll guess that it's not a keyword
        this.keyword = null;

        // first we read the identifier content into our value buffer
        // if the value is quoted, use the escape char loop, otherwise
        // look for the non-identifier character (and throw it back)

        if (!readIdentifierContents(c)) { // not quoted (true is quoted)
            // anything in quotes (even single quotes) is not a keyword
            // and here we're not in quoted content (that is handled above)
            // so see if it's also a keyword
            this.keyword = IonTokenReader.matchKeyword(value, 0, value.length());
            if (this.keyword != null) {
                if (this.keyword == Type.kwNull) {
                    c = this.read();
                    if (c == '.') {
                        int dot = value.length();
                        value.append((char)c);
                        c = this.read();
                        int added = readIdentifierContents(c, IonTokenConstsX.TN_MAX_NAME_LENGTH + 1); // +1 is "enough roap" so if there are extra letters at the end of the keyword we keep at least 1
                        int kw = IonTokenConstsX.keyword(value, dot+1, dot+added+1);
                        switch (kw) {
                        case IonTokenConstsX.KEYWORD_NULL:
                        case IonTokenConstsX.KEYWORD_BOOL:
                        case IonTokenConstsX.KEYWORD_INT:
                        case IonTokenConstsX.KEYWORD_FLOAT:
                        case IonTokenConstsX.KEYWORD_DECIMAL:
                        case IonTokenConstsX.KEYWORD_TIMESTAMP:
                        case IonTokenConstsX.KEYWORD_SYMBOL:
                        case IonTokenConstsX.KEYWORD_STRING:
                        case IonTokenConstsX.KEYWORD_BLOB:
                        case IonTokenConstsX.KEYWORD_CLOB:
                        case IonTokenConstsX.KEYWORD_LIST:
                        case IonTokenConstsX.KEYWORD_SEXP:
                        case IonTokenConstsX.KEYWORD_STRUCT:
                            this.keyword = setNullType(value, dot + 1, value.length() - dot - 1);
                            break;
                        default:
                            // not a valid type name - so we have to unread back to the dot
                            for (int ii=value.length(); ii>dot; ) {
                                ii--;
                                char uc = value.charAt(ii);
                                unread(uc);
                            }

                            String message =
                                position()
                                + ": Expected Ion type after 'null.' but found: "
                                + value;
                            throw new IonException(message);
                        }
                    }
                    else {
                        unread(c);
                    }
                }
                this.t = this.keyword;
                return this.t;
            }
        }

        // see if we're a user type of a member name
        c = this.readIgnoreWhitespace();
        if (c != ':') {
            unread(c);
        }
        else {
            c = read();
            if (c != ':') {
                unread(c);
                this.t = Type.constMemberName;
            }
            else {
                this.t = Type.constUserTypeDecl;
            }
        }
        return this.t;
    }