LLDB mainline
scanner.c File Reference
#include "tree_sitter/parser.h"
#include <string.h>
#include <wctype.h>

Go to the source code of this file.

Classes

struct  ScannerState

Macros

#define TOKEN_COUNT   33
#define OPERATOR_COUNT   20
#define RESERVED_OP_COUNT   31
#define NON_CONSUMING_CROSS_SEMI_CHAR_COUNT   3
#define DIRECTIVE_COUNT   4

Enumerations

enum  TokenType {
  BLOCK_COMMENT , RAW_STR_PART , RAW_STR_CONTINUING_INDICATOR , RAW_STR_END_PART ,
  IMPLICIT_SEMI , EXPLICIT_SEMI , ARROW_OPERATOR , DOT_OPERATOR ,
  CONJUNCTION_OPERATOR , DISJUNCTION_OPERATOR , NIL_COALESCING_OPERATOR , EQUAL_SIGN ,
  EQ_EQ , PLUS_THEN_WS , MINUS_THEN_WS , BANG ,
  THROWS_KEYWORD , RETHROWS_KEYWORD , DEFAULT_KEYWORD , WHERE_KEYWORD ,
  ELSE_KEYWORD , CATCH_KEYWORD , AS_KEYWORD , AS_QUEST ,
  AS_BANG , ASYNC_KEYWORD , CUSTOM_OPERATOR , HASH_SYMBOL ,
  DIRECTIVE_IF , DIRECTIVE_ELSEIF , DIRECTIVE_ELSE , DIRECTIVE_ENDIF ,
  FAKE_TRY_BANG
}
enum  IllegalTerminatorGroup { ALPHANUMERIC , OPERATOR_SYMBOLS , OPERATOR_OR_DOT , NON_WHITESPACE }
enum  ParseDirective {
  CONTINUE_PARSING_NOTHING_FOUND , CONTINUE_PARSING_TOKEN_FOUND , CONTINUE_PARSING_SLASH_CONSUMED , STOP_PARSING_NOTHING_FOUND ,
  STOP_PARSING_TOKEN_FOUND , STOP_PARSING_END_OF_FILE
}
 All possible results of having performed some sort of parsing. More...

Functions

static bool is_cross_semi_token (enum TokenType op)
void * tree_sitter_swift_external_scanner_create ()
void tree_sitter_swift_external_scanner_destroy (void *payload)
void tree_sitter_swift_external_scanner_reset (void *payload)
unsigned tree_sitter_swift_external_scanner_serialize (void *payload, char *buffer)
void tree_sitter_swift_external_scanner_deserialize (void *payload, const char *buffer, unsigned length)
static void advance (TSLexer *lexer)
static bool should_treat_as_wspace (int32_t character)
static int32_t encountered_op_count (bool *encountered_operator)
static bool any_reserved_ops (uint8_t *encountered_reserved_ops)
static bool is_legal_custom_operator (int32_t char_idx, int32_t first_char, int32_t cur_char)
static bool eat_operators (TSLexer *lexer, const bool *valid_symbols, bool mark_end, const int32_t prior_char, enum TokenType *symbol_result)
static enum ParseDirective eat_comment (TSLexer *lexer, const bool *valid_symbols, bool mark_end, enum TokenType *symbol_result)
static enum ParseDirective eat_whitespace (TSLexer *lexer, const bool *valid_symbols, enum TokenType *symbol_result)
static enum TokenType find_possible_compiler_directive (TSLexer *lexer)
static bool eat_raw_str_part (struct ScannerState *state, TSLexer *lexer, const bool *valid_symbols, enum TokenType *symbol_result)
bool tree_sitter_swift_external_scanner_scan (void *payload, TSLexer *lexer, const bool *valid_symbols)

Variables

const char * OPERATORS [OPERATOR_COUNT]
enum IllegalTerminatorGroup OP_ILLEGAL_TERMINATORS [OPERATOR_COUNT]
enum TokenType OP_SYMBOLS [OPERATOR_COUNT]
const uint64_t OP_SYMBOL_SUPPRESSOR [OPERATOR_COUNT]
const char * RESERVED_OPS [RESERVED_OP_COUNT]
const uint32_t NON_CONSUMING_CROSS_SEMI_CHARS [NON_CONSUMING_CROSS_SEMI_CHAR_COUNT]
const char * DIRECTIVES [OPERATOR_COUNT] = {"if", "elseif", "else", "endif"}
enum TokenType DIRECTIVE_SYMBOLS [DIRECTIVE_COUNT]

Macro Definition Documentation

◆ DIRECTIVE_COUNT

#define DIRECTIVE_COUNT   4

Definition at line 642 of file Swift/tree-sitter-swift/scanner.c.

Referenced by find_possible_compiler_directive().

◆ NON_CONSUMING_CROSS_SEMI_CHAR_COUNT

#define NON_CONSUMING_CROSS_SEMI_CHAR_COUNT   3

Definition at line 160 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_whitespace().

◆ OPERATOR_COUNT

#define OPERATOR_COUNT   20

Definition at line 43 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_operators(), and encountered_op_count().

◆ RESERVED_OP_COUNT

#define RESERVED_OP_COUNT   31

Definition at line 124 of file Swift/tree-sitter-swift/scanner.c.

Referenced by any_reserved_ops(), and eat_operators().

◆ TOKEN_COUNT

#define TOKEN_COUNT   33

Definition at line 5 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_operators().

Enumeration Type Documentation

◆ IllegalTerminatorGroup

Enumerator
ALPHANUMERIC 
OPERATOR_SYMBOLS 
OPERATOR_OR_DOT 
NON_WHITESPACE 

Definition at line 50 of file Swift/tree-sitter-swift/scanner.c.

◆ ParseDirective

All possible results of having performed some sort of parsing.

A parser can return a result along two dimensions:

  1. Should the scanner continue trying to find another result?
  2. Was some result produced by this parsing attempt?

These are flattened into a single enum together. When the function returns one of the TOKEN_FOUND cases, it will always populate its symbol_result field. When it returns one of the STOP_PARSING cases, callers should immediately return (with the value, if there is one).

Enumerator
CONTINUE_PARSING_NOTHING_FOUND 
CONTINUE_PARSING_TOKEN_FOUND 
CONTINUE_PARSING_SLASH_CONSUMED 
STOP_PARSING_NOTHING_FOUND 
STOP_PARSING_TOKEN_FOUND 
STOP_PARSING_END_OF_FILE 

Definition at line 177 of file Swift/tree-sitter-swift/scanner.c.

◆ TokenType

enum TokenType
Enumerator
BLOCK_COMMENT 
RAW_STR_PART 
RAW_STR_CONTINUING_INDICATOR 
RAW_STR_END_PART 
IMPLICIT_SEMI 
EXPLICIT_SEMI 
ARROW_OPERATOR 
DOT_OPERATOR 
CONJUNCTION_OPERATOR 
DISJUNCTION_OPERATOR 
NIL_COALESCING_OPERATOR 
EQUAL_SIGN 
EQ_EQ 
PLUS_THEN_WS 
MINUS_THEN_WS 
BANG 
THROWS_KEYWORD 
RETHROWS_KEYWORD 
DEFAULT_KEYWORD 
WHERE_KEYWORD 
ELSE_KEYWORD 
CATCH_KEYWORD 
AS_KEYWORD 
AS_QUEST 
AS_BANG 
ASYNC_KEYWORD 
CUSTOM_OPERATOR 
HASH_SYMBOL 
DIRECTIVE_IF 
DIRECTIVE_ELSEIF 
DIRECTIVE_ELSE 
DIRECTIVE_ENDIF 
FAKE_TRY_BANG 

Definition at line 7 of file Swift/tree-sitter-swift/scanner.c.

Function Documentation

◆ advance()

void advance ( TSLexer * lexer)
static

Definition at line 228 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_comment(), and eat_raw_str_part().

◆ any_reserved_ops()

bool any_reserved_ops ( uint8_t * encountered_reserved_ops)
static

Definition at line 245 of file Swift/tree-sitter-swift/scanner.c.

References RESERVED_OP_COUNT.

Referenced by eat_operators().

◆ eat_comment()

enum ParseDirective eat_comment ( TSLexer * lexer,
const bool * valid_symbols,
bool mark_end,
enum TokenType * symbol_result )
static

◆ eat_operators()

◆ eat_raw_str_part()

bool eat_raw_str_part ( struct ScannerState * state,
TSLexer * lexer,
const bool * valid_symbols,
enum TokenType * symbol_result )
static

◆ eat_whitespace()

◆ encountered_op_count()

int32_t encountered_op_count ( bool * encountered_operator)
static

Definition at line 234 of file Swift/tree-sitter-swift/scanner.c.

References OPERATOR_COUNT.

Referenced by eat_operators().

◆ find_possible_compiler_directive()

enum TokenType find_possible_compiler_directive ( TSLexer * lexer)
static

◆ is_cross_semi_token()

◆ is_legal_custom_operator()

bool is_legal_custom_operator ( int32_t char_idx,
int32_t first_char,
int32_t cur_char )
static

Definition at line 255 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_operators().

◆ should_treat_as_wspace()

bool should_treat_as_wspace ( int32_t character)
static

Definition at line 230 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_whitespace().

◆ tree_sitter_swift_external_scanner_create()

void * tree_sitter_swift_external_scanner_create ( )

Definition at line 190 of file Swift/tree-sitter-swift/scanner.c.

◆ tree_sitter_swift_external_scanner_deserialize()

void tree_sitter_swift_external_scanner_deserialize ( void * payload,
const char * buffer,
unsigned length )

◆ tree_sitter_swift_external_scanner_destroy()

void tree_sitter_swift_external_scanner_destroy ( void * payload)

Definition at line 194 of file Swift/tree-sitter-swift/scanner.c.

◆ tree_sitter_swift_external_scanner_reset()

void tree_sitter_swift_external_scanner_reset ( void * payload)

◆ tree_sitter_swift_external_scanner_scan()

◆ tree_sitter_swift_external_scanner_serialize()

unsigned tree_sitter_swift_external_scanner_serialize ( void * payload,
char * buffer )

Variable Documentation

◆ DIRECTIVE_SYMBOLS

◆ DIRECTIVES

const char* DIRECTIVES[OPERATOR_COUNT] = {"if", "elseif", "else", "endif"}

Definition at line 643 of file Swift/tree-sitter-swift/scanner.c.

Referenced by find_possible_compiler_directive().

◆ NON_CONSUMING_CROSS_SEMI_CHARS

const uint32_t NON_CONSUMING_CROSS_SEMI_CHARS[NON_CONSUMING_CROSS_SEMI_CHAR_COUNT]
Initial value:
= {
'?', ':', '{'}

Definition at line 162 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_whitespace().

◆ OP_ILLEGAL_TERMINATORS

◆ OP_SYMBOL_SUPPRESSOR

const uint64_t OP_SYMBOL_SUPPRESSOR[OPERATOR_COUNT]
Initial value:
= {
0,
0,
0,
0,
0,
0,
0,
0,
0,
1UL << FAKE_TRY_BANG,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
}

Definition at line 101 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_operators().

◆ OP_SYMBOLS

enum TokenType OP_SYMBOLS[OPERATOR_COUNT]
Initial value:

Definition at line 80 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_operators().

◆ OPERATORS

const char* OPERATORS[OPERATOR_COUNT]
Initial value:
= {
"->", ".", "&&", "||", "??", "=", "==",
"+", "-", "!", "throws", "rethrows", "default", "where",
"else", "catch", "as", "as?", "as!", "async"}

Definition at line 45 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_operators().

◆ RESERVED_OPS

const char* RESERVED_OPS[RESERVED_OP_COUNT]
Initial value:
= {
"/", "=", "-", "+", "!", "*", "%", "<", ">", "&", "|",
"^", "?", "~", ".", "..", "->", "/*", "*/", "+=", "-=", "*=",
"/=", "%=", ">>", "<<", "++", "--", "===", "...", "..<"}

Definition at line 126 of file Swift/tree-sitter-swift/scanner.c.

Referenced by eat_operators().