Skip to content

the-lstv/Atrium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Group 357

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.


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

Embedded mode

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 (Currently not fully implemented)

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

Performance

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.

Flexibility

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 }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published