MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / scan_string_content

Function scan_string_content

codegraph-kernel/grammars/kotlin/scanner.c:81–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81static bool scan_string_content(TSLexer *lexer, Stack *stack) {
82 if (stack->size == 0) return false; // Stack is empty. We're not in a string.
83 Delimiter end_char = stack->contents[stack->size - 1]; // peek
84 bool is_triple = false;
85 bool has_content = false;
86 if (end_char & 1) {
87 is_triple = true;
88 end_char -= 1;
89 }
90 while (lexer->lookahead) {
91 if (lexer->lookahead == '$') {
92 // if we did not just start reading stuff, then we should stop
93 // lexing right here, so we can offer the opportunity to lex a
94 // interpolated identifier
95 if (has_content) {
96 lexer->result_symbol = STRING_CONTENT;
97 return has_content;
98 }
99 // otherwise, if this is the start, determine if it is an
100 // interpolated identifier.
101 // otherwise, it's just string content, so continue
102 advance(lexer);
103 if (iswalpha(lexer->lookahead) || lexer->lookahead == '{') {
104 // this must be a string interpolation, let's
105 // fail so we parse it as such
106 return false;
107 }
108 lexer->result_symbol = STRING_CONTENT;
109 lexer->mark_end(lexer);
110 return true;
111 }
112 if (lexer->lookahead == '\\') {
113 // if we see a \, then this might possibly escape a dollar sign
114 // in which case, we should not defer to the interpolation
115 advance(lexer);
116 // this dollar sign is escaped, so it must be content.
117 // we consume it here so we don't enter the dollar sign case above,
118 // which leaves the possibility that it is an interpolation
119 if (lexer->lookahead == '$') {
120 advance(lexer);
121 // however this leaves an edgecase where an escaped dollar sign could
122 // appear at the end of a string (e.g "aa\$") which isn't handled
123 // correctly; if we were at the end of the string, terminate properly
124 if (lexer->lookahead == end_char) {
125 stack_pop(stack);
126 advance(lexer);
127 lexer->mark_end(lexer);
128 lexer->result_symbol = STRING_END;
129 return true;
130 }
131 }
132 } else if (lexer->lookahead == end_char) {
133 if (is_triple) {
134 lexer->mark_end(lexer);
135 for (unsigned count = 1; count < DELIMITER_LENGTH; ++count) {
136 advance(lexer);
137 if (lexer->lookahead != end_char) {
138 lexer->mark_end(lexer);

Calls 2

stack_popFunction · 0.85
advanceFunction · 0.70

Tested by

no test coverage detected