Exemple #1
0
//static
Command* Command::parseTokens( Tokens& tokens, bool helpMode )
{
    if (tokens.empty()) THROW( CWDB_ERR_PARSER, "Bad syntax: no tokens to parse");
    Command* result = 0;
    try {
        switch(tokens.front().m_angen) {
            case ANGEN_CREATE:   parseCreate( tokens, helpMode, result ); break;
            case ANGEN_DESCR:    parseDescr( tokens, helpMode, result ); break;
            case ANGEN_DROP:     parseDrop( tokens, helpMode, result ); break;
            case ANGEN_DUMP:     parseDump( tokens, helpMode, result ); break;
            case ANGEN_GET:
            case ANGEN_SET:
            case ANGEN_PUT:      parseInput( tokens, helpMode, result ); break;
            case ANGEN_QUERY:    parseQuery( tokens, helpMode, result ); break;
            case ANGEN_USE:      parseUse( tokens, helpMode, result ); break;
            case ANGEN_GENERATE: parseGenerate( tokens, helpMode, result ); break;
            case ANGEN_VERSION:  parseVersion( tokens, helpMode, result ); break;
            case ANGEN_FORMAT:   parseFormat( tokens, helpMode, result ); break;
            case ANGEN_COMPACT:  parseCompact( tokens, helpMode, result ); break;
            case ANGEN_UPDATE:   parseUpdate( tokens, helpMode, result ); break;
            case ANGEN_START:
            case ANGEN_STOP:     parseStart( tokens, helpMode, result ); break;
            case ANGEN_EXPORT:   parseExport( tokens, helpMode, result ); break;
            case ANGEN_IMPORT:   parseImport( tokens, helpMode, result ); break;
            default: THROW( CWDB_ERR_PARSER, "Bad syntax: unknown command" );
        }
    }
    catch (CWDBException& e) {
        if (result != 0) {
            delete result;
            result = 0;
        }
        throw e;
    }

    return result;
}
void LayoutParser::parseKeyboard()
{
    const QXmlStreamAttributes attributes(m_xml.attributes());
    const QString version(attributes.value(QLatin1String("version")).toString());
    const QString actual_version(version.isEmpty() ? "1.0" : version);
    const QString title(attributes.value(QLatin1String("title")).toString());
    const QString language(attributes.value(QLatin1String("language")).toString());
    const QString catalog(attributes.value(QLatin1String("catalog")).toString());
    const bool autocapitalization(boolValue(attributes.value(QLatin1String("autocapitalization")), true));
    m_keyboard = TagKeyboardPtr(new TagKeyboard(actual_version, title, language,
                                                catalog, autocapitalization));

    while (m_xml.readNextStartElement()) {
        const QStringRef name(m_xml.name());

        if (name == QLatin1String("import")) {
            parseImport();
        } else if (name == QLatin1String("layout")) {
            parseLayout();
        } else {
            error(QString::fromLatin1("Expected '<layout>' or '<import>', but got '<%1>'.").arg(name.toString()));
        }
    }
}
Exemple #3
0
bool Parser::parseSchemaTag( ParserContext *context, const QDomElement &root )
{
  QName name(root.tagName());
  if ( name.localName() != QLatin1String("schema") ) {
    qDebug() << "ERROR localName=" << name.localName();
    return false;
  }

  // Already done by caller when coming from type.cpp, but doesn't hurt to do twice
  context->namespaceManager()->enterChild(root);

  // This method can call itself recursively, so save/restore the member attribute.
  QString oldNamespace = d->mNameSpace;
  if ( root.hasAttribute( QLatin1String("targetNamespace") ) )
    d->mNameSpace = root.attribute( QLatin1String("targetNamespace") );

  if (root.attribute( QLatin1String("elementFormDefault") ) == QLatin1String("qualified"))
      d->mDefaultQualifiedElements = true;

  if (root.attribute( QLatin1String("attributeFormDefault") ) == QLatin1String("qualified"))
      d->mDefaultQualifiedAttributes = true;

 // mTypesTable.setTargetNamespace( mNameSpace );

  QDomElement element = root.firstChildElement();
  while ( !element.isNull() ) {
    NSManager namespaceManager( context, element );
    const QName name( element.tagName() );
    if (debugParsing())
        qDebug() << "Schema: parsing" << name.localName();
    if ( name.localName() == QLatin1String("import") ) {
      parseImport( context, element );
    } else if ( name.localName() == QLatin1String("element") ) {
      addGlobalElement( parseElement( context, element, d->mNameSpace, element ) );
    } else if ( name.localName() == QLatin1String("complexType") ) {
      ComplexType ct = parseComplexType( context, element );
      d->mComplexTypes.append( ct );
    } else if ( name.localName() == QLatin1String("simpleType") ) {
      SimpleType st = parseSimpleType( context, element );
      d->mSimpleTypes.append( st );
    } else if ( name.localName() == QLatin1String("attribute") ) {
      addGlobalAttribute( parseAttribute( context, element, d->mNameSpace ) );
    } else if ( name.localName() == QLatin1String("attributeGroup") ) {
      d->mAttributeGroups.append( parseAttributeGroup( context, element, d->mNameSpace ) );
    } else if ( name.localName() == QLatin1String("group") ) {
      d->mGroups.append( parseGroup( context, element, d->mNameSpace ) );
    } else if ( name.localName() == QLatin1String("annotation") ) {
      d->mAnnotations = parseAnnotation( context, element );
    } else if ( name.localName() == QLatin1String("include") ) {
      parseInclude( context, element );
    } else {
        qWarning() << "Unsupported schema element" << name.localName();
    }

    element = element.nextSiblingElement();
  }

  if (!resolveForwardDeclarations())
      return false;

  d->mNameSpace = oldNamespace;

  return true;
}
Exemple #4
0
bool Parser::parseSchemaTag( ParserContext *context, const QDomElement &root )
{
  QName name = root.tagName();
  if ( name.localName() != QLatin1String("schema") )
    return false;

  NSManager *parentManager = context->namespaceManager();
  NSManager namespaceManager;

  // copy namespaces from wsdl
  if ( parentManager )
    namespaceManager = *parentManager;

  context->setNamespaceManager( &namespaceManager );

  QDomNamedNodeMap attributes = root.attributes();
  for ( int i = 0; i < attributes.count(); ++i ) {
    QDomAttr attribute = attributes.item( i ).toAttr();
    if ( attribute.name().startsWith( QLatin1String("xmlns:") ) ) {
      QString prefix = attribute.name().mid( 6 );
      context->namespaceManager()->setPrefix( prefix, attribute.value() );
    }
  }

  if ( root.hasAttribute( QLatin1String("targetNamespace") ) )
    d->mNameSpace = root.attribute( QLatin1String("targetNamespace") );

 // mTypesTable.setTargetNamespace( mNameSpace );

  QDomElement element = root.firstChildElement();
  while ( !element.isNull() ) {
    QName name = element.tagName();
    if ( name.localName() == QLatin1String("import") ) {
      parseImport( context, element );
    } else if ( name.localName() == QLatin1String("element") ) {
      addGlobalElement( parseElement( context, element, d->mNameSpace, element ) );
    } else if ( name.localName() == QLatin1String("complexType") ) {
      ComplexType ct = parseComplexType( context, element );
      d->mComplexTypes.append( ct );
    } else if ( name.localName() == QLatin1String("simpleType") ) {
      SimpleType st = parseSimpleType( context, element );
      d->mSimpleTypes.append( st );
    } else if ( name.localName() == QLatin1String("attribute") ) {
      addGlobalAttribute( parseAttribute( context, element ) );
    } else if ( name.localName() == QLatin1String("attributeGroup") ) {
      d->mAttributeGroups.append( parseAttributeGroup( context, element ) );
    } else if ( name.localName() == QLatin1String("annotation") ) {
      d->mAnnotations = parseAnnotation( context, element );
    } else if ( name.localName() == QLatin1String("include") ) {
      parseInclude( context, element );
    }

    element = element.nextSiblingElement();
  }

  context->setNamespaceManager( parentManager );
  d->mNamespaces = joinNamespaces( d->mNamespaces, namespaceManager.uris() );
  d->mNamespaces = joinNamespaces( d->mNamespaces, QStringList( d->mNameSpace ) );

  resolveForwardDeclarations();

  return true;
}
Exemple #5
0
std::string CSeqWriter::transformAS( CSeqLog &log, const char* packetPath, std::list<std::string> &import, std::map< std::string, std::string > &classDir )
{
    if ( log.className == "SPackHead" )
        log.className = "SPackHead";
    std::list<std::string> importList = import;

    //import 统计
    if ( !classDir.empty() )
        parseImport( log, classDir, importList );

    std::stringstream stream;

    //输出package{
    stream << "package";
    if ( packetPath != NULL && packetPath[0] != '\0' )
        stream << " " << packetPath;
    stream << std::endl;
    stream << '{' << std::endl;

    //输出import
    for ( std::vector< wd::CSeqEle >::iterator iter = log.eleList.begin();
        iter != log.eleList.end();
        ++iter )
    {
        if ( VarType2As( iter->eleType ) == "ByteArray" )
        {
            stream << taps << "import flash.utils.ByteArray;" << std::endl;
            break;
        }
    }
    if ( !importList.empty() )
    {
        for ( std::list<std::string>::iterator iter = importList.begin();
            iter != importList.end();
            ++iter )
        {
            stream << taps << "import " << *iter << ";" << std::endl;
        }
    }
    stream << std::endl;

    //输出注释
    if ( !log.classDescript.empty() )
    {
        std::string descript = log.classDescript;
        for ( int i = (int)descript.find_first_of( '\n' ); i >= 0 && i < (int)descript.length(); )
        {
            if ( descript[i] == '\n' )
            {
                descript.insert( i + 1, taps );
                i += sizeof( taps );
            }
            else
                ++i;
        }
        stream << taps << "/*" << descript << "*/" << std::endl;
    }

    //输出类名
    stream << taps << "public class " << log.className;

    //输出父类
    if ( !log.classParent.empty() )
        stream << " extends " << log.classParent;
    else
        stream << " extends CSeq";
    stream << std::endl;

    //类 {
    stream << taps << '{' << std::endl;

    for ( std::vector< wd::CSeqEle >::iterator iter = log.eleList.begin();
        iter != log.eleList.end();
        ++iter )
    {
        std::string init_type;
        stream << taps << taps << "public var " << iter->eleName << ':' << output_element_as( *iter, init_type );

        if ( !init_type.empty() )
            stream << " = " << init_type;
        stream << ";";

        if ( !iter->eleDescript.empty() )
            stream << taps << "//" << iter->eleDescript;

        stream << std::endl;
    }
    stream << std::endl;

    //输出构造
    stream << taps << taps << "public function " << log.className << "()" << std::endl;
    stream << taps << taps << '{' << std::endl;
    stream << taps << taps << taps << "elementInfo = static_element_info;" << std::endl;

    //输出构造项
    if ( !log.initList.empty() )
    {
        stream << std::endl;

        for ( std::vector< CSeqInit >::iterator iter = log.initList.begin();
            iter != log.initList.end();
            ++iter )
        {
            stream << taps << taps << taps << iter->eleName << " = " << iter->eleDefault << ';' << std::endl;
        }
    }

    stream << taps << taps << '}' << std::endl;

    stream << std::endl;

    //输出父类结构继承
    stream << taps << taps << "static protected var static_element_info:Vector.<CSeqEleInfo> = ";
    if ( !log.classParent.empty() )
        stream << log.classParent;
    else
        stream << "CSeq";
    stream << ".static_element_info" << std::endl;
    stream << taps << taps << taps << ".concat" << std::endl;
    stream << taps << taps << taps << '(' << std::endl;
    stream << taps << taps << taps << taps << "new <CSeqEleInfo>" << std::endl;
    stream << taps << taps << taps << taps << '[' << std::endl;
    for ( std::vector< wd::CSeqEle >::iterator iter = log.eleList.begin();
        iter != log.eleList.end();
        ++iter )
    {
        stream << taps << taps << taps << taps << taps;

        stream << output_register_as( *iter );

        if ( iter + 1 != log.eleList.end() )
            stream << ',';
        stream << std::endl;
    }
    stream << taps << taps << taps << taps << ']' << std::endl;
    stream << taps << taps << taps << ");" << std::endl;

    //类 }
    stream << taps << '}' << std::endl;

    //package }
    stream << '}' << std::endl;

    return stream.str();
}