Rena.js

Rena.js is a library of parsing texts. Rena.js makes parsing text easily.
Rena.js can treat recursion of pattern, hence Rena.js can parse languages which described top down parsing like arithmetic expressions and so on.
Rena.js can also treat synthesized and inherited attributes.
'Rena' is an acronym of REpetation (or REcursion) Notation API.

installation

Install Rena.js:

npm install rena-js

Use module(node.js):

var M = require('rena-js');

Use module(Browser):

<script src='rena.js'></script>

Examples

Parsing CSV texts


var csvparser = R.t(
  R.attr([]).thenMaybe(
    R.delimitArray(
      R.delimitArray(R.or(
        R('"').t(/(""|[^"])+/, function(x) { return x.replace('""', '"'); }).t('"'),
        R(/[^",\n\r]+/, R.I)), ','), R.br())))
  .thenMaybe(R.br());

// outputs [['a','b','c'],['d','e\n\"f','g'],['h']]
console.log(csvparser.parse('a,b,c\nd,"e\n""f",g\nh\n').attribute)
        

Parsing simple arithmetic expressions


var expr = R.Yn(function(t, f, e) {
  return R.then(f).thenMaybe(R.or(
    R.then("+").then(f, function(x, a, b) { return b + a; }),
    R.then("-").then(f, function(x, a, b) { return b - a; })));
  },
  function(t, f, e) {
    return R.then(e).thenMaybe(R.or(
      R.then("*").then(e, function(x, a, b) { return b * a; }),
      R.then("/").then(e, function(x, a, b) { return b / a; })));
  },
  function(t, f, e) {
    return R.or(R.thenInt(/[0-9]+/), R.then("(").then(t).then(")"))
  });

console.log(expr.parse("1+2*3").attribute);  // outputs 7
console.log(expr.parse("4-6/2").attribute);  // outputs 1
        

Documentation

A document of Rena.js is Here.