Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
/ skript-parser Public archive

A light-weight javascript library for parsing skript indentations in to an object to be easily read by a program.

License

Notifications You must be signed in to change notification settings

PondWader/skript-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

skript-parser

A light-weight javascript library for parsing skript indentations in to an object to be easily read by a program.

npm

Installing

To install skript-parser first make sure you have npm installed then run npm i skript-parser.

Example Usage

Start with skript file:

on break:
    cancel event
    
on place
    cancel event

command /test:
  trigger:
    if player is on the ground:
      send "on ground"
    broadcast "test"

Run javascript (nodejs) code:

const parse = require('skript-parser');
const fs = require('fs');

const file = fs.readFileSync('./myskript.sk').toString();

const parsed = parse(file);

fs.writeFileSync('./output.json', JSON.stringify(parsed));

The output file should then show the following:

{
    "errors": [
        {
            "error": "A missing colon was found at the end of line 4",
            "line": 4,
            "content": "on place"
        }
    ],
    "lines": [
        {
            "line": 1,
            "content": "on break:",
            "children": [
                {
                    "line": 2,
                    "content": "cancel event"
                }
            ]
        },
        {
            "line": 7,
            "content": "command /test:",
            "children": [
                {
                    "line": 8,
                    "content": "trigger:",
                    "children": [
                        {
                            "line": 9,
                            "content": "if player is on the ground:",
                            "children": [
                                {
                                    "line": 10,
                                    "content": "send \"on ground\""
                                }
                            ]
                        },
                        {
                            "line": 11,
                            "content": "broadcast \"test\""
                        }
                    ]
                }
            ]
        }
    ]
}

PLEASE NOTE: This package only parses indentations and not other errors in skript code

About

A light-weight javascript library for parsing skript indentations in to an object to be easily read by a program.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages