Skip to content

Commit b75c212

Browse files
Add regex debugger
1 parent 2a5f33a commit b75c212

18 files changed

+885
-235
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ COPY ./Package.* ./
2525
RUN swift package resolve
2626

2727
COPY . .
28-
RUN swift build -c release --static-swift-stdlib -Xswiftc -enable-testing
28+
RUN swift build -c release --static-swift-stdlib -Xswiftc -DPROCESSOR_MEASUREMENTS_ENABLED -Xswiftc -enable-testing
2929

3030
WORKDIR /staging
3131

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
.macOS(.v12)
88
],
99
dependencies: [
10-
.package(url: "https://github.com/apple/swift-experimental-string-processing.git", branch: "main"),
10+
.package(url: "https://github.com/kishikawakatsumi/swift-experimental-string-processing.git", branch: "metrics"),
1111
.package(url: "https://github.com/vapor/vapor.git", from: "4.114.0"),
1212
.package(url: "https://github.com/vapor/leaf.git", from: "4.4.1"),
1313
],
@@ -23,17 +23,6 @@ let package = Package(
2323
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release)),
2424
]
2525
),
26-
.executableTarget(
27-
name: "DSLParser",
28-
dependencies: [
29-
.product(name: "_StringProcessing", package: "swift-experimental-string-processing"),
30-
.product(name: "_RegexParser", package: "swift-experimental-string-processing"),
31-
],
32-
swiftSettings: [
33-
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"]),
34-
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release)),
35-
]
36-
),
3726
.executableTarget(
3827
name: "ExpressionParser",
3928
dependencies: [
@@ -59,17 +48,19 @@ let package = Package(
5948
.executableTarget(
6049
name: "App",
6150
dependencies: [
51+
.product(name: "_StringProcessing", package: "swift-experimental-string-processing"),
52+
.product(name: "_RegexParser", package: "swift-experimental-string-processing"),
6253
.product(name: "Vapor", package: "vapor"),
6354
.product(name: "Leaf", package: "leaf"),
6455
],
6556
swiftSettings: [
66-
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
57+
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"]),
58+
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release)),
6759
]
6860
),
6961
.testTarget(
7062
name: "RegexTests", dependencies: [
7163
.target(name: "DSLConverter"),
72-
.target(name: "DSLParser"),
7364
.target(name: "ExpressionParser"),
7465
.target(name: "Matcher"),
7566
.target(name: "App"),

Public/css/common.css

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
.nav-link {
2-
padding: 2px 1rem;
3-
min-width: 180px;
4-
}
5-
61
.active-tick .checkable::after {
72
font-family: "Font Awesome 6 Pro";
83
content: "\f00c";
@@ -54,6 +49,39 @@
5449
font-size: 90%;
5550
}
5651

52+
.button-circle {
53+
width: 2rem;
54+
height: 2rem;
55+
}
56+
57+
#debugger-button {
58+
background-color: rgba(51, 51, 51, 0.05);
59+
border-radius: 15px;
60+
border-width: 0;
61+
color: #333333;
62+
cursor: pointer;
63+
display: inline-block;
64+
list-style: none;
65+
margin: 0 6px;
66+
padding: 4px 16px;
67+
text-align: center;
68+
transition: all 200ms;
69+
vertical-align: baseline;
70+
white-space: nowrap;
71+
user-select: none;
72+
-webkit-user-select: none;
73+
touch-action: manipulation;
74+
font-size: 90%;
75+
}
76+
77+
#debugger-button:hover {
78+
background-color: #2222221a;
79+
}
80+
81+
#debugger-regex {
82+
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
83+
}
84+
5785
.dropdown-menu {
5886
min-width: 200px;
5987
}

