Skip to content

Commit 34b676d

Browse files
committed
fix: codestyle
1 parent 9745007 commit 34b676d

16 files changed

+24
-58
lines changed

Diff for: packages/pgen/compile.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ const compileTerminal = (node: g.Terminal): Compiler<ExprWithType> => ctx => {
220220
return ewt(emitCall('str', [wrapped]), t.tsLiteralType(t.stringLiteral(value)));
221221
};
222222

223-
const compileClass = ({ insensitive, negated, seqs }: g.Class): Compiler<ExprWithType> => ctx => {
223+
const compileClass = ({ negated, seqs }: g.Class): Compiler<ExprWithType> => ctx => {
224224
const prefix = negated ? "^" : "";
225225
const children = seqs.map(seq => compileSeq(seq));
226226
const body = children.map(child => child.expr).join('');
@@ -234,7 +234,6 @@ const compileClass = ({ insensitive, negated, seqs }: g.Class): Compiler<ExprWit
234234
negated
235235
? emitCall('negateExps', [expectables])
236236
: expectables,
237-
// t.booleanLiteral(insensitive)
238237
],
239238
[t.tsUnionType(types)]
240239
),

Diff for: packages/pgen/index.ts

-16
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,6 @@ const main = async () => {
1919

2020
const code = await fs.readFile(source, 'utf-8');
2121

22-
// const ident = (
23-
// (
24-
// $.regex<string | "_">("a-z_", [$.ExpRange("a", "z"), $.ExpString("_")]),
25-
// // $.right(
26-
// // $.regex<string | "_">("a-z_", [$.ExpRange("a", "z"), $.ExpString("_")]),
27-
// // $.right(
28-
// // $.star(
29-
// // $.regex<string | string | "_">(
30-
// // "a-z0-9_", [$.ExpRange("a", "z"), $.ExpRange("0", "9"), $.ExpString("_")]
31-
// // )
32-
// // ),
33-
// // $.eps
34-
// // )
35-
// // )
36-
// )
37-
// );
3822
const ast = $.parse($.compile(G.Grammar, G.space))(code);
3923
if (ast.$ === 'error') {
4024
console.error(ast.error);

Diff for: packages/pgen/runtime.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ export const sat = (cond: (c: string) => boolean, message: string): Parser<strin
173173
return ctx.assert(ctx.p < ctx.l && cond(c), message, 1, c);
174174
};
175175

176-
export const regex = <K = string>(s: string, insensitive: boolean = false): Parser<K> => {
177-
const r = new RegExp(`^[${s}]$`, insensitive ? "i" : undefined);
176+
export const regex = <K = string>(s: string): Parser<K> => {
177+
const r = new RegExp(`^[${s}]$`);
178178
return sat(c => r.test(c), `[${s}]`) as Parser<K>;
179179
};
180180

Diff for: packages/pgen/transform.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export type Optional = { readonly $: 'Optional', readonly expr: Expr }
6464
export const Optional = (expr: Expr): Optional => ({ $: "Optional", expr });
6565
export type Call = { readonly $: "Call", readonly name: string, readonly params: readonly Expr[] }
6666
export const Call = (name: string, params: readonly Expr[]): Call => ({ $: "Call", name, params });
67-
export type Class = { readonly $: "Class", readonly seqs: readonly (Group | ClassChar | SpecialClass | Escape)[], readonly negated: boolean, readonly insensitive: boolean }
68-
export const Class = (seqs: readonly (Group | ClassChar | SpecialClass | Escape)[], negated: boolean, insensitive: boolean): Class => ({ $: "Class", insensitive, negated, seqs });
67+
export type Class = { readonly $: "Class", readonly seqs: readonly (Group | ClassChar | SpecialClass | Escape)[], readonly negated: boolean }
68+
export const Class = (seqs: readonly (Group | ClassChar | SpecialClass | Escape)[], negated: boolean): Class => ({ $: "Class", negated, seqs });
6969
export type Group = { readonly $: "Group", readonly from: ClassChar | SpecialClass | Escape, readonly to: ClassChar | SpecialClass | Escape }
7070
export const Group = (from: ClassChar | SpecialClass | Escape, to: ClassChar | SpecialClass | Escape): Group => ({ $: "Group", from, to });
7171
export type ClassChar = { readonly $: "ClassChar", readonly value: string }
@@ -89,11 +89,6 @@ export const Long = (value: string): Long => ({ $: "Long", value });
8989
export type Ascii = { readonly $: "Ascii", readonly value: string }
9090
export const Ascii = (value: string): Ascii => ({ $: "Ascii", value });
9191

92-
type SkipType =
93-
| 'no-space' // no space rule
94-
| 'skip-space' // has space rule, compile with skipping
95-
| 'keep-space' // has space rule, compile without skipping
96-
9792
type Context = {
9893
formals: Set<string>;
9994
}
@@ -205,7 +200,7 @@ const transformAny = (_node: g.Any): Transform<Expr> => () => {
205200
};
206201

207202
const transformClass = ({ negated, seqs }: g.Class): Transform<Expr> => () => {
208-
return Class(seqs, negated === '^', false);
203+
return Class(seqs, negated === '^');
209204
};
210205

211206
const transformTerminal = ({ value }: g.Terminal): Transform<Expr> => () => {

Diff for: packages/runtime/lib/located.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type Parser<T> = P.Parser<readonly [T, L.Loc]>;
55
export declare const any: Parser<string>;
66
export declare const range: (from: string, to: string) => Parser<string>;
77
export declare const str: <K extends string>(s: K) => Parser<K>;
8-
export declare const regex: <K = string>(s: string, exps: Expectable[], insensitive?: boolean) => Parser<K>;
8+
export declare const regex: <K = string>(s: string, exps: Expectable[]) => Parser<K>;
99
export declare const app: <A, B>(child: Parser<A>, f: (a: A) => B) => Parser<B>;
1010
export declare const seq: <T, U>(left: Parser<T>, right: Parser<U>) => Parser<[T, U]>;
1111
export declare const alt: <T, U>(left: Parser<T>, right: Parser<U>) => Parser<T | U>;

Diff for: packages/runtime/lib/located.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

Diff for: packages/runtime/lib/located.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,10 @@ const str = (s) => {
5656
return terminal(P.str(s));
5757
};
5858
exports.str = str;
59-
const regex = (s, exps, insensitive = false) => {
60-
return terminal(P.regex(s, exps, insensitive));
59+
const regex = (s, exps) => {
60+
return terminal(P.regex(s, exps));
6161
};
6262
exports.regex = regex;
63-
// export const pure = <const T>(t: T): Parser<T> => ctx => {
64-
// return P.app(P.pure(t), t => [t, L.emptyLoc(ctx.p)] as const)(ctx);
65-
// };
6663
const app = (child, f) => {
6764
return P.app(child, ([v, l]) => [f(v), l]);
6865
};

Diff for: packages/runtime/lib/runtime.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type GetResult<T> = T extends Parser<infer T> ? T : never;
2525
export declare const terminal: <T>(kind: E.Expectable, child: (ctx: Context) => Result<T>) => Parser<T>;
2626
export declare const any: Parser<string>;
2727
export declare const range: (from: string, to: string) => Parser<string>;
28-
export declare const regex: <K = string>(s: string, exps: E.Expectable[], insensitive?: boolean) => Parser<K>;
28+
export declare const regex: <K = string>(s: string, exps: E.Expectable[]) => Parser<K>;
2929
export declare const str: <K extends string>(s: K) => Parser<K>;
3030
export declare const app: <A, B>(child: Parser<A>, f: (a: A) => B) => Parser<B>;
3131
export declare const seq: <T, U>(left: Parser<T>, right: Parser<U>) => Parser<[T, U]>;

Diff for: packages/runtime/lib/runtime.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

Diff for: packages/runtime/lib/runtime.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ const range = (from, to) => (0, exports.terminal)(E.ExpRange(from, to), ctx => {
7777
}
7878
});
7979
exports.range = range;
80-
const regex = (s, exps, insensitive = false) => {
81-
const r = new RegExp(`^[${s}]$`, insensitive ? "i" : undefined);
80+
const regex = (s, exps) => {
81+
const r = new RegExp(`^[${s}]$`);
8282
return ctx => {
8383
const at = ctx.p;
8484
const c = ctx.s[at];
@@ -103,7 +103,6 @@ const str = (s) => (0, exports.terminal)(E.ExpString(s), ctx => {
103103
}
104104
});
105105
exports.str = str;
106-
// export const pure = <const T>(t: T): Parser<T> => () => success(t);
107106
const app = (child, f) => ctx => {
108107
const r = child(ctx);
109108
return {

Diff for: packages/runtime/lib/spaced.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export declare const lift2: <T, U, V>(f: (p: L.Parser<T>, q: L.Parser<U>) => L.P
1010
export declare const any: Parser<string>;
1111
export declare const str: <K extends string>(s: K) => Parser<K>;
1212
export declare const range: (from: string, to: string) => Parser<string>;
13-
export declare const regex: <K = string>(s: string, exps: Expectable[], insensitive?: boolean) => Parser<K>;
13+
export declare const regex: <K = string>(s: string, exps: Expectable[]) => Parser<K>;
1414
export declare const lex: <T>(child: Parser<T>) => Parser<T>;
1515
export declare const pure: <const T>(t: T) => Parser<T>;
1616
export declare const app: <A, B>(child: Parser<A>, f: (a: A) => B) => Parser<B>;

Diff for: packages/runtime/lib/spaced.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

Diff for: packages/runtime/lib/spaced.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ const range = (from, to) => {
5858
return (0, exports.terminal)(L.range(from, to));
5959
};
6060
exports.range = range;
61-
const regex = (s, exps, insensitive = false) => {
62-
return (0, exports.terminal)(L.regex(s, exps, insensitive));
61+
const regex = (s, exps) => {
62+
return (0, exports.terminal)(L.regex(s, exps));
6363
};
6464
exports.regex = regex;
6565
const lex = (child) => {

0 commit comments

Comments
 (0)