stream-token-parser
Version:
Token parser designed based on stream property. Accept chunk string and parse it into tokens simultaneously. [readme-lang:zh]基于流特性设计的token解析器,接受一个chunk的字符串,同时解析成tokens。
26 lines (20 loc) • 477 B
JavaScript
;
let {
isString, isFunction
} = require('basetype');
let {
MATCH, WAIT, QUIT
} = require('./const');
let stringMatch = (word) => (prefix) => {
if (word === prefix) return MATCH;
if (word.indexOf(prefix) !== -1) return WAIT;
return QUIT;
};
let getMatch = (match) => {
if (isFunction(match)) return match;
if (isString(match)) return stringMatch(match);
// TODO analysis regular expression
};
module.exports = {
getMatch
};