Skip to content

chore: use erasableSyntaxOnly #78

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as frontend from 'llparse-frontend';

import source = frontend.source;
import { source } from 'llparse-frontend';

import { Compiler, ICompilerOptions, ICompilerResult } from './compiler';

Expand All @@ -12,6 +10,8 @@ export { source, ICompilerOptions, ICompilerResult };
* LLParse graph builder and compiler.
*/
export class LLParse extends source.Builder {
private readonly prefix: string;

/**
* The prefix controls the names of methods and state struct in generated
* public C headers:
Expand All @@ -28,10 +28,11 @@ export class LLParse extends source.Builder {
*
* @param prefix Prefix to be used when generating public API.
*/
constructor(private readonly prefix: string = 'llparse') {
constructor(prefix: string = 'llparse') {
super();
this.prefix = prefix;
}

/**
* Compile LLParse graph to the C code and C headers
*
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/header-builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as frontend from 'llparse-frontend';
import source = frontend.source;
import { source } from 'llparse-frontend';

export interface IHeaderBuilderOptions {
readonly prefix: string;
Expand Down
12 changes: 8 additions & 4 deletions src/compiler/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as debugAPI from 'debug';
import * as frontend from 'llparse-frontend';

import source = frontend.source;
import { source } from 'llparse-frontend';

import * as cImpl from '../implementation/c';
import { HeaderBuilder } from './header-builder';
Expand Down Expand Up @@ -50,8 +49,13 @@ export interface ICompilerResult {
}

export class Compiler {
constructor(public readonly prefix: string,
public readonly options: ICompilerOptions) {
public readonly prefix: string;
public readonly options: ICompilerOptions;

constructor(prefix: string,
options: ICompilerOptions) {
this.prefix = prefix;
this.options = options;
}

public compile(root: source.node.Node,
Expand Down
4 changes: 3 additions & 1 deletion src/implementation/c/code/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { Compilation } from '../compilation';

export abstract class Code<T extends frontend.code.Code> {
protected cachedDecl: string | undefined;
public readonly ref: T;

constructor(public readonly ref: T) {
constructor(ref: T) {
this.ref = ref;
}

public abstract build(ctx: Compilation, out: string[]): void;
Expand Down
14 changes: 11 additions & 3 deletions src/implementation/c/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ export class Compilation {
Map<string, MatchSequence> = new Map();
private readonly resumptionTargets: Set<string> = new Set();

constructor(public readonly prefix: string,
private readonly properties: ReadonlyArray<ICompilationProperty>,
public readonly prefix: string;
private readonly properties: ReadonlyArray<ICompilationProperty>;
private readonly options: ICompilationOptions;

constructor(prefix: string,
properties: ReadonlyArray<ICompilationProperty>,
resumptionTargets: ReadonlySet<WrappedNode>,
private readonly options: ICompilationOptions) {
options: ICompilationOptions) {
this.prefix = prefix;
this.properties = properties;
this.options = options;

for (const node of resumptionTargets) {
this.resumptionTargets.add(STATE_PREFIX + node.ref.id.name);
}
Expand Down
5 changes: 4 additions & 1 deletion src/implementation/c/helpers/match-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { Compilation } from '../compilation';
type TransformWrap = Transform<frontend.transform.Transform>;

export class MatchSequence {
constructor(private readonly transform: TransformWrap) {
private readonly transform: TransformWrap;

constructor(transform: TransformWrap) {
this.transform = transform;
}

public static buildGlobals(out: string[]): void {
Expand Down
5 changes: 4 additions & 1 deletion src/implementation/c/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ export interface ICPublicOptions {
}

export class CCompiler {
public readonly options: ICCompilerOptions;

constructor(container: frontend.Container,
public readonly options: ICCompilerOptions) {
options: ICCompilerOptions) {
this.options = options;
container.add(CONTAINER_KEY, { code, node, transform });
}

Expand Down
4 changes: 3 additions & 1 deletion src/implementation/c/node/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export interface INodeEdge {
export abstract class Node<T extends frontend.node.Node> {
protected cachedDecl: string | undefined;
protected privCompilation: Compilation | undefined;
public readonly ref: T;

constructor(public readonly ref: T) {
constructor(ref: T) {
this.ref = ref;
}

public build(compilation: Compilation): string {
Expand Down
5 changes: 4 additions & 1 deletion src/implementation/c/transform/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import * as frontend from 'llparse-frontend';
import { Compilation } from '../compilation';

export abstract class Transform<T extends frontend.transform.Transform> {
constructor(public readonly ref: T) {
public readonly ref: T;

constructor(ref: T) {
this.ref = ref;
}

public abstract build(ctx: Compilation, value: string): string;
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"pretty": true,
"sourceMap": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true
"noUnusedLocals": true,
"erasableSyntaxOnly": true
},
"include": [
"src/**/*.ts"
Expand Down
Loading