Compiler test infrastructure
This commit is contained in:
parent
4843c76784
commit
644891ce76
|
@ -0,0 +1,7 @@
|
||||||
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
|
export default {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
};
|
|
@ -18,7 +18,9 @@
|
||||||
"rollup": "../../node_modules/.bin/rollup -c",
|
"rollup": "../../node_modules/.bin/rollup -c",
|
||||||
"rollup:watch": "../../node_modules/.bin/rollup -c -w",
|
"rollup:watch": "../../node_modules/.bin/rollup -c -w",
|
||||||
"clean": "rm -rf lib dist",
|
"clean": "rm -rf lib dist",
|
||||||
"veryclean": "yarn run clean && rm -rf node_modules"
|
"veryclean": "yarn run clean && rm -rf node_modules",
|
||||||
|
"test": "../../node_modules/.bin/jest",
|
||||||
|
"test:watch": "yarn test --watch"
|
||||||
},
|
},
|
||||||
"main": "dist/syndicate-compiler.js",
|
"main": "dist/syndicate-compiler.js",
|
||||||
"module": "lib/index.js",
|
"module": "lib/index.js",
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
|
|
||||||
Items, Pattern, Templates, Substitution, TokenType,
|
Items, Pattern, Templates, Substitution, TokenType,
|
||||||
SourceMap, CodeWriter, TemplateFunction, Token, SpanIndex, match, TokenBase, getRange, Pos,
|
SourceMap, CodeWriter, TemplateFunction, Token, SpanIndex, match, TokenBase, getRange, Pos,
|
||||||
} from '../syntax/index.js';
|
} from '../syntax/index';
|
||||||
import {
|
import {
|
||||||
SyndicateParser, SyndicateTypedParser,
|
SyndicateParser, SyndicateTypedParser,
|
||||||
Identifier,
|
Identifier,
|
||||||
|
@ -17,7 +17,7 @@ import {
|
||||||
|
|
||||||
compilePattern,
|
compilePattern,
|
||||||
SpawnStatement,
|
SpawnStatement,
|
||||||
} from './grammar.js';
|
} from './grammar';
|
||||||
|
|
||||||
export function stripShebang(items: Items): Items {
|
export function stripShebang(items: Items): Items {
|
||||||
if ((items.length > 0) &&
|
if ((items.length > 0) &&
|
||||||
|
|
|
@ -9,8 +9,8 @@ import {
|
||||||
scope, bind, seq, alt, upTo, atom, atomString, group,
|
scope, bind, seq, alt, upTo, atom, atomString, group,
|
||||||
repeat, option, withoutSpace, map, mapm, rest, discard,
|
repeat, option, withoutSpace, map, mapm, rest, discard,
|
||||||
value, succeed, fail, separatedOrTerminatedBy, not,
|
value, succeed, fail, separatedOrTerminatedBy, not,
|
||||||
} from '../syntax/index.js';
|
} from '../syntax/index';
|
||||||
import * as Matcher from '../syntax/matcher.js';
|
import * as Matcher from '../syntax/matcher';
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// AST types
|
// AST types
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
export * as Grammar from './grammar.js';
|
export * as Grammar from './grammar';
|
||||||
export * as Codegen from './codegen.js';
|
export * as Codegen from './codegen';
|
||||||
export { compile, CompileOptions } from './codegen.js';
|
export { compile, CompileOptions } from './codegen';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
export * as Syntax from './syntax/index.js';
|
export * as Syntax from './syntax/index';
|
||||||
export * from './compiler/index.js';
|
export * from './compiler/index';
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
import { Token, TokenType, Item, Items, isGroup } from './tokens.js';
|
import { Token, TokenType, Item, Items, isGroup } from './tokens';
|
||||||
import { Pos, startPos, advancePos } from './position.js';
|
import { Pos, startPos, advancePos } from './position';
|
||||||
import { vlqEncode } from './vlq.js';
|
import { vlqEncode } from './vlq';
|
||||||
import { SpanInfo } from './span.js';
|
import { SpanInfo } from './span';
|
||||||
|
|
||||||
export interface SourceMap {
|
export interface SourceMap {
|
||||||
version: 3;
|
version: 3;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
export * from './codewriter.js';
|
export * from './codewriter';
|
||||||
export * from './list.js';
|
export * from './list';
|
||||||
export * from './matcher.js';
|
export * from './matcher';
|
||||||
export * from './position.js';
|
export * from './position';
|
||||||
export * from './reader.js';
|
export * from './reader';
|
||||||
export * from './scanner.js';
|
export * from './scanner';
|
||||||
export * from './span.js';
|
export * from './span';
|
||||||
export * from './template.js';
|
export * from './template';
|
||||||
export * from './tokens.js';
|
export * from './tokens';
|
||||||
export * from './vlq.js';
|
export * from './vlq';
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
import {
|
import {
|
||||||
Token, TokenType, Items, Item,
|
Token, TokenType, Items, Item,
|
||||||
isGroup, isToken, isSpace, isTokenType,
|
isGroup, isToken, isSpace, isTokenType,
|
||||||
} from './tokens.js';
|
} from './tokens';
|
||||||
import { Pos, startPos } from './position.js';
|
import { Pos, startPos } from './position';
|
||||||
import { List, ArrayList, atEnd, notAtEnd } from './list.js';
|
import { List, ArrayList, atEnd, notAtEnd } from './list';
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// Patterns over Item
|
// Patterns over Item
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
import { TokenType, Token, Group, GroupInProgress, Item, Items, finishGroup } from './tokens.js';
|
import { TokenType, Token, Group, GroupInProgress, Item, Items, finishGroup } from './tokens';
|
||||||
import { Pos, startPos } from './position.js';
|
import { Pos, startPos } from './position';
|
||||||
import { Scanner, StringScanner } from './scanner.js';
|
import { Scanner, StringScanner } from './scanner';
|
||||||
|
|
||||||
function matchingParen(c: string): string | null {
|
function matchingParen(c: string): string | null {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
import { TokenType, Token, Item, GroupInProgress } from './tokens.js';
|
import { TokenType, Token, Item, GroupInProgress } from './tokens';
|
||||||
import { Pos, advancePos } from './position.js';
|
import { Pos, advancePos } from './position';
|
||||||
|
|
||||||
export abstract class Scanner implements IterableIterator<Token> {
|
export abstract class Scanner implements IterableIterator<Token> {
|
||||||
readonly pos: Pos;
|
readonly pos: Pos;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
import { Items } from './tokens.js';
|
import { Items } from './tokens';
|
||||||
import { Pos, startPos } from './position.js';
|
import { Pos, startPos } from './position';
|
||||||
import { laxRead, LaxReadOptions } from './reader.js';
|
import { laxRead, LaxReadOptions } from './reader';
|
||||||
import * as M from './matcher.js';
|
import * as M from './matcher';
|
||||||
|
|
||||||
const substPat = M.scope((o: { pos: Pos }) =>
|
const substPat = M.scope((o: { pos: Pos }) =>
|
||||||
M.seq(M.atom('$'),
|
M.seq(M.atom('$'),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/// SPDX-License-Identifier: GPL-3.0-or-later
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
import { Pos } from './position.js';
|
import { Pos } from './position';
|
||||||
|
|
||||||
export enum TokenType {
|
export enum TokenType {
|
||||||
SPACE,
|
SPACE,
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
/// SPDX-FileCopyrightText: Copyright © 2016-2024 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
|
import { is, preserves } from '@preserves/core';
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
namespace jest {
|
||||||
|
interface Matchers<R> {
|
||||||
|
is(expected: any): R;
|
||||||
|
toThrowFilter(f: (e: Error) => boolean): R;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect.extend({
|
||||||
|
is(actual, expected) {
|
||||||
|
return is(actual, expected)
|
||||||
|
? { message: () => preserves`expected ${actual} not to be Preserves.is to ${expected}`,
|
||||||
|
pass: true }
|
||||||
|
: { message: () => preserves`expected ${actual} to be Preserves.is to ${expected}`,
|
||||||
|
pass: false };
|
||||||
|
},
|
||||||
|
|
||||||
|
toThrowFilter(thunk, f) {
|
||||||
|
try {
|
||||||
|
thunk();
|
||||||
|
return { message: () => preserves`expected an exception`, pass: false };
|
||||||
|
} catch (e) {
|
||||||
|
if (f(e)) {
|
||||||
|
return { message: () => preserves`expected an exception not matching the filter`,
|
||||||
|
pass: true };
|
||||||
|
} else {
|
||||||
|
return { message: () => preserves`expected an exception matching the filter: ${(e as any)?.constructor?.name}`,
|
||||||
|
pass: false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue