Atrium is the parser that powers Akeno.
It is extremely fast, zero-dependency, memory-efficient and highly configurable and versatile parser written in JavaScript.
It efficiently manages block states and only clones objects when necesarry.
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
Atrium also works inside text, 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>"
}
})Streaming allows for realtime or more efficient parsing, when you receive content in chunks, to avoid having to concat all chunks and parse them all at once.
const { parserStream } = require("./atrium")
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 highly optimized for both speed and memory efficiency.
This is so it can be used in places where latency and efficiency matter (like webservers, dynamic scripting, etc.).
You can use this performance as an advantage for any usecase - from config files to realtime scripting.
Atrium has an extremely flexible syntax, allowing you to use it in many ways.
All of the following are valid block definitions:
block;
block key;
block();
block() key;
block() { key }
block { key }
