-
Notifications
You must be signed in to change notification settings - Fork 0
String Parser
Malexion edited this page Nov 6, 2016
·
2 revisions
-
keywordsObject map with given keywords/chars as property keys and functions to process those keys. -
[options][Optional] Option params,{ ignoreCase: true, defaultAction: (char, idx, str, event) => {} }
var target = '(this and that)',
build = [];
var parser = new __.lib.StringParser({
'(': function(char, idx, fullString, event) {
build.push('');
},
')': function() {
console.log(build); // we are done print it out
},
' ': function() {
// ignore space characters
},
'!': function(c, i, s, event) {
event.skip = 5; // skip the next 5 characters in the string.
},
'and': function(phrase, idx, fullString, event) {
build.push('[{0}]'.format(phrase));
build.push('');
}
}, {
defaultAction: function(char, idx, fullString, event) {
build[build.length - 1] += char;
}
});
parser.parse(target);