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

Function eat_operators

codegraph-kernel/grammars/swift/scanner.c:378–539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376}
377
378static bool eat_operators(
379 TSLexer *lexer,
380 const bool *valid_symbols,
381 bool mark_end,
382 const int32_t prior_char,
383 enum TokenType *symbol_result
384) {
385 bool possible_operators[OPERATOR_COUNT];
386 uint8_t reserved_operators[RESERVED_OP_COUNT];
387 for (int op_idx = 0; op_idx < OPERATOR_COUNT; op_idx++) {
388 possible_operators[op_idx] = valid_symbols[OP_SYMBOLS[op_idx]] && (!prior_char || OPERATORS[op_idx][0] == prior_char);
389 }
390 for (int op_idx = 0; op_idx < RESERVED_OP_COUNT; op_idx++) {
391 reserved_operators[op_idx] = !prior_char || RESERVED_OPS[op_idx][0] == prior_char;
392 }
393
394 bool possible_custom_operator = valid_symbols[CUSTOM_OPERATOR];
395 int32_t first_char = prior_char ? prior_char : lexer->lookahead;
396 int32_t last_examined_char = first_char;
397
398 int32_t str_idx = prior_char ? 1 : 0;
399 int32_t full_match = -1;
400 while(true) {
401 for (int op_idx = 0; op_idx < OPERATOR_COUNT; op_idx++) {
402 if (!possible_operators[op_idx]) {
403 continue;
404 }
405
406 if (OPERATORS[op_idx][str_idx] == '\0') {
407 // Make sure that the operator is allowed to have the next character as its lookahead.
408 enum IllegalTerminatorGroup illegal_terminators = OP_ILLEGAL_TERMINATORS[op_idx];
409 switch (lexer->lookahead) {
410 // See "Operators":
411 // https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID418
412 case '/':
413 case '=':
414 case '-':
415 case '+':
416 case '!':
417 case '*':
418 case '%':
419 case '<':
420 case '>':
421 case '&':
422 case '|':
423 case '^':
424 case '?':
425 case '~':
426 if (illegal_terminators == OPERATOR_SYMBOLS) {
427 break;
428 } // Otherwise, intentionally fall through to the OPERATOR_OR_DOT case
429 // fall through
430 case '.':
431 if (illegal_terminators == OPERATOR_OR_DOT) {
432 break;
433 } // Otherwise, fall through to DEFAULT which checks its groups directly
434 // fall through
435 default:

Callers 2

eat_whitespaceFunction · 0.85

Calls 4

is_legal_custom_operatorFunction · 0.85
encountered_op_countFunction · 0.85
any_reserved_opsFunction · 0.85
advanceMethod · 0.80

Tested by

no test coverage detected