Parser Class Reference

This parser is in fact a lexical analyzer for ScaleUnit's It matches Numbers (IsNumeric) & Qualifiers (IsCharUnitType). Anything else is considered Unknown. This is just a fill in while I consider how to provide something more generic. The code is blardy awful, partly because of lack of support in the StringBase class. To use it (not that you would), do something like: MonoOn: Parser myParser(stringToParse); if (PrepareForParse() == FALSE) ... if (GetToken() == Parser::TK_QUALIFIER)... myQualifier = GetSemanticValue(); MonoOff: Repeated calls to GetToken() will move along the stringToParse until the end of the string is reached when TK_EOS is returned. More...

List of all members.

Public Types

enum  TOKEN { TK_EOS, TK_UNKNOWN, TK_QUALIFIER, TK_NUMBER }

Public Member Functions

 Parser (const StringBase &ParseString)
BOOL PrepareForParse ()
 Prepares the parser to parse the string given in the constructor from the beginning. Scope: public.
TOKEN GetToken ()
 Retrieves a TOKEN from the input string to be used by some parser somewhere. Scope: public See Also: class Parser.
String_256 GetSemanticValue ()
UINT32 GetCurrentIndex ()

Protected Attributes

const StringBasem_pParseString
UINT32 m_uParsePosition
String_256 m_SemVal

Private Member Functions

 CC_DECLARE_MEMDUMP (Parser)


Detailed Description

This parser is in fact a lexical analyzer for ScaleUnit's It matches Numbers (IsNumeric) & Qualifiers (IsCharUnitType). Anything else is considered Unknown. This is just a fill in while I consider how to provide something more generic. The code is blardy awful, partly because of lack of support in the StringBase class. To use it (not that you would), do something like: MonoOn: Parser myParser(stringToParse); if (PrepareForParse() == FALSE) ... if (GetToken() == Parser::TK_QUALIFIER)... myQualifier = GetSemanticValue(); MonoOff: Repeated calls to GetToken() will move along the stringToParse until the end of the string is reached when TK_EOS is returned.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96

Definition at line 1416 of file scunit.cpp.


Member Enumeration Documentation

enum Parser::TOKEN
 

Enumerator:
TK_EOS 
TK_UNKNOWN 
TK_QUALIFIER 
TK_NUMBER 

Definition at line 1422 of file scunit.cpp.

01423     {
01424         TK_EOS,
01425         TK_UNKNOWN,
01426         TK_QUALIFIER,
01427         TK_NUMBER
01428     };


Constructor & Destructor Documentation

Parser::Parser const StringBase ParseString  )  [inline]
 

Definition at line 1420 of file scunit.cpp.

01420 : m_pParseString(ParseString), m_uParsePosition(0) {}


Member Function Documentation

Parser::CC_DECLARE_MEMDUMP Parser   )  [private]
 

UINT32 Parser::GetCurrentIndex  )  [inline]
 

Definition at line 1433 of file scunit.cpp.

01433 {   return m_uParsePosition;    }

String_256 Parser::GetSemanticValue  )  [inline]
 

Definition at line 1432 of file scunit.cpp.

01432 {   return m_SemVal;    }

Parser::TOKEN Parser::GetToken  ) 
 

Retrieves a TOKEN from the input string to be used by some parser somewhere. Scope: public See Also: class Parser.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Returns:
The TOKEN representing a possible syntactic value for the string starting at the GetCurrentIndex() position in the string on entry to the function and ending at GetCurrentIndex() on exit. Possible values are: TK_QUALIFIER : A possible qualifier token. GetSemanticValue() will contain the string. TK_NUMBER : A number as defined by IsNumeric(). GetSemanticValue() will contain the number corresponding. TK_EOS : End of string has been reached. No more tokens to read. TK_UNKNOWN : Not one of the above

Definition at line 1483 of file scunit.cpp.

01484 {
01485     m_SemVal.Empty();
01486     UINT32 Length = m_pParseString.Length();
01487     while (m_uParsePosition < Length)
01488     {
01489         TCHAR c = m_pParseString[m_uParsePosition];
01490         if (Convert::IsCharUnitType(c))
01491         {
01492             do
01493             {
01494                 m_SemVal += c;
01495                 ++m_uParsePosition;
01496                 c = m_pParseString[m_uParsePosition];
01497             } while (Convert::IsCharUnitType(c) && m_uParsePosition < Length);
01498             return TK_QUALIFIER;
01499         }
01500         else if (StringBase::IsNumeric(c) || (c == Convert::GetDecimalPointChar()))
01501         {
01502             do
01503             {
01504                 m_SemVal += c;
01505                 ++m_uParsePosition;
01506                 c = m_pParseString[m_uParsePosition];
01507             } while ((StringBase::IsNumeric(c)  || (c == Convert::GetDecimalPointChar()))
01508                         && m_uParsePosition < Length);
01509 
01510             return TK_NUMBER;
01511         }
01512         else if (camIsspace(c))
01513         {
01514             ++m_uParsePosition;
01515             continue;
01516         }
01517         else
01518         {
01519             ++m_uParsePosition;
01520             return TK_UNKNOWN;
01521         }
01522     }
01523     return TK_EOS;
01524 }

BOOL Parser::PrepareForParse  ) 
 

Prepares the parser to parse the string given in the constructor from the beginning. Scope: public.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
02/05/96
Returns:
TRUE : If the parser was prepared OK FALSE : otherwise

Definition at line 1456 of file scunit.cpp.

01457 {
01458     m_uParsePosition = 0;
01459     return TRUE;
01460 }


Member Data Documentation

const StringBase& Parser::m_pParseString [protected]
 

Definition at line 1436 of file scunit.cpp.

String_256 Parser::m_SemVal [protected]
 

Definition at line 1438 of file scunit.cpp.

UINT32 Parser::m_uParsePosition [protected]
 

Definition at line 1437 of file scunit.cpp.


The documentation for this class was generated from the following file:
Generated on Sat Nov 10 03:59:27 2007 for Camelot by  doxygen 1.4.4