Better errors!
This commit is contained in:
parent
c44f06268f
commit
9d1b079361
8 changed files with 305 additions and 132 deletions
41
src/main.ts
41
src/main.ts
|
|
@ -4,34 +4,45 @@ import { tokenize } from './lexer'
|
|||
import { Parser } from './parser'
|
||||
import { runApp } from './runtime';
|
||||
import { builtins } from './builtins';
|
||||
import { CGError } from './error';
|
||||
|
||||
import stdlibCode from './stdlib.cg?raw';
|
||||
import designTokensCode from './design-tokens.cg?raw';
|
||||
import uiComponentsCode from './ui-components.cg?raw';
|
||||
|
||||
import textInputCode from './textinput-test.cg?raw';
|
||||
import testCode from './test.cg?raw';
|
||||
import counterApp from './counter.cg?raw';
|
||||
// import testCode from './test.cg?raw';
|
||||
// import counterApp from './counter.cg?raw';
|
||||
|
||||
const canvas = document.createElement('canvas') as HTMLCanvasElement;
|
||||
document.body.appendChild(canvas);
|
||||
|
||||
const cgCode = stdlibCode + '\n' + designTokensCode + '\n' + uiComponentsCode + '\n' + textInputCode;
|
||||
|
||||
const tokens = tokenize(cgCode);
|
||||
const parser = new Parser(tokens);
|
||||
const ast = parser.parse();
|
||||
console.log(ast);
|
||||
try {
|
||||
const tokens = tokenize(cgCode);
|
||||
const parser = new Parser(tokens, cgCode);
|
||||
const ast = parser.parse();
|
||||
// console.log(ast);
|
||||
|
||||
const env: Env = new Map(Object.entries(builtins));
|
||||
const appRecord = evaluate(ast, env);
|
||||
console.log("appRecord", appRecord);
|
||||
const env: Env = new Map(Object.entries(builtins));
|
||||
const appRecord = evaluate(ast, env, cgCode);
|
||||
// console.log("appRecord", appRecord);
|
||||
|
||||
if (appRecord.kind !== 'record')
|
||||
throw new Error('Expected record');
|
||||
if (appRecord.kind !== 'record')
|
||||
throw new Error('Expected record');
|
||||
|
||||
const init = appRecord.fields.init;
|
||||
const update = appRecord.fields.update;
|
||||
const view = appRecord.fields.view;
|
||||
const init = appRecord.fields.init;
|
||||
const update = appRecord.fields.update;
|
||||
const view = appRecord.fields.view;
|
||||
|
||||
runApp({ init, update, view }, canvas);
|
||||
runApp({ init, update, view }, canvas, cgCode);
|
||||
} catch(error) {
|
||||
console.log('CAUGHT ERROR:', error);
|
||||
console.log('Is CGError??', error instanceof CGError);
|
||||
if (error instanceof CGError) {
|
||||
console.error(error.format());
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue