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

Function eat_operators

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

Source from the content-addressed store, hash-verified

516}
517
518static bool eat_operators(
519 TSLexer *lexer,
520 const bool *valid_symbols,
521 bool mark_end,
522 bool token_is_immediate,
523 const int32_t prior_char,
524 enum TokenType *symbol_result
525) {
526 int32_t first_char = prior_char ? prior_char : lexer->lookahead;
527 bool possible_custom_operator = valid_symbols[CUSTOM_OPERATOR] &&
528 is_legal_custom_operator(0, first_char, first_char);
529 uint8_t possible_operators[4];
530 uint32_t possible_operator_count = collect_fixed_operator_candidates(
531 first_char,
532 valid_symbols,
533 possible_operators
534 );
535 if (possible_operator_count == 0 && !possible_custom_operator) {
536 return false;
537 }
538
539 uint8_t reserved_operators[RESERVED_OP_COUNT];
540 if (possible_custom_operator) {
541 for (int op_idx = 0; op_idx < RESERVED_OP_COUNT; op_idx++) {
542 reserved_operators[op_idx] = RESERVED_OPS[op_idx][0] == first_char;
543 }
544 }
545
546 int32_t last_examined_char = first_char;
547
548 int32_t str_idx = prior_char ? 1 : 0;
549 int32_t full_match = -1;
550 while(true) {
551 uint32_t candidate_idx = 0;
552 while (candidate_idx < possible_operator_count) {
553 int op_idx = possible_operators[candidate_idx];
554
555 if (OPERATORS[op_idx][str_idx] == '\0') {
556 // Make sure that the operator is allowed to have the next character as its lookahead.
557 enum IllegalTerminatorGroup illegal_terminators = OP_ILLEGAL_TERMINATORS[op_idx];
558 switch (lexer->lookahead) {
559 // See "Operators":
560 // https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID418
561 case '/':
562 case '=':
563 case '-':
564 case '+':
565 case '!':
566 case '*':
567 case '%':
568 case '<':
569 case '>':
570 case '&':
571 case '|':
572 case '^':
573 case '?':
574 case '~':
575 if (illegal_terminators == OPERATOR_SYMBOLS) {

Callers 2

eat_whitespaceFunction · 0.85

Calls 4

is_legal_custom_operatorFunction · 0.85
any_reserved_opsFunction · 0.85
advanceMethod · 0.80

Tested by

no test coverage detected