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.3.2 to 0.3.3

14

moo.js

@@ -445,5 +445,13 @@ (function(root, factory) {

Lexer.prototype.has = function(tokenType) {
var groups = this.groups;
for (var i=groups.length; i--; ) {
if (groups[i].tokenType === tokenType) return true
for (var s in this.states) {
var groups = this.states[s].groups
for (var i=0; i<groups.length; i++) {
var group = groups[i]
if (group.tokenType === tokenType) return true
if (group.keywords) {
for (var k in group.keywords) {
if (group.keywords[k].tokenType === tokenType) return true
}
}
}
}

@@ -450,0 +458,0 @@ return false

{
"name": "moo",
"version": "0.3.2",
"version": "0.3.3",
"description": "Optimised tokenizer/lexer generator! πŸ„ Uses /y for performance. Moo!",

@@ -5,0 +5,0 @@ "main": "moo.js",

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

* is even [Iterable](#iteration)
* has no dependencies
* <3KB gzipped

@@ -37,3 +38,3 @@ * Moo!

First, you need to do the needful: `$ npm install moo`, `$ yarn install moo`, or whatever will ship this code to your computer. Alternatively, grab the `moo.js` file by itself and slap it into your web page via a `<script>` tag; it's completely standalone.
First, you need to do the needful: `$ npm install moo`, or whatever will ship this code to your computer. Alternatively, grab the `moo.js` file by itself and slap it into your web page via a `<script>` tag; moo is completely standalone.

@@ -106,12 +107,14 @@ Then you can start roasting your very own lexer/tokenizer:

moo.compile({
word: /[a-z]+/,
foo: 'foo',
}).reset('foo').next() // -> { type: 'word', value: 'foo' }
identifier: /[a-z0-9]+/,
number: /[0-9]+/,
}).reset('42').next() // -> { type: 'identifier', value: '42' }
moo.compile({
foo: 'foo',
word: /[a-z]+/,
}).reset('foo').next() // -> { type: 'foo', value: 'foo' }
number: /[0-9]+/,
identifier: /[a-z0-9]+/,
}).reset('42').next() // -> { type: 'number', value: '42' }
```
(Note: moo [special-cases keywords](#keywords); in which case order is ignored.)
* Moo uses **multiline RegExps**. This has a few quirks: for example, the **dot `/./` doesn't include newlines**. Use `[^]` instead if you want to match newlines too.

@@ -164,5 +167,5 @@

moo.compile({
['lparen', '('],
['rparen', ')'],
['keyword', ['while', 'if', 'else', 'moo', 'cows']],
lparen: '(',
rparen: ')',
keyword: ['while', 'if', 'else', 'moo', 'cows'],
})

@@ -288,2 +291,8 @@ ```

Create an array of tokens.
```js
let tokens = Array.from(lexer);
```
Use [itt](https://github.com/nathan/itt)'s iteration tools with Moo.

@@ -290,0 +299,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