mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-29 14:51:17 +00:00
ecs: import
This commit is contained in:
parent
83238f30f1
commit
dcb11a7080
@ -13,10 +13,11 @@ export enum ECSTokenType {
|
|||||||
|
|
||||||
export class ECSCompiler extends Tokenizer {
|
export class ECSCompiler extends Tokenizer {
|
||||||
|
|
||||||
em = new EntityManager(new Dialect_CA65()); // TODO
|
|
||||||
currentScope: EntityScope | null = null;
|
currentScope: EntityScope | null = null;
|
||||||
|
|
||||||
constructor() {
|
constructor(
|
||||||
|
public readonly em: EntityManager)
|
||||||
|
{
|
||||||
super();
|
super();
|
||||||
//this.includeEOL = true;
|
//this.includeEOL = true;
|
||||||
this.setTokenRules([
|
this.setTokenRules([
|
||||||
@ -53,9 +54,17 @@ export class ECSCompiler extends Tokenizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getImportFile: (path: string) => string;
|
||||||
|
|
||||||
|
importFile(path: string) {
|
||||||
|
let text = this.getImportFile && this.getImportFile(path);
|
||||||
|
if (!text) this.compileError(`I can't find the import file "${path}".`);
|
||||||
|
new ECSCompiler(this.em).parseFile(path, text);
|
||||||
|
}
|
||||||
|
|
||||||
parseTopLevel() {
|
parseTopLevel() {
|
||||||
//this.skipBlankLines();
|
//this.skipBlankLines();
|
||||||
let tok = this.expectTokens(['component', 'system', 'scope', 'resource', 'comment']);
|
let tok = this.expectTokens(['component', 'system', 'scope', 'resource', 'import', 'demo', 'comment']);
|
||||||
if (tok.str == 'component') {
|
if (tok.str == 'component') {
|
||||||
return this.em.defineComponent(this.parseComponentDefinition());
|
return this.em.defineComponent(this.parseComponentDefinition());
|
||||||
}
|
}
|
||||||
@ -68,6 +77,16 @@ export class ECSCompiler extends Tokenizer {
|
|||||||
if (tok.str == 'resource') {
|
if (tok.str == 'resource') {
|
||||||
return this.em.defineSystem(this.parseResource());
|
return this.em.defineSystem(this.parseResource());
|
||||||
}
|
}
|
||||||
|
if (tok.str == 'import') {
|
||||||
|
let tok = this.expectTokenTypes([ECSTokenType.QuotedString]);
|
||||||
|
let path = tok.str.substring(1, tok.str.length-1);
|
||||||
|
return this.importFile(path);
|
||||||
|
}
|
||||||
|
if (tok.str == 'demo') {
|
||||||
|
let scope = this.parseScope();
|
||||||
|
scope.isDemo = true;
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
if (tok.str == 'comment') {
|
if (tok.str == 'comment') {
|
||||||
this.expectTokenTypes([ECSTokenType.CodeFragment]);
|
this.expectTokenTypes([ECSTokenType.CodeFragment]);
|
||||||
return;
|
return;
|
||||||
@ -253,6 +272,7 @@ export class ECSCompiler extends Tokenizer {
|
|||||||
parseScope() : EntityScope {
|
parseScope() : EntityScope {
|
||||||
let name = this.expectIdent().str;
|
let name = this.expectIdent().str;
|
||||||
let scope = this.em.newScope(name, this.currentScope || undefined);
|
let scope = this.em.newScope(name, this.currentScope || undefined);
|
||||||
|
scope.filePath = this.path;
|
||||||
this.currentScope = scope;
|
this.currentScope = scope;
|
||||||
let cmd;
|
let cmd;
|
||||||
while ((cmd = this.expectTokens(['using', 'entity', 'scope', 'comment', 'end']).str) != 'end') {
|
while ((cmd = this.expectTokens(['using', 'entity', 'scope', 'comment', 'end']).str) != 'end') {
|
||||||
|
@ -56,7 +56,6 @@ crazy idea -- full expansion, then relooper
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import { throws } from "assert";
|
|
||||||
import { SourceLocated, SourceLocation } from "../workertypes";
|
import { SourceLocated, SourceLocation } from "../workertypes";
|
||||||
|
|
||||||
export class ECSError extends Error {
|
export class ECSError extends Error {
|
||||||
@ -730,6 +729,8 @@ export class EntityScope implements SourceLocated {
|
|||||||
maxTempBytes = 0;
|
maxTempBytes = 0;
|
||||||
resources = new Set<string>();
|
resources = new Set<string>();
|
||||||
state = new ActionState();
|
state = new ActionState();
|
||||||
|
isDemo = false;
|
||||||
|
filePath = '';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly em: EntityManager,
|
public readonly em: EntityManager,
|
||||||
@ -1139,7 +1140,10 @@ export class EntityManager {
|
|||||||
exportToFile(file: SourceFileExport) {
|
exportToFile(file: SourceFileExport) {
|
||||||
file.text(this.dialect.HEADER); // TODO
|
file.text(this.dialect.HEADER); // TODO
|
||||||
for (let scope of Object.values(this.topScopes)) {
|
for (let scope of Object.values(this.topScopes)) {
|
||||||
scope.dump(file);
|
// TODO: demos
|
||||||
|
if (!scope.isDemo) {
|
||||||
|
scope.dump(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
file.text(this.dialect.FOOTER); // TODO
|
file.text(this.dialect.FOOTER); // TODO
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ export class Tokenizer {
|
|||||||
expectTokens(strlist: string[], msg?: string): Token {
|
expectTokens(strlist: string[], msg?: string): Token {
|
||||||
let tok = this.consumeToken();
|
let tok = this.consumeToken();
|
||||||
let tokstr = tok.str;
|
let tokstr = tok.str;
|
||||||
if (strlist.indexOf(tokstr) < 0) {
|
if (!strlist.includes(tokstr)) {
|
||||||
this.compileError(msg || `There should be a ${strlist.map((s) => `"${s}"`).join(' or ')} here, not "${tokstr}".`);
|
this.compileError(msg || `There should be a ${strlist.map((s) => `"${s}"`).join(' or ')} here, not "${tokstr}".`);
|
||||||
}
|
}
|
||||||
return tok;
|
return tok;
|
||||||
|
@ -150,6 +150,7 @@ export class CodeProject {
|
|||||||
files.push(dir + '/' + fn);
|
files.push(dir + '/' + fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: use tool id to parse files, not platform
|
||||||
parseIncludeDependencies(text:string):string[] {
|
parseIncludeDependencies(text:string):string[] {
|
||||||
let files = [];
|
let files = [];
|
||||||
let m;
|
let m;
|
||||||
@ -199,13 +200,18 @@ export class CodeProject {
|
|||||||
this.pushAllFiles(files, m[2]);
|
this.pushAllFiles(files, m[2]);
|
||||||
}
|
}
|
||||||
// for wiz
|
// for wiz
|
||||||
let re5 = /^\s*(import|embed)\s+"(.+?)";/gmi;
|
let re5 = /^\s*(import|embed)\s*"(.+?)";/gmi;
|
||||||
while (m = re5.exec(text)) {
|
while (m = re5.exec(text)) {
|
||||||
if (m[1] == 'import')
|
if (m[1] == 'import')
|
||||||
this.pushAllFiles(files, m[2] + ".wiz");
|
this.pushAllFiles(files, m[2] + ".wiz");
|
||||||
else
|
else
|
||||||
this.pushAllFiles(files, m[2]);
|
this.pushAllFiles(files, m[2]);
|
||||||
}
|
}
|
||||||
|
// for ecs
|
||||||
|
let re6 = /^\s*(import)\s*"(.+?)"/gmi;
|
||||||
|
while (m = re6.exec(text)) {
|
||||||
|
this.pushAllFiles(files, m[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,8 @@ function testECS() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testCompiler() {
|
function testCompiler() {
|
||||||
let c = new ECSCompiler();
|
let em = new EntityManager(new Dialect_CA65()); // TODO
|
||||||
|
let c = new ECSCompiler(em);
|
||||||
try {
|
try {
|
||||||
c.parseFile(`
|
c.parseFile(`
|
||||||
// comment
|
// comment
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
import { ECSCompiler } from "../../common/ecs/compiler";
|
import { ECSCompiler } from "../../common/ecs/compiler";
|
||||||
import { ECSError } from "../../common/ecs/ecs";
|
import { Dialect_CA65, ECSError, EntityManager } from "../../common/ecs/ecs";
|
||||||
import { CompileError } from "../../common/tokenizer";
|
import { CompileError } from "../../common/tokenizer";
|
||||||
import { CodeListingMap } from "../../common/workertypes";
|
import { CodeListingMap } from "../../common/workertypes";
|
||||||
import { BuildStep, BuildStepResult, gatherFiles, getWorkFileAsString, putWorkFile, staleFiles } from "../workermain";
|
import { BuildStep, BuildStepResult, gatherFiles, getWorkFileAsString, putWorkFile, staleFiles } from "../workermain";
|
||||||
|
|
||||||
export function assembleECS(step: BuildStep): BuildStepResult {
|
export function assembleECS(step: BuildStep): BuildStepResult {
|
||||||
let compiler = new ECSCompiler();
|
let em = new EntityManager(new Dialect_CA65()); // TODO
|
||||||
|
let compiler = new ECSCompiler(em);
|
||||||
|
compiler.getImportFile = (path: string) => {
|
||||||
|
return getWorkFileAsString(path);
|
||||||
|
}
|
||||||
gatherFiles(step, { mainFilePath: "main.ecs" });
|
gatherFiles(step, { mainFilePath: "main.ecs" });
|
||||||
var destpath = step.prefix + '.ca65';
|
var destpath = step.prefix + '.ca65';
|
||||||
if (staleFiles(step, [destpath])) {
|
if (staleFiles(step, [destpath])) {
|
||||||
|
Loading…
Reference in New Issue
Block a user