') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Renaming Package to SyntaxKit by leogdion · Pull Request #14 · brightdigit/SyntaxKit · GitHub
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
16 changes: 8 additions & 8 deletions .vscode/launch.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,19 +4,19 @@
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:SwiftBuilder}",
"name": "Debug SwiftBuilderCLI",
"program": "${workspaceFolder:SwiftBuilder}/.build/debug/SwiftBuilderCLI",
"preLaunchTask": "swift: Build Debug SwiftBuilderCLI"
"cwd": "${workspaceFolder:SyntaxKit}",
"name": "Debug skit",
"program": "${workspaceFolder:SyntaxKit}/.build/debug/skit",
"preLaunchTask": "swift: Build Debug skit"
},
{
"type": "swift",
"request": "launch",
"args": [],
"cwd": "${workspaceFolder:SwiftBuilder}",
"name": "Release SwiftBuilderCLI",
"program": "${workspaceFolder:SwiftBuilder}/.build/release/SwiftBuilderCLI",
"preLaunchTask": "swift: Build Release SwiftBuilderCLI"
"cwd": "${workspaceFolder:SyntaxKit}",
"name": "Release skit",
"program": "${workspaceFolder:SyntaxKit}/.build/release/skit",
"preLaunchTask": "swift: Build Release skit"
}
]
}
2 changes: 1 addition & 1 deletion Examples/blackjack/dsl.swift
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import SwiftBuilder
import SyntaxKit

// Example of generating a BlackjackCard struct with a nested Suit enum
let structExample = Struct("BlackjackCard") {
Expand Down
2 changes: 1 addition & 1 deletion Examples/card_game/dsl.swift
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import SwiftBuilder
import SyntaxKit

// Example of generating a BlackjackCard struct with a nested Suit enum
let structExample = Group {
Expand Down
2 changes: 1 addition & 1 deletion Examples/generics/dsl.swift
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import SwiftBuilder
import SyntaxKit

// Example of generating a BlackjackCard struct with a nested Suit enum
let structExample = Struct("Stack", generic: "Element") {
Expand Down
20 changes: 10 additions & 10 deletions Package.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,19 +4,19 @@
import PackageDescription

let package = Package(
name: "SwiftBuilder",
name: "SyntaxKit",
platforms: [
.macOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "SwiftBuilder",
targets: ["SwiftBuilder"]
name: "SyntaxKit",
targets: ["SyntaxKit"]
),
.executable(
name: "SwiftBuilderCLI",
targets: ["SwiftBuilderCLI"]
name: "skit",
targets: ["skit"]
),
],
dependencies: [
Expand All@@ -26,20 +26,20 @@ let package = Package(
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "SwiftBuilder",
name: "SyntaxKit",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax")
]
),
.executableTarget(
name: "SwiftBuilderCLI",
dependencies: ["SwiftBuilder"]
name: "skit",
dependencies: ["SyntaxKit"]
),
.testTarget(
name: "SwiftBuilderTests",
dependencies: ["SwiftBuilder"]
name: "SyntaxKitTests",
dependencies: ["SyntaxKit"]
),
]
)
12 changes: 6 additions & 6 deletions README.md
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
# SwiftBuilder
# SyntaxKit

SwiftBuilder is a Swift package that allows developers to build Swift code using result builders. It provides a declarative way to generate Swift code structures using SwiftSyntax.
SyntaxKit is a Swift package that allows developers to build Swift code using result builders. It provides a declarative way to generate Swift code structures using SwiftSyntax.

## Installation

Add SwiftBuilder to your project using Swift Package Manager:
Add SyntaxKit to your project using Swift Package Manager:

```swift
dependencies: [
.package(url: "https://github.com/yourusername/SwiftBuilder.git", from: "1.0.0")
.package(url: "https://github.com/yourusername/SyntaxKit.git", from: "1.0.0")
]
```

## Usage

SwiftBuilder provides a set of result builders that allow you to create Swift code structures in a declarative way. Here's an example:
SyntaxKit provides a set of result builders that allow you to create Swift code structures in a declarative way. Here's an example:

```swift
import SwiftBuilder
import SyntaxKit

let code = Struct("BlackjackCard") {
Enum("Suit") {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
//
// Case.swift
// SwiftBuilder
// SyntaxKit
//
// Created by Leo Dion on 6/15/25.
//
Expand Down
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
//
// Default.swift
// SwiftBuilder
// SyntaxKit
//
// Created by Leo Dion on 6/15/25.
//
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
//
// PlusAssign.swift
// SwiftBuilder
// SyntaxKit
//
// Created by Leo Dion on 6/15/25.
//
Expand Down
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
//
// Switch.swift
// SwiftBuilder
// SyntaxKit
//
// Created by Leo Dion on 6/15/25.
//
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
//
// SwitchCase.swift
// SwiftBuilder
// SyntaxKit
//
// Created by Leo Dion on 6/15/25.
//
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
//
// Variable.swift
// SwiftBuilder
// SyntaxKit
//
// Created by Leo Dion on 6/15/25.
//
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
//
// VariableExp.swift
// SwiftBuilder
// SyntaxKit
//
// Created by Leo Dion on 6/15/25.
//
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
import Foundation
import SwiftBuilder
import SyntaxKit

// Read Swift code from stdin
let code = String(data: FileHandle.standardInput.readDataToEndOfFile(), encoding: .utf8) ?? ""

do {
// Parse the code using SwiftBuilder
// Parse the code using SyntaxKit
let response = try SyntaxParser.parse(code: code, options: ["fold"])

// Output the JSON to stdout
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftBuilderTests/SwiftBuilderCommentTests.swift
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import XCTest
@testable import SwiftBuilder
@testable import SyntaxKit

final class SwiftBuilderCommentTests: XCTestCase {
final class SyntaxKitCommentTests: XCTestCase {
func testCommentInjection() {
let syntax = Group {
Struct("Card") {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftBuilderTests/SwiftBuilderLiteralTests.swift
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import XCTest
@testable import SwiftBuilder
@testable import SyntaxKit

final class SwiftBuilderLiteralTests: XCTestCase {
final class SyntaxKitLiteralTests: XCTestCase {
func testGroupWithLiterals() {
let group = Group {
Return {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftBuilderTests/SwiftBuilderTestsA.swift
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import XCTest
@testable import SwiftBuilder
@testable import SyntaxKit

final class SwiftBuilderTestsA: XCTestCase {
final class SyntaxKitTestsA: XCTestCase {
func testBlackjackCardExample() throws {
let blackjackCard = Struct("BlackjackCard") {
Enum("Suit") {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftBuilderTests/SwiftBuilderTestsB.swift
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import XCTest
@testable import SwiftBuilder
@testable import SyntaxKit

final class SwiftBuilderTestsB: XCTestCase {
final class SyntaxKitTestsB: XCTestCase {
func testBlackjackCardExample() throws {
let syntax = Struct("BlackjackCard") {
Enum("Suit") {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftBuilderTests/SwiftBuilderTestsC.swift
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import XCTest
@testable import SwiftBuilder
@testable import SyntaxKit

final class SwiftBuilderTestsC: XCTestCase {
final class SyntaxKitTestsC: XCTestCase {
func testBasicFunction() throws {
let function = Function("calculateSum", returns: "Int") {
Parameter(name: "a", type: "Int")
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftBuilderTests/SwiftBuilderTestsD.swift
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import XCTest
@testable import SwiftBuilder
@testable import SyntaxKit

final class SwiftBuilderTestsD: XCTestCase {
final class SyntaxKitTestsD: XCTestCase {
func normalize(_ code: String) -> String {
return code
.replacingOccurrences(of: "//.*$", with: "", options: .regularExpression) // Remove comments
Expand Down