MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / isOrKeyword

Function isOrKeyword

packages/queryLanguage/src/tokens.ts:65–98  ·  view source on GitHub ↗

* Checks if current position starts with "or" that will be recognized as the OR operator. * This matches the logic in orToken - only returns true if "or" is NOT at start, * is followed by non-alphanumeric, AND there's actual content after it (not EOF).

(input: InputStream)

Source from the content-addressed store, hash-verified

63 * is followed by non-alphanumeric, AND there's actual content after it (not EOF).
64 */
65function isOrKeyword(input: InputStream): boolean {
66 if (input.peek(0) !== 111 /* 'o' */ || input.peek(1) !== 114 /* 'r' */) {
67 return false;
68 }
69
70 // Don't match "or" at the start of input
71 if (input.pos === 0) {
72 return false;
73 }
74
75 const afterOr = input.peek(2);
76
77 // Must not be alphanumeric (to avoid matching "orange")
78 if (isAlphaNumUnderscore(afterOr)) {
79 return false;
80 }
81
82 // Must not be EOF (at EOF, "or" should be a word, not a keyword)
83 if (afterOr === EOF) {
84 return false;
85 }
86
87 // Check that what follows (after whitespace) is not EOF
88 let offset = 2;
89 while (isWhitespace(input.peek(offset))) {
90 offset++;
91 }
92 if (input.peek(offset) === EOF) {
93 return false;
94 }
95
96 // It's a valid OR keyword
97 return true;
98}
99
100/**
101 * Checks if current position starts with a prefix keyword.

Callers 1

tokens.tsFile · 0.85

Calls 2

isAlphaNumUnderscoreFunction · 0.85
isWhitespaceFunction · 0.85

Tested by

no test coverage detected