Swiftpack.co - underthestars-zhy/JOP as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by underthestars-zhy.
underthestars-zhy/JOP Beta0.0.1
JOP is the Json organization program. It can run on any platform that supports Swift.
⭐️ 1
🕓 1 week ago
.package(url: "https://github.com/underthestars-zhy/JOP.git", from: "Beta0.0.1")

JOP

JOP is a program organized in JSON files. It is based on Swift, provides a syntax similar to Swift, and has the same strong security as Swift. This project only provides JOP running call interface, you need to call it in Swift. JOP is still undergoing rapid development, and destructive changes will be more obvious.

Run

The following code needs to be called in Swift.

public static func run(_ text: String, filePath: URL, errorHandle: ((Error) -> Void)? = nil) -> Processer?
public static func run(_ dict: [String : Any], filePath: URL, errorHandle: ((Error) -> Void)? = nil) -> Processer?
  • text: JSON file to be parsed
  • dict: Dict to be parsed
  • filePath: The path of the program at startup
  • errorHandle: Called when the program encounters an error

JOP.run supports calling through a dictionary([String : Any]), or through a JSON string. JOP.run return a Processer.

Use start() to start the processer

JOP.run("", filePath: URL(fileURLWithPath: "")) { error in
    print(error)
}?
.start()

start() will use the Runner internally to start itself.

Callback

The callback function acts on the Processor!

OnPrint

Callback function triggered when the program calls print()

JOP.run(run, filePath: URL(fileURLWithPath: "")) { error in
    print(error)
}?
.onOutPut{ outPut in
    print(outPut.text)
}
.start()

output is a type instance of OutPut.

OutPut stores the text, text color, bold and other information.

public struct OutPut {
    var color: String?
    var bold: Bool
    var text: String
}

Example

let run: [String : Any] = [
    "main" : [
        [
            "command": "define",
            "name": "theFirstValue",
            "type": "String"
        ],
        [
            "command": "assignment",
            "name": "theFirstValue",
            "value": "hello, world!"
        ],
        [
            "command": "call",
            "type": "func",
            "name": "print",
            "passBy": "$theFirstValue"
        ],
        [
            "command": "assignment",
            "name": "theFirstValue",
            "value": "hello, JOP!"
        ],
        [
            "command": "call",
            "type": "func",
            "name": "print",
            "passBy": "$theFirstValue"
        ]
    ]
]

JOP.run(run, filePath: URL(fileURLWithPath: "")) { error in
    print(error)
}?
.onOutPut{ outPut in
    print(outPut.text)
}
.start()

Ouput:

hello, world!
hello, JOP!

GitHub

link
Stars: 1
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Beta0.0.1
1 week ago

Hello, world! Hello, JOP!

Now you can use JOP to output content.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics