Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Small javascript LL(1) Parser generator through simple and expressive DSL.
Allow to describe parser rules with structured sentences based on Method Chaining.
Take a look at examples in ./examples.
Create a rule instance :
var rule = new Rule();
or using shortcut :
var r = Rule.initializer;
var rule = r.oneOf(...);
The Atom :
The fundamental atom of elenpi : a simple handler that take an object (env
) containing the rest of the string to parse and the errors report, and the current descriptor
where to store catched information.
.done(function(env, descriptor){
// place information in current descriptor
descriptor.foo = env.string...;
// when information catched : your responsible to replace THE REST of the string in env.
env.string = env.string.substring(...);
}) : Rule
Recognize a terminal (aka try to match a regexp at beginning of current string) :
.terminal(RegExp, ?String || ?function(env, descriptor, captured){
descriptor.something = captured[1]; // example
}) : Rule
Second argument :
Recognize a single char, that will not be stored in descriptor :
.char( String ) : Rule
Need the end of string there :
.end() : Rule
Use a rule, either by name (will be found in parser's rules), or by providing a rule instance (that will be "inserted" there) :
.use(ruleName:String||rule:Rule) : Rule
Skip an element : Place a skip:true
in current descriptor and so elenpi will ignored it :
.skip() : Rule
Recognized an optional space (/^\s+/ : one or more) :
.space(needed = false) : Rule
Force error if parser execute it (Only aimed to be used in .oneOf() as last rule - so if no other rule have been matched -> force error) :
.error(msg): Rule
Match elements in strings through one rule (maybe optional) :
.one(rule || {
rule:rule,
?as:function(){ return Instance },
?set:'name' || function(env, parent, descriptor){ ... }
}) : Rule
.maybeOne(rule || {
rule:rule,
?as:function(){ return Instance },
?set:'name' || function(env, parent, descriptor){ ... }
}) : Rule
Match elements in strings through one of provided rules :
.oneOf(...rules || {
rules:[rules],
?as:function(){ return Instance },
?set:'name' || function(env, parent, descriptor){ ... }
}) : Rule
.maybeOneOf(...rules || {
rules:[rules],
?as:function(){ return Instance },
?set:'name' || function(env, parent, descriptor){ ... }
})
Match x or more elements in string with provided rule (and maybe a separator rule) :
.xOrMore({
rule:rule,
minimum:int = 0,
?as:function(){ return Instance },
?pushTo:'name' || function(env, parent, descriptor){ ... },
?separator:rule,
?maximum:int = Infinity
}) : Rule
xOrMore shortcuts :
.zeroOrMore(opt /* as above in xOrMore */) : Rule
.oneOrMore(opt /* as above in xOrMore (minimum = 1) */) : Rule
Constructor :
var parser = new Parser(rulesObject, 'defaultRulesName');
var r = parser.parse('a string to parse', ?ruleToApply); // parse until the end of string
// r is false if parsing failed
// Otherwise, r is a descriptor object containing catched properties
var descriptor = {};
var r = parser.parse('a string to parse', ruleToApply = null, objectWhereStoreTokens = null);
// r is false if parsing failed
// Otherwise, r is the string that still to be parsed
// If parsing succeed, descriptor has been decorated with catched properties
see parsers examples in ./examples
The MIT License
Copyright (c) 2015-2017 Gilles Coomans gilles.coomans@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Small DSL for LL(1) parser
We found that elenpi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.