Skip to content

Commit 5101473

Browse files
authored
Merge pull request #36 from gnidan/typescript
Convert to TypeScript
2 parents e5b9ae8 + 7d66e0a commit 5101473

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

+3794
-4084
lines changed

.eslintrc.js

Lines changed: 12 additions & 275 deletions
Original file line numberDiff line numberDiff line change
@@ -1,277 +1,14 @@
1+
/* eslint-env node */
12
module.exports = {
2-
"env": {
3-
"browser": true,
4-
"es6": true,
5-
"node": true
6-
},
7-
"extends": "eslint:recommended",
8-
"parserOptions": {
9-
"sourceType": "module"
10-
},
11-
"rules": {
12-
"accessor-pairs": "error",
13-
"array-bracket-spacing": [
14-
"error",
15-
"never"
16-
],
17-
"array-callback-return": "error",
18-
"arrow-body-style": "error",
19-
"arrow-parens": "off",
20-
"arrow-spacing": [
21-
"error",
22-
{
23-
"after": true,
24-
"before": true
25-
}
26-
],
27-
"block-scoped-var": "error",
28-
"block-spacing": "error",
29-
"brace-style": "error",
30-
"callback-return": "error",
31-
"camelcase": "error",
32-
"capitalized-comments": "off",
33-
"class-methods-use-this": "off",
34-
"comma-dangle": "error",
35-
"comma-spacing": [
36-
"error",
37-
{
38-
"after": true,
39-
"before": false
40-
}
41-
],
42-
"comma-style": [
43-
"error",
44-
"last"
45-
],
46-
"complexity": "error",
47-
"computed-property-spacing": [
48-
"error",
49-
"never"
50-
],
51-
"consistent-return": "error",
52-
"consistent-this": "error",
53-
"curly": "error",
54-
"default-case": "error",
55-
"dot-location": "error",
56-
"dot-notation": "error",
57-
"eol-last": "error",
58-
"eqeqeq": "error",
59-
"func-call-spacing": "error",
60-
"func-name-matching": "error",
61-
"func-names": [
62-
"error",
63-
"never"
64-
],
65-
"func-style": [
66-
"error",
67-
"declaration",
68-
{
69-
"allowArrowFunctions": true
70-
}
71-
],
72-
"generator-star-spacing": "error",
73-
"global-require": "error",
74-
"guard-for-in": "error",
75-
"handle-callback-err": "error",
76-
"id-blacklist": "error",
77-
"id-length": "off",
78-
"id-match": "error",
79-
"indent": "off",
80-
"init-declarations": "error",
81-
"jsx-quotes": "error",
82-
"key-spacing": "error",
83-
"keyword-spacing": "error",
84-
"line-comment-position": "error",
85-
"linebreak-style": [
86-
"error",
87-
"unix"
88-
],
89-
"lines-around-comment": "error",
90-
"lines-around-directive": "error",
91-
"max-depth": "error",
92-
"max-len": "off",
93-
"max-lines": "error",
94-
"max-nested-callbacks": "error",
95-
"max-params": "off",
96-
"max-statements": "off",
97-
"max-statements-per-line": "error",
98-
"multiline-ternary": [
99-
"error",
100-
"never"
101-
],
102-
"new-cap": "error",
103-
"new-parens": "error",
104-
"newline-after-var": "off",
105-
"newline-before-return": "error",
106-
"newline-per-chained-call": "error",
107-
"no-alert": "error",
108-
"no-array-constructor": "error",
109-
"no-await-in-loop": "error",
110-
"no-bitwise": "error",
111-
"no-caller": "error",
112-
"no-catch-shadow": "error",
113-
"no-compare-neg-zero": "error",
114-
"no-confusing-arrow": "off",
115-
"no-continue": "error",
116-
"no-div-regex": "error",
117-
"no-duplicate-imports": "error",
118-
"no-else-return": "error",
119-
"no-empty-function": "error",
120-
"no-eq-null": "error",
121-
"no-eval": "error",
122-
"no-extend-native": "error",
123-
"no-extra-bind": "error",
124-
"no-extra-label": "error",
125-
"no-extra-parens": "error",
126-
"no-floating-decimal": "error",
127-
"no-implicit-coercion": "error",
128-
"no-implicit-globals": "error",
129-
"no-implied-eval": "error",
130-
"no-inline-comments": "error",
131-
"no-inner-declarations": [
132-
"error",
133-
"functions"
134-
],
135-
"no-invalid-this": "error",
136-
"no-iterator": "error",
137-
"no-label-var": "error",
138-
"no-labels": "error",
139-
"no-lone-blocks": "error",
140-
"no-lonely-if": "error",
141-
"no-loop-func": "off",
142-
"no-magic-numbers": "off",
143-
"no-mixed-operators": "error",
144-
"no-mixed-requires": "error",
145-
"no-multi-assign": "error",
146-
"no-multi-spaces": "error",
147-
"no-multi-str": "error",
148-
"no-multiple-empty-lines": "error",
149-
"no-native-reassign": "error",
150-
"no-negated-condition": "error",
151-
"no-negated-in-lhs": "error",
152-
"no-nested-ternary": "error",
153-
"no-new": "error",
154-
"no-new-func": "error",
155-
"no-new-object": "error",
156-
"no-new-require": "error",
157-
"no-new-wrappers": "error",
158-
"no-octal-escape": "error",
159-
"no-param-reassign": "off",
160-
"no-path-concat": "error",
161-
"no-plusplus": [
162-
"error",
163-
{
164-
"allowForLoopAfterthoughts": true
165-
}
166-
],
167-
"no-process-env": "error",
168-
"no-process-exit": "error",
169-
"no-proto": "error",
170-
"no-prototype-builtins": "error",
171-
"no-restricted-globals": "error",
172-
"no-restricted-imports": "error",
173-
"no-restricted-modules": "error",
174-
"no-restricted-properties": "error",
175-
"no-restricted-syntax": "error",
176-
"no-return-assign": "error",
177-
"no-return-await": "error",
178-
"no-script-url": "error",
179-
"no-self-compare": "error",
180-
"no-sequences": "error",
181-
"no-shadow": "error",
182-
"no-shadow-restricted-names": "error",
183-
"no-spaced-func": "error",
184-
"no-sync": "error",
185-
"no-tabs": "error",
186-
"no-template-curly-in-string": "error",
187-
"no-ternary": "off",
188-
"no-throw-literal": "error",
189-
"no-trailing-spaces": "error",
190-
"no-undef-init": "error",
191-
"no-undefined": "off",
192-
"no-underscore-dangle": "off",
193-
"no-unmodified-loop-condition": "error",
194-
"no-unneeded-ternary": "error",
195-
"no-unused-expressions": "error",
196-
"no-use-before-define": "error",
197-
"no-useless-call": "error",
198-
"no-useless-computed-key": "error",
199-
"no-useless-concat": "error",
200-
"no-useless-constructor": "error",
201-
"no-useless-escape": "error",
202-
"no-useless-rename": "error",
203-
"no-useless-return": "error",
204-
"no-var": "off",
205-
"no-void": "error",
206-
"no-warning-comments": "error",
207-
"no-whitespace-before-property": "error",
208-
"no-with": "error",
209-
"nonblock-statement-body-position": "error",
210-
"object-curly-newline": "off",
211-
"object-curly-spacing": "error",
212-
"object-property-newline": "error",
213-
"object-shorthand": "error",
214-
"one-var": "off",
215-
"one-var-declaration-per-line": "error",
216-
"operator-assignment": [
217-
"error",
218-
"always"
219-
],
220-
"operator-linebreak": "error",
221-
"padded-blocks": "off",
222-
"prefer-arrow-callback": "off",
223-
"prefer-const": "off",
224-
"prefer-numeric-literals": "error",
225-
"prefer-promise-reject-errors": "error",
226-
"prefer-reflect": "error",
227-
"prefer-rest-params": "error",
228-
"prefer-spread": "error",
229-
"prefer-template": "off",
230-
"quote-props": "off",
231-
"quotes": "off",
232-
"radix": [
233-
"error",
234-
"as-needed"
235-
],
236-
"require-await": "error",
237-
"require-jsdoc": "off",
238-
"rest-spread-spacing": "error",
239-
"semi": "off",
240-
"semi-spacing": [
241-
"error",
242-
{
243-
"after": true,
244-
"before": false
245-
}
246-
],
247-
"sort-imports": "error",
248-
"sort-keys": "off",
249-
"sort-vars": "error",
250-
"space-before-blocks": "error",
251-
"space-before-function-paren": "off",
252-
"space-in-parens": [
253-
"error",
254-
"never"
255-
],
256-
"space-infix-ops": "error",
257-
"space-unary-ops": "error",
258-
"spaced-comment": "error",
259-
"strict": "off",
260-
"symbol-description": "error",
261-
"template-curly-spacing": [
262-
"error",
263-
"never"
264-
],
265-
"template-tag-spacing": "error",
266-
"unicode-bom": [
267-
"error",
268-
"never"
269-
],
270-
"valid-jsdoc": "error",
271-
"vars-on-top": "off",
272-
"wrap-iife": "error",
273-
"wrap-regex": "error",
274-
"yield-star-spacing": "error",
275-
"yoda": "error"
276-
}
3+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint'],
6+
root: true,
7+
rules: {
8+
"@typescript-eslint/no-unused-vars": [
9+
"error",
10+
{ "argsIgnorePattern": "^_[0-9]*$", "varsIgnorePattern": "^_[0-9]*$" }
11+
],
12+
}
13+
27714
};

