MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / DefBlockSyntaxTokeniserFunc

Class DefBlockSyntaxTokeniserFunc

libs/parser/DefBlockSyntaxParser.h:401–665  ·  view source on GitHub ↗

* Stateless tokeniser function cutting the incoming character range into * qualified DefSyntaxTokens, returning one token at a time. */

Source from the content-addressed store, hash-verified

399 * qualified DefSyntaxTokens, returning one token at a time.
400 */
401class DefBlockSyntaxTokeniserFunc
402{
403 // Enumeration of states
404 enum class State
405 {
406 Searching, // haven't found anything yet
407 Whitespace, // on whitespace
408 Token, // non-whitespace, non-control character
409 BracedBlock, // within a braced block
410 BlockComment, // within a /* block comment */
411 EolComment, // on an EOL comment starting with //
412 QuotedStringWithinBlock, // within a quoted string within a block
413 BlockCommentWithinBlock, // within a /* block comment */ within a block
414 EolCommentWithinBlock, // an EOL within a block
415 };
416
417 constexpr static const char* const Delims = " \t\n\v\r";
418
419 constexpr static char OpeningBrace = '{';
420 constexpr static char ClosingBrace = '}';
421
422 static bool IsWhitespace(char c)
423 {
424 for (const char* curDelim = Delims; *curDelim != 0; ++curDelim)
425 {
426 if (*curDelim == c) return true;
427 }
428 return false;
429 }
430
431public:
432 /**
433 * REQUIRED by the string::Tokeniser. The operator() will be invoked by the Tokeniser.
434 * This function must search for a token between the two iterators next and end, and if
435 * a token is found, set tok to the token, set next to position to start
436 * parsing on the next call, and return true. The function will return false,
437 * meaning it didn't find anything before reaching the end iterator.
438 */
439 template<typename InputIterator>
440 bool operator() (InputIterator& next, const InputIterator& end, DefSyntaxToken& tok)
441 {
442 // Initialise state, no persistence between calls
443 auto state = State::Searching;
444
445 // Clear out the token, no guarantee that it is empty
446 tok.clear();
447
448 std::size_t openedBlocks = 0;
449
450 while (next != end)
451 {
452 char ch = *next;
453
454 switch (state)
455 {
456 case State::Searching:
457 if (IsWhitespace(ch))
458 {

Callers 2

createTokeniserFunction · 0.85
DefBlockSyntaxParserMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected