bring over the odinfmt code

This commit is contained in:
Daniel Gavin
2021-04-13 23:59:40 +02:00
parent 2001384ae6
commit 3157467e4b
3 changed files with 407 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
package odin_format
import "core:odin/printer"
import "core:odin/parser"
import "core:odin/ast"
default_style := printer.default_style;
simplify :: proc(file: ^ast.File) {
}
format :: proc(source: [] u8, config: printer.Config, allocator := context.allocator) -> ([] u8, bool) {
pkg := ast.Package {
kind = .Normal,
};
file := ast.File {
pkg = &pkg,
src = source,
};
p := parser.default_parser();
ok := parser.parse_file(&p, &file);
if !ok || file.syntax_error_count > 0 {
return {}, false;
}
prnt := printer.make_printer(config, allocator);
return transmute([]u8) printer.print(&prnt, &file), true;
}