Atrium is the parser that powers Akeno.
It is an extremely fast, highly configurable and versatile parser written in JavaScript.
This is the most basic way to use the parser:
const { parse } = require("./atrium")
parse("hello { world }", {
onBlock(block) {
console.log(block) // { name: "hello", attributes: [], properties: { world: [ true ] } }
}
})
Options include:
content
: the content to parseembedded
: run in embedded modestrict
: if true, errors will terminate parsingonBlock
: called when a block is parsedonText
: called on text in embed modeonError
: called on syntax errorsasArray
: if the parse function should return an array of blocksasLookupTable
: if the parse function should a lookup map for efficient data access
Streaming content is possible: Streaming allows for some extra performance and chunked parsing, for when you receive content in chunks, to avoid having to concat all chunks and parse them at once.
const { parserStream } = require("./atrium")
// NOTE: parserStream currently doesnt work with options like "asArray".
const stream = new parserStream({
onBlock(block) {
console.log(block)
}
})
stream.write("blo")
stream.write("ck {")
stream.write("} ") // At this point, onBlock would be called
stream.end()
Atrium is designed to work among other formats, like HTML, using embedded mode.
Embedded mode requires all blocks to begin with "@".
const { parse } = require("./atrium")
parse("<div> @hello { world } </div>", {
embedded: true,
onBlock(block) {
console.log(block)
},
onText(text) {
console.log(text) // "<div> ", " </div>"
}
})
Atrium is really highly optimized for both speed and memory efficiency (especially since recent releases).
This is so it can be used in places where latency and efficiency matter (like high-frequency webservers).
You can use this performance as an advantage for any usecase - from config files to realtime scripting.