mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-22 14:33:51 +00:00
ecs: skip parsing demo if not in main file
This commit is contained in:
parent
75fb2a8e5c
commit
e7e5ea7847
@ -184,3 +184,8 @@ end
|
||||
ldy {{<index}}
|
||||
{{!SetHorizPos}}
|
||||
---
|
||||
|
||||
Slice PNGs into sprites
|
||||
Maybe output decoder text
|
||||
|
||||
Action priorities - before, after
|
||||
|
@ -22,10 +22,11 @@ export class ECSCompiler extends Tokenizer {
|
||||
|
||||
currentScope: EntityScope | null = null;
|
||||
currentContext: ActionContext | null = null;
|
||||
debuginfo = false;
|
||||
includeDebugInfo = false;
|
||||
|
||||
constructor(
|
||||
public readonly em: EntityManager) {
|
||||
public readonly em: EntityManager,
|
||||
public readonly isMainFile: boolean) {
|
||||
super();
|
||||
//this.includeEOL = true;
|
||||
this.setTokenRules([
|
||||
@ -71,8 +72,8 @@ export class ECSCompiler extends Tokenizer {
|
||||
let text = this.getImportFile && this.getImportFile(path);
|
||||
if (!text) this.compileError(`I can't find the import file "${path}".`);
|
||||
this.em.imported[path] = true;
|
||||
let comp = new ECSCompiler(this.em);
|
||||
comp.debuginfo = this.debuginfo; // TODO: clone compiler
|
||||
let comp = new ECSCompiler(this.em, false);
|
||||
comp.includeDebugInfo = this.includeDebugInfo; // TODO: clone compiler
|
||||
try {
|
||||
comp.parseFile(text, path);
|
||||
} catch (e) {
|
||||
@ -103,11 +104,15 @@ export class ECSCompiler extends Tokenizer {
|
||||
return this.importFile(path);
|
||||
}
|
||||
if (tok.str == 'demo') {
|
||||
let scope = this.parseScope();
|
||||
scope.isDemo = true;
|
||||
// TODO: make required
|
||||
if (this.peekToken().str == 'demo') this.expectToken('demo');
|
||||
return scope;
|
||||
if (this.isMainFile) {
|
||||
let scope = this.parseScope();
|
||||
scope.isDemo = true;
|
||||
this.expectToken('demo');
|
||||
return scope;
|
||||
} else {
|
||||
this.skipDemo(); // don't even parse it, just skip it
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (tok.str == 'comment') {
|
||||
this.expectTokenTypes([ECSTokenType.CodeFragment]);
|
||||
@ -116,6 +121,17 @@ export class ECSCompiler extends Tokenizer {
|
||||
this.compileError(`Unexpected top-level keyword: ${tok.str}`);
|
||||
}
|
||||
|
||||
skipDemo() {
|
||||
var tok;
|
||||
while ((tok = this.consumeToken()) && !this.isEOF()) {
|
||||
if (tok.str == 'end' && this.peekToken().str == 'demo') {
|
||||
this.consumeToken();
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new ECSError(`Expected "end demo" after a "demo" declaration.`);
|
||||
}
|
||||
|
||||
parseComponentDefinition(): ComponentType {
|
||||
let name = this.expectIdent().str;
|
||||
let fields = [];
|
||||
@ -387,7 +403,7 @@ export class ECSCompiler extends Tokenizer {
|
||||
let code = tok.str.substring(3, tok.str.length - 3);
|
||||
// TODO: add after parsing maybe?
|
||||
let lines = code.split('\n');
|
||||
if (this.debuginfo) this.addDebugInfo(lines, tok.$loc.line);
|
||||
if (this.includeDebugInfo) this.addDebugInfo(lines, tok.$loc.line);
|
||||
code = lines.join('\n');
|
||||
|
||||
let acomp = new ECSActionCompiler(context);
|
||||
|
@ -1149,6 +1149,11 @@ export class EntityScope implements SourceLocated {
|
||||
}
|
||||
}
|
||||
}
|
||||
*iterateChildScopes() {
|
||||
for (let scope of this.childScopes) {
|
||||
yield scope;
|
||||
}
|
||||
}
|
||||
entitiesMatching(atypes: EntityArchetype[]) {
|
||||
let result: Entity[] = [];
|
||||
for (let e of this.entities) {
|
||||
@ -1543,8 +1548,8 @@ export class EntityScope implements SourceLocated {
|
||||
let subcall = this.dialect.call(stats.labels[0]);
|
||||
for (let label of stats.labels) {
|
||||
// TODO: use dialect
|
||||
let startdelim = `;;; start action ${label}`
|
||||
let enddelim = `;;; end action ${label}`
|
||||
let startdelim = this.dialect.comment(`start action ${label}`);
|
||||
let enddelim = this.dialect.comment(`end action ${label}`);
|
||||
let istart = code.indexOf(startdelim);
|
||||
let iend = code.indexOf(enddelim, istart);
|
||||
if (istart >= 0 && iend > istart) {
|
||||
@ -1729,10 +1734,23 @@ export class EntityManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
*iterateScopes() {
|
||||
for (let scope of Object.values(this.topScopes)) {
|
||||
yield scope;
|
||||
scope.iterateChildScopes();
|
||||
}
|
||||
}
|
||||
getDebugTree() : {} {
|
||||
let scopes = this.topScopes;
|
||||
let components = this.components;
|
||||
let fields = this.name2cfpairs;
|
||||
let systems = this.systems;
|
||||
return { scopes, components, systems };
|
||||
let events = this.event2systems;
|
||||
let entities : {[key:string]:Entity} = {};
|
||||
for (let scope of Array.from(this.iterateScopes())) {
|
||||
for (let e of scope.entities)
|
||||
entities[e.name || '#'+e.id.toString()] = e;
|
||||
}
|
||||
return { scopes, components, fields, systems, events, entities };
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import { Dialect_CA65, EntityManager, SourceFileExport } from "../common/ecs/ecs
|
||||
|
||||
function testCompiler() {
|
||||
let em = new EntityManager(new Dialect_CA65()); // TODO
|
||||
let c = new ECSCompiler(em);
|
||||
let c = new ECSCompiler(em, true);
|
||||
try {
|
||||
c.parseFile(`
|
||||
// comment
|
||||
@ -93,7 +93,7 @@ describe('Compiler', function() {
|
||||
let dialect = new Dialect_CA65();
|
||||
let em = new EntityManager(dialect);
|
||||
em.mainPath = ecspath;
|
||||
let compiler = new ECSCompiler(em);
|
||||
let compiler = new ECSCompiler(em, true);
|
||||
compiler.getImportFile = (path: string) => {
|
||||
return readFileSync(testdir + path, 'utf-8');
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import { BuildStep, BuildStepResult, fixParamsWithDefines, gatherFiles, getWorkF
|
||||
|
||||
export function assembleECS(step: BuildStep): BuildStepResult {
|
||||
let em = new EntityManager(new Dialect_CA65()); // TODO
|
||||
let compiler = new ECSCompiler(em);
|
||||
let compiler = new ECSCompiler(em, true);
|
||||
compiler.getImportFile = (path: string) => {
|
||||
return getWorkFileAsString(path);
|
||||
}
|
||||
@ -17,7 +17,7 @@ export function assembleECS(step: BuildStep): BuildStepResult {
|
||||
let code = getWorkFileAsString(step.path);
|
||||
fixParamsWithDefines(step.path, step.params);
|
||||
try {
|
||||
compiler.debuginfo = true;
|
||||
compiler.includeDebugInfo = true;
|
||||
compiler.parseFile(code, step.path);
|
||||
let outtext = compiler.export().toString();
|
||||
putWorkFile(destpath, outtext);
|
||||
|
Loading…
Reference in New Issue
Block a user