MCPcopy Create free account
hub / github.com/AlexErrant/Pentive / buildContent

Function buildContent

shared-dom/src/language/query2sql.ts:172–256  ·  view source on GitHub ↗
(node: SyntaxNodeRef, input: string, negate: boolean)

Source from the content-addressed store, hash-verified

170}
171
172function buildContent(node: SyntaxNodeRef, input: string, negate: boolean) {
173 let valueFrom
174 let valueTo
175 const regex: string[] = []
176 if (node.node.firstChild == null) throwExp()
177 let child = node.node.firstChild.nextSibling
178 let close = null
179 while (child != null) {
180 if (
181 child.type.id === qt.Content_1 ||
182 child.type.id === qt.Content_2 ||
183 child.type.id === qt.Content_3 ||
184 child.type.id === qt.RawQuoted1Content ||
185 child.type.id === qt.RawQuoted2Content ||
186 child.type.id === qt.RawHtmlContent
187 ) {
188 const value = input.slice(child.from, child.to)
189 regex.push(escapeRegExp(value))
190 valueFrom ??= child.from
191 valueTo = child.to
192 } else if (
193 child.type.id === qt.Squared_1 ||
194 child.type.id === qt.Squared_2 ||
195 child.type.id === qt.Squared_3
196 ) {
197 valueFrom ??= child.from
198 valueTo = child.to
199 regex.push(input.slice(child.from, child.to))
200 } else if (
201 child.type.id === qt.Wildcard_1 ||
202 child.type.id === qt.Wildcard_2 ||
203 child.type.id === qt.Wildcard_3
204 ) {
205 valueFrom ??= child.from
206 valueTo = child.to
207 regex.push('.*')
208 } else if (
209 child.type.id === qt.Wildcard1_1 ||
210 child.type.id === qt.Wildcard1_2 ||
211 child.type.id === qt.Wildcard1_3
212 ) {
213 valueFrom ??= child.from
214 valueTo = child.to
215 regex.push('.')
216 } else if (
217 child.type.id === qt.Quoted1Close ||
218 child.type.id === qt.Quoted2Close ||
219 child.type.id === qt.RawQuoted1Close ||
220 child.type.id === qt.RawQuoted2Close ||
221 child.type.id === qt.HtmlClose ||
222 child.type.id === qt.RawHtmlClose
223 ) {
224 close = input.slice(child.from, child.to)
225 break
226 }
227 child = child.nextSibling
228 }
229 const open = input.slice(node.node.firstChild.from, node.node.firstChild.to)

Callers 1

astEnterFunction · 0.85

Calls 2

throwExpFunction · 0.90
escapeRegExpFunction · 0.90

Tested by

no test coverage detected