MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / detectGen2Syntax

Function detectGen2Syntax

src/ast/ast_parse.cpp:541–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

539 }
540
541 bool detectGen2Syntax ( const char * text, uint32_t length, bool& value ) {
542 // we search for #gen2#, and return true if its there
543 // we skip /* */ and // comments
544 bool in_single_line_comment = false;
545 bool in_multi_line_comment = false;
546 bool in_string = false;
547 for (uint32_t i = 0; i < length; ++i) {
548 if (in_string) {
549 if (text[i] == '\\' && i + 1 < length) {
550 ++i; // skip escaped character
551 } else if (text[i] == '"') {
552 in_string = false;
553 }
554 continue;
555 }
556 if (in_single_line_comment) {
557 if (text[i] == '\n') {
558 in_single_line_comment = false;
559 }
560 continue;
561 }
562 if (in_multi_line_comment) {
563 if (text[i] == '*' && i + 1 < length && text[i + 1] == '/') {
564 in_multi_line_comment = false;
565 ++i;
566 }
567 continue;
568 }
569 if (text[i] == '"') {
570 in_string = true;
571 continue;
572 }
573 if (text[i] == '/' && i + 1 < length) {
574 if (text[i + 1] == '/') {
575 in_single_line_comment = true;
576 ++i;
577 continue;
578 } else if (text[i + 1] == '*') {
579 in_multi_line_comment = true;
580 ++i;
581 continue;
582 }
583 }
584 // check for options\s*gen2
585 if (text[i] == 'o' && i + 7 < length && text[i + 1] == 'p' && text[i + 2] == 't' && text[i + 3] == 'i' && text[i + 4] == 'o' && text[i + 5] == 'n' && text[i + 6] == 's' && isspace(text[i + 7]) ) {
586 i += 7;
587 while (i < length && isspace(text[i])) {
588 ++i;
589 }
590 if (i + 5 < length && text[i] == 'g' && text[i + 1] == 'e' && text[i + 2] == 'n' && text[i + 3] == '2' && !isalnum(text[i + 4]) && text[i + 4] != '_') {
591 i += 4;
592 while (i < length && (isspace(text[i]) || text[i] == '=') && text[i] != '\n' && text[i] != '\r') {
593 ++i;
594 }
595 value = !(i + 4 < length && text[i] == 'f' && text[i + 1] == 'a' && text[i + 2] == 'l' && text[i + 3] == 's' && text[i + 4] == 'e');
596 return true;
597 }
598 }

Callers 1

parseDaScriptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected