Skip to content

Commit dbcce3d

Browse files
committed
New: the first implementation
1 parent c3af648 commit dbcce3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+52635
-1
lines changed

.eslintrc.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
extends:
2+
- mysticatea
3+
- mysticatea/modules
4+
- plugin:prettier/recommended
5+
6+
rules:
7+
class-methods-use-this: off
8+
complexity: off
9+
mysticatea/arrow-parens: off
10+
prettier/prettier:
11+
- error
12+
- tabWidth: 4
13+
semi: false
14+
trailingComma: all
15+
parser: typescript
16+
17+
overrides:
18+
- files: ["*.ts"]
19+
parser: typescript-eslint-parser
20+
rules:
21+
lines-between-class-members: off
22+
no-invalid-this: off
23+
no-loop-func: off
24+
no-undef: off
25+
no-unused-vars: off
26+
no-use-before-define: off
27+
require-jsdoc: off
28+
valid-jsdoc: off
29+
settings:
30+
node:
31+
tryExtensions: [".ts"]
32+
33+
- files: ["src/unicode/ids.ts"]
34+
rules:
35+
import/exports-last: off
36+
37+
- files: ["src/unicode/property-data.ts"]
38+
rules:
39+
camelcase: off

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.temp
2+
/node_modules
3+
/index.*
4+
/test.*

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock = false

.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"eslint.validate": [
3+
"javascript",
4+
{"autoFix": true, "language": "typescript"}
5+
],
6+
"typescript.tsdk": "node_modules\\typescript\\lib"
7+
}

README.md

+148-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,149 @@
11
# regexpp
2-
RegExp parser.
2+
3+
[![npm version](https://img.shields.io/npm/v/regexpp.svg)](https://www.npmjs.com/package/regexpp)
4+
[![Downloads/month](https://img.shields.io/npm/dm/regexpp.svg)](http://www.npmtrends.com/regexpp)
5+
[![Build Status](https://travis-ci.org/mysticatea/regexpp.svg?branch=master)](https://travis-ci.org/mysticatea/regexpp)
6+
[![Dependency Status](https://david-dm.org/mysticatea/regexpp.svg)](https://david-dm.org/mysticatea/regexpp)
7+
8+
The regular expression parser for ECMAScript.
9+
10+
## 💿 Installation
11+
12+
```bash
13+
$ npm install regexpp
14+
```
15+
16+
- require Node.js 4.0.0 or newer.
17+
18+
## 📖 Usage
19+
20+
```ts
21+
import {
22+
AST,
23+
RegExpParser,
24+
RegExpValidator,
25+
parseRegExpLiteral,
26+
validateRegExpLiteral,
27+
} from "regexpp"
28+
```
29+
30+
### parseRegExpLiteral(source, options?)
31+
32+
Parse a given regular expression literal then make AST object.
33+
34+
This is equivalent to `new RegExpParser(options).parseLiteral(source)`.
35+
36+
- **Parameters:**
37+
- `source` (`string`) The source code to parse.
38+
- `options?` ([`RegExpParser.Options`]) The options to parse.
39+
- **Return:**
40+
- The AST of the regular expression.
41+
42+
### validateRegExpLiteral(source, options?)
43+
44+
Validate a given regular expression literal.
45+
46+
This is equivalent to `new RegExpValidator(options).validateLiteral(source)`.
47+
48+
- **Parameters:**
49+
- `source` (`string`) The source code to validate.
50+
- `options?` ([`RegExpValidator.Options`]) The options to validate.
51+
52+
### RegExpParser
53+
54+
#### new RegExpParser(options?)
55+
56+
- **Parameters:**
57+
- `options?` ([`RegExpParser.Options`]) The options to parse.
58+
59+
#### parser.parseLiteral(source, start?, end?)
60+
61+
Parse a regular expression literal.
62+
63+
- **Parameters:**
64+
- `source` (`string`) The source code to parse. E.g. `"/abc/g"`.
65+
- `start?` (`number`) The start index in the source code. Default is `0`.
66+
- `end?` (`number`) The end index in the source code. Default is `source.length`.
67+
- **Return:**
68+
- The AST of the regular expression.
69+
70+
#### parser.parsePattern(source, start?, end?, uFlag?)
71+
72+
Parse a regular expression pattern.
73+
74+
- **Parameters:**
75+
- `source` (`string`) The source code to parse. E.g. `"abc"`.
76+
- `start?` (`number`) The start index in the source code. Default is `0`.
77+
- `end?` (`number`) The end index in the source code. Default is `source.length`.
78+
- `uFlag?` (`boolean`) The flag to enable Unicode mode.
79+
- **Return:**
80+
- The AST of the regular expression pattern.
81+
82+
#### parser.parseFlags(source, start?, end?)
83+
84+
Parse a regular expression flags.
85+
86+
- **Parameters:**
87+
- `source` (`string`) The source code to parse. E.g. `"gim"`.
88+
- `start?` (`number`) The start index in the source code. Default is `0`.
89+
- `end?` (`number`) The end index in the source code. Default is `source.length`.
90+
- **Return:**
91+
- The AST of the regular expression flags.
92+
93+
### RegExpValidator
94+
95+
#### new RegExpValidator(options)
96+
97+
- **Parameters:**
98+
- `options` ([`RegExpValidator.Options`]) The options to validate.
99+
100+
#### validator.validateLiteral(source, start, end)
101+
102+
Validate a regular expression literal.
103+
104+
- **Parameters:**
105+
- `source` (`string`) The source code to validate.
106+
- `start?` (`number`) The start index in the source code. Default is `0`.
107+
- `end?` (`number`) The end index in the source code. Default is `source.length`.
108+
109+
#### validator.validatePattern(source, start, end, uFlag)
110+
111+
Validate a regular expression pattern.
112+
113+
- **Parameters:**
114+
- `source` (`string`) The source code to validate.
115+
- `start?` (`number`) The start index in the source code. Default is `0`.
116+
- `end?` (`number`) The end index in the source code. Default is `source.length`.
117+
- `uFlag?` (`boolean`) The flag to enable Unicode mode.
118+
119+
#### validator.validateFlags(source, start, end)
120+
121+
Validate a regular expression flags.
122+
123+
- **Parameters:**
124+
- `source` (`string`) The source code to validate.
125+
- `start?` (`number`) The start index in the source code. Default is `0`.
126+
- `end?` (`number`) The end index in the source code. Default is `source.length`.
127+
128+
## 📰 Changelog
129+
130+
- [GitHub Releases](https://github.com/mysticatea/regexpp/releases)
131+
132+
## 🍻 Contributing
133+
134+
Welcome contributing!
135+
136+
Please use GitHub's Issues/PRs.
137+
138+
### Development Tools
139+
140+
- `npm test` runs tests and measures coverage.
141+
- `npm run build` compiles TypeScript source code to `index.js`, `index.js.map`, and `index.d.ts`.
142+
- `npm run clean` removes the temporary files which are created by `npm test` and `npm run build`.
143+
- `npm run lint` runs ESLint.
144+
- `npm run update:test` updates test fixtures.
145+
- `npm run update:ids` updates `src/unicode/ids.ts`.
146+
- `npm run watch` runs tests with `--watch` option.
147+
148+
[`RegExpParser.Options`]: src/parser.ts#L527
149+
[`RegExpValidator.Options`]: src/validator.ts#L127

package.json

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"name": "regexpp",
3+
"version": "0.0.0",
4+
"description": "Regular expression parser for ECMAScript 2018.",
5+
"engines": {
6+
"node": ">=4.0.0"
7+
},
8+
"main": "index.js",
9+
"files": [
10+
"index.d.ts",
11+
"index.js.map"
12+
],
13+
"devDependencies": {
14+
"@types/eslint": "^4.16.0",
15+
"@types/mocha": "^2.2.48",
16+
"@types/node": "^9.4.6",
17+
"dts-bundle": "^0.7.3",
18+
"eslint": "^4.18.0",
19+
"eslint-config-mysticatea": "^13.0.2",
20+
"eslint-config-prettier": "^2.9.0",
21+
"eslint-plugin-prettier": "^2.4.0",
22+
"mocha": "^5.0.1",
23+
"npm-run-all": "^4.1.2",
24+
"prettier": "^1.9.2",
25+
"rollup": "^0.56.1",
26+
"rollup-plugin-node-resolve": "^3.0.3",
27+
"rollup-plugin-sourcemaps": "^0.4.2",
28+
"rollup-watch": "^4.3.1",
29+
"ts-node": "^5.0.0",
30+
"typescript": "^2.7.2",
31+
"typescript-eslint-parser": "^14.0.0"
32+
},
33+
"scripts": {
34+
"prebuild": "npm run -s clean",
35+
"build": "tsc --project tsconfig.prod.json && rollup -c -o index.js && dts-bundle --name regexpp --main .temp/index.d.ts --out ../index.d.ts",
36+
"clean": "rimraf .temp index.*",
37+
"lint": "eslint src test tools --ext .ts",
38+
"pretest": "run-s build lint",
39+
"test": "_mocha --require ts-node/register --reporter dot --timeout 10000 \"test/*.ts\"",
40+
"update:test": "ts-node tools/update-fixtures.ts",
41+
"update:ids": "ts-node tools/update-unicode-ids.ts",
42+
"preversion": "npm test",
43+
"version": "npm run -s build",
44+
"postversion": "git push && git push --tags",
45+
"prewatch": "npm run -s clean",
46+
"watch": "npm run -s test -- --watch-extensions .ts --watch --growl"
47+
},
48+
"repository": {
49+
"type": "git",
50+
"url": "git+https://github.com/mysticatea/regexpp.git"
51+
},
52+
"keywords": [
53+
"regexp",
54+
"regular",
55+
"expression",
56+
"parser",
57+
"validator",
58+
"ast",
59+
"abstract",
60+
"syntax",
61+
"tree",
62+
"ecmascript",
63+
"es2015",
64+
"es2016",
65+
"es2017",
66+
"es2018",
67+
"annexB"
68+
],
69+
"author": "Toru Nagashima (https://github.com/mysticatea)",
70+
"license": "MIT",
71+
"bugs": {
72+
"url": "https://github.com/mysticatea/regexpp/issues"
73+
},
74+
"homepage": "https://github.com/mysticatea/regexpp#readme"
75+
}

rollup.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import resolve from "rollup-plugin-node-resolve"
2+
import sourcemaps from "rollup-plugin-sourcemaps"
3+
4+
export default {
5+
input: ".temp/index.js",
6+
output: {
7+
file: "index.js",
8+
format: "cjs",
9+
sourcemap: true,
10+
sourcemapFile: "index.js.map",
11+
strict: true,
12+
banner: `/*!
13+
* @author Toru Nagashima <https://github.com/mysticatea>
14+
*/`,
15+
},
16+
plugins: [sourcemaps(), resolve()],
17+
}

0 commit comments

Comments
 (0)