Code Monkey home page Code Monkey logo

stollen's Introduction

Stollen

it's like pollen but stolen (and bad)

It's a simple markup langage that can be compiled(?) to tree of javascript objects.

Basic Usage

const st = require('stollen');

let text = 
`{|h1 class : title}[Hello World|]

{|div}[
    {|em}[Hi buddy!|]
    {|img file : "./sup.png"|}
    [|Howdy|]
|]

Goodbye World!
`

let [root, errorMsg] = st.parse(text, '');


/*produces tree that looks like this
{
    "attributeList": [],
    "attributeMap": {},
    "body": [
        {
            "attributeList": ["h1"],
            "attributeMap": {"class": "title"},
            "body": ["Hello World"]
        },
        "\n\n",
        {
            "attributeList": ["div"],
            "attributeMap": {},
            "body": [
                {
                    "attributeList": ["em"],
                    "attributeMap": {},
                    "body": ["Hi buddy!"]
                },
                "\n",
                {
                    "attributeList": ["img"],
                    "attributeMap": {"file": "./sup.png"},
                    "body": []
                },
                "\n",
                {
                    "attributeList": [],
                    "attributeMap": {},
                    "body": ["Howdy"]
                }
            ]
        },
        "\n\nGoodbye World!"
    ]
}
*/

Syntax

Syntax is like this

outer text
{| attribute1 key : "and value"}[
    some text
    
    {|"child attribute 1" "child attribute 2"}[
        child text
    |]

    [|body with no attributes|]

    {|"has body" : false|}

    other text
|]
other outer text

And it will convert this file to javascript objects.

//it also has a pointer to it's parent
//but I don't know how to describe circular relations with JSON
{
    "attributeList": [],
    "attributeMap": {},
    "body": [
        "outer text\n",
        {
            "attributeList": ["attribute1"],
            "attributeMap": {"key": "and value"},
            "body": [
                "some text\n\n",
                {
                    "attributeList": [
                        "child attribute 1",
                        "child attribute 2"
                    ],
                    "attributeMap": {},
                    "body": ["child text"]
                },
                "\n\n",
                {
                    "attributeList": [],
                    "attributeMap": {},
                    "body": ["body with no attributes"]
                },
                "\n\n",
                {
                    "attributeList": [],
                    "attributeMap": {"has body": "false"},
                    "body": []
                },
                "\n\nother text"
            ]
        },
        "\nother outer text"
    ]
}

White Space

Stollen mostly tries to keep whitespaces intact, except indents.

It is mainly to make the original stollen code more readable.

This is how it works.

Stollen checks how much the first line is indented. For example :

{|animals}[
    cat
    dog
|]

In this case first line 'cat' starts with 4 spaces. Stollen notices this and removes following lines 4 spaces.

But what about the cases where you want to start the text with tab or spaces?

In these cases, you can start your text with | and then insert whitespaces.

{|div}[
    |    This scentence starts after 4 spaces.
    |  And this starts after 2 spaces
|]

Stollen always ignore the first | after indent in multi-line text.

If you want to start your multi-line text with |, just put it two times
(sorry but it was the best I could come up with)

Escaping

Escape character is @. To type @, insert @@.

You only need to escape characters that are important in that context.

you always have to escpae
@@

in most outer body, you only need to escpae
@{| @[| @|]

{|
    in attributes you only need to escape
    @} @" @: @|}
}
[
    same as most outer body, you only need to escpae
    @{| @[| @|]
|]

TODO

  • a way to add comment
  • rigorous testing
  • better code

stollen's People

Contributors

imprity avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.