GitHub - PratikDeoghare/brashtag: A notation for writing trees and a parser for it

2 min read Original article ↗

Brashtag is a notation for specifying trees. Purpose of the notation is to allow you to surround a piece of text with hints that programs can later exploit.

The notation

There are three kinds of nodes blobs, bags, codes.

  • Blobs contain text.
  • Bags contain blobs, codes and other bags. They can be tagged.
  • Codes also contain text. More on them later.

The following snippet constructs tree with a bag tagged "card" that contains two bags tagged "front" and "back". The bag tagged "front" contains a blob with text "This is front.". The bag tagged back contains a blob with text "This is back.".

#card{
   #front{
      This is front.
   } 
   #back{
      This is back.
   }
}

Any text is allowed inside tags and blobs except these four characters #, {, }, ` (tick). Because these characters are also used by the notation. If you want to put text with those characters in the tree you have to surround it by ` ticks. That creates a node of kind code. You need to surround the code node with more ticks than maximum number of consecutive ticks inside its text.

Following snippet constructs a code node with tag ` and func main() { fmt.Println("Hello") } text.

`
func main() { fmt.Println("Hello") }
`

And this snippet constructs a code node with tag `` and text Some `code` here. .

Examples Texts and Corresponding Trees

One

Two

Hello, World!

#comment{
    A first program!
}

Three

Hello, World!

#comment{
    A first program!
}

Code to compute nth fibonacci number.

`
def fibs(n):
    if n == 0 or n == 1:
        return 1
    return fibs(n-1) + fibs(n-2)
`

Four

Hello, World!

#comment{
    A first program!
}

Code to compute nth fibonacci number.

`
def fibs(n):
    if n == 0 or n == 1:
        return 1
    return fibs(n-1) + fibs(n-2)
`

That is all.

Some Programs

These are quickly hacked together, unpolished programs. Making this kind of hacking easy is what this notation is invented for.

  • barkdown - converts brashtag to html.
  • carter - flashcards study program.
  • todot - outputs brashtag tree in dot format from a brashtag document.
  • notebook - use a brashtag document as a jupyter notebook

Install

Golang:

import "github.com/pratikdeoghare/brashtag"

Python:

pip install git+https://github.com/PratikDeoghare/brashtag.git

Javascript:

npm install git+https://github.com/pratikdeoghare/brashtag.git

TODO

  • Write tests.
  • Better error reporting.
  • Write tutorial.
  • Write docs.