@@ -13,10 +13,6 @@ import {
13
13
PATH_DELIMITER
14
14
} from "./common" ;
15
15
16
- import {
17
- Program
18
- } from "./program" ;
19
-
20
16
import {
21
17
Tokenizer ,
22
18
Token ,
@@ -28,7 +24,8 @@ import {
28
24
29
25
import {
30
26
DiagnosticCode ,
31
- DiagnosticEmitter
27
+ DiagnosticEmitter ,
28
+ DiagnosticMessage
32
29
} from "./diagnostics" ;
33
30
34
31
import {
@@ -95,8 +92,6 @@ import {
95
92
/** Parser interface. */
96
93
export class Parser extends DiagnosticEmitter {
97
94
98
- /** Program being created. */
99
- program : Program ;
100
95
/** Source file names to be requested next. */
101
96
backlog : string [ ] = new Array ( ) ;
102
97
/** Source file names already seen, that is processed or backlogged. */
@@ -109,11 +104,16 @@ export class Parser extends DiagnosticEmitter {
109
104
currentSource : Source ;
110
105
/** Dependency map **/
111
106
dependees : Map < string , Source > = new Map ( ) ;
107
+ /** An array of parsed sources. */
108
+ sources : Source [ ] ;
112
109
113
110
/** Constructs a new parser. */
114
- constructor ( program : Program ) {
115
- super ( program . diagnostics ) ;
116
- this . program = program ;
111
+ constructor (
112
+ diagnostics : DiagnosticMessage [ ] | null = null ,
113
+ sources : Source [ ] | null = null
114
+ ) {
115
+ super ( diagnostics ) ;
116
+ this . sources = sources ? sources : new Array < Source > ( ) ;
117
117
}
118
118
119
119
/** Parses a file and adds its definitions to the program. */
@@ -145,12 +145,12 @@ export class Parser extends DiagnosticEmitter {
145
145
: SourceKind . LIBRARY
146
146
: SourceKind . USER
147
147
) ;
148
- var program = this . program ;
149
- program . sources . push ( source ) ;
148
+
149
+ this . sources . push ( source ) ;
150
150
this . currentSource = source ;
151
151
152
152
// tokenize and parse
153
- var tn = new Tokenizer ( source , program . diagnostics ) ;
153
+ var tn = new Tokenizer ( source , this . diagnostics ) ;
154
154
tn . onComment = this . onComment ;
155
155
var statements = source . statements ;
156
156
while ( ! tn . skip ( Token . ENDOFFILE ) ) {
0 commit comments