Socket
Socket
Sign inDemoInstall

moo

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moo - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

67

moo.js

@@ -83,3 +83,3 @@ (function(root, factory) {

var key = keys[i]
result.push([key, object[key]])
result.push(ruleOptions(key, object[key]))
}

@@ -89,2 +89,14 @@ return result

function arrayToRules(array) {
var result = []
for (var i=0; i<array.length; i++) {
var obj = array[i]
if (!obj.name) {
throw new Error('Rule has no name: ' + JSON.stringify(obj))
}
result.push(ruleOptions(obj.name, obj))
}
return result
}
function ruleOptions(name, obj) {

@@ -115,6 +127,3 @@ if (typeof obj !== 'object' || Array.isArray(obj) || isRegExp(obj)) {

for (var i=0; i<rules.length; i++) {
var rule = rules[i]
// get options
var options = ruleOptions(rule[0], rule[1])
var options = rules[i]
var match = options.match

@@ -164,3 +173,3 @@

function compileRules(rules, hasStates) {
if (!Array.isArray(rules)) rules = objectToRules(rules)
rules = Array.isArray(rules) ? arrayToRules(rules) : objectToRules(rules)

@@ -283,3 +292,2 @@ rules = sortRules(rules)

this.state = state
var index = this.re ? this.re.lastIndex : 0
var info = this.states[state]

@@ -289,3 +297,2 @@ this.groups = info.groups

this.re = info.regexp
this.re.lastIndex = index
}

@@ -302,10 +309,7 @@

Lexer.prototype.eat = hasSticky ? function(re) {
// assume re is /y
Lexer.prototype.eat = hasSticky ? function(re) { // assume re is /y
return re.exec(this.buffer)
} : function(re) {
// assume re is /g
} : function(re) { // assume re is /g
var match = re.exec(this.buffer)
// assert(match)
// assert(match.index === 0)
// will always match, since we used the |(?:) trick
if (match[0].length === 0) {

@@ -316,3 +320,2 @@ return null

}
// TODO: try instead the |(?:) trick?

@@ -327,7 +330,7 @@ function tokenToString() {

if (re.lastIndex === buffer.length) {
var index = re.lastIndex = this.index
if (index === buffer.length) {
return // EOF
}
var start = re.lastIndex
var match = this.eat(re)

@@ -343,3 +346,3 @@ var group, value, text

// consume rest of buffer
text = value = buffer.slice(start)
text = value = buffer.slice(index)
re.lastIndex = buffer.length

@@ -383,3 +386,3 @@

toString: tokenToString,
offset: start,
offset: index,
size: size,

@@ -395,2 +398,3 @@ lineBreaks: lineBreaks,

this.index += size
this.line += lineBreaks

@@ -420,9 +424,5 @@ if (lineBreaks !== 0) {

Lexer.prototype.index = function() {
return this.re.lastIndex
}
Lexer.prototype.reset = function(data, state) {
this.buffer = data || ''
this.re.lastIndex = 0
this.index = 0
this.line = state ? state.line : 1

@@ -445,22 +445,7 @@ this.col = state ? state.col : 1

Lexer.prototype.remaining = function() {
return this.buffer.slice(this.re.lastIndex)
Lexer.prototype.clone = function() {
return new Lexer(this.states, this.state)
}
Lexer.prototype.clone = function(input) {
var map = Object.create(null)
var keys = Object.getOwnPropertyNames(this.states)
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
var s = this.states[key]
map[key] = {
groups: s.groups,
regexp: new RegExp(s.regexp.source, s.regexp.flags),
error: this.error,
}
}
return new Lexer(map, this.state, input)
}
return {

@@ -467,0 +452,0 @@ compile: compile,

{
"name": "moo",
"version": "0.1.1",
"version": "0.2.0",
"description": "Optimised tokenizer/lexer generator! πŸ„ Uses /y for performance. Moo!",
"main": "moo.js",
"files": ["moo.js"],
"files": [
"moo.js"
],
"repository": "https://github.com/tjvr/moo.git",
"author": "Tim Radvan <tim@tjvr.org>",
"contributors": ["Nathan"],
"contributors": [
"Nathan"
],
"license": "BSD-3-Clause",

@@ -14,7 +18,7 @@ "scripts": {

"lint": "eslint moo.js",
"benchmark": "node test/benchmark.js",
"benchmark": "benchr test/benchmark.js",
"moo": "echo 'Mooooo!'"
},
"devDependencies": {
"benchmark": "^2.1.3",
"benchr": "^3.2.0",
"chevrotain": "^0.23.0",

@@ -21,0 +25,0 @@ "eslint": "^3.17.1",

@@ -16,2 +16,3 @@ ![](cow.png)

* is even [Iterable](#iteration)
* <3KB gzipped
* Moo!

@@ -18,0 +19,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc