Moved BindingGenerator from gen html project. It makes more sense here.

This commit is contained in:
2025-10-25 00:06:22 -04:00
parent 58a8419984
commit 603a0aa0e3
141 changed files with 12738 additions and 7 deletions

View File

@@ -6,6 +6,9 @@
// Non-commercial license, see LICENSE.MD in the project root for details
//
import System
import Foundation
public protocol IFlowContent : HTMLNode {}
public protocol IGlobalContainer {
@@ -96,6 +99,39 @@ public struct HtmlIterator : IteratorProtocol {
}
}*/
public protocol IHtmlNodeContainer {
var rootNodeGeneric: HTMLNode { get }
}
public class IHtmlNodeContainerUtility {
nonisolated(unsafe) public static let sharedInstance = IHtmlNodeContainerUtility()
public var defaultBaseDir = ""
public static func readHtmlFromFile(_ baseDir:String? = nil, _ fileName:String) throws -> [HTMLNode] {
let dir = baseDir ?? sharedInstance.defaultBaseDir
let strFp = "file://\(dir)/\(fileName)"
guard let url = URL(string:strFp) else {
throw AppError("String not valid url: \(strFp)")
}
let data = try Foundation.Data(contentsOf: url)
guard let str = String(data: data, encoding: .utf8) else {
throw AppError("Data not utf8")
}
/*
let fp = FilePath("\(strFp)")
guard let str = String(validating: fp) else {
throw AppError("File not found at path: \(strFp)")
}
if str == strFp {
throw AppError("File not found at path: \(str)")
}*/
guard let xmlReader = XMLParser(str: str) else { throw AppError("Empty String") }
let rootNodes = try xmlReader.readObjects()
return rootNodes
}
}
public class HTMLNode : XMLNode, IGlobalContainer {
public var globalAttributes:Dictionary<GlobalAttributeKey, String> = [:]
@@ -231,7 +267,7 @@ public class HTMLNode : XMLNode, IGlobalContainer {
newDepth = nextDepth
result += renderedChild
}
result += "<\(nodeName)/>"
result += "</\(nodeName)>"
}
return (newDepth, result)
}

View File

@@ -8,7 +8,9 @@
import Foundation
final class AppError: LocalizedError, Sendable {
final class AppError: LocalizedError, Sendable, CustomStringConvertible {
var description: String { get {message}}
let message: String
@@ -28,4 +30,13 @@ final class AppError: LocalizedError, Sendable {
return message
}
}
/// A localized message describing the reason for the failure.
var failureReason: String? { get { message } }
var localizedDescription: String? {
get {
message
}
}
}

View File

@@ -27,14 +27,16 @@ final class EmptyStringError: Error, Sendable {
init() { }
}
final class XmlError: Error, Sendable {
final class XmlError: Error, Sendable, CustomStringConvertible {
var description: String { get {errorDescription ?? "XMLError"} }
let message: String
let line:Int
let column:Int
init(_ message: String, _ line:Int, _ column:Int) {
self.message = "\(line):\(column) \(message)"
self.message = "\(line):\(column): \(message)"
self.line = line
self.column = column
}
@@ -386,6 +388,9 @@ public class XMLParser
}*/
public init?(str:String) {
if (str.isEmpty) {
return nil
}
iterator = str.unicodeScalars.makeIterator()
position = Position()
}
@@ -438,6 +443,8 @@ public class XMLParser
switch state {
case .end_markup:
return nil
case .data:
return nil
default:
throw XmlError("unexpected end of stream inside markup structure", position.line, position.column)
}