diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/App.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/App.xcscheme new file mode 100644 index 0000000..8d67fbe --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/App.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/DSLConverter.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/DSLConverter.xcscheme new file mode 100644 index 0000000..2e747ed --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/DSLConverter.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/ExpressionParser.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/ExpressionParser.xcscheme new file mode 100644 index 0000000..228c78a --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/ExpressionParser.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/Matcher.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/Matcher.xcscheme new file mode 100644 index 0000000..7f10829 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/Matcher.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/swiftregex-Package.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/swiftregex-Package.xcscheme new file mode 100644 index 0000000..12679bd --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/swiftregex-Package.xcscheme @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Public/js/views/test_highlighter.js b/Public/js/views/test_highlighter.js index a48accc..0b8cf06 100644 --- a/Public/js/views/test_highlighter.js +++ b/Public/js/views/test_highlighter.js @@ -34,10 +34,11 @@ export default class TestHighlighter extends EventDispatcher { tooltip += "
"; for (const [i, capture] of token.captures.entries()) { const value = Utils.htmlSafe(capture.value || ""); + const name = Utils.htmlSafe(capture.name || ""); tooltip += `
-
group #${i + 1}: ${ - value === "" ? "empty string" : value - }
+
group #${i + 1}${ + name ? ` ${name}` : "" + }: ${value === "" ? "empty string" : value}
`; } } diff --git a/Sources/ExpressionParser/ExpressionParser.swift b/Sources/ExpressionParser/ExpressionParser.swift index 626afec..6ad9d48 100644 --- a/Sources/ExpressionParser/ExpressionParser.swift +++ b/Sources/ExpressionParser/ExpressionParser.swift @@ -95,10 +95,11 @@ struct ExpressionParser { category = "groups" key = "group" substitution = ["{{group.num}}": "\(groupCount)"] - case .namedCapture(_): + case .namedCapture(let name): groupCount += 1 category = "groups" key = "namedgroup" + substitution = ["{{name}}": name.value] case .balancedCapture(_): groupCount += 1 category = "groups" diff --git a/Sources/Matcher/Matcher.swift b/Sources/Matcher/Matcher.swift index 7a198d5..5a3b0b1 100644 --- a/Sources/Matcher/Matcher.swift +++ b/Sources/Matcher/Matcher.swift @@ -21,12 +21,14 @@ struct Matcher { start: range.lowerBound.utf16Offset(in: text), end: range.upperBound.utf16Offset(in: text) ), - value: String(text[range]) + value: String(text[range]), + name: $0.name ) } else { return Group( location: nil, - value: nil + value: nil, + name: $0.name ) } } @@ -52,6 +54,7 @@ struct Match: Codable { struct Group: Codable { let location: Location? let value: String? + let name: String? } struct Location: Codable {