Skip to content

Commit

Permalink
feat: get rid of cjs module
Browse files Browse the repository at this point in the history
BREAKING CHANGE: only provide esm module
  • Loading branch information
arlac77 committed Jan 2, 2019
1 parent 35aea72 commit 067a4fd
Show file tree
Hide file tree
Showing 17 changed files with 344 additions and 367 deletions.
6 changes: 2 additions & 4 deletions .markdown-doctest-setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
require: {
'pratt-parser': require('./dist/parser')
}
}
require: {}
};
91 changes: 45 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ Based on
[Top Down Operator Precedence](https://tdop.github.io) and
[Douglas Crockford TDOP](https://github.com/douglascrockford/TDOP)

<!-- skip-example -->

```javascript
const {Parser, WhiteSpaceToken, NumberToken} = require('pratt-parser');
import { Parser, WhiteSpaceToken, NumberToken } from "pratt-parser";

function Value(value) {
return Object.create(null, {
Expand All @@ -35,34 +37,31 @@ function Value(value) {
}

const myGrammar = new Parser({
tokens: [
WhiteSpaceToken,
NumberToken
],
tokens: [WhiteSpaceToken, NumberToken],
prefix: {
'(': {
"(": {
nud(grammar) {
const e = grammar.expression(0);
grammar.advance(')');
grammar.advance(")");
return e;
}
}
},
infix: {
')': {},
'+': {
")": {},
"+": {
precedence: 50,
combine: (left, right) => Value(left.value + right.value)
},
'-': {
"-": {
precedence: 50,
combine: (left, right) => Value(left.value - right.value)
},
'*': {
"*": {
precedence: 60,
combine: (left, right) => Value(left.value * right.value)
},
'/': {
"/": {
precedence: 60,
combine: (left, right) => Value(left.value / right.value)
}
Expand All @@ -78,27 +77,27 @@ console.log(myGrammar.parse("(1 + (1 + 4 * 3)) * (2 + 1)").value);

### Table of Contents

- [pratt-parser](#pratt-parser)
- [pratt-parser](#pratt-parser-1)
- [pratt-parser](#pratt-parser-2)
- [Parser](#parser)
- [Parameters](#parameters)
- [error](#error)
- [Parameters](#parameters-1)
- [parse](#parse)
- [Parameters](#parameters-2)
- [RootToken](#roottoken)
- [parseString](#parsestring)
- [Parameters](#parameters-3)
- [WhiteSpaceToken](#whitespacetoken)
- [LineCommentToken](#linecommenttoken)
- [EOFToken](#eoftoken)
- [Tokenizer](#tokenizer)
- [Parameters](#parameters-4)
- [tokens](#tokens)
- [Parameters](#parameters-5)
- [error](#error-1)
- [Parameters](#parameters-6)
- [pratt-parser](#pratt-parser)
- [pratt-parser](#pratt-parser-1)
- [pratt-parser](#pratt-parser-2)
- [Parser](#parser)
- [Parameters](#parameters)
- [error](#error)
- [Parameters](#parameters-1)
- [parse](#parse)
- [Parameters](#parameters-2)
- [RootToken](#roottoken)
- [parseString](#parsestring)
- [Parameters](#parameters-3)
- [WhiteSpaceToken](#whitespacetoken)
- [LineCommentToken](#linecommenttoken)
- [EOFToken](#eoftoken)
- [Tokenizer](#tokenizer)
- [Parameters](#parameters-4)
- [tokens](#tokens)
- [Parameters](#parameters-5)
- [error](#error-1)
- [Parameters](#parameters-6)

## pratt-parser

Expand All @@ -112,16 +111,16 @@ Creates a grammar for later parsing

### Parameters

- `grammar` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** definition of the grammar with operators...
- `options` (optional, default `{}`)
- `grammar` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** definition of the grammar with operators...
- `options` (optional, default `{}`)

### error

Forwards error to the tokenizer

#### Parameters

- `args` **...any**
- `args` **...any**

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** error

Expand All @@ -131,8 +130,8 @@ Parses the input and delivers the outermoost expression.

#### Parameters

- `chunk` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** input text
- `context` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object transparently passed to tokenizer
- `chunk` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** input text
- `context` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** object transparently passed to tokenizer

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** evaluated input

Expand All @@ -147,9 +146,9 @@ Modifies ParsePosition so that it points behind the detected token.

#### Parameters

- `pp` **PrsePosition**
- `pp` **PrsePosition**

Returns **Token**
Returns **Token**

## WhiteSpaceToken

Expand All @@ -169,24 +168,24 @@ Creates a tokenizer for later parsing

### Parameters

- `grammar` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** definition of the grammar with operators...
- `grammar` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** definition of the grammar with operators...

### tokens

delivers tokens from the input

#### Parameters

- `chunk` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the input to be processed
- `context` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** additional info to be used by the actual token types
- `chunk` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the input to be processed
- `context` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** additional info to be used by the actual token types

### error

#### Parameters

- `message` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `context` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** token initiating the error
- `value` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
- `message` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `context` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** token initiating the error
- `value` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?**

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** error

Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"publishConfig": {
"access": "public"
},
"main": "dist/parser.js",
"module": "src/parser.js",
"main": "src/parser.mjs",
"module": "src/parser.mjs",
"description": "TDOP parser",
"keywords": [
"tokenizer",
Expand All @@ -23,9 +23,8 @@
"scripts": {
"cover": "c8 --temp-directory build/coverage ava && c8 report -r lcov --temp-directory build/coverage",
"docs": "documentation readme src/parser.js --section=API",
"lint": "documentation lint src/parser.js",
"posttest": "markdown-doctest && npm run prepare",
"pretest": "rollup -c tests/rollup.config.js",
"lint": "documentation lint src/parser.mjs",
"posttest": "markdown-doctest",
"test": "ava"
},
"dependencies": {},
Expand Down
18 changes: 0 additions & 18 deletions rollup.config.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 067a4fd

Please sign in to comment.