Skip to content

Commit

Permalink
Extend the environment (#156)
Browse files Browse the repository at this point in the history
* Provide the code with more detailed documentation comments

* Fix typo

* Refactor the code a bit

* Use the right environment key

* Add a conditional statement to handle environment specific conditions

* Add a loop statement to handle environment specific sequences

* Make string interpolation of a environment value possible

* Make environmentvalue conditionable

* Refactor the code a bit

* Avoid type casting by using a type erasure

* Test the error reporting for the environment through the provider

* Make environment statement and sequence a global element

* Introduce a method to unwrap optional environment values

* Tidy up a bit

* Rename the method for the conditional statement
  • Loading branch information
mattesmohr authored Jan 10, 2025
1 parent 44b4722 commit 8d87959
Show file tree
Hide file tree
Showing 21 changed files with 1,508 additions and 157 deletions.
42 changes: 42 additions & 0 deletions Sources/HTMLKit/Framework/Environment/Condition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// A type representing a conditional that compares an environment value against another value
@_documentation(visibility: internal)
public struct Condition {

/// A enumeration of potential comparison
public enum Comparison {

/// Indicates an equal comparison
case equal

/// Indicates a not-equal comparison
case unequal

/// Indicates a greater-than comparison
case greater

/// Indicates a less-than comparison
case less
}

/// The left-hand side value
internal let lhs: EnvironmentValue

/// The right-hand side value to test against
internal let rhs: any Comparable

/// The comparison to perfom
internal let comparison: Comparison

/// Initializes a condition
///
/// - Parameters:
/// - lhs: The origin value
/// - rhs: The value to atest against
/// - operation: The comparison to perfom
public init(lhs: EnvironmentValue, rhs: any Comparable, comparison: Comparison) {

self.lhs = lhs
self.rhs = rhs
self.comparison = comparison
}
}
19 changes: 19 additions & 0 deletions Sources/HTMLKit/Framework/Environment/Conditional.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// A type that defines a conditonal value which will be evualuated by the renderer.
@_documentation(visibility: internal)
public indirect enum Conditional {

/// Holds an optional
case optional(EnvironmentValue)

/// Holds an relation
case relation(Relation)

/// Holds a condition
case condition(Condition)

/// Holds a negation
case negation(Negation)

/// Holds a value
case value(EnvironmentValue)
}
Loading

0 comments on commit 8d87959

Please sign in to comment.