diff --git a/src/parse/grammar/checks.ts b/src/parse/grammar/checks.ts index 4061c97a0..8340aa1b5 100644 --- a/src/parse/grammar/checks.ts +++ b/src/parse/grammar/checks.ts @@ -222,7 +222,7 @@ namespace chevrotain.checks { let isFirstOptional = gast.isOptionalProd(firstProd) let hasMore = definition.length > 1 if (isFirstOptional && hasMore) { - let rest = _.drop(definition) + let rest = utils.drop(definition) return result.concat(getFirstNoneTerminal(rest)) } else { @@ -244,7 +244,7 @@ namespace chevrotain.checks { let ors = orCollector.alternations let errors = _.reduce(ors, (errors, currOr) => { - let exceptLast = _.dropRight(currOr.definition) + let exceptLast = utils.dropRight(currOr.definition) let currErrors = utils.map(exceptLast, (currAlternative:IProduction, currAltIdx) => { if (utils.isEmpty(first.first(currAlternative))) { return { diff --git a/src/parse/grammar/rest.ts b/src/parse/grammar/rest.ts index 0fd2d0f10..de3287b8a 100644 --- a/src/parse/grammar/rest.ts +++ b/src/parse/grammar/rest.ts @@ -10,7 +10,7 @@ namespace chevrotain.rest { walk(prod:g.AbstractProduction, prevRest:any[] = []):void { utils.forEach(prod.definition, (subProd:gast.IProduction, index) => { - let currRest = _.drop(prod.definition, index + 1) + let currRest = utils.drop(prod.definition, index + 1) if (subProd instanceof g.NonTerminal) { this.walkProdRef(subProd, currRest, prevRest) diff --git a/src/scan/lexer.ts b/src/scan/lexer.ts index a38d253e1..ca41ca106 100644 --- a/src/scan/lexer.ts +++ b/src/scan/lexer.ts @@ -39,7 +39,7 @@ namespace chevrotain { else if (utils.isString(groupName)) { return groupName } - else if (_.isUndefined(groupName)) { + else if (utils.isUndefined(groupName)) { return "default" } else { @@ -193,7 +193,7 @@ namespace chevrotain { identicalPatterns = _.compact(identicalPatterns) let duplicatePatterns = _.filter(identicalPatterns, (currIdenticalSet) => { - return _.size(currIdenticalSet) > 1 + return currIdenticalSet.length > 1 }) let errors = utils.map(duplicatePatterns, (setOfIdentical:any) => { diff --git a/src/scan/tokens_public.ts b/src/scan/tokens_public.ts index ee4d9bb72..572cee921 100644 --- a/src/scan/tokens_public.ts +++ b/src/scan/tokens_public.ts @@ -33,7 +33,7 @@ namespace chevrotain { patternOrParent === chevrotain.Lexer.NA) { pattern = patternOrParent } - else if (_.isFunction(patternOrParent)) { + else if (utils.isFunction(patternOrParent)) { parentConstructor = patternOrParent pattern = undefined } @@ -51,7 +51,7 @@ namespace chevrotain { derivedCostructor.tokenName = tokenName derivedCostructor.prototype = Object.create(parentConstructor.prototype) derivedCostructor.prototype.constructor = derivedCostructor - if (!_.isUndefined(pattern)) { + if (!utils.isUndefined(pattern)) { derivedCostructor.PATTERN = pattern } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 7d47f0753..0d26e47ac 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -70,4 +70,20 @@ namespace chevrotain.utils { export function isString(item:any):boolean { return typeof item === "string" } + + export function isUndefined(item:any):boolean { + return item === undefined + } + + export function isFunction(item:any):boolean { + return item instanceof Function + } + + export function drop(arr:T[], howMuch:number = 1):T[] { + return arr.slice(howMuch, arr.length) + } + + export function dropRight(arr:T[], howMuch:number = 1):T[] { + return arr.slice(0, arr.length - howMuch) + } } diff --git a/test/utils/utils_spec.ts b/test/utils/utils_spec.ts index 89a824504..24bd530fa 100644 --- a/test/utils/utils_spec.ts +++ b/test/utils/utils_spec.ts @@ -29,5 +29,19 @@ namespace chevrotain.utils.spec { expect(isString(null)).to.be.false }) + it("exports a drop utility", () => { + expect(drop([])).to.deep.equal([]) + expect(drop([1, 2, 3])).to.deep.equal([2, 3]) + expect(drop([1, 2, 3], 2)).to.deep.equal([3]) + expect(drop([1, 2, 3], 3)).to.deep.equal([]) + }) + + it("exports a dropRight utility", () => { + expect(dropRight([])).to.deep.equal([]) + expect(dropRight([1, 2, 3])).to.deep.equal([1, 2]) + expect(dropRight([1, 2, 3], 2)).to.deep.equal([1]) + expect(dropRight([1, 2, 3], 3)).to.deep.equal([]) + }) + }) }