v1.4.0 release: live-coding scratch editor, interpreted Graph DSL, ClosureSynthesizer + SampleLoop
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// DSLExpr.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// The DSL expression AST: number literals, generator calls, and the binary math
|
||||
// operators, plus the call-argument node.
|
||||
|
||||
/// A DSL expression.
|
||||
public indirect enum DSLExpr: Equatable, Sendable {
|
||||
|
||||
/// A binary math operator (`+ - * /`).
|
||||
public enum BinaryOp: String, Equatable, Sendable {
|
||||
case add = "+"
|
||||
case subtract = "-"
|
||||
case multiply = "*"
|
||||
case divide = "/"
|
||||
}
|
||||
|
||||
/// One argument to a call: an optional label and a value expression.
|
||||
public struct Argument: Equatable, Sendable {
|
||||
public let label: String?
|
||||
public let value: DSLExpr
|
||||
public let span: DSLSpan
|
||||
|
||||
public init(label: String?, value: DSLExpr, span: DSLSpan) {
|
||||
self.label = label
|
||||
self.value = value
|
||||
self.span = span
|
||||
}
|
||||
}
|
||||
|
||||
/// A numeric literal.
|
||||
case number(Double, DSLSpan)
|
||||
/// A bare identifier referencing a host resource (a buffer).
|
||||
case reference(name: String, DSLSpan)
|
||||
/// A generator call: `Name(arg, …)` or `Name.Audio(…)` / `Name.Control(…)`.
|
||||
/// `rate` is the explicit rate from an `.Audio`/`.Control` suffix (the exact
|
||||
/// Swift nested-class names), or `nil` for the default (audio-preferred)
|
||||
/// resolution.
|
||||
case call(name: String, rate: DSLRate?, arguments: [Argument], DSLSpan)
|
||||
/// A binary operation.
|
||||
case binary(op: BinaryOp, lhs: DSLExpr, rhs: DSLExpr, DSLSpan)
|
||||
|
||||
/// The source span covering this expression.
|
||||
public var span: DSLSpan {
|
||||
switch self {
|
||||
case .number(_, let s): return s
|
||||
case .reference(_, let s): return s
|
||||
case .call(_, _, _, let s): return s
|
||||
case .binary(_, _, _, let s): return s
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user