Beispiel #1
0
/**********************************************************************************************
 *
 * ReadProcessingInstruction
 *
 * ProcessingInstruction = '<?' QualifiedName ( Whitespace (Character)* ) ? '?>' ;
 *
 *********************************************************************************************/
XMLScanner::TOKEN XMLScanner::ReadProcessingInstruction () {
    QualfiedName targer = ReadQualifiedName ();
    if (isWhitespace (current)) {
        while (ReadCharacter ()) {
            if (current == '?') {
                ReadCharacter ();
                if (current == '>') {
                    ReadCharacter ();
                    return TOKEN_PROCESSING_INSTRUCTION;

                } else {
                    output.Append ('?');
                    output.Append (current);
                    continue;
                }

            } else {
                output.Append (current);
            }
        }
        throw UnexpectedEndException ();

    } else {
        throw UnexpectedCharacterException ();
    }
}
Beispiel #2
0
/**********************************************************************************************
 *
 * ReadQualifiedName
 *
 * QualifiedName = Name ? ":" ? Name ;
 *
 * Name = NameStartCharacter ( NameCharacter )* ;
 *
 * NameStartCharacter = "_" | [A-Z] | [a-z] ;
 *
 * NameCharacter = NameStartCharacter | "-" | "." | [0-9] ;
 *
 *********************************************************************************************/
QualifiedName XMLParser::ReadQualifiedName () {
    static const int name_charachters [] = {
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
        0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
        0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
    };

    bool first = true;
    bool valid = true;

    std::string specifier;
    std::string name;

    do {
        if (valid && current == ':') {
            if (specifier == "") {
                specifier = output.toString ();
                output.Reset ();
            } else {
                valid = false;
            }

        } else if (current == '\x20' || current == '\x9' || current ==  '\xD' || current == '\xA') {
            Position end = position;

            if (!valid) throw InvalidNameException     ();
            if (first ) throw UnexpectedTokenException ();

            return QualifiedName (specifier, name);

        } else if ('\0' <= current && current < '\x7f' && name_characters [(int) current] == 1) {
            if ((first && '9' < current) || !first) {
                first = false;
                output.AppendIgnoreCase (current);
            } else {
                valid = false;
            }

        } else {
            valid = false;
            continue;
        }

    } while (ReadCharacter ());

    return UnexpectedEndException ();
}
Beispiel #3
0
/**********************************************************************************************
 *
 * ReadCDATASection
 *
 * CDATASection = '<![CDATA[' Character *  ']]>' ;
 *
 *********************************************************************************************/
void XMLScanner::ReadCDATASection () {
    if (current == '[') {
        ReadCharacter ();
        if (current == 'C') {
            ReadCharacter ();
            if (current == 'D') {
                ReadCharacter ();
                if (current == 'A') {
                    ReadCharacter ();
                    if (current == 'T') {
                        ReadCharacter ();
                        if (current == 'A') {
                            ReadCharacter ();
                            if (current == '[') {
                                /* CDATA section content */
                                while (ReadCharacter ()) {
                                    if (current == ']') {
                                        ReadCharacter ();
                                        if (current == ']') {
                                            ReadCharacter ();
                                            if (current == '>') {
                                                ReadCharacter ();
                                                return ;
                                            } else {
                                                output.Append (']');
                                                output.Append (']');
                                                output.Append (current);
                                            }
                                        } else {
                                            output.Append (']');
                                            output.Append (current);
                                        }
                                    } else {
                                        output.Append (current);
                                    }
                                }
                                throw UnexpectedEndException ();
                            }
                        }
                    }
                }
            }
        }
    }
    throw UnexpectedCharacterException ();
}
Beispiel #4
0
void Reader::expectToken(const std::wstring &token)
{
    std::wstring readedToken;

    CASE_BEGIN
    getToken(readedToken);

    if (readedToken!=token) {
        throw(WrongTokenException(token, readedToken));
    }

    return;

    CASE_END

    throw(UnexpectedEndException());
}
Beispiel #5
0
/**********************************************************************************************
 *
 * ReadComment
 *
 * Comment = '<!--' ((Character - '-') | ('-' (Character - '-')))*  '-->' ;
 *
 *********************************************************************************************/
void XMLScanner::ReadComment () {
    if (current == '-') {
        ReadCharacter ();
        if (current == '-') {
            ReadCharacter ();
            while (ReadCharacter ()) {
                if (current == '-') {
                    ReadCharacter ();
                    if (current == '-') {
                        ReadCharacter ();
                        if (current == '>') {
                            ReadCharacter ();
                            return ;
                        } else {
                            // TODO : Warning : Illegal sequence '--' inside comment
                        }
                    }
                }
            }
            throw UnexpectedEndException ();
        }
    }
    throw UnexpectedCharacterException ();
}
Beispiel #6
0
void Reader::getToken(std::wstring &token)
{
    CASE_BEGIN
    token.clear();

    while (pos<str.size() && iswspace(str[pos])) {
        ++pos;
    }

    if (pos>=str.size()) {
        throw(UnexpectedEndException());
    }

    wchar_t ch = str[pos];

    switch (ch) {
    case L'(':
    case L')':
    case L',':
    case L'↑':
    case L'¬':
    case L'∧':
    case L'∨':
    case L'⇒':
    case L'⇔':
    case L'⊤':
    case L'⊥':
    case L'∀':
    case L'∃':
    case L'=':
    case L'.':
        token.push_back(ch);
        ++pos;

        return;

        break;
    }

    if (iswalpha(ch)==false) {
        throw(AlphaExpectedException());
    }

    ++pos;

    if (pos<str.size() && str[pos]==L'_') {
        ++pos;

        if (pos>=str.size() || iswalpha(str[pos])==false) {
            throw(AlphaExpectedException());
        }

        while (pos<str.size() && iswalnum(str[pos])) {
            token += str[pos++];
        }

        Symbol s = dictionary(token);

        switch (ch) {
        case L'v':
            if (s.type==NONE_SYMBOL) {
                Variable v;

                dictionary.insert(token, v);
                dictionaryExtender.merge();
            } else if (s.type!=VARIABLE) {
                throw(VariableExpectedException());
            }

            return;

            break;
        case L'c':
            if (s.type==NONE_SYMBOL) {
                ConstantSymbol c;

                dictionary.insert(token, c);
                dictionaryExtender.merge();
            } else if (s.type!=CONSTANT) {
                throw(ConstantExpectedException());
            }

            return;

        case L'f':
            if (s.type==NONE_SYMBOL) {
                token = std::wstring(L"f_")+token;
            } else if (s.type!=OPERATION) {
                throw(OperationExpectedException());
            }

            return;

        case L'R':
            if (s.type==NONE_SYMBOL) {
                token = std::wstring(L"R_")+token;
            } else if (s.type!=RELATION) {
                throw(RelationExpectedException());
            }

            return;

            break;

        default:
            throw(OneOfExpectedException(L"vcfR"));

            break;
        }
    }

    --pos;

    while (pos<str.size() && iswalnum(str[pos])) {
        token += str[pos++];
    }

    return;

    CASE_END

    throw(UnexpectedEndException());
}