core/src/lexer.h
author Tom Sutcliffe <thomas.sutcliffe@accenture.com>
Thu, 26 Aug 2010 00:49:35 +0100
changeset 45 534b01198c2d
parent 0 7f656887cf89
child 95 b3ffff030d5c
permissions -rw-r--r--
Added ENotifyKeypresses and ECaptureCtrlC flags to CCommandBase. Commands can now get keypresses and handle ctrl-C via callbacks instead of having to implement custom active objects. As part of this extended the CCommandBase extension interface to MCommandExtensionsV2 for the new virtual functions KeyPressed(TUint aKeyCode, TUint aModifiers) and CtrlCPressed(). sudo now cleans up correctly by using ECaptureCtrlC.

// lexer.h
// 
// Copyright (c) 2006 - 2010 Accenture. All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
// 
// Initial Contributors:
// Accenture - Initial contribution
//

#ifndef __LEXER_H__
#define __LEXER_H__

#include <e32base.h>

class CReservedLookup;


class TToken
	{
public:
	enum TType
		{
		ENull,
		EString,
		EPipe,
		EDoublePipe,
		ERedirectStdinFromFile,
		ERedirectStdoutToFile,
		ERedirectStdoutToFileAppend,
		ERedirectStdoutToStderr,
		ERedirectStderrToFile,
		ERedirectStderrToFileAppend,
		ERedirectStderrToStdout,
		EAmpersand,
		EDoubleAmpersand,
		EAmpersandPipe,
		ENewLine,
		ESemicolon,
		EVariable
		};
public:
	TToken();
	TToken(TType aType, const TDesC& aToken, TInt aPos);
	TToken& operator=(const TToken& aToken);
	TType Type() const;
	TInt Position() const;
	const TDesC& String() const;
private:
	TType iType;
	TPtrC iToken;
	TInt iPos;
	};


class CLexer : public CBase
	{
public:
	enum TBehaviour
		{
		EHandleSingleQuotes	= 0x00000001,	///< Causes text within single quotes to be reported as a single TToken::EString type token.
		EHandleDoubleQuotes	= 0x00000002,	///< Causes text within double quotes to be reported as a single TToken::EString type token.
		EHandleComments		= 0x00000004	///< Causes text following a '#' until the end of the line to be discarded.
		};
public:
	static CLexer* NewL();
	static CLexer* NewL(TUint aBehaviour);
	static CLexer* NewLC();
	static CLexer* NewLC(TUint aBehaviour);
	~CLexer();
	void DefineTokenTypeL(TToken::TType aTokenType, const TDesC& aString);
	void Set(const TDesC& aDes, const TChar& aEscapeChar);
	TToken NextToken();
	TInt CurrentOffset() const;
	TBool More();
private:
	CLexer(TUint aBehaviour);
	void ConstructL();
	void SkipSingleQuotedChars();
	void SkipDoubleQuotedChars();
	void SkipComment();
	void SkipWhiteSpace();
private:
	TUint iBehaviour;
	TChar iEscapeChar;
	TLex iLex;
	CReservedLookup* iReservedLookup;
	};


#endif // __LEXER_H__