Ejemplo n.º 1
0
void ParserThread::HandleForWhile()
{
    SymbolKind id;
    Token * tok = ConsumeToken(); //eat for or while key word
    id = (tok->type_id()==TKN_FOR)? tkFor:tkWhile;
    Symbol * sym = DoAddToken(id,*tok);
    ConsumeToken(); //eat the left parenthesis
    PushContext();  //save the old context
    m_Context.parentToken=sym;
    DoParse();      // do a parse, and should returned on an unbalanced right parenthesis
    PopContext();   // restore the old context

    tok = PeekToken();
    if(tok->type_id()==TKN_L_BRACE)
    {
        ConsumeToken(); //eat {
        PushContext();  //save the old context
        m_Context.parentToken=sym;
        DoParse();      // do a parse, and should returned on an unbalanced right brace
        PopContext();   // restore the old context
    }
    else
        SkipStatementBlock();

}
Ejemplo n.º 2
0
// Parse a single resource
bool XML_ResourceFork::ParseResource(ResType Type, short ID)
{
    ResourceHandle = Get1Resource(Type,ID);
    if (ResourceHandle == NULL) {
        return false;
    }

    HLock(ResourceHandle);
    if (!DoParse()) {
        const char *Name = SourceName ? SourceName : "[]";
#ifdef TARGET_API_MAC_CARBON
        csprintf(
            temporary,
            "There were configuration-file parsing errors in resource %hd of object %s",
            ID,Name);
        SimpleAlert(kAlertStopAlert,temporary);
#else
        psprintf(
            ptemporary,
            "There were configuration-file parsing errors in resource %hd of object %s",
            ID,Name);
        ParamText(ptemporary,0,0,0);
        Alert(FatalErrorAlert,NULL);
#endif
        ExitToShell();
    }
    HUnlock(ResourceHandle);
    ReleaseResource(ResourceHandle);
    return true;
}
Ejemplo n.º 3
0
bool PluginLoader::ParsePlugin(FileSpecifier& file_name)
{
  OpenedFile file;
  if (file_name.Open(file)) {
    int32 data_size;
    file.GetLength(data_size);
    m_data.resize(data_size);

    if (file.Read(data_size, &m_data[0])) {
      file_name.ToDirectory(current_plugin_directory);

      char name[256];
      current_plugin_directory.GetName(name);
      m_name = name;

      if (!DoParse()) {
        logError1("There were parsing errors in %s Plugin.xml\n", m_name.c_str());
      }
    }

    m_data.clear();
    return true;
  }
  return false;
}
Ejemplo n.º 4
0
void ParserThread::HandleNamespace()
{
    ConsumeToken();
    Token *pk = PeekToken();
    Token name;
    if(pk->type_id()==TKN_IDENTIFIER)
    {
        name = *pk;
        ConsumeToken();
    }
    else
    {
        //un-named namespace
    }

    pk = PeekToken();
    if(pk->type_id()==TKN_L_BRACE)
    {
        ConsumeToken();
        Symbol * sym = DoAddToken(tkNamespace,name);
        PushContext();
        m_Context.parentToken = sym;
        DoParse();
        PopContext();
        TRACE("end of namespace\n");
    }

}
Ejemplo n.º 5
0
bool XML_Loader_SDL::ParseFile(FileSpecifier &file_name)
{
  // Open file
  OpenedFile file;
  if (file_name.Open(file)) {
    printf ( "Parsing: %s\n", file_name.GetPath() );
    // Get file size and allocate buffer
    file.GetLength(data_size);
    data = new char[data_size];

    // In case there were errors...
    file_name.GetName(FileName);

    // Read and parse file
    if (file.Read(data_size, data)) {
      if (!DoParse()) {
        fprintf(stderr, "There were parsing errors in configuration file %s\n",
                FileName);
      }
    }

    // Delete buffer
    delete[] data;
    data = NULL;
    return true;
  } else {
    printf ( "Couldn't open: %s\n", file_name.GetPath() );
  }
  return false;
}
Ejemplo n.º 6
0
GRAPHDB_API bool LoadDOT(IGraph * graph, const std::string & dot)
{
	AttrMap attrs;
	CGraphvizVisitor visitor(graph, false);
	DoParse(dot.c_str(), &visitor);
	visitor.ProcessEdges();
	return true;
}
Ejemplo n.º 7
0
void ParserThread::HandleFunction()
{
    //TRACE("HandleFunction() : %s %s()",m_Context.type.back().name.get_text().c_str(),name.c_str());

    // should always at the ( , so we firstly read the parentheses
    if(m_Context.nameQueue.size()==0)
    {
        m_Context.nameQueue = m_Context.typeQueue;
        m_Context.typeQueue.clear();
    }
    Symbol * sym = DoAddToken(tkFunction, m_Context.nameQueue.back().name);

    ArgumentList args;
    ReadFunctionArguments(args);

    Token * peek = PeekToken();

    if(peek->type_id() == TKN_CONST)
        ConsumeToken();

    // skip the member initialization list
    if(PeekToken()->type_id() == TKN_COLON)
    {
        ConsumeToken();
        while(true)
        {
            if(PeekToken()->type_id()!=TKN_L_BRACE)
                ConsumeToken();
            else
                break;
        }
    }



    peek = PeekToken();
    if (peek->type_id() == TKN_L_BRACE)   // function definition
    {
        TRACE("Function definition");

        //SkipBrace();
        ConsumeToken();
        //Symbol * sym = DoAddToken(tkFunction, m_Context.nameQueue.back().name);
        PushContext();
        m_Context.parentToken = sym;
        DoParse();
        PopContext();

    }
    else if (peek->type_id() == TKN_SEMICOLON)
    {
        TRACE("Function declaration");
        //DoAddToken(tkFunction, m_Context.nameQueue.back().name);
        //newToken->m_Args = args;
        ConsumeToken();
    }
    m_Context.EndStatement();
}
Ejemplo n.º 8
0
//void Conv2Bin()
void Conv2Bin(char *ifname,char *ofname)
{
//	char *ifname = "D:\\falcon4\\TOOLS\\tacref\\tacrefdb.txt";
//	char *ofname = "D:\\falcon4\\TOOLS\\tacref\\tacrefdb.bin";
	long bytesread;

	ifh = _open( ifname, _O_BINARY|_O_RDONLY );
	if( ifh == -1 ) {
		printf("Error: can't open input file (%s)\n",ifname);
		return;	// Error
	}
	//DrawText( gblhdc, "File Opened for Reading!", -1, &gblrect, DT_SINGLELINE);

	ofh = _open( ofname, _O_TRUNC|_O_CREAT|_O_BINARY|_O_WRONLY, _S_IREAD|_S_IWRITE );
	if( ofh == -1 ) {
		if ( ifh ) _close ( ifh );
		printf("Can't create output file (%s)\n",ofname);
		return;
	}

	// Get file length
	flen = _filelength( ifh );
	/* Allocate space for dumping database file  */
	trdata = NULL;
	trdata = (char *) malloc( flen );
	if( !trdata ) {
		// Error, printf( "Insufficient memory !\n" );
		if ( ifh ) _close ( ifh );
		if ( ofh ) _close ( ofh );
		return;
	}

	// reads in the database file
	if (( bytesread = (long) _read( ifh, trdata, flen )) <= 0 ) {
		// Error, perror( "Problem reading file" );
		if ( ifh )    _close ( ifh );
		if ( ofh )    _close ( ofh );
		if ( trdata ) { free( trdata ); trdata = NULL; }
		return;
	}

	startdata   = trdata;
	endingdata  = startdata+flen;

	trdata      = SkipJunk( trdata );
	startentity = trdata;
	InitVar();
	// Conversion
	DoParse();

	_close( ifh );
    _close( ofh );
	DrawText( gblhdc, "Both files are Closed !            ", -1, &gblrect, DT_SINGLELINE);

    free( startdata );
}
Anything GenericXMLParser::Parse(std::istream &reader, const char *filename, long startline, Allocator *a)
{
	StartTrace(GenericXMLParser.Parse);
	fReader = &reader;
	fFileName = filename;
	fLine = startline;
	fParseTree = Anything();
	fParseTree.SetAllocator(a);
	DoParse("", fParseTree);
	return fParseTree;
}
Ejemplo n.º 10
0
void ParserThread::ReadFunctionArguments(ArgumentList &args)
{
    //TKN_L_PAREN
    args.clear();
    ConsumeToken();//remove the first TKN_L_PAREN

    PushContext();
    m_Context.parseType = FunctionParameter;
    DoParse();
    PopContext();

}
Ejemplo n.º 11
0
bool ParserThread::Parse()
{

    TRACE("Start parsing!...................");
    m_Context.inTypedef = false;
    m_Context.parentToken = 0;
    m_Context.parseType = Normal;

    try
    {
        DoParse();
    }
    catch(ParserException& e)
    {
        TRACE("Parse(): End of file");
    }
    m_SymbolTree.Dump();
    cc_string statement = "aaa.bbb.ccc";
    //StatementSolver state(statement,&m_SymbolTree);
    return true;
}
Ejemplo n.º 12
0
//  Simple recursive parser for ASN1 BER.
MHParseNode *MHParseBinary::DoParse()
{
    unsigned char ch;
    // Tag class
    enum { Universal, Context/*, Pseudo*/ } tagClass = Universal;
    // Byte count of end of this item.  Set to INDEFINITE_LENGTH if the length is Indefinite.
    int endOfItem;
    unsigned int tagNumber = 0;

    // Read the first character.
    ch = GetNextChar();

    // ASN1 Coding rules: Top two bits (0 and 1) indicate the tag class.
    // 0x00 - Universal,  0x40 - Application, 0x80 - Context-specific, 0xC0 - Private
    // We only use Universal and Context.
    switch (ch & 0xC0)
    {
        case 0x00: // Universal
            tagClass = Universal;
            break;
        case 0x80:
            tagClass = Context;
            break;
        default:
            MHERROR(QString("Invalid tag class = %1").arg(ch, 0, 16));
    }

    // Bit 2 indicates whether it is a simple or compound type.  Not used.
    // Lower bits are the tag number.
    tagNumber = ch & 0x1f;

    if (tagNumber == 0x1f)   // Except that if it is 0x1F then the tag is encoded in the following bytes.
    {
        tagNumber = 0;

        do
        {
            ch = GetNextChar();
            tagNumber = (tagNumber << 7) | (ch & 0x7f);
        }
        while (ch & 0x80);   // Top bit set means there's more to come.
    }

    // Next byte is the length.  If it is less than 128 it is the actual length, otherwise it
    // gives the number of bytes containing the length, except that if this is zero the item
    // has an "indefinite" length and is terminated by two zero bytes.
    ch = GetNextChar();

    if (ch & 0x80)
    {
        int lengthOfLength = ch & 0x7f;

        if (lengthOfLength == 0)
        {
            endOfItem = INDEFINITE_LENGTH;
        }
        else
        {
            endOfItem = 0;

            while (lengthOfLength--)
            {
                ch = GetNextChar();
                endOfItem = (endOfItem << 8) | ch;
            }

            endOfItem += m_p;
        }
    }
    else
    {
        endOfItem = ch + m_p;
    }

    if (tagClass == Context)
    {
        MHPTagged *pNode = new MHPTagged(tagNumber);

        try
        {
            // The argument here depends on the particular tag we're processing.
            switch (tagNumber)
            {
                case C_MULTIPLE_SELECTION:
                case C_OBSCURED_INPUT:
                case C_INITIALLY_AVAILABLE:
                case C_WRAP_AROUND:
                case C_TEXT_WRAPPING:
                case C_INITIALLY_ACTIVE:
                case C_MOVING_CURSOR:
                case C_SHARED:
                case C_ENGINE_RESP:
                case C_TILING:
                case C_BORDERED_BOUNDING_BOX:
                {
                    // BOOL
                    // If there is no argument we need to indicate that so that it gets
                    // the correct default value.
                    if (m_p != endOfItem)
                    {
                        int intVal = ParseInt(endOfItem); // May raise an exception
                        pNode->AddArg(new MHPBool(intVal != 0));
                    }

                    break;
                }

                case C_INPUT_TYPE:
                case C_SLIDER_STYLE:
                case C_TERMINATION:
                case C_ORIENTATION:
                case C_HORIZONTAL_JUSTIFICATION:
                case C_BUTTON_STYLE:
                case C_START_CORNER:
                case C_LINE_ORIENTATION:
                case C_VERTICAL_JUSTIFICATION:
                case C_STORAGE:
                {
                    // ENUM
                    if (m_p != endOfItem)
                    {
                        int intVal = ParseInt(endOfItem); // May raise an exception
                        pNode->AddArg(new MHPEnum(intVal));
                    }

                    break;
                }

                case C_INITIAL_PORTION:
                case C_STEP_SIZE:
                case C_INPUT_EVENT_REGISTER:
                case C_INITIAL_VALUE:
                case C_IP_CONTENT_HOOK:
                case C_MAX_VALUE:
                case C_MIN_VALUE:
                case C_LINE_ART_CONTENT_HOOK:
                case C_BITMAP_CONTENT_HOOK:
                case C_TEXT_CONTENT_HOOK:
                case C_STREAM_CONTENT_HOOK:
                case C_MAX_LENGTH:
                case C_CHARACTER_SET:
                case C_ORIGINAL_TRANSPARENCY:
                case C_ORIGINAL_GC_PRIORITY:
                case C_LOOPING:
                case C_ORIGINAL_LINE_STYLE:
                case C_STANDARD_VERSION:
                case C_ORIGINAL_LINE_WIDTH:
                case C_CONTENT_HOOK:
                case C_CONTENT_CACHE_PRIORITY:
                case C_COMPONENT_TAG:
                case C_ORIGINAL_VOLUME:
                case C_PROGRAM_CONNECTION_TAG:
                case C_CONTENT_SIZE:
                {
                    // INT
                    if (m_p != endOfItem)
                    {
                        int intVal = ParseInt(endOfItem); // May raise an exception
                        pNode->AddArg(new MHPInt(intVal));
                    }

                    break;
                }

                case C_OBJECT_INFORMATION:
                case C_CONTENT_REFERENCE:
                case C_FONT_ATTRIBUTES:
                case C_CHAR_LIST:
                case C_NAME:
                case C_ORIGINAL_LABEL:
                {
                    // STRING
                    // Unlike INT, BOOL and ENUM we can't distinguish an empty string
                    // from a missing string.
                    MHOctetString str;
                    ParseString(endOfItem, str);
                    pNode->AddArg(new MHPString(str));
                    break;
                }

                default:
                {
                    // Everything else has either no argument or is self-describing
                    // TODO: Handle indefinite length.
                    if (endOfItem == INDEFINITE_LENGTH)
                    {
                        MHERROR("Indefinite length arguments are not implemented");
                    }

                    while (m_p < endOfItem)
                    {
                        pNode->AddArg(DoParse());
                    }
                }
            }
        }
        catch (...)
        {
            // Memory clean-up
            delete pNode;
            throw;
        }

        return pNode;
    }
    else   // Universal - i.e. a primitive type.
    {
        // Tag values

        switch (tagNumber)
        {
            case U_BOOL: // Boolean
            {
                int intVal = ParseInt(endOfItem);
                return new MHPBool(intVal != 0);
            }
            case U_INT: // Integer
            {
                int intVal = ParseInt(endOfItem);
                return new MHPInt(intVal);
            }
            case U_ENUM: // ENUM
            {
                int intVal = ParseInt(endOfItem);
                return new MHPEnum(intVal);
            }
            case U_STRING: // String
            {
                MHOctetString str;
                ParseString(endOfItem, str);
                return new MHPString(str);
            }
            case U_NULL: // ASN1 NULL
            {
                return new MHPNull;
            }
            case U_SEQUENCE: // Sequence
            {
                MHParseSequence *pNode = new MHParseSequence();

                if (endOfItem == INDEFINITE_LENGTH)
                {
                    MHERROR("Indefinite length sequences are not implemented");
                }

                try
                {
                    while (m_p < endOfItem)
                    {
                        pNode->Append(DoParse());
                    }
                }
                catch (...)
                {
                    // Memory clean-up if error.
                    delete pNode;
                    throw;
                }

                return pNode;
            }
            default:
                MHERROR(QString("Unknown universal %1").arg(tagNumber));
        }
    }
}
Ejemplo n.º 13
0
clCommandLineParser::clCommandLineParser(const wxString& str, size_t flags)
    : m_commandline(str)
    , m_flags(flags)
{
    DoParse();
}
//************************************************************************************
void CBCGPOutlineParser::UpdateOutlining (CString& strBuffer, int nOffsetFrom, int nCharsCount,
							  CBCGPOutlineNode* pOutlineNode, BCGP_EDIT_OUTLINE_CHANGES& changes)
{
	ASSERT_VALID (this);
	ASSERT (nOffsetFrom >= 0);
	ASSERT (nCharsCount >= 0);
	ASSERT (nOffsetFrom + nCharsCount <= strBuffer.GetLength ());
	ASSERT_VALID (pOutlineNode);

	int nStartOffset = nOffsetFrom;
	int nEndOffset = nOffsetFrom + nCharsCount - 1;
	CBCGPOutlineNode* pChangedNode = GetRangeToReparse (pOutlineNode, nStartOffset, nEndOffset);
	nStartOffset = max (0, nStartOffset);
	nEndOffset = min (strBuffer.GetLength () - 1, nEndOffset);

	if (nStartOffset > nEndOffset)
	{
		return;	// no reparse needed
	}

	changes.m_nStartOffset = min (nStartOffset, changes.m_nStartOffset);
	changes.m_nEndOffset = max (nEndOffset, changes.m_nEndOffset);

	// --------------------------------------------------------------
	// 1) Parse text and find new blocks and part of blocks (markers)
	// --------------------------------------------------------------
	CObList lstBlocks;
	DoParse (strBuffer, nStartOffset, nEndOffset, lstBlocks);

		// ----------------------------------------------------------
		// Reparse text once more
		// if parser found blocks that are greater then parsing range 
		// ----------------------------------------------------------
		int nMin = nStartOffset, nMax = nEndOffset;
		CalcMinMaxBounds (lstBlocks, nMin, nMax);

		if (nMin < nStartOffset || nMax > nEndOffset)
		{
			nStartOffset = min (nMin, nStartOffset);
			nEndOffset = max (nMax, nEndOffset);

			pChangedNode = GetRangeToReparse (pOutlineNode, nStartOffset, nEndOffset);
			nStartOffset = max (0, nStartOffset);
			nEndOffset = min (strBuffer.GetLength () - 1, nEndOffset);

			changes.m_nStartOffset = min (nStartOffset, changes.m_nStartOffset);
			changes.m_nEndOffset = max (nEndOffset, changes.m_nEndOffset);

			while (!lstBlocks.IsEmpty ())
			{
				delete lstBlocks.RemoveTail ();
			}
			DoParse (strBuffer, nStartOffset, nEndOffset, lstBlocks);
		}

	// Update name offsets, start offsets and end offsets:
	DoUpdateOffsets (strBuffer, nStartOffset, nEndOffset, lstBlocks);

	// ------------------------
	// Reconstruct outline tree
	// ------------------------

	// 2) Del old blocks
	pOutlineNode->DeleteBlocksInRange (nStartOffset, nEndOffset, changes); // do not remove user blocks

	for (POSITION pos = lstBlocks.GetHeadPosition (); pos != NULL; )
	{
		POSITION posSave = pos;
		CBCGPOutlineNode* pNode = (CBCGPOutlineNode*) lstBlocks.GetNext (pos);
		ASSERT_VALID (pNode);

		BlockType* pBlockType = m_arrBlockTypes [pNode->m_nBlockType];
		if (pBlockType != NULL && !pBlockType->m_bIgnore)
		{
			if ((pNode->m_dwFlags & g_dwOBFComplete) != 0)
			{
				// 3) Add new blocks
				AddNode (pNode, pOutlineNode, changes);
			}
			else if ((pNode->m_dwFlags & g_dwOBFLeft) != 0 ||
					 (pNode->m_dwFlags & g_dwOBFRight) != 0)
			{
				// it's possible that pChangedNode was removed from outline tree
				POSITION posChangedNode = changes.m_lstRemoved.Find (pChangedNode);
				if (posChangedNode != NULL)
				{
					if ((pNode->m_dwFlags & g_dwOBFLeft) != 0)
					{
						pChangedNode = pOutlineNode->GetInnermostBlock (pNode->m_nStart);
					}
					else if ((pNode->m_dwFlags & g_dwOBFRight) != 0)
					{
						pChangedNode = pOutlineNode->GetInnermostBlock (pNode->m_nEnd);
					}
					if (pChangedNode == NULL)
					{
						pChangedNode = pOutlineNode;
					}
				}

				ASSERT_VALID (pChangedNode);

				// 4) Reconstruct outline tree (add new markers)
				if (!AddMarker (pNode, pChangedNode, changes))
				{
					lstBlocks.RemoveAt (posSave);
					delete pNode;	// to prevent memory leak
				}
			}
		}
		else
		{
			// delete temporary blocks:
			lstBlocks.RemoveAt (posSave);
			delete pNode;
		}
	}
}
Ejemplo n.º 15
0
// Run the parser
MHParseNode *MHParseText::Parse()
{
    GetNextChar(); // Initialise m_ch
    NextSym(); // Initialise the symbol values.
    return DoParse();
}
Ejemplo n.º 16
0
MHParseNode *MHParseText::DoParse()
{
    MHParseNode *pRes = NULL;
    try {
        switch (m_nType) {
        case PTStartSection: // Open curly bracket
            {
                NextSym();
                // Should be followed by a tag.
                if (m_nType != PTTag) Error("Expected ':' after '{'");
                MHPTagged *pTag = new MHPTagged(m_nTag);
                pRes = pTag;
                NextSym();
                while (m_nType != PTEndSection) {
                    pTag->AddArg(DoParse());
                }
                NextSym(); // Remove the close curly bracket.
                break;
            }

        case PTTag: // Tag on its own.
            {
                int nTag = m_nTag;
                MHPTagged *pTag = new MHPTagged(nTag);
                pRes = pTag;
                NextSym();
                switch (nTag) {
                case C_ITEMS:
                case C_LINK_EFFECT:
                case C_ACTIVATE:
                case C_ADD:
                case C_ADD_ITEM:
                case C_APPEND:
                case C_BRING_TO_FRONT:
                case C_CALL:
                case C_CALL_ACTION_SLOT:
                case C_CLEAR:
                case C_CLONE:
                case C_CLOSE_CONNECTION:
                case C_DEACTIVATE:
                case C_DEL_ITEM:
                case C_DESELECT:
                case C_DESELECT_ITEM:
                case C_DIVIDE:
                case C_DRAW_ARC:
                case C_DRAW_LINE:
                case C_DRAW_OVAL:
                case C_DRAW_POLYGON:
                case C_DRAW_POLYLINE:
                case C_DRAW_RECTANGLE:
                case C_DRAW_SECTOR:
                case C_FORK:
                case C_GET_AVAILABILITY_STATUS:
                case C_GET_BOX_SIZE:
                case C_GET_CELL_ITEM:
                case C_GET_CURSOR_POSITION:
                case C_GET_ENGINE_SUPPORT:
                case C_GET_ENTRY_POINT:
                case C_GET_FILL_COLOUR:
                case C_GET_FIRST_ITEM:
                case C_GET_HIGHLIGHT_STATUS:
                case C_GET_INTERACTION_STATUS:
                case C_GET_ITEM_STATUS:
                case C_GET_LABEL:
                case C_GET_LAST_ANCHOR_FIRED:
                case C_GET_LINE_COLOUR:
                case C_GET_LINE_STYLE:
                case C_GET_LINE_WIDTH:
                case C_GET_LIST_ITEM:
                case C_GET_LIST_SIZE:
                case C_GET_OVERWRITE_MODE:
                case C_GET_PORTION:
                case C_GET_POSITION:
                case C_GET_RUNNING_STATUS:
                case C_GET_SELECTION_STATUS:
                case C_GET_SLIDER_VALUE:
                case C_GET_TEXT_CONTENT:
                case C_GET_TEXT_DATA:
                case C_GET_TOKEN_POSITION:
                case C_GET_VOLUME:
                case C_LAUNCH:
                case C_LOCK_SCREEN:
                case C_MODULO:
                case C_MOVE:
                case C_MOVE_TO:
                case C_MULTIPLY:
                case C_OPEN_CONNECTION:
                case C_PRELOAD:
                case C_PUT_BEFORE:
                case C_PUT_BEHIND:
                case C_QUIT:
                case C_READ_PERSISTENT:
                case C_RUN:
                case C_SCALE_BITMAP:
                case C_SCALE_VIDEO:
                case C_SCROLL_ITEMS:
                case C_SELECT:
                case C_SELECT_ITEM:
                case C_SEND_EVENT:
                case C_SEND_TO_BACK:
                case C_SET_BOX_SIZE:
                case C_SET_CACHE_PRIORITY:
                case C_SET_COUNTER_END_POSITION:
                case C_SET_COUNTER_POSITION:
                case C_SET_COUNTER_TRIGGER:
                case C_SET_CURSOR_POSITION:
                case C_SET_CURSOR_SHAPE:
                case C_SET_DATA:
                case C_SET_ENTRY_POINT:
                case C_SET_FILL_COLOUR:
                case C_SET_FIRST_ITEM:
                case C_SET_FONT_REF:
                case C_SET_HIGHLIGHT_STATUS:
                case C_SET_INTERACTION_STATUS:
                case C_SET_LABEL:
                case C_SET_LINE_COLOUR:
                case C_SET_LINE_STYLE:
                case C_SET_LINE_WIDTH:
                case C_SET_OVERWRITE_MODE:
                case C_SET_PALETTE_REF:
                case C_SET_PORTION:
                case C_SET_POSITION:
                case C_SET_SLIDER_VALUE:
                case C_SET_SPEED:
                case C_SET_TIMER:
                case C_SET_TRANSPARENCY:
                case C_SET_VARIABLE:
                case C_SET_VOLUME:
                case C_SPAWN:
                case C_STEP:
                case C_STOP:
                case C_STORE_PERSISTENT:
                case C_SUBTRACT:
                case C_TEST_VARIABLE:
                case C_TOGGLE:
                case C_TOGGLE_ITEM:
                case C_TRANSITION_TO:
                case C_UNLOAD:
                case C_UNLOCK_SCREEN:
                case C_CONTENT_REFERENCE:
                case C_TOKEN_GROUP_ITEMS:
                case C_POSITIONS:
                case C_MULTIPLEX:
                    {   // These are parenthesised in the text form.  We have to remove the
                        // parentheses otherwise we will return a sequence which will not be
                        // be compatible with the binary form.
                        if (m_nType != PTStartSeq) Error("Expected '('");
                        NextSym();
                        while (m_nType != PTEndSeq) pTag->AddArg(DoParse());
                        NextSym(); // Remove the close parenthesis.
                        break;
                    }
                case C_ORIGINAL_CONTENT:
                case C_NEW_GENERIC_BOOLEAN:
                case C_NEW_GENERIC_INTEGER:
                case C_NEW_GENERIC_OCTETSTRING:
                case C_NEW_GENERIC_OBJECT_REF:
                case C_NEW_GENERIC_CONTENT_REF:
                case C_ORIGINAL_VALUE:
                    // These always have an argument which may be a tagged item.
                    {
                        // Is it always the case that there is at least one argument so if we haven't
                        // had any arguments yet we should always process a tag as an argument?
                        pTag->AddArg(DoParse());
                        break;
                    }
                default:
                    // This can be followed by an int, etc but a new tag is dealt with by the caller.
                    while (m_nType == PTBool ||m_nType == PTInt || m_nType == PTString || m_nType == PTEnum || m_nType == PTStartSeq) {
                        pTag->AddArg(DoParse());
                    }

                }
                break;
            }

        case PTInt:
            {
                pRes = new MHPInt(m_nInt);
                NextSym();
                break;
            }

        case PTBool:
            {
                pRes = new MHPBool(m_fBool);
                NextSym();
                break;
            }

        case PTString:
            {
                MHOctetString str;
                str.Copy(MHOctetString((const char *)m_String, m_nStringLength));
                pRes = new MHPString(str);
                NextSym();
                break;
            }

        case PTEnum:
            {
                pRes = new MHPEnum(m_nInt);
                NextSym();
                break;
            }

        case PTNull:
            {
                pRes = new MHPNull;
                NextSym();
                break;
            }

        case PTStartSeq: // Open parenthesis.
            {
                MHParseSequence *pSeq = new MHParseSequence;
                pRes = pSeq;
                NextSym();
                while (m_nType != PTEndSeq) pSeq->Append(DoParse());
                NextSym(); // Remove the close parenthesis.
                break;
            }

        default:
            Error("Unexpected symbol");
        }
        return pRes;
    }
    catch (...) {
        delete(pRes);
        throw;
    }
}
void GenericXMLParser::DoParse(String theTag, Anything &tag)
{
	StartTrace(GenericXMLParser.DoParse);
	int c, lookahead;
	Anything &tagbody = tag; // now just append, allow for different things like tagbody = tag["body"]
	String reply;

	while ((c = Get()) != 0 && c != EOF) {
		switch (c) {
			case '<':
				Store(tagbody, reply);
				lookahead = Peek();
				switch (lookahead) {
					case '!':
						Store(tagbody, reply);
						Store(tagbody, ParseCommentCdataOrDtd());
						break;
					case '/': {
						Get();
						String tagname = ParseName();
						c = Peek();
						if ('>' == c && tagname == theTag) {
							Get();
							return; // done
							//reply.Append("</").Append(tagname).Append(char(c));
						} else {
							// a potential syntax error...
							reply.Append("</").Append(tagname);
							String msg("Unexpected character <x");
							msg.AppendAsHex((unsigned char)c).Append('>');
							msg.Append(" or mismatched tag: ").Append(tagname);
							msg.Append(" expected: ").Append(theTag);
							Error(msg);
						}
						break;
					}
					case '?': {
						Store(tagbody, ParseXmlOrProcessingInstruction());
						break;
					}
					default:
						if (IsValidNameChar(lookahead)) {
							String tagname;
							Anything subTag;
							Anything attrs;
							bool hasbody = ParseTag(tagname, attrs);
							subTag[tagname] = attrs;
							if (hasbody) {
								DoParse(tagname, subTag);
							}
							Store(tagbody, subTag);
							//if (hasbody)
							//Store (ProcessTag(tagname,attributes));
							//else
							//Store(RenderTagAsLiteral(tagname,attributes));
						} else {
							// it cannot be a tag, so just append the '<'
							reply << (char)c;
						}
				}
				break;
			case '\x0D':// normalize line feeds
				if ('\x0A' == Peek()) {
					Get();
				}
				c = '\x0A' ;
				// Fall Through...
			default:
				reply << ((char)c);
		}
	}
	Store(tagbody, reply);
}
Ejemplo n.º 18
0
void ParserThread::HandleClass(EClassType ct)
{

    // class xxx {   or class {
    // the keyworkd "class" is already comsumed

    //assert(CurrentToken()->type_id()==TKN_CLASS);
    ConsumeToken();


    Token * current =  ConsumeToken();      // class name
    Token * next    =  PeekToken();

    TRACE("HandleClass() : Found class '%s'", current->get_text().c_str() );


    // Check current firstly
    if (current->type_id() == TKN_L_BRACE)   // unnamed class/struct/union
    {
//                cc_string unnamedTmp;
//                unnamedTmp.Printf(_T("%s%s%d"),
//                                  ParserConsts::unnamed.wx_str(),
//                                  ct == ctClass ? _T("Class") :
//                                  ct == ctUnion ? _T("Union") :
//                                                  _T("Struct"), ++m_pTokensTree->m_StructUnionUnnamedCount);
//
//                Token* newToken = DoAddToken(tkClass, unnamedTmp, lineNr);
//
//                PushContext();
//                m_Context.Clear();
//                m_Context.parentToken = newToken;
//                m_Context.accessScope  = ct == ctClass ? tsPrivate : tsPublic; // struct has default public scope
//
//				newToken->m_ImplLine = lineNr;
//				newToken->m_ImplLineStart = m_Tokenizer.GetLineNumber();
//
//                DoParse();
//
//                PopContext();
    }
    else if (current->type_id() == TKN_IDENTIFIER)     //OK, we need to check the next
    {
        //parser base clause
        if ( next->type_id() == TKN_COLON )
        {
            //ReadType
            //ConsumeToken(); //remove :id
            ConsumeToken(); //remove  :
            ConsumeToken(); //remove protect/public/private
            //ConsumeToken(); //need to read the id
            ParseFullIdentifer();
        }
        next = PeekToken();
        if ( next->type_id() == TKN_L_BRACE)   // class AAA {, we find the "{" here
        {

            //ParserThreadContext savedContext = m_Context;
            //m_Context.EndStatement();
            //m_Context.parentToken = newToken;
            ConsumeToken();// consume {
            Symbol * sym = DoAddToken(tkClass, *current);
            PushContext();
            m_Context.parentToken = sym;
            DoParse();  // when meet a }, we should return from DoParse()
            PopContext();
            current = ConsumeToken();
            if(current->type_id()==TKN_SEMICOLON)  // class A {.....};
                return;
            else
                SkipStatementBlock(); //struct A {....} a b;

        }
    }
    else
    {
        // something wrong, should be skip to a semicolon
        SkipStatementBlock();
    }

}