Skip to content

Commit 71debba

Browse files
committed
fix: locations
1 parent 29bbf38 commit 71debba

18 files changed

+121
-94
lines changed

packages/pgen/compile.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,13 @@ export const compile = (node: g.Grammar): t.File => {
2424
definedRules.add(rule.name);
2525
}
2626

27-
// const exports = t.returnStatement(t.objectExpression(
28-
// names.map(name => t.objectProperty(
29-
// t.identifier(name),
30-
// emitCall('compile', [
31-
// t.identifier(name),
32-
// t.arrowFunctionExpression([], t.identifier('space')),
33-
// ]),
34-
// false,
35-
// true,
36-
// ))
37-
// ));
38-
3927
return t.file(t.program([
4028
...imports,
4129
t.exportNamedDeclaration(t.tsModuleDeclaration(
4230
t.identifier(astGlobal),
4331
t.tsModuleBlock(ast),
4432
)),
4533
...stmts,
46-
// t.exportNamedDeclaration(t.variableDeclaration("const", [
47-
// t.variableDeclarator(t.identifier("getParser"), t.arrowFunctionExpression(
48-
// [withType(
49-
// t.identifier(primGlobal),
50-
// t.tsTypeReference(
51-
// t.tsQualifiedName(t.identifier(libGlobal), t.identifier('Algebra')),
52-
// )
53-
// )],
54-
// t.blockStatement([
55-
// ...stmts,
56-
// exports,
57-
// ]),
58-
// ))
59-
// ])),
6034
]));
6135
};
6236

packages/pgen/transform.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,3 @@ const transformSeq = ({ exprs }: g.Seq): Transform<Expr> => (ctx) => {
325325
e.push(Eps);
326326
return e.reduceRight((prev, expr) => Ap(expr, prev, 'r'));
327327
};
328-
329-
// const spaced = (node: Expr): Transform<Expr> => (ctx) => {
330-
// return Ap(node, Star(Call("space$noSkip", [])), 'l');
331-
// };

packages/runtime/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Context, createContext, getSuccess, isFailure, Parser } from "./runtime";
22

33
export { Parser, Located, alt, any, ap, app, compile, debug, eof, eps, field, left, lex, loc, lookNeg, lookPos, opt, plus, pure, ref, regex, right, rule, sat, seq, star, str, stry, terminal, where, withLoc } from './spaced';
4-
export { Loc, LocEmpty, LocRange } from './located';
4+
export * from './loc';
55

66
export type ParseResult<T> = ParseResultSuccess<T> | ParseResultError
77
export type ParseResultError = {

packages/runtime/lib/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Parser } from "./runtime";
22
export { Parser, Located, alt, any, ap, app, compile, debug, eof, eps, field, left, lex, loc, lookNeg, lookPos, opt, plus, pure, ref, regex, right, rule, sat, seq, star, str, stry, terminal, where, withLoc } from './spaced';
3-
export { Loc, LocEmpty, LocRange } from './located';
3+
export * from './loc';
44
export type ParseResult<T> = ParseResultSuccess<T> | ParseResultError;
55
export type ParseResultError = {
66
readonly $: "error";

packages/runtime/lib/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/runtime/lib/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
14+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15+
};
216
Object.defineProperty(exports, "__esModule", { value: true });
317
exports.parse = exports.withLoc = exports.where = exports.terminal = exports.stry = exports.str = exports.star = exports.seq = exports.sat = exports.rule = exports.right = exports.regex = exports.ref = exports.pure = exports.plus = exports.opt = exports.lookPos = exports.lookNeg = exports.loc = exports.lex = exports.left = exports.field = exports.eps = exports.eof = exports.debug = exports.compile = exports.app = exports.ap = exports.any = exports.alt = void 0;
418
const runtime_1 = require("./runtime");
@@ -32,6 +46,7 @@ Object.defineProperty(exports, "stry", { enumerable: true, get: function () { re
3246
Object.defineProperty(exports, "terminal", { enumerable: true, get: function () { return spaced_1.terminal; } });
3347
Object.defineProperty(exports, "where", { enumerable: true, get: function () { return spaced_1.where; } });
3448
Object.defineProperty(exports, "withLoc", { enumerable: true, get: function () { return spaced_1.withLoc; } });
49+
__exportStar(require("./loc"), exports);
3550
const parse = (grammar) => (text) => {
3651
const ctx = (0, runtime_1.createContext)(text);
3752
const result = grammar(ctx);

packages/runtime/lib/loc.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export type Loc = LocRange | LocEmpty;
2+
export type LocRange = {
3+
readonly $: 'range';
4+
readonly start: number;
5+
readonly end: number;
6+
};
7+
export declare const rangeLoc: (start: number, end: number) => LocRange;
8+
export type LocEmpty = {
9+
readonly $: 'empty';
10+
readonly at: number;
11+
};
12+
export declare const emptyLoc: (at: number) => LocEmpty;
13+
export declare const isEmptyLoc: (loc: Loc) => loc is LocEmpty;
14+
export declare const mergeLoc: (left: Loc, right: Loc) => Loc;
15+
//# sourceMappingURL=loc.d.ts.map

packages/runtime/lib/loc.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/runtime/lib/loc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.mergeLoc = exports.isEmptyLoc = exports.emptyLoc = exports.rangeLoc = void 0;
4+
const rangeLoc = (start, end) => {
5+
if (start === 32 && end === 32)
6+
debugger;
7+
return { $: 'range', start, end };
8+
};
9+
exports.rangeLoc = rangeLoc;
10+
const emptyLoc = (at) => ({ $: 'empty', at });
11+
exports.emptyLoc = emptyLoc;
12+
const isEmptyLoc = (loc) => loc.$ === 'empty';
13+
exports.isEmptyLoc = isEmptyLoc;
14+
const mergeLoc = (left, right) => {
15+
return (0, exports.isEmptyLoc)(left) ? right : (0, exports.isEmptyLoc)(right) ? left : (0, exports.rangeLoc)(left.start, right.end);
16+
};
17+
exports.mergeLoc = mergeLoc;

packages/runtime/lib/located.d.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import * as P from './runtime';
2-
export type Parser<T> = P.Parser<[T, Loc]>;
3-
export type Loc = LocRange | LocEmpty;
4-
export type LocRange = {
5-
readonly $: 'range';
6-
readonly start: number;
7-
readonly end: number;
8-
};
9-
export type LocEmpty = {
10-
readonly $: 'empty';
11-
readonly at: number;
12-
};
2+
import * as L from './loc';
3+
export type Parser<T> = P.Parser<readonly [T, L.Loc]>;
134
export declare const rule: <T>(child: Parser<T>) => Parser<T>;
145
export declare const pure: <const T>(t: T) => Parser<T>;
156
export declare const ap: <T, U>(left: Parser<(t: T) => U>, right: Parser<T>) => Parser<U>;
@@ -35,5 +26,5 @@ export declare const lookNeg: <T>(child: Parser<T>) => Parser<undefined>;
3526
export declare const eof: Parser<undefined>;
3627
export declare const debug: <T>(child: Parser<T>) => Parser<T>;
3728
export declare const where: Parser<number>;
38-
export declare const withLoc: <T>(child: Parser<T>) => Parser<[T, Loc]>;
29+
export declare const withLoc: <T>(child: Parser<T>) => Parser<[T, L.Loc]>;
3930
//# sourceMappingURL=located.d.ts.map

0 commit comments

Comments
 (0)