MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / tokenizeLineWithGrammar

Function tokenizeLineWithGrammar

packages/core/src/widgets/codeEditorSyntax.ts:932–1015  ·  view source on GitHub ↗
(
  line: string,
  grammar: LanguageGrammar,
  language: CanonicalLanguage,
)

Source from the content-addressed store, hash-verified

930}
931
932function tokenizeLineWithGrammar(
933 line: string,
934 grammar: LanguageGrammar,
935 language: CanonicalLanguage,
936): readonly CodeEditorSyntaxToken[] {
937 const scanner: Scanner = { source: line, index: 0, tokens: [] };
938
939 while (scanner.index < line.length) {
940 const ch = asChar(line, scanner.index);
941 const next = asChar(line, scanner.index + 1);
942
943 if (isWhitespace(ch)) {
944 consumeWhitespace(scanner);
945 continue;
946 }
947
948 if (grammar.lineComment === "#" && ch === "#") {
949 pushToken(scanner.tokens, line.slice(scanner.index), "comment");
950 break;
951 }
952
953 if (grammar.lineComment === "//" && ch === "/" && next === "/") {
954 pushToken(scanner.tokens, line.slice(scanner.index), "comment");
955 break;
956 }
957
958 if (grammar.blockComments && ch === "/" && next === "*") {
959 const start = scanner.index;
960 scanner.index += 2;
961 while (scanner.index < line.length) {
962 const a = asChar(line, scanner.index);
963 const b = asChar(line, scanner.index + 1);
964 scanner.index += 1;
965 if (a === "*" && b === "/") {
966 scanner.index += 1;
967 break;
968 }
969 }
970 pushToken(scanner.tokens, line.slice(start, scanner.index), "comment");
971 continue;
972 }
973
974 if (language === "csharp" && ch === "@" && next === '"') {
975 pushToken(scanner.tokens, consumeCSharpVerbatimString(scanner), "string");
976 continue;
977 }
978
979 if (
980 (ch === "'" && grammar.allowSingleQuotedStrings) ||
981 (ch === '"' && grammar.allowDoubleQuotedStrings) ||
982 (ch === "`" && grammar.allowBacktickStrings)
983 ) {
984 pushToken(scanner.tokens, consumeString(scanner, ch), "string");
985 continue;
986 }
987
988 if (isDigit(ch) || (ch === "-" && isDigit(next))) {
989 pushToken(scanner.tokens, consumeNumber(scanner), "number");

Callers 1

tokenizeCodeEditorLineFunction · 0.85

Calls 13

asCharFunction · 0.85
consumeWhitespaceFunction · 0.85
pushTokenFunction · 0.85
consumeStringFunction · 0.85
consumeNumberFunction · 0.85
consumeWordFunction · 0.85
classifyWordFunction · 0.85
consumeOperatorFunction · 0.85
isWhitespaceFunction · 0.70
isDigitFunction · 0.70
isWordStartFunction · 0.70

Tested by

no test coverage detected