os/graphics/graphicstools/bitmapfonttools/src/READER.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * Header READER.CPP
    16 *
    17 */
    18 
    19 
    20 #include "READER.H"
    21 
    22 Reader::Reader()
    23 	{
    24 	iLexAnal = NULL;
    25 	}
    26 
    27 boolean Reader::Open(const String& aFilename)
    28 	{
    29 	boolean state;
    30 	String string = aFilename;
    31 	if (iLexAnal != NULL)
    32 		delete iLexAnal;
    33 	iLexAnal = new LexAnal(string.Text());
    34 
    35 	if (iLexAnal)
    36 		{
    37 		state = etrue;
    38 		iLex =& (iLexAnal->iLex);
    39 		iLexAnal->Read();	// reads first lexical
    40 		}
    41 	else
    42 		state = efalse;
    43 
    44 	return state;
    45 	}
    46 
    47 Reader::~Reader()
    48 	{
    49 	if (iLexAnal != NULL)
    50 		delete iLexAnal;
    51 	}
    52 
    53 boolean Reader::_EOF()
    54 	{
    55 	return ((iLex->iType) == ELexEOF);
    56 	}
    57 
    58 boolean Reader::NewLine()
    59 	{
    60 	boolean state;
    61 	if (iLex->iType == ELexNL)
    62 		{
    63 		iLexAnal->Read();
    64 		state = etrue;
    65 		}
    66 	else
    67 		{
    68 		Error(String("Newline expected"));
    69 		state = efalse;
    70 		}
    71 	return state;
    72 	}
    73 
    74 boolean Reader::Number(int& aNumber)
    75 	{
    76 	boolean state;
    77 	if (iLex->iType == ELexNumber)
    78 		{
    79 		aNumber = iLex->iNumber;
    80 		iLexAnal->Read();
    81 		state = etrue;
    82 		}
    83 	else
    84 		{
    85 		Error(String("Number expected"));
    86 		state = efalse;
    87 		}
    88 	return state;
    89 	}
    90 
    91 boolean Reader::IdentComp(const String& aIdent)
    92 	{
    93 	boolean state;
    94 	if (iLex->iType == ELexIdent)
    95 		{
    96 		if (aIdent == iLex->iText)
    97 			{
    98 			iLexAnal->Read();
    99 			state = etrue;
   100 			}
   101 		else
   102 			state = efalse;
   103 		}
   104 	else
   105 		{
   106 		state = efalse;
   107 		}
   108 	return state;
   109 	}
   110 
   111 boolean Reader::IdentCopy(String& aIdent)
   112 	{
   113 	boolean state;
   114 	if (iLex->iType == ELexIdent)
   115 		{
   116 		aIdent = iLex->iText;
   117 		iLexAnal->Read();
   118 		state = etrue;
   119 		}
   120 	else
   121 		{
   122 		Error(String("Identifier expected"));
   123 		state = efalse;
   124 		}
   125 	return state;
   126 	}
   127 
   128 boolean Reader::StringCopy(String& aString)
   129 	{
   130 	boolean state;
   131 	if (iLex->iType == ELexString)
   132 		{
   133 		aString = iLex->iText;
   134 		iLexAnal->Read();
   135 		state = etrue;
   136 		}
   137 	else
   138 		{
   139 		Error(String("String expected"));
   140 		state = efalse;
   141 		}
   142 	return state;
   143 	}
   144 
   145 boolean Reader::Operator(char& aCh)
   146 	{
   147 	boolean state;
   148 	if (iLex->iType == ELexOperator)
   149 		{
   150 		aCh = iLex->iText[0];
   151 		iLexAnal->Read();
   152 		state = etrue;
   153 		}
   154 	else
   155 		{
   156 		Error(String("Operator expected"));
   157 		state = efalse;
   158 		}
   159 	return state;
   160 	}
   161 
   162 EXPORT_C void Reader::Error(const String& aString)
   163 	{
   164 	cerr << "Error: " << aString;
   165 	iLexAnal->Report();
   166 	while ((iLex->iType != ELexNL) && (iLex->iType != ELexEOF))
   167 		iLexAnal->Read();
   168 	}