1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-05-28 08:41:30 +00:00

ecs: debug info

This commit is contained in:
Steven Hugg 2022-01-29 12:24:38 -06:00
parent 3f241bfcc2
commit 9b6f797451
3 changed files with 20 additions and 2 deletions

View File

@ -183,7 +183,13 @@ export class ECSCompiler extends Tokenizer {
}
parseCode(): string {
return this.expectTokenTypes([TokenType.CodeFragment]).str;
let tok = this.expectTokenTypes([TokenType.CodeFragment]);
let code = tok.str;
let lines = code.split('\n');
for (let i=0; i<lines.length; i++) {
lines[i] = ` .dbg line, "${this.path}", ${tok.$loc.line+i}\n` + lines[i];
}
return lines.join('\n');
}
parseScope() : EntityScope {
@ -263,6 +269,7 @@ export class ECSCompiler extends Tokenizer {
export() {
let src = new SourceFileExport();
src.debug_file(this.path);
this.exportToFile(src);
return src.toString();
}

View File

@ -220,6 +220,12 @@ export class SourceFileExport {
for (let l of s.split('\n'))
this.lines.push(l);
}
debug_file(path: string) {
this.lines.push(` .dbg file, "${path}", 0, 0`);
}
debug_line(path: string, line: number) {
this.lines.push(` .dbg line, "${path}", ${line}`);
}
toString() {
return this.lines.join('\n');
}

View File

@ -71,6 +71,7 @@ export class Tokenizer {
includeEOL = false;
errorOnCatchAll = false;
codeFragment : string | null = null;
codeFragmentStart : SourceLocation | null = null;
constructor() {
this.lineno = 0;
@ -110,9 +111,13 @@ export class Tokenizer {
switch (rule.type) {
case TokenType.CodeFragment:
if (this.codeFragment) {
this._pushToken({ str: this.codeFragment, type: rule.type, $loc: loc }); //TODO: merge start/end
let codeLoc = mergeLocs(this.codeFragmentStart, loc);
this._pushToken({ str: this.codeFragment, type: rule.type, $loc: codeLoc }); //TODO: merge start/end
this.codeFragmentStart = null;
this.codeFragment = null;
} else {
loc.line++;
this.codeFragmentStart = loc;
this.codeFragment = '';
return; // don't add any more tokens (TODO: check for trash?)
}