diff options
Diffstat (limited to 'src/analysis.odin')
| -rw-r--r-- | src/analysis.odin | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/src/analysis.odin b/src/analysis.odin index 8cba000..3e0fc4c 100644 --- a/src/analysis.odin +++ b/src/analysis.odin @@ -5,6 +5,8 @@ import "core:odin/ast" import "core:odin/tokenizer" import "core:fmt" import "core:log" +import "core:strings" +import "core:path" ParserError :: struct { message: string, @@ -22,13 +24,20 @@ ProcedureSymbol :: struct { }; +PackageSymbol :: struct { + +}; + Symbol :: union { StructSymbol, ProcedureSymbol, + PackageSymbol }; DocumentSymbols :: struct { + file: ast.File, globals: map [string] Symbol, + imports: [] string, }; DocumentPositionContext :: struct { @@ -52,10 +61,14 @@ parser_warning_handler :: proc(pos: tokenizer.Pos, msg: string, args: ..any) { Parses and walks through the ast saving all the global symbols for the document. Local symbols are not saved because they are determined by the position. - Document is responsible in freeing the DocumentSymbols + Document is responsible in freeing the DocumentSymbols with free_document_symbols + + Returns DocumentSymbols, Errors, file package name, imports processed with correct path directory */ -parse_document_symbols :: proc(document: ^Document) -> (DocumentSymbols, [dynamic] ParserError, bool) { +parse_document_symbols :: proc(document: ^Document, config: ^Config) -> (DocumentSymbols, [dynamic] ParserError, string, []string, bool) { + + symbols: DocumentSymbols; p := parser.Parser { err = parser_error_handler, @@ -64,17 +77,47 @@ parse_document_symbols :: proc(document: ^Document) -> (DocumentSymbols, [dynami current_errors = make([dynamic] ParserError, context.temp_allocator); - - ast := ast.File { + symbols.file = ast.File { fullpath = document.path, src = document.text[:document.used_text], }; - parser.parse_file(&p, &ast); + parser.parse_file(&p, &symbols.file); + + symbols.imports = make([]string, len(symbols.file.imports)); + + for imp, index in symbols.file.imports { + + //collection specified + if i := strings.index(imp.fullpath, ":"); i != -1 { + + collection := imp.fullpath[1:i]; + p := imp.fullpath[i+1:len(imp.fullpath)-1]; - return DocumentSymbols {}, current_errors, true; + dir, ok := config.collections[collection]; + + if !ok { + continue; + } + + symbols.imports[index] = path.join(allocator = context.temp_allocator, elems = {dir, p}); + + } + + //relative + else { + + } + } + + + + return symbols, current_errors, symbols.file.pkg_name, symbols.imports, true; } +free_document_symbols :: proc(symbols: DocumentSymbols) { + +} /* |