Skip to content
Merged
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
26 changes: 13 additions & 13 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import {
PATH_DELIMITER
} from "./common";

import {
Program
} from "./program";

import {
Tokenizer,
Token,
Expand All @@ -28,7 +24,8 @@ import {

import {
DiagnosticCode,
DiagnosticEmitter
DiagnosticEmitter,
DiagnosticMessage
} from "./diagnostics";

import {
Expand Down Expand Up @@ -95,8 +92,6 @@ import {
/** Parser interface. */
export class Parser extends DiagnosticEmitter {

/** Program being created. */
program: Program;
/** Source file names to be requested next. */
backlog: string[] = new Array();
/** Source file names already seen, that is processed or backlogged. */
Expand All @@ -109,11 +104,16 @@ export class Parser extends DiagnosticEmitter {
currentSource: Source;
/** Dependency map **/
dependees: Map<string, Source> = new Map();
/** An array of parsed sources. */
sources: Source[];

/** Constructs a new parser. */
constructor(program: Program) {
super(program.diagnostics);
this.program = program;
constructor(
diagnostics: DiagnosticMessage[] | null = null,
sources: Source[] | null = null
) {
super(diagnostics);
this.sources = sources ? sources : new Array<Source>();
}

/** Parses a file and adds its definitions to the program. */
Expand Down Expand Up @@ -145,12 +145,12 @@ export class Parser extends DiagnosticEmitter {
: SourceKind.LIBRARY
: SourceKind.USER
);
var program = this.program;
program.sources.push(source);

this.sources.push(source);
this.currentSource = source;

// tokenize and parse
var tn = new Tokenizer(source, program.diagnostics);
var tn = new Tokenizer(source, this.diagnostics);
tn.onComment = this.onComment;
var statements = source.statements;
while (!tn.skip(Token.ENDOFFILE)) {
Expand Down
2 changes: 1 addition & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export class Program extends DiagnosticEmitter {
var nativeFile = new File(this, nativeSource);
this.nativeFile = nativeFile;
this.filesByName.set(nativeFile.internalName, nativeFile);
this.parser = new Parser(this);
this.parser = new Parser(this.diagnostics, this.sources);
this.resolver = new Resolver(this);
}

Expand Down