package
SimpleGrammar define parsers
npm install simplegrammarGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
SimpleGrammar define parsers.
Via npm on Node:
npm install simplegrammarReference in your program:
var sg = require('simplegrammar');
var get = sg.get;
var peek = sg.peek;There are rules, that process string input:
var rulefor = get('for'); // the word 'for'
var ruledigit = get('0-9'); // digits
var ruleaorb = get(['a', 'b']); // an array is an 'or'
var ruletwodigit = get('0-9', '0-9'); // two digitsAn array means an option: the rule accepts one of the elements.
More than one parameter is a sequence: the rule accepts the sequence.
The rule can process a string:
var result = get('for').process('for'); // result is 'for'
var noresult = get('for').process('if'); // noresult is nullBut in general, the rules are invoked by a parser.
var parser = sg.createParser(text, [rulefor, ruledigit, ... ]);A parser has an array of rule to execute.
There are peek rules to get an element, but without removing it from the parser process:
var rule = peek('for'); var rule2 = get('for'); var parser = sg.createParser('for'); // without rules, invoke the rule directly rule.process(parser); // success, it detects 'for' rule2.process(parser); // success again, it detects and remove 'for'
TBD: explain other rules (generate, not, oneOrMore, zeroOrMore, zeroOrOne, ...) and more examples
git clone git://github.com/ajlopez/SimpleGrammar.git
cd SimpleGrammar
npm install
npm testTBD
Projects that use SimpleGrammar:
TBD
MIT
Feel free to file issues and submit pull requests � contributions are welcome<
If you submit a pull request, please be sure to add or update corresponding
test cases, and ensure that npm test continues to pass.