Skip to content

the-lstv/Atrium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Group 357

Atrium is the parser that powers Akeno.
It is an extremely fast, highly configurable and versatile parser written in JavaScript.


Usage

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 parse
  • embedded: run in embedded mode
  • strict: if true, errors will terminate parsing
  • onBlock: called when a block is parsed
  • onText: called on text in embed mode
  • onError: called on syntax errors
  • asArray: if the parse function should return an array of blocks
  • asLookupTable: if the parse function should a lookup map for efficient data access

Syntax

Syntax

Streaming

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()

Embedded mode

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>"
  }
})

Performance

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published