Skip to content

decorate all global variable with @lazy #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assembly/char.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// @ts-ignore
// prettier-ignore
@lazy
export const enum Char {
None = -1,
HorizontalTab = 0x09,
Expand Down
24 changes: 20 additions & 4 deletions assembly/nfa/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ import {
import { Flags } from "../regexp";
import { Range } from "../util";

// @ts-ignore
// prettier-ignore
@lazy
const enum MatcherType {
Character,
CharacterRange,
CharacterSet,
CharacterClass,
}

let _flags: Flags;
// @ts-ignore
@lazy
let _flags: Flags;

export class Matcher {
constructor(readonly type: MatcherType) {}
Expand Down Expand Up @@ -93,9 +98,20 @@ export class CharacterMatcher extends Matcher {
}
}

const LOWERCASE_LETTERS = new Range(Char.a, Char.z);
const UPPERCASE_LETTERS = new Range(Char.A, Char.Z);
const UPPER_LOWER_OFFSET = Char.a - Char.A;
// @ts-ignore
// prettier-ignore
@lazy
const LOWERCASE_LETTERS = new Range(Char.a, Char.z);

// @ts-ignore
// prettier-ignore
@lazy
const UPPERCASE_LETTERS = new Range(Char.A, Char.Z);

// @ts-ignore
// prettier-ignore
@lazy
const UPPER_LOWER_OFFSET = Char.a - Char.A;

export class CharacterRangeMatcher extends Matcher {
private ranges: Range[];
Expand Down
8 changes: 7 additions & 1 deletion assembly/nfa/nfa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { Char } from "../char";
import { Matcher } from "./matcher";
import { Flags } from "../regexp";

// @ts-ignore
// prettier-ignore
@lazy
export enum MatchResult {
// a match has occurred - which is a signal to consume a character
Match,
Expand All @@ -24,7 +27,10 @@ export enum MatchResult {
Ignore,
}

let _stateId: u32 = 0;
// @ts-ignore
// prettier-ignore
@lazy
let _stateId: u32 = 0;

/* eslint @typescript-eslint/no-empty-function: ["error", { "allow": ["constructors", "methods"] }] */
export class State {
Expand Down
13 changes: 11 additions & 2 deletions assembly/parser/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Char } from "../char";
import { replaceAtIndex } from "../util";

// @ts-ignore
// prettier-ignore
@lazy
export const enum NodeType {
AST,
Assertion,
Expand All @@ -15,7 +18,10 @@ export const enum NodeType {
Group,
}

const emptyNodeArray = new Array<Node>();
// @ts-ignore
// prettier-ignore
@lazy
const emptyNodeArray = new Array<Node>();

export abstract class Node {
constructor(public type: NodeType) {}
Expand Down Expand Up @@ -210,7 +216,10 @@ export class AlternationNode extends Node {
}
}

let _id = 0;
// @ts-ignore
// prettier-ignore
@lazy
let _id = 0;

export class GroupNode extends Node {
constructor(
Expand Down
5 changes: 4 additions & 1 deletion assembly/parser/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export function walker(ast: AST, visitor: (node: NodeVisitor) => void): void {
// range quantifiers are implemented via 'expansion', which significantly
// increases the size of the AST. This imposes a hard limit to prevent
// memory-related issues
const QUANTIFIER_LIMIT = 1000;
// @ts-ignore
// prettier-ignore
@lazy
const QUANTIFIER_LIMIT = 1000;

function parentAsConcatNode(visitor: NodeVisitor): ConcatenationNode {
let concatNode: ConcatenationNode | null = null;
Expand Down
5 changes: 4 additions & 1 deletion assembly/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export class Match {
}
}

let gm = new Array<GroupStartMarkerState>();
// @ts-ignore
// prettier-ignore
@lazy
let gm = new Array<GroupStartMarkerState>();

export class Flags {
global: bool = false;
Expand Down