Public/css/highlight.css

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
span.match {
8888
background: rgba(112, 176, 224, 0.5);
8989
color: #101112;
90+
border-right: solid 1px #ffffff;
91+
border-left: solid 1px #ffffff;
92+
margin-right: -2px;
9093
}
9194
span.error {
9295
color: #d22;
@@ -95,13 +98,18 @@ span.error {
9598
span.error.warning {
9699
color: #d22;
97100
}
98-
span.match {
99-
border-right: solid 1px #ffffff;
100-
border-left: solid 1px #ffffff;
101-
margin-right: -2px;
102-
margin-right: -2px;
103-
}
104101
span.highlight {
105102
background: rgba(255, 128, 0, 0.5);
106103
color: #101112;
107104
}
105+
106+
span.debuggermatch {
107+
background: rgba(112, 176, 224, 0.5);
108+
color: #101112;
109+
border-right: solid 1px rgba(112, 176, 224, 0.5);
110+
border-left: solid 1px rgba(112, 176, 224, 0.5);
111+
}
112+
113+
span.debuggerbacktrack {
114+
background: rgba(255, 0, 0, 0.2);
115+
}

Public/index.html

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
<h1 class="h5 my-2">
3434
<a class="text-decoration-none" href="/">
3535
<span class="fab fa-swift fa-lg text-primary"></span><span class="ms-2 me-1 text-dark">Swift Regex</span>
36-
<span class="text-muted me-1">β</span>
3736
</a>
3837
</h1>
3938
</div>
@@ -145,6 +144,7 @@ <h1 class="h5 my-2">
145144
</div>
146145
<div class="col align-self-center">
147146
<div class="text-end mt-2">
147+
<button id="debugger-button" data-bs-toggle="modal" data-bs-target="#debugger-modal">Debug</button>
148148
<span id="match-count" class="text-bg-light border px-3 py-1">no match</span>
149149
</div>
150150
</div>
@@ -163,6 +163,80 @@ <h1 class="h5 my-2">
163163
</div>
164164
</div>
165165

166+
<div class="modal fade" id="debugger-modal" tabindex="-1" aria-labelledby="debugger-modal-title" aria-hidden="true">
167+
<div class="modal-dialog modal-dialog-scrollable modal-xl">
168+
<div class="modal-content">
169+
<div class="modal-header">
170+
<h1 class="modal-title fs-5" id="debugger-modal-title">Regex Debugger</h1>
171+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
172+
</div>
173+
<div class="modal-body">
174+
<div class="d-flex">
175+
<div class="me-4" style="max-width: 40%;">
176+
<div style="font-weight: 600;">Metrics</div>
177+
<div class="border my-2" style="font-size: 90%;">
178+
<table class="table table-borderless table-sm my-0">
179+
<thead>
180+
<tr>
181+
<th>Cycle Count</th>
182+
<th>Resets</th>
183+
<th>Backtracks</th>
184+
</tr>
185+
<tbody>
186+
<tr class="font-monospace">
187+
<td id="debugger-total-cycle-count">0</td>
188+
<td id="debugger-resets">0</td>
189+
<td id="debugger-backtracks">0</td>
190+
</tr>
191+
</tbody>
192+
</table>
193+
</div>
194+
195+
<div style="overflow: auto;">
196+
<div class="my-2" style="font-weight: 600;">Instructions</div>
197+
<div class="my-2" style="font-size: 90%;">
198+
<table class="border table table-borderless table-sm font-monospace">
199+
<tbody id="debugger-instructions">
200+
</tbody>
201+
</table>
202+
</div>
203+
</div>
204+
</div>
205+
206+
<div class="flex-grow-1">
207+
<label for="debugger-step-range" class="form-label" style="font-weight: 600;">Match Steps</label>
208+
<input id="debugger-step-range" type="range" class="form-range" value="1" min="1" max="100">
209+
<p class="mb-0" style="text-align: center">
210+
<button id="debugger-go-start" class="btn btn-sm btn-outline-secondary rounded-circle button-circle">
211+
<i class="fa-solid fa-backward-step fa-lg"></i>
212+
</button>
213+
<button id="debugger-step-backward"
214+
class="btn btn-sm btn-outline-secondary rounded-circle button-circle">
215+
<i class="fa-solid fa-caret-left fa-lg"></i>
216+
</button>
217+
<button id="debugger-step-forward"
218+
class="btn btn-sm btn-outline-secondary rounded-circle button-circle">
219+
<i class="fa-solid fa-caret-right fa-lg"></i>
220+
</button>
221+
<button id="debugger-go-end" class="btn btn-sm btn-outline-secondary rounded-circle button-circle">
222+
<i class="fa-solid fa-forward-step fa-lg"></i>
223+
</button>
224+
</p>
225+
226+
<div class="my-1" style="font-weight: 600;">Match Step <span id="debugger-match-step"></span></div>
227+
<div id="debugger-regex" class="border mb-3">
228+
</div>
229+
230+
<div class="border my-3">
231+
<div id="debugger-text-container" class="editor multiline"></div>
232+
</div>
233+
</div>
234+
</div>
235+
</div>
236+
</div>
237+
</div>
238+
</div>
239+
166240
<footer class="p-2">
167241
<div class="row">
168242
<div class="col text-center">

Public/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ import "./js/misc/icons";
1111
import "bootstrap";
1212
import { App } from "./js/app";
1313

14-
const app = new App();
14+
new App();

0 commit comments

Comments
 (0)