regulation-parser

0.1.0 • Public • Published

regulation-parser

A parser for Regulation lang, outputting JSON. The intention of this library is that Regulation syntax can be parsed and converted into any other language.

See regulation-js for an example conversion from Regulation -> JavaScript.

Installation

$ npm install -g regulation-parser

Usage

$ regulation ./examples/twitter.regu
{
  "Entity": [
    [
      {
        "type": "regex",
        "value": "@@﹫"
      },
      {
        "type": "regex",
        "value": "a-zA-Z0-9_",
        "constraint": {
          "min": "1",
          "max": "16"
        }
      },
      {
        "type": "literal",
        "value": "/"
      },
      {
        "type": "regex",
        "value": "a-zA-Z0-9",
        "operator": "+"
      }
    ],
    [
      {
        "type": "regex",
        "value": "@@﹫"
      },
      {
        "type": "regex",
        "value": "a-zA-Z0-9_",
        "constraint": {
          "min": "1",
          "max": "16"
        }
      }
    ]
  ],
  "User": [
    [
      {
        "type": "regex",
        "value": "@@﹫"
      },
      {
        "type": "regex",
        "value": "a-zA-Z0-9_",
        "constraint": {
          "min": "1",
          "max": "16"
        }
      }
    ]
  ],
  "List": [
    [
      {
        "type": "regex",
        "value": "@@﹫"
      },
      {
        "type": "regex",
        "value": "a-zA-Z0-9_",
        "constraint": {
          "min": "1",
          "max": "16"
        }
      },
      {
        "type": "literal",
        "value": "/"
      },
      {
        "type": "regex",
        "value": "a-zA-Z0-9",
        "operator": "+"
      }
    ]
  ],
  "Screenname": [
    [
      {
        "type": "regex",
        "value": "a-zA-Z0-9_",
        "constraint": {
          "min": "1",
          "max": "16"
        }
      }
    ]
  ]
}

API

import parse from 'regulation-parser';
 
const regulation = `
Entity
  = List
  / User
 
User
  = [@@﹫] Screenname
 
List
  = User '/' [a-zA-Z0-9]+
 
Screenname
  = [a-zA-Z0-9_]{1,16}
`;
 
const parsed = parse(regulation);

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    2

Package Sidebar

Install

npm i regulation-parser

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • cameronhunter