MCPcopy Create free account
hub / github.com/AztecProtocol/aztec-packages / lookForMatch

Function lookForMatch

docs/src/preprocess/include_code.js:101–134  ·  view source on GitHub ↗
(regex)

Source from the content-addressed store, hash-verified

99 * Search for one of the regex statements in the code file. If it's found, return the line as a string and the line number.
100 */
101 const lookForMatch = (regex) => {
102 let match;
103 let matchFound = false;
104 let matchedLineNum = null;
105 let actualMatch = null;
106 let lines = fileContent.split("\n");
107 while ((match = regex.exec(fileContent))) {
108 if (match !== null) {
109 const identifiers = match[1].split(":");
110 let tempMatch = identifiers.includes(identifier) ? match : null;
111
112 if (tempMatch === null) {
113 // If it's not a match, we'll make a note that we should remove the matched text, because it's from some other identifier and should not appear in the snippet for this identifier.
114 for (let i = 0; i < lines.length; i++) {
115 let line = lines[i];
116 if (line.trim() == match[0].trim()) {
117 linesToRemove.push(i + 1); // lines are indexed from 1
118 }
119 }
120 } else {
121 if (matchFound === true) {
122 throw new Error(
123 `Duplicate for regex ${regex} and identifier ${identifier}`
124 );
125 }
126 matchFound = true;
127 matchedLineNum = getLineNumberFromIndex(fileContent, tempMatch.index);
128 actualMatch = tempMatch;
129 }
130 }
131 }
132
133 return [actualMatch, matchedLineNum];
134 };
135
136 let [startMatch, startLineNum] = lookForMatch(startRegex);
137 let [endMatch, endLineNum] = lookForMatch(endRegex);

Callers 1

extractCodeSnippetFunction · 0.70

Calls 3

getLineNumberFromIndexFunction · 0.70
pushMethod · 0.65
execMethod · 0.45

Tested by

no test coverage detected