initial commit
This commit is contained in:
42
comb.odin
Normal file
42
comb.odin
Normal file
@@ -0,0 +1,42 @@
|
||||
package comb
|
||||
|
||||
import "core:log"
|
||||
import "core:fmt"
|
||||
import "core:strings"
|
||||
import "core:flags"
|
||||
import "core:os/os2"
|
||||
|
||||
example_1 :: string(#load("example_1.md"))
|
||||
|
||||
CLI_Options :: struct {
|
||||
file_path: string `args:"pos=0,required" usage:"Input file"`
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
context.logger = log.create_console_logger()
|
||||
opt: CLI_Options
|
||||
flags.parse_or_exit(&opt, os2.args)
|
||||
// TODO: handle error
|
||||
data, _ := os2.read_entire_file(opt.file_path, context.allocator)
|
||||
defer delete(data)
|
||||
content := string(data)
|
||||
// TODO: handle error
|
||||
blocks, _ := parse_code_blocks(content)
|
||||
defer for b in blocks do destroy_code_block(b)
|
||||
if len(blocks) == 0 {
|
||||
log.info("No code blocks detected.")
|
||||
return
|
||||
}
|
||||
for block, i in blocks {
|
||||
log.infof("Executing block #%v (%v), starting on line %v...", i, block.language, block.line_start)
|
||||
stdout, stderr, err := eval_code_block(block)
|
||||
defer delete(stdout)
|
||||
defer delete(stderr)
|
||||
if err != nil {
|
||||
log.errorf("Failed to execute code block: %v", err)
|
||||
return
|
||||
}
|
||||
log.infof("Stdout: %v", stdout)
|
||||
log.infof("Stderr: %v", stderr)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user