bin/solregex.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/* eslint no-console: 0 */
2+
3+
const { ArgumentParser }: any = require("argparse"); /* eslint-disable-line */
4+
5+
import { version as VERSION } from "../package.json";
6+
7+
import { SolidityDFAWriter } from "../src/solidity/dfa";
8+
import { GraphvizDFAWriter } from "../src/graphviz/dfa";
9+
import { GraphvizNFAWriter } from "../src/graphviz/nfa";
10+
import { dfaFromNFA } from "../src/dfa";
11+
import { nfaFromRegex } from "../src/nfa";
12+
13+
14+
const argParser = new ArgumentParser({
15+
version: VERSION,
16+
addHelp: true,
17+
description: "Regex Solidity Generator"
18+
});
19+
20+
21+
argParser.addArgument(
22+
['-n', '--name'],
23+
{
24+
help: "name for generated regex contract"
25+
}
26+
);
27+
28+
argParser.addArgument(
29+
"regex",
30+
{
31+
help: "regular expression to compile"
32+
}
33+
);
34+
35+
argParser.addArgument(
36+
["--sol", "--solidity"],
37+
{
38+
help: "write Solidity contract",
39+
dest: "outputs",
40+
action: "appendConst",
41+
constant: "solidity"
42+
}
43+
);
44+
45+
argParser.addArgument(
46+
["--dot", "--graphviz"],
47+
{
48+
help: "write DOT graph",
49+
dest: "outputs",
50+
action: "appendConst",
51+
constant: "graphviz"
52+
}
53+
);
54+
55+
argParser.addArgument(
56+
["--nfa", "-N"],
57+
{
58+
help: "generate output for NFA (only works with --dot)",
59+
dest: "nfa",
60+
action: "storeConst",
61+
constant: true,
62+
default: false
63+
}
64+
);
65+
66+
const args = argParser.parseArgs();
67+
68+
const nfa = nfaFromRegex(args.regex);
69+
70+
if (args.nfa) {
71+
for (const target of args.outputs) {
72+
if (target !== "graphviz") {
73+
console.error("Use of --nfa only works with --dot output");
74+
process.exit(1);
75+
}
76+
77+
const writer = new GraphvizNFAWriter();
78+
const output = writer.write(nfa, {
79+
name: args.name,
80+
regex: args.regex
81+
});
82+
83+
console.log(output.trim());
84+
}
85+
86+
process.exit(0);
87+
}
88+
89+
const dfa = dfaFromNFA(nfa);
90+
91+
const writers = {
92+
solidity: SolidityDFAWriter,
93+
graphviz: GraphvizDFAWriter,
94+
} as const;
95+
96+
args.outputs = args.outputs || ["solidity"];
97+
98+
for (const target of args.outputs) {
99+
const writer = new writers[target as keyof typeof writers]();
100+
101+
const output = writer.write(dfa, {
102+
name: args.name,
103+
regex: args.regex
104+
});
105+
106+
console.log(output.trim());
107+
}

0 commit comments

Comments
 (0)