Supports streaming, custom types and resolving.
dependencies {
implementation("com.huskerdev:webidl-kt:1.0.1")
}The simplest way is to parse text into a definitions AST.
It ignores type incompatibilities and missing identifiers, but uses some basic syntax checks.
val root = WebIDL.parseDefinitions("""
[Exposed=Window]
interface TestInterface {
attribute long a;
};
""".trimIndent())It is possible to "stream" definitions as they are parsed, without storing them in memory. This can be effective when converting "on the fly".
WebIDL.streamDefinitions("""
[Exposed=Window]
interface TestInterface {
attribute long a;
};
""".trimIndent(), object: IdlParserConsumer {
override fun enter(definition: IdlDefinition) {
// Definition opened
}
override fun exit() {
// Definition closed
}
})Constructor can also accept an Iterator<Char>.
So it is possible to work with a data stream (for example, a file).
For working with files, the JVM part of this library has a special helper class that converts an
Readerto anIterator<Char>
val iterator = File("someFile.idl").bufferedReader().iterator()
// parse definitions
val root = WebIDL.parseDefinitions(iterator)
// or stream
WebIDL.streamDefinitions(iterator, object: IdlParserConsumer {
override fun enter(definition: IdlDefinition) {
// Definition opened
}
override fun exit() {
// Definition closed
}
})The library contains a module for resolving types.
It will check type compatibility, create references, and merge all mixins and partials.
val resolver = WebIDL.resolve("""
[Exposed=Window]
interface TestInterface {
attribute long a;
};
""".trimIndent())