Skip to content

JamesFrost/gnip-rule-parser

Repository files navigation

gnip-rule-parser Build Status

Parse GNIP PowerTrack/Search rules into an abstract syntax tree.

Try the online demo here.

If you want to validate rules, I strongly suggest you use the validation API endpoint.

Getting Started

Installation

npm install --save gnip-rule-parser

Running The Tests

mocha

Usage

var parser = require( 'gnip-rule-parser' );

try
{
  var ast = parser.parse( 'happy OR party' );

  console.log( ast ); 
}
catch( err )
{ 
  // Rule isn't valid
}

Output

[ 
  {
    name: 'boolean',
    value: 'OR',
    leftBranch: 
    { 
      name: 'keyword', 
      value: 'happy' 
    },
    rightBranch: 
    { 
      name: 'keyword', 
      value: 'party' 
    } 
  } 
]

License

MIT