Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ <h1 class="modal-title fs-5" id="debugger-modal-title">Regex Debugger</h1>
<th>Resets</th>
<th>Backtracks</th>
</tr>
</thead>
<tbody>
<tr class="font-monospace">
<td id="debugger-total-cycle-count">0</td>
Expand Down Expand Up @@ -280,7 +281,7 @@ <h1 class="modal-title fs-5" id="debugger-modal-title">Regex Debugger</h1>
<div class="d-inline-block mx-2">
<a class="text-reset text-decoration-none small" href="https://github.com/sponsors/kishikawakatsumi"
target="_blank" rel="nofollow noopener noreferrer">
<span class="fa-solid fa-heart" style="color: #bf3989;"></span></span><span class="mx-2">Donate</span></a>
<span class="fa-solid fa-heart" style="color: #bf3989;"></span><span class="mx-2">Donate</span></a>
</div>
</div>
</footer>
Expand Down
11 changes: 6 additions & 5 deletions Public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export class App {
this.onDebuggerStepChange();
});

const matchStepRange = document.getElementById("debugger-step-range");
matchStepRange.addEventListener("input", () => {
this.onDebuggerStepChange();
});

this.debuggerModal = document.getElementById("debugger-modal");
this.debuggerModal.addEventListener("shown.bs.modal", () =>
this.launchDebugger(),
Expand Down Expand Up @@ -219,10 +224,6 @@ export class App {
this.debuggerText.value = text;

this.onDebuggerStepChange();

matchStepRange.addEventListener("input", (e) => {
this.onDebuggerStepChange();
});
}

onExpressionFieldChange() {
Expand Down Expand Up @@ -450,7 +451,7 @@ export class App {

const backtracks = document.getElementById("debugger-backtracks");

const previousBacktracks = backtracks.textContent;
const previousBacktracks = Number(backtracks.textContent);
backtracks.textContent = metrics.backtracks;

this.debuggerText.highlighter.draw(
Expand Down
30 changes: 28 additions & 2 deletions Sources/App/routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,41 @@ func routes(_ app: Application) throws {
process.standardOutput = standardOutput
process.standardError = standardError

var stdoutData = Data()
var stderrData = Data()
let group = DispatchGroup()

group.enter()
standardOutput.fileHandleForReading.readabilityHandler = { handle in
let chunk = handle.availableData
if chunk.isEmpty {
standardOutput.fileHandleForReading.readabilityHandler = nil
group.leave()
} else {
stdoutData.append(chunk)
}
}

group.enter()
standardError.fileHandleForReading.readabilityHandler = { handle in
let chunk = handle.availableData
if chunk.isEmpty {
standardError.fileHandleForReading.readabilityHandler = nil
group.leave()
} else {
stderrData.append(chunk)
}
}

try process.run()

group.wait()
process.waitUntilExit()

let stdoutData = standardOutput.fileHandleForReading.readDataToEndOfFile()
guard let stdout = String(data: stdoutData, encoding: .utf8) else {
throw Abort(.internalServerError)
}

let stderrData = standardError.fileHandleForReading.readDataToEndOfFile()
guard let stderr = String(data: stderrData, encoding: .utf8) else {
throw Abort(.internalServerError)
}
Expand Down
9 changes: 0 additions & 9 deletions Sources/ExpressionParser/ExpressionParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,45 +119,36 @@ struct ExpressionParser {
category = "groups"
key = "noncapgroup"
case .nonCaptureReset:
groupCount += 1
category = "groups"
key = "branchreset"
case .atomicNonCapturing:
groupCount += 1
category = "groups"
key = "atomic"
case .lookahead:
category = "lookaround"
key = "poslookahead"
case .negativeLookahead:
groupCount += 1
category = "lookaround"
key = "neglookahead"
case .nonAtomicLookahead:
groupCount += 1
category = "lookaround"
key = "nonatomicposlookahead"
case .lookbehind:
category = "lookaround"
key = "poslookbehind"
case .negativeLookbehind:
groupCount += 1
category = "lookaround"
key = "neglookbehind"
case .nonAtomicLookbehind:
groupCount += 1
category = "lookaround"
key = "nonatomicposlookbehind"
case .scriptRun:
groupCount += 1
category = "Script run. "
key = ""
case .atomicScriptRun:
groupCount += 1
category = "Atomic script run. "
key = ""
case .changeMatchingOptions(_):
groupCount += 1
category = "Change matching options"
key = ""
}
Expand Down
Loading