Skip to content

Commit

Permalink
Refactor parseFile function in LibClangParser
Browse files Browse the repository at this point in the history
Refactored the `parseFile` function in `LibClangParser.kt` to improve file handling. The function now validates if the file exists before parsing and supports parsing with file object besides file name. The changes enhance error prevention and enable more flexible file handling options.
  • Loading branch information
Alexandre Mommers committed Dec 28, 2023
1 parent 805b5ce commit 27ae205
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package klang.parser.libclang

import klang.DeclarationRepository
import java.io.File

enum class ParserTechnology {
JNA,
Panama
}

fun parseFile(file: String, parserTechnology: ParserTechnology = ParserTechnology.Panama) = when (parserTechnology) {
ParserTechnology.JNA -> parseFileWithJna(file)
ParserTechnology.Panama -> parseFileWithPanama(file)
fun parseFile(fileAsString: String, parserTechnology: ParserTechnology = ParserTechnology.Panama): DeclarationRepository {
val file = File(fileAsString)
assert(file.exists())
return parseFile(file, parserTechnology)
}

internal fun parseFile(file: File, parserTechnology: ParserTechnology = ParserTechnology.Panama) = when (parserTechnology) {
ParserTechnology.JNA -> parseFileWithJna(file.absolutePath)
ParserTechnology.Panama -> parseFileWithPanama(file.absolutePath)
}

0 comments on commit 27ae205

Please sign in to comment.