MCPcopy Create free account
hub / github.com/NativeScript/android / tokenize

Function tokenize

test-app/runtime/src/main/cpp/ada/ada.cpp:16320–16622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16318}
16319
16320tl::expected<std::vector<token>, errors> tokenize(std::string_view input,
16321 token_policy policy) {
16322 ada_log("tokenize input: ", input);
16323 // Let tokenizer be a new tokenizer.
16324 // Set tokenizer's input to input.
16325 // Set tokenizer's policy to policy.
16326 auto tokenizer = Tokenizer(input, policy);
16327 // While tokenizer's index is less than tokenizer's input's code point length:
16328 while (tokenizer.index < tokenizer.input.size()) {
16329 // Run seek and get the next code point given tokenizer and tokenizer's
16330 // index.
16331 tokenizer.seek_and_get_next_code_point(tokenizer.index);
16332
16333 // If tokenizer's code point is U+002A (*):
16334 if (tokenizer.code_point == '*') {
16335 // Run add a token with default position and length given tokenizer and
16336 // "asterisk".
16337 tokenizer.add_token_with_defaults(token_type::ASTERISK);
16338 ada_log("add ASTERISK token");
16339 // Continue.
16340 continue;
16341 }
16342
16343 // If tokenizer's code point is U+002B (+) or U+003F (?):
16344 if (tokenizer.code_point == '+' || tokenizer.code_point == '?') {
16345 // Run add a token with default position and length given tokenizer and
16346 // "other-modifier".
16347 tokenizer.add_token_with_defaults(token_type::OTHER_MODIFIER);
16348 // Continue.
16349 continue;
16350 }
16351
16352 // If tokenizer's code point is U+005C (\):
16353 if (tokenizer.code_point == '\\') {
16354 // If tokenizer's index is equal to tokenizer's input's code point length
16355 // - 1:
16356 if (tokenizer.index == tokenizer.input.size() - 1) {
16357 // Run process a tokenizing error given tokenizer, tokenizer's next
16358 // index, and tokenizer's index.
16359 if (auto error = tokenizer.process_tokenizing_error(
16360 tokenizer.next_index, tokenizer.index)) {
16361 ada_log("process_tokenizing_error failed");
16362 return tl::unexpected(*error);
16363 }
16364 continue;
16365 }
16366
16367 // Let escaped index be tokenizer's next index.
16368 auto escaped_index = tokenizer.next_index;
16369 // Run get the next code point given tokenizer.
16370 tokenizer.get_next_code_point();
16371 // Run add a token with default length given tokenizer, "escaped-char",
16372 // tokenizer's next index, and escaped index.
16373 tokenizer.add_token_with_default_length(
16374 token_type::ESCAPED_CHAR, tokenizer.next_index, escaped_index);
16375 ada_log("add ESCAPED_CHAR token on next_index ", tokenizer.next_index,
16376 " with escaped index ", escaped_index);
16377 // Continue.

Callers 2

parse_pattern_stringFunction · 0.85
parseMethod · 0.85

Calls 12

TokenizerClass · 0.85
unexpectedClass · 0.85
valid_name_code_pointFunction · 0.85
is_asciiFunction · 0.85
get_next_code_pointMethod · 0.80
add_tokenMethod · 0.80
sizeMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected