MCPcopy Create free account
hub / github.com/OGRECave/ogre-next / tokenize

Method tokenize

OgreMain/src/OgreScriptLexer.cpp:39–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 ScriptLexer::ScriptLexer() {}
38
39 ScriptTokenListPtr ScriptLexer::tokenize( const String &str )
40 {
41 // State enums
42 enum
43 {
44 READY = 0,
45 COMMENT,
46 MULTICOMMENT,
47 WORD,
48 QUOTE,
49 VAR,
50 POSSIBLECOMMENT
51 };
52
53 // Set up some constant characters of interest
54#if OGRE_WCHAR_T_STRINGS
55 const wchar_t varopener = L'$', quote = L'\"', slash = L'/', backslash = L'\\', openbrace = L'{',
56 closebrace = L'}', colon = L':', star = L'*', cr = L'\r', lf = L'\n';
57 wchar_t c = 0, lastc = 0;
58#else
59 const wchar_t varopener = '$', quote = '\"', slash = '/', backslash = '\\', openbrace = '{',
60 closebrace = '}', colon = ':', star = '*', cr = '\r', lf = '\n';
61 char c = 0, lastc = 0;
62#endif
63
64 String lexeme;
65 uint32 line = 1, state = READY, lastQuote = 0;
66 ScriptTokenListPtr tokens( OGRE_NEW_T( ScriptTokenList, MEMCATEGORY_GENERAL )(), SPFM_DELETE_T );
67 lexemeStorage.reserve( str.length() );
68
69 // Iterate over the input
70 const char *i = str.c_str(), *end = i + str.size();
71 while( i != end )
72 {
73 lastc = c;
74 c = *i;
75
76 if( c == quote )
77 lastQuote = line;
78
79 switch( state )
80 {
81 case READY:
82 if( c == slash && lastc == slash )
83 {
84 // Comment start, clear out the lexeme
85 lexeme = "";
86 state = COMMENT;
87 }
88 else if( c == star && lastc == slash )
89 {
90 lexeme = "";
91 state = MULTICOMMENT;
92 }
93 else if( c == quote )
94 {
95 // Clear out the lexeme ready to be filled with quotes!
96 lexeme = c;

Callers 4

compileMethod · 0.80
_generateASTMethod · 0.80
loadImportPathMethod · 0.80
processVariablesMethod · 0.80

Calls 7

toStringFunction · 0.70
reserveMